From 2f5eb1800b76288ad3fbd6404b6b08ab26fb9158 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 13 Jan 2020 14:06:03 -0500 Subject: Tests: Add RunCMake.CTestTimeout test This test will consolidate CTest timeout-related tests. --- Tests/RunCMake/CMakeLists.txt | 1 + Tests/RunCMake/CTestTimeout/Basic-stdout.txt | 6 ++++++ Tests/RunCMake/CTestTimeout/CMakeLists.txt.in | 15 +++++++++++++++ Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake | 14 ++++++++++++++ Tests/RunCMake/CTestTimeout/TestTimeout.c | 17 +++++++++++++++++ Tests/RunCMake/CTestTimeout/test.cmake.in | 16 ++++++++++++++++ 6 files changed, 69 insertions(+) create mode 100644 Tests/RunCMake/CTestTimeout/Basic-stdout.txt create mode 100644 Tests/RunCMake/CTestTimeout/CMakeLists.txt.in create mode 100644 Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/CTestTimeout/TestTimeout.c create mode 100644 Tests/RunCMake/CTestTimeout/test.cmake.in diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index b8ac45b..b249d37 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -349,6 +349,7 @@ add_RunCMake_test(alias_targets) add_RunCMake_test(interface_library) add_RunCMake_test(no_install_prefix) add_RunCMake_test(configure_file) +add_RunCMake_test(CTestTimeout -DTIMEOUT=${CTestTestTimeout_TIME}) add_RunCMake_test(CTestTimeoutAfterMatch) # ctresalloc links against CMakeLib and CTestLib, which means it can't be built diff --git a/Tests/RunCMake/CTestTimeout/Basic-stdout.txt b/Tests/RunCMake/CTestTimeout/Basic-stdout.txt new file mode 100644 index 0000000..30ed178 --- /dev/null +++ b/Tests/RunCMake/CTestTimeout/Basic-stdout.txt @@ -0,0 +1,6 @@ +Test project [^ +]*/Tests/RunCMake/CTestTimeout/Basic-build + Start 1: TestTimeout +1/1 Test #1: TestTimeout ......................\*\*\*Timeout +[0-9.]+ sec ++ +0% tests passed, 1 tests failed out of 1 diff --git a/Tests/RunCMake/CTestTimeout/CMakeLists.txt.in b/Tests/RunCMake/CTestTimeout/CMakeLists.txt.in new file mode 100644 index 0000000..20faa94 --- /dev/null +++ b/Tests/RunCMake/CTestTimeout/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.16) +project(CTestTest@CASE_NAME@ C) +include(CTest) + +add_executable(TestTimeout TestTimeout.c) + +if(NOT TIMEOUT) + set(TIMEOUT 4) +endif() +target_compile_definitions(TestTimeout PRIVATE TIMEOUT=${TIMEOUT}) + +add_test(NAME TestTimeout COMMAND TestTimeout) +set_property(TEST TestTimeout PROPERTY TIMEOUT ${TIMEOUT}) + +@CASE_CMAKELISTS_SUFFIX_CODE@ diff --git a/Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake b/Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake new file mode 100644 index 0000000..428d0b7 --- /dev/null +++ b/Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake @@ -0,0 +1,14 @@ +include(RunCTest) + +if(NOT TIMEOUT) + # Give the process time to load and start running. + set(TIMEOUT 4) +endif() + +function(run_ctest_timeout CASE_NAME) + configure_file(${RunCMake_SOURCE_DIR}/TestTimeout.c + ${RunCMake_BINARY_DIR}/${CASE_NAME}/TestTimeout.c COPYONLY) + run_ctest(${CASE_NAME}) +endfunction() + +run_ctest_timeout(Basic) diff --git a/Tests/RunCMake/CTestTimeout/TestTimeout.c b/Tests/RunCMake/CTestTimeout/TestTimeout.c new file mode 100644 index 0000000..52a5648 --- /dev/null +++ b/Tests/RunCMake/CTestTimeout/TestTimeout.c @@ -0,0 +1,17 @@ +#if defined(_WIN32) +# include +#else +# include +#endif + +#include + +int main(void) +{ +#if defined(_WIN32) + Sleep((TIMEOUT + 4) * 1000); +#else + sleep((TIMEOUT + 4)); +#endif + return 0; +} diff --git a/Tests/RunCMake/CTestTimeout/test.cmake.in b/Tests/RunCMake/CTestTimeout/test.cmake.in new file mode 100644 index 0000000..be2625b --- /dev/null +++ b/Tests/RunCMake/CTestTimeout/test.cmake.in @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.16) +@CASE_TEST_PREFIX_CODE@ + +set(CTEST_SITE "test-site") +set(CTEST_BUILD_NAME "test-build-name") +set(CTEST_SOURCE_DIRECTORY "@RunCMake_BINARY_DIR@/@CASE_NAME@") +set(CTEST_BINARY_DIRECTORY "@RunCMake_BINARY_DIR@/@CASE_NAME@-build") +set(CTEST_CMAKE_GENERATOR "@RunCMake_GENERATOR@") +set(CTEST_CMAKE_GENERATOR_PLATFORM "@RunCMake_GENERATOR_PLATFORM@") +set(CTEST_CMAKE_GENERATOR_TOOLSET "@RunCMake_GENERATOR_TOOLSET@") +set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}") + +ctest_start(Experimental) +ctest_configure(OPTIONS "-DTIMEOUT=@TIMEOUT@") +ctest_build() +ctest_test() -- cgit v0.12 From d1976cd1f226a6da00dbab1b851202f0c69341db Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 13 Jan 2020 16:17:19 -0500 Subject: CTest: Fix timeout when grandchild keeps pipes open When a test's process creates its own child and exits, the grandchild may keep pipes open. Fix CTest logic to correctly timeout if the grandchild does not exit and close the pipes before the timeout expires. This was broken by commit b5e21d7d2e (CTest: Re-implement test process handling using libuv, 2017-12-10, v3.11.0-rc1~117^2) which added an unnecessary condition to the timeout handling. Fixes: #20116 --- Source/CTest/cmProcess.cxx | 3 --- Tests/RunCMake/CTestTimeout/Fork-stdout.txt | 6 ++++++ Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake | 8 ++++++++ Tests/RunCMake/CTestTimeout/TestTimeout.c | 7 +++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 Tests/RunCMake/CTestTimeout/Fork-stdout.txt diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx index 2ec9622..cdf899c 100644 --- a/Source/CTest/cmProcess.cxx +++ b/Source/CTest/cmProcess.cxx @@ -278,9 +278,6 @@ void cmProcess::OnTimeoutCB(uv_timer_t* timer) void cmProcess::OnTimeout() { - if (this->ProcessState != cmProcess::State::Executing) { - return; - } this->ProcessState = cmProcess::State::Expired; bool const was_still_reading = !this->ReadHandleClosed; if (!this->ReadHandleClosed) { diff --git a/Tests/RunCMake/CTestTimeout/Fork-stdout.txt b/Tests/RunCMake/CTestTimeout/Fork-stdout.txt new file mode 100644 index 0000000..284e4b1 --- /dev/null +++ b/Tests/RunCMake/CTestTimeout/Fork-stdout.txt @@ -0,0 +1,6 @@ +Test project [^ +]*/Tests/RunCMake/CTestTimeout/Fork-build + Start 1: TestTimeout +1/1 Test #1: TestTimeout ......................\*\*\*Timeout +[0-9.]+ sec ++ +0% tests passed, 1 tests failed out of 1 diff --git a/Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake b/Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake index 428d0b7..7e96b6d 100644 --- a/Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestTimeout/RunCMakeTest.cmake @@ -12,3 +12,11 @@ function(run_ctest_timeout CASE_NAME) endfunction() run_ctest_timeout(Basic) + +if(UNIX) + string(CONCAT CASE_CMAKELISTS_SUFFIX_CODE [[ + target_compile_definitions(TestTimeout PRIVATE FORK) +]]) + run_ctest_timeout(Fork) + unset(CASE_CMAKELISTS_SUFFIX_CODE) +endif() diff --git a/Tests/RunCMake/CTestTimeout/TestTimeout.c b/Tests/RunCMake/CTestTimeout/TestTimeout.c index 52a5648..5a008a7 100644 --- a/Tests/RunCMake/CTestTimeout/TestTimeout.c +++ b/Tests/RunCMake/CTestTimeout/TestTimeout.c @@ -8,6 +8,13 @@ int main(void) { +#ifdef FORK + pid_t pid = fork(); + if (pid != 0) { + return 0; + } +#endif + #if defined(_WIN32) Sleep((TIMEOUT + 4) * 1000); #else -- cgit v0.12