| the Compartmented Robust Posix C++ Unit Test system | hosted by |
|---|
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 |
|---|---|
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. |
![]() | Note |
|---|---|
DEADLINE_REALTIME_MS(ms) cannot be
used together with
EXPECT_REALTIME_TIMEOUT_MS(ms).
|
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="post_mortem" ----------------------------------------------------------
Timed out - killed
Expected normal exit
-------------------------------------------------------------------------------
===============================================================================
FAILED: slight_overdraw
phase="destroying" -----------------------------------------------------------
Realtime timeout 2ms exceeded.
Actual time to completion was 9ms
-------------------------------------------------------------------------------
===============================================================================
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, ...).
![]() | Note |
|---|---|
It is possible to temporarily disable the deadline with the
-t / --disable-timeouts
command line flag.
|