diff options
author | Brad King <brad.king@kitware.com> | 2014-05-23 13:47:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-05-23 14:30:39 (GMT) |
commit | 9afcecaf32acb4333b33d46522f98457bfa8856d (patch) | |
tree | c27da3ad5fcafddaf930e517b05c5c392e1e92af | |
parent | 8ae05b420e513252d1fd68dc6085d8dd92f3e624 (diff) | |
download | CMake-9afcecaf32acb4333b33d46522f98457bfa8856d.zip CMake-9afcecaf32acb4333b33d46522f98457bfa8856d.tar.gz CMake-9afcecaf32acb4333b33d46522f98457bfa8856d.tar.bz2 |
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.
-rw-r--r-- | Tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/CMakeLists.txt | 12 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/check.cmake | 9 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/sleep.c | 21 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/test.cmake.in | 13 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/timeout.c | 18 | ||||
-rw-r--r-- | Tests/CTestTestTimeout/timeout.cmake | 2 |
7 files changed, 40 insertions, 37 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 5014ef3..8d2b7fc 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 476d0a5..2e3bd6a 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=$<TARGET_FILE:Timeout> + COMMAND ${CMAKE_COMMAND} -D Sleep=$<TARGET_FILE: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=$<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) +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 b16f2aa..0000000 --- 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 0000000..33ce307 --- /dev/null +++ b/Tests/CTestTestTimeout/sleep.c @@ -0,0 +1,21 @@ +#if defined(_WIN32) +# include <windows.h> +#else +# include <unistd.h> +#endif + +#include <stdio.h> + +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 4178849..68c74d8 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 370ab22..0000000 --- a/Tests/CTestTestTimeout/timeout.c +++ /dev/null @@ -1,18 +0,0 @@ -#if defined(_WIN32) -# include <windows.h> -#else -# include <unistd.h> -#endif - -#include <stdio.h> - -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 198cc97..0989b65 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}) |