From 88eefaced14bee4bffb7f1dd1c5a2aa02bc97101 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 30 Nov 2009 16:31:28 -0500 Subject: CTest: Test process tree kill on timeout We extend the CTestTestTimeout test to check that when a test times out its children (grandchildren of ctest) are killed. Instead of running the timeout executable directly, we run it through a cmake script that redirects the timeout executable output to a file. A second test later runs and verifies that the timeout executable was unable to complete and write data to the log file. Only if the first inner test times out and the second inner test passes (log is empty) does the CTestTestTimeout test pass. --- Tests/CMakeLists.txt | 3 ++- Tests/CTestTestTimeout/CMakeLists.txt | 16 ++++++++++++++-- Tests/CTestTestTimeout/check.cmake | 9 +++++++++ Tests/CTestTestTimeout/timeout.c | 3 +++ Tests/CTestTestTimeout/timeout.cmake | 6 ++++++ 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 Tests/CTestTestTimeout/check.cmake create mode 100644 Tests/CTestTestTimeout/timeout.cmake diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 3fe02b2..7d2d28d 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1231,11 +1231,12 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=CVS -P ${CMake_SOURCE_DIR}/Utilities/Rel "${CMake_BINARY_DIR}/Tests/CTestTestTimeout/test.cmake" @ONLY ESCAPE_QUOTES) ADD_TEST(CTestTestTimeout ${CMAKE_CTEST_COMMAND} + -C "\${CTEST_CONFIGURATION_TYPE}" -S "${CMake_BINARY_DIR}/Tests/CTestTestTimeout/test.cmake" -V --output-log "${CMake_BINARY_DIR}/Tests/CTestTestTimeout/testOutput.log" ) SET_TESTS_PROPERTIES(CTestTestTimeout PROPERTIES - PASS_REGULAR_EXPRESSION "\\*\\*\\*Timeout") + PASS_REGULAR_EXPRESSION "TestTimeout *\\.+ *\\*\\*\\*Timeout.*CheckChild *\\.+ *Passed") CONFIGURE_FILE( "${CMake_SOURCE_DIR}/Tests/CTestTestRunScript/test.cmake.in" diff --git a/Tests/CTestTestTimeout/CMakeLists.txt b/Tests/CTestTestTimeout/CMakeLists.txt index 15942c8..ed7f175 100644 --- a/Tests/CTestTestTimeout/CMakeLists.txt +++ b/Tests/CTestTestTimeout/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 2.8) PROJECT(CTestTestTimeout) SET(DART_ROOT "" CACHE STRING "" FORCE) @@ -12,7 +12,19 @@ ADD_EXECUTABLE (Timeout timeout.c) ENABLE_TESTING () -ADD_TEST (TestTimeout Timeout) +ADD_TEST(NAME TestTimeout + COMMAND ${CMAKE_COMMAND} -D Timeout=$ + -D Log=${CMAKE_CURRENT_BINARY_DIR}/timeout.log + -P ${CMAKE_CURRENT_SOURCE_DIR}/timeout.cmake + ) SET_TESTS_PROPERTIES(TestTimeout PROPERTIES TIMEOUT 1) +ADD_TEST(NAME CheckChild + COMMAND ${CMAKE_COMMAND} -D Timeout=$ + -D Log=${CMAKE_CURRENT_BINARY_DIR}/timeout.log + -P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake + ) +SET_TESTS_PROPERTIES(CheckChild PROPERTIES DEPENDS TestTimeout) + + INCLUDE (CTest) 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/timeout.c b/Tests/CTestTestTimeout/timeout.c index 559b6a5..ba91bc0 100644 --- a/Tests/CTestTestTimeout/timeout.c +++ b/Tests/CTestTestTimeout/timeout.c @@ -4,6 +4,8 @@ # include #endif +#include + int main(void) { #if defined(_WIN32) @@ -11,5 +13,6 @@ int main(void) #else sleep(5); #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}) -- cgit v0.12