the Compartmented Robust Posix C++ Unit Test system

EXPECT_REALTIME_TIMEOUT_MS(ms)

A modifier which states a minimum duration of the test function run to pass.

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

The parameter to EXPECT_REALTIME_TIMEOUT_MS(ms) is the minimum duration in milliseconds.

If the test finishes earlier it fails. If the test duration is longer the test process is killed.

[Note]Note
EXPECT_REALTIME_TIMEOUT_MS(ms) cannot be combined with DEADLINE_REALTIME_MS(n).
[Tip]Tip
Combine EXPECT_REALTIME_TIMEOUT_MS(ms) with DEADLINE_CPU_MS(n) to verify that the test goes to sleep.

Example: The test program

     #include <crpcut.hpp>
     
     extern "C"
     {
     #include <signal.h>
     }
     
     TEST(fail_too_quick, EXPECT_REALTIME_TIMEOUT_MS(100))
     {
     }
     
     TEST(pass_busy_wait, EXPECT_REALTIME_TIMEOUT_MS(100))
     {
       for (;;)
         ;
     }
     
     TEST(fail_busy_wait, EXPECT_REALTIME_TIMEOUT_MS(100), DEADLINE_CPU_MS(3))
     {
       for (;;)
         ;
     }
     
     TEST(pass_sleep, EXPECT_REALTIME_TIMEOUT_MS(100), DEADLINE_CPU_MS(3))
     {
       sleep(1);
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

reports 2 failed tests:


     FAILED: fail_too_quick
     phase="running"  --------------------------------------------------------------
     Unexpectedly survived
     Expected 100ms realtime timeout
     -------------------------------------------------------------------------------
     ===============================================================================
     FAILED: fail_busy_wait
     phase="running"  --------------------------------------------------------------
     Test consumed 97ms CPU-time
     Limit was 3ms
     -------------------------------------------------------------------------------
     ===============================================================================
     Total 4 test cases selected
     UNTESTED : 0
     PASSED   : 2
     FAILED   : 2