From 9afcecaf32acb4333b33d46522f98457bfa8856d Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 23 May 2014 09:47:44 -0400 Subject: [PATCH] Tests: Try to make CTestTestTimeout more robust Write to the timeout test log file before sleeping and flush to be sure it is created. Move the check that the after-sleep line is not written out to the ctest script. Rename the CheckChild test to TestSleep since it no longer checks. Do not try to read the log file if it does not exist. --- Tests/CMakeLists.txt | 2 +- Tests/CTestTestTimeout/CMakeLists.txt | 12 ++++-------- Tests/CTestTestTimeout/check.cmake | 9 --------- Tests/CTestTestTimeout/sleep.c | 21 +++++++++++++++++++++ Tests/CTestTestTimeout/test.cmake.in | 13 +++++++++++++ Tests/CTestTestTimeout/timeout.c | 18 ------------------ Tests/CTestTestTimeout/timeout.cmake | 2 +- 7 files changed, 40 insertions(+), 37 deletions(-) delete mode 100644 Tests/CTestTestTimeout/check.cmake create mode 100644 Tests/CTestTestTimeout/sleep.c delete mode 100644 Tests/CTestTestTimeout/timeout.c diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 5014ef332..8d2b7fc9d 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2394,7 +2394,7 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release --output-log "${CMake_BINARY_DIR}/Tests/CTestTestTimeout/testOutput.log" ) set_tests_properties(CTestTestTimeout PROPERTIES - PASS_REGULAR_EXPRESSION "TestTimeout *\\.+ *\\*\\*\\*Timeout.*CheckChild *\\.+ *Passed") + PASS_REGULAR_EXPRESSION "TestTimeout *\\.+ *\\*\\*\\*Timeout.*TestSleep *\\.+ *Passed.*timeout correctly killed child") add_test( NAME CTestTestRerunFailed diff --git a/Tests/CTestTestTimeout/CMakeLists.txt b/Tests/CTestTestTimeout/CMakeLists.txt index 476d0a5e0..2e3bd6ad4 100644 --- a/Tests/CTestTestTimeout/CMakeLists.txt +++ b/Tests/CTestTestTimeout/CMakeLists.txt @@ -11,18 +11,14 @@ if(NOT TIMEOUT) endif() add_definitions(-DTIMEOUT=${TIMEOUT}) -add_executable (Timeout timeout.c) +add_executable (Sleep sleep.c) add_test(NAME TestTimeout - COMMAND ${CMAKE_COMMAND} -D Timeout=$ + COMMAND ${CMAKE_COMMAND} -D Sleep=$ -D Log=${CMAKE_CURRENT_BINARY_DIR}/timeout.log -P ${CMAKE_CURRENT_SOURCE_DIR}/timeout.cmake ) set_tests_properties(TestTimeout PROPERTIES TIMEOUT ${TIMEOUT}) -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) +add_test(NAME TestSleep COMMAND Sleep) +set_tests_properties(TestSleep PROPERTIES DEPENDS TestTimeout) diff --git a/Tests/CTestTestTimeout/check.cmake b/Tests/CTestTestTimeout/check.cmake deleted file mode 100644 index b16f2aab9..000000000 --- a/Tests/CTestTestTimeout/check.cmake +++ /dev/null @@ -1,9 +0,0 @@ -# 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/sleep.c b/Tests/CTestTestTimeout/sleep.c new file mode 100644 index 000000000..33ce30772 --- /dev/null +++ b/Tests/CTestTestTimeout/sleep.c @@ -0,0 +1,21 @@ +#if defined(_WIN32) +# include +#else +# include +#endif + +#include + +int main(void) +{ + fprintf(stderr, "before sleep\n"); + fflush(stderr); /* should not be needed, but just in case */ +#if defined(_WIN32) + Sleep((TIMEOUT+4)*1000); +#else + sleep((TIMEOUT+4)); +#endif + fprintf(stderr, "after sleep\n"); + fflush(stderr); /* should not be needed, but just in case */ + return 0; +} diff --git a/Tests/CTestTestTimeout/test.cmake.in b/Tests/CTestTestTimeout/test.cmake.in index 4178849bb..68c74d855 100644 --- a/Tests/CTestTestTimeout/test.cmake.in +++ b/Tests/CTestTestTimeout/test.cmake.in @@ -24,3 +24,16 @@ CTEST_START(Experimental) CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) + +set(log ${CTEST_BINARY_DIRECTORY}/timeout.log) +if(EXISTS "${log}") + # Verify that the timeout test did not finish sleeping. + file(STRINGS "${log}" after_sleep REGEX "after sleep") + if(after_sleep) + message(FATAL_ERROR "Log indicates timeout did not kill child.") + else() + message("Log indicates timeout correctly killed child.") + endif() +else() + message(FATAL_ERROR "Log does not exist:\n ${log}") +endif() diff --git a/Tests/CTestTestTimeout/timeout.c b/Tests/CTestTestTimeout/timeout.c deleted file mode 100644 index 370ab22ed..000000000 --- a/Tests/CTestTestTimeout/timeout.c +++ /dev/null @@ -1,18 +0,0 @@ -#if defined(_WIN32) -# include -#else -# include -#endif - -#include - -int main(void) -{ -#if defined(_WIN32) - Sleep((TIMEOUT+4)*1000); -#else - sleep((TIMEOUT+4)); -#endif - printf("timeout process finished sleeping!\n"); - return -1; -} diff --git a/Tests/CTestTestTimeout/timeout.cmake b/Tests/CTestTestTimeout/timeout.cmake index 198cc9713..0989b65df 100644 --- a/Tests/CTestTestTimeout/timeout.cmake +++ b/Tests/CTestTestTimeout/timeout.cmake @@ -3,4 +3,4 @@ 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}) +execute_process(COMMAND ${Sleep} ERROR_FILE ${Log})