summaryrefslogtreecommitdiff
path: root/Tests/CTestTestTimeout
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-05-23 09:47:44 -0400
committerBrad King <brad.king@kitware.com>2014-05-23 10:30:39 -0400
commit9afcecaf32acb4333b33d46522f98457bfa8856d (patch)
treec27da3ad5fcafddaf930e517b05c5c392e1e92af /Tests/CTestTestTimeout
parent8ae05b420e513252d1fd68dc6085d8dd92f3e624 (diff)
downloadcmake-9afcecaf32acb4333b33d46522f98457bfa8856d.tar.gz
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.
Diffstat (limited to 'Tests/CTestTestTimeout')
-rw-r--r--Tests/CTestTestTimeout/CMakeLists.txt12
-rw-r--r--Tests/CTestTestTimeout/check.cmake9
-rw-r--r--Tests/CTestTestTimeout/sleep.c21
-rw-r--r--Tests/CTestTestTimeout/test.cmake.in13
-rw-r--r--Tests/CTestTestTimeout/timeout.c18
-rw-r--r--Tests/CTestTestTimeout/timeout.cmake2
6 files changed, 39 insertions, 36 deletions
diff --git a/Tests/CTestTestTimeout/CMakeLists.txt b/Tests/CTestTestTimeout/CMakeLists.txt
index 476d0a5e0b..2e3bd6ad44 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 b16f2aab99..0000000000
--- 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 0000000000..33ce307720
--- /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 4178849bb3..68c74d8554 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 370ab22ed1..0000000000
--- 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 198cc9713b..0989b65df0 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})