the Compartmented Robust Posix C++ Unit Test system | hosted by |
---|
A test modifier to set the maximum CPU-time (in milliseconds) a test is allowed before it is considered failed. If the CPU-time consumed is vastly more, the test process is killed.
Used in: The modifier list of a test definition. See
TEST(name, ...)
![]() | Note |
---|---|
The CPU-time consumption is enforced using
setrlimit() with RLIMIT_CPU . If
set it to something else inside the test, crpcut may be unable
to enforce the limit. |
![]() | Note |
---|---|
The time measured is the running of the test function only.
Construction and destruction time are excluded (see
TEST(name, ...) for information
about fixtures.) |
Example: The test program
#include <crpcut.hpp> extern "C" { #include "unistd.h" } TEST(test_killed, DEADLINE_CPU_MS(2)) { for (;;) ; } TEST(test_succeeds_long_wait, DEADLINE_CPU_MS(2)) { usleep(50000); // realtime passes, not cpu-time since process is inactive } int main(int argc, char *argv[]) { return crpcut::run(argc, argv); }
reports one failed test:
FAILED: test_killed /tmp/crpcutY0TOSY/test_killed is not empty!! phase="running" -------------------------------------------------------------- Died with core dump ------------------------------------------------------------------------------- =============================================================================== Files remain under /tmp/crpcutY0TOSY Total 2 test cases selected UNTESTED : 0 PASSED : 1 FAILED : 1
See also
DEADLINE_REALTIME_MS(n)
for a deadline in real-time rather than CPU-time. Both can be
combined in the modifier list for the same
TEST(name, ...)
.