24

My CMakeLists.txt includes the lines

include(CTest)
enable_testing()
set(CTEST_TEST_TIMEOUT 3)
add_test(...)

ctest works, but ignores my attempt to set the timeout. Rather, it runs with the default timeout of 1500.

How to change the default timeout? How is CTEST_TEST_TIMEOUT meant to be used?

Joachim W
  • 7,290
  • 5
  • 31
  • 59

1 Answers1

38

CTEST_TEST_TIMEOUT is for use within the CTest script, not a CMakeLists.txt file. You can control the timeout in CMake for individual tests with the TIMEOUT test property, but there isn't a CMake variable that sets the global timeout default. The following sets the timeout to 30 seconds for just the sometest test:

add_test(sometest ...)
set_tests_properties(sometest PROPERTIES TIMEOUT 30) 

You can, however, override the default timeout when you invoke ctest using the --timeout option. E.g. to run the tests with the global timeout default set to 120 seconds:

ctest --timeout 120

A timeout specified in CMake for an individual test still takes precedence over the globally set default timeout, even when the --timeout option is used.

Craig Scott
  • 9,238
  • 5
  • 56
  • 85
  • "You can control the timeout in CMake for individual tests with the TIMEOUT test property" - how would I do this? – Joachim W Jul 10 '17 at 21:51
  • 1
    Is there a global setting for `CMakeLists.txt` files? Just like many other properties have global defaults, e.g `CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS` and `WINDOWS_EXPORT_ALL_SYMBOLS`. – kuga May 31 '22 at 16:06
  • There's nothing you can put directly in a `CMakeLists.txt` file to control it. The `CTEST_TEST_TIMEOUT` variable can be put in a CTest dashboard script, but that's as close as you can get currently. – Craig Scott May 31 '22 at 22:22