5

I am specifying a test in my CMakeLists.txt which runs an executable and is supposed to look for a specific output (the PASS_REGULAR_EXPRESSION) to determine success.

Since the binary doesn't terminate itself, I would also like to terminate the executable after some TIMEOUT.

The test should pass if my PASS_REGULAR_EXPRESSION occurs before the TIMEOUT, otherwise it should fail.

My CMakeLists.txt looks lie:

add_test(NAME sometest COMMAND my_binary)
set_tests_properties(sometest PROPERTIES 
                     PASS_REGULAR_EXPRESSION "All systems go[.]"
                     TIMEOUT 10) 

Unfortunately, having a TIMEOUT always marks the test as failed. Is it possible to specify a non-failing timeout?

Felix
  • 2,064
  • 3
  • 21
  • 31
  • I'm trying to find a solution to the same problem. This usecase doesn't seem to be supported by ctest. – danba Jun 11 '18 at 07:29

1 Answers1

0

I was just looking for a solution of the similar problem, and I found it on the CMake mailing list:

CMakeLists.txt:

add_test(NAME mytest 
         COMMAND ${CMAKE_COMMAND} -DMYEXE=${PATH_TO_MYEXE} -DARG_TIMEOUT -P ${CMAKE_CURRENT_LIST_DIR}/ExecuteTest.cmake)

ExecuteTest.cmake:

execute_process(COMMAND ${PATH_TO_MYEXE}
                TIMEOUT ${ARG_TIMEOUT}
                OUTPUT_VARIABLE output)

if(NOT output MATCHES "^my_desired_regex$")
  message(FATAL_ERROR "myexe did not produce desired output")
endif()
Bartosz Charuza
  • 491
  • 1
  • 7