Added support to run unit tests in a multithreaded context

- This is controlled by specifying the 'mtstress' argument when running
  `unit_test`.
- The goal is to detect if the operator/transformation  fails in this
  context.
- In this mode, the test will be executed 5'000 times in 50 threads
  concurrently.
- Allocation & initialization of the operator/transformation is
  performed once in the main thread, while the evaluation is executed in
  the threads.
  - This is consistent with the library's support for multithreading,
    where initialization and loading of rules is expected to run once.
    See issue #3215.
This commit is contained in:
Eduardo Arias
2024-08-09 06:54:35 -07:00
parent 7bdc3c825c
commit ee5f95eb04
5 changed files with 165 additions and 69 deletions

View File

@@ -34,12 +34,13 @@ template <class T> class ModSecurityTest :
ModSecurityTest()
: m_test_number(0),
m_automake_output(false),
m_count_all(false) { }
m_count_all(false),
m_test_multithreaded(false) { }
std::string header();
void cmd_options(int, char **);
std::pair<std::string, std::vector<T *>>* load_tests();
std::pair<std::string, std::vector<T *>>* load_tests(const std::string &path);
void load_tests();
void load_tests(const std::string &path);
bool load_test_json(const std::string &file);
std::string target;
@@ -48,6 +49,7 @@ template <class T> class ModSecurityTest :
int m_test_number;
bool m_automake_output;
bool m_count_all;
bool m_test_multithreaded;
};
} // namespace modsecurity_test