the Compartmented Robust Posix C++ Unit Test system

FIXTURE_DESTRUCTION_DEADLINE_REALTIME_MS(ms)

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

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

The parameter to FIXTURE_DESTRUCTION_DEADLINE_REALTIME_MS(ms) is the maximum number of milliseconds real time that destruction of the fixtures for the test are allowed to consume. If the destructors 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 destruction_sleeper
     {
       ~destruction_sleeper() { usleep(us); }
     };
     
     TEST(fail_long_sleep, destruction_sleeper<2000000>)
     {
     }
     
     TEST(pass_long_sleep, destruction_sleeper<2000000>,
          FIXTURE_DESTRUCTION_DEADLINE_REALTIME_MS(3000))
     {
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

reports one failed test:


     FAILED!: fail_long_sleep
     phase="destroying"  -----------------------------------------------------------
     samples/fixture_destruction_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.