Timeouts
Ensuring your program runs fast
Some times, programs may cause an infinite loop or be extremely slow. This would cause CST to get stuck on a specific test, so what if we want to avoid that? Well, CST offers a solution, timeouts.
Timeouts can be specified either project-wide (Default timeout) or test only. By default, CST has a timeout value of 0. A timeout of 0 is a special value, it means no timeout will be enforced, so the test is allowed to take infinite time.
Default timeout
A default timeout for all tests can be specified with the -timeout flag. Let's imagine you named the executable for the test run "test_run". Then we could do this:
./test_run -timeout=10This will make the default timeout 10 milliseconds. So, by default, if any test takes more than 10 milliseconds, it will time out and fail.
Overriding the default timeout
Individual tests may override the default timeout. This is useful if you have a specific test that is expected to take more or less time than the default. Here is an example
#include "cst.h"
TEST("Example", "Timeout test", 1) {
while (true)
continue;
}Of course, that's an infinite loop. This test will timeout after 1 millisecond, no matter the default value specified with the -timeout flag.
Last updated
Was this helpful?