the Compartmented Robust Posix C++ Unit Test system

FIXTURE_CONSTRUCTION_DEADLINE_REALTIME_MS(ms)

Change the default timeout for fixture construction from 1s the specified number of milliseconds.

Used in: The modifier list of a test. See TEST(name, ...)

The parameter to FIXTURE_CONSTRUCTION_DEADLINE_REALTIME_MS(ms) is the maximum number of milliseconds real time that construction of the fixtures for the test are allowed to consume. If the constructors require more time than that to finish, the test process is killed and the test failed.

Example: The test program

     
     #include <crpcut.hpp>
     extern "C"
     {
     #include "unistd.h"
     }
     
     template <unsigned long us>
     struct construction_sleeper
     {
       construction_sleeper() { usleep(us); }
     };
     
     TEST(fail_long_sleep, construction_sleeper<2000000>)
     {
     }
     
     TEST(pass_long_sleep, construction_sleeper<2000000>,
          FIXTURE_CONSTRUCTION_DEADLINE_REALTIME_MS(3000))
     {
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

reports one failed test:


     FAILED!: fail_long_sleep
     phase="creating"  -------------------------------------------------------------
     samples/fixture_construction_timeout.cpp:40
     Timed out - killed
     Expected normal exit
     -------------------------------------------------------------------------------
     ===============================================================================
     2 test cases selected
     
                    Sum   Critical   Non-critical
     PASSED   :       1          1              0
     FAILED   :       1          1              0

[Note]Note
It is possible to extend the timeout limit using the command line parameter --timeout-multiplier=factor, which can be useful when running the test program with time consuming tools like valgrind.
[Note]Note
It is also possible to temporarily disable the deadline with the -t / --disable-timeouts command line flag.