the Compartmented Robust Posix C++ Unit Test system

DEADLINE_REALTIME_MS(n)

A test modifier to set the maximum real-time (in milliseconds) a test is allowed before it is considered failed. If the real-time consumed is vastly more, the test process is killed.

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

[Note]Note
The time measured is the running of the test function only. Construction and destruction time for fixtures are excluded (see TEST(name, ...) for information about fixtures.

By default, all tests have a read-time deadline of 2 seconds, to catch accidental infinite loops. Should your test require more, you can set it higher.

Example: The test program

     
     #include <crpcut.hpp>
     extern "C"
     {
     #include "unistd.h"
     }
     
     TEST(test_killed, DEADLINE_REALTIME_MS(2))
     {
       for (;;)
         ;
     }
     
     TEST(slight_overdraw, DEADLINE_REALTIME_MS(2))
     {
       usleep(5000);
     }
     
     TEST(quick_function, DEADLINE_CPU_MS(2))
     {
       usleep(1000);
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

reports two failed test:


     FAILED: test_killed
     phase="running"  --------------------------------------------------------------
     Timed out - killed
     -------------------------------------------------------------------------------
     ===============================================================================
     FAILED: slight_overdraw
     phase="destroying"  -----------------------------------------------------------
     Realtime timeout 2ms exceeded.
       Actual time to completion was 6ms
     -------------------------------------------------------------------------------
     ===============================================================================
     Total 3 test cases selected
     UNTESTED : 0
     PASSED   : 1
     FAILED   : 2

See also DEADLINE_CPU_MS(n) for a deadline in CPU-time rather than real-time. Both can be combined in the modifier list for the same TEST(name, ...).