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

@@ -102,15 +102,15 @@ std::string UnitTest::print() {
i << " \"param\": \"" << this->param << "\"" << std::endl;
i << " \"output\": \"" << this->output << "\"" << std::endl;
i << "}" << std::endl;
if (this->ret != this->obtained) {
if (this->ret != this->result.ret) {
i << "Expecting: \"" << this->ret << "\" - returned: \"";
i << this->obtained << "\"" << std::endl;
i << this->result.ret << "\"" << std::endl;
}
if (this->output != this->obtainedOutput) {
if (this->output != this->result.output) {
i << "Expecting: \"";
i << modsecurity::utils::string::toHexIfNeeded(this->output);
i << "\" - returned: \"";
i << modsecurity::utils::string::toHexIfNeeded(this->obtainedOutput);
i << modsecurity::utils::string::toHexIfNeeded(this->result.output);
i << "\"";
i << std::endl;
}