diff options
Diffstat (limited to 'Tests/CTestTestTimeout')
-rw-r--r-- | Tests/CTestTestTimeout/CMakeLists.txt | 34 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/check.cmake | 9 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/test.cmake.in | 6 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/timeout.c | 7 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/timeout.cmake | 6 |
5 files changed, 43 insertions, 19 deletions
diff --git a/Tests/CTestTestTimeout/CMakeLists.txt b/Tests/CTestTestTimeout/CMakeLists.txt index 15942c8..0fd1ceb 100644 --- a/Tests/CTestTestTimeout/CMakeLists.txt +++ b/Tests/CTestTestTimeout/CMakeLists.txt @@ -1,18 +1,28 @@ -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 2.8) PROJECT(CTestTestTimeout) +INCLUDE(CTest) -SET(DART_ROOT "" CACHE STRING "" FORCE) -ENABLE_TESTING() -INCLUDE (${CMAKE_ROOT}/Modules/Dart.cmake) - -GET_FILENAME_COMPONENT(CTEST_COMMAND "${CMAKE_COMMAND}" PATH) -SET(CTEST_COMMAND "${CTEST_COMMAND}/ctest") +IF(NOT TIMEOUT) + IF(CYGWIN) + SET(TIMEOUT 4) # Cygwin CMake sometimes takes > 1 second to load! + ELSE() + SET(TIMEOUT 1) + ENDIF() +ENDIF() +ADD_DEFINITIONS(-DTIMEOUT=${TIMEOUT}) ADD_EXECUTABLE (Timeout timeout.c) -ENABLE_TESTING () - -ADD_TEST (TestTimeout Timeout) -SET_TESTS_PROPERTIES(TestTimeout PROPERTIES TIMEOUT 1) +ADD_TEST(NAME TestTimeout + COMMAND ${CMAKE_COMMAND} -D Timeout=$<TARGET_FILE:Timeout> + -D Log=${CMAKE_CURRENT_BINARY_DIR}/timeout.log + -P ${CMAKE_CURRENT_SOURCE_DIR}/timeout.cmake + ) +SET_TESTS_PROPERTIES(TestTimeout PROPERTIES TIMEOUT ${TIMEOUT}) -INCLUDE (CTest) +ADD_TEST(NAME CheckChild + COMMAND ${CMAKE_COMMAND} -D Timeout=$<TARGET_FILE:Timeout> + -D Log=${CMAKE_CURRENT_BINARY_DIR}/timeout.log + -P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake + ) +SET_TESTS_PROPERTIES(CheckChild PROPERTIES DEPENDS TestTimeout) diff --git a/Tests/CTestTestTimeout/check.cmake b/Tests/CTestTestTimeout/check.cmake new file mode 100644 index 0000000..b16f2aa --- /dev/null +++ b/Tests/CTestTestTimeout/check.cmake @@ -0,0 +1,9 @@ +# Block just as long as timeout.cmake would if it were not killed. +execute_process(COMMAND ${Timeout}) + +# Verify that the log is empty, which indicates that the grandchild +# was killed before it finished sleeping. +file(READ "${Log}" LOG) +if(NOT "${LOG}" STREQUAL "") + message(FATAL_ERROR "${LOG}") +endif() diff --git a/Tests/CTestTestTimeout/test.cmake.in b/Tests/CTestTestTimeout/test.cmake.in index 4582801..6ed11a4 100644 --- a/Tests/CTestTestTimeout/test.cmake.in +++ b/Tests/CTestTestTimeout/test.cmake.in @@ -8,8 +8,6 @@ SET(CTEST_BUILD_NAME "CTestTest-@BUILDNAME@-Timeout") SET(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTestTimeout") SET(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestTestTimeout") SET(CTEST_CVS_COMMAND "@CVSCOMMAND@") -SET(CMAKE_TEST_MAKEPROGRAM "@CMAKE_TEST_MAKEPROGRAM@") -SET(MAKECOMMAND "@MAKECOMMAND@") SET(CTEST_CMAKE_GENERATOR "@CMAKE_TEST_GENERATOR@") SET(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}") SET(CTEST_MEMORYCHECK_COMMAND "@MEMORYCHECK_COMMAND@") @@ -21,9 +19,7 @@ SET(CTEST_NOTES_FILES "${CTEST_SCRIPT_DIRECTORY}/${CTEST_SCRIP #CTEST_EMPTY_BINARY_DIRECTORY(${CTEST_BINARY_DIRECTORY}) FILE(WRITE "${CTEST_BINARY_DIRECTORY}/CMakeCache.txt" " -CMAKE_TEST_GENERATOR:STRING=@CMAKE_TEST_GENERATOR@ -CMAKE_TEST_MAKEPROGRAM:FILEPATH=@CMAKE_TEST_MAKEPROGRAM@ -MAKECOMMAND:STRING=@MAKECOMMAND@ +TIMEOUT:STRING=@CTestTestTimeout_TIME@ ") CTEST_START(Experimental) diff --git a/Tests/CTestTestTimeout/timeout.c b/Tests/CTestTestTimeout/timeout.c index 559b6a5..370ab22 100644 --- a/Tests/CTestTestTimeout/timeout.c +++ b/Tests/CTestTestTimeout/timeout.c @@ -4,12 +4,15 @@ # include <unistd.h> #endif +#include <stdio.h> + int main(void) { #if defined(_WIN32) - Sleep(5000); + Sleep((TIMEOUT+4)*1000); #else - sleep(5); + sleep((TIMEOUT+4)); #endif + printf("timeout process finished sleeping!\n"); return -1; } diff --git a/Tests/CTestTestTimeout/timeout.cmake b/Tests/CTestTestTimeout/timeout.cmake new file mode 100644 index 0000000..198cc97 --- /dev/null +++ b/Tests/CTestTestTimeout/timeout.cmake @@ -0,0 +1,6 @@ +# Remove the log file. +file(REMOVE ${Log}) + +# Run a child that sleeps longer than the timout of this test. +# Log its output so check.cmake can verify it dies. +execute_process(COMMAND ${Timeout} OUTPUT_FILE ${Log}) |