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, ...)
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" --------------------------------------------------------------
samples/deadline_realtime.cpp:34
Timed out - killed
Expected normal exit
-------------------------------------------------------------------------------
===============================================================================
FAILED!: slight_overdraw
phase="destroying" -----------------------------------------------------------
samples/deadline_realtime.cpp:40
Realtime timeout 2ms exceeded.
Actual time to completion was 5ms
-------------------------------------------------------------------------------
===============================================================================
3 test cases selected
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 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.
|