| the Compartmented Robust Posix C++ Unit Test system |
|
|---|
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 |
|---|---|
EXPECT_REALTIME_TIMEOUT_MS(ms) cannot be
combined with
DEADLINE_REALTIME_MS(n).
|
![]() | 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>
# include <unistd.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" --------------------------------------------------------------
samples/expect_realtime_timeout.cpp:35
Unexpectedly survived
Expected 100ms realtime timeout
-------------------------------------------------------------------------------
===============================================================================
FAILED!: fail_busy_wait
phase="running" --------------------------------------------------------------
samples/expect_realtime_timeout.cpp:45
Test consumed 102ms CPU-time
Limit was 3ms
-------------------------------------------------------------------------------
===============================================================================
4 test cases selected
Sum Critical Non-critical
PASSED : 2 2 0
FAILED : 2 2 0
![]() | 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 |
|---|---|
It is also possible to temporarily disable the expectation with the
-t / --disable-timeouts
command line flag.
|