the Compartmented Robust Posix C++ Unit Test system |
|
---|
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 longer, 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.
For deadlines on construction and destruction time for fixtures,
see FIXTURE_CONSTRUCTION_DEADLINE_REALTIME_MS(ms) and
FIXTURE_DESTRUCTION_DEADLINE_REALTIME_MS(ms) .
See also 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="running" -------------------------------------------------------------- Timed out - killed Expected normal exit ------------------------------------------------------------------------------- =============================================================================== FAILED!: slight_overdraw phase="destroying" ----------------------------------------------------------- Realtime timeout ms exceeded. Actual time to completion was 9ms ------------------------------------------------------------------------------- =============================================================================== 3 test cases selected Total : Sum Critical Non-critical PASSED : 1 1 0 FAILED : 2 2 0
![]() | Note |
---|---|
When the time consumed is longer than allowed, but not long
long enough to get the test process killed, the reported phase is
destroying .
|
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.
|