summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-12-07 08:03:11 -0500
committerBrad King <brad.king@kitware.com>2017-12-07 08:03:11 -0500
commitafae027d6398462906e762da29f306f41d21c6ee (patch)
tree7604ad4c90941999a342a28c5fd329412a304e10
parent05f86af716e00b58b5103b231a22515edcc95321 (diff)
parent935848a8a7164631b9410a0e6f7c5574b01bb85c (diff)
downloadcmake-afae027d6398462906e762da29f306f41d21c6ee.tar.gz
Merge branch 'gtest-discovery-timeout' into release-3.10
Merge-request: !1534
-rw-r--r--Modules/GoogleTest.cmake14
-rw-r--r--Modules/GoogleTestAddTests.cmake11
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-test-missing-result.txt1
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-test-missing-stderr.txt2
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-timeout-result.txt1
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-timeout-stdout.txt7
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest.cmake6
-rw-r--r--Tests/RunCMake/GoogleTest/RunCMakeTest.cmake21
-rw-r--r--Tests/RunCMake/GoogleTest/timeout_test.cpp15
9 files changed, 74 insertions, 4 deletions
diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake
index 3d47367d5e..c525101c7d 100644
--- a/Modules/GoogleTest.cmake
+++ b/Modules/GoogleTest.cmake
@@ -217,6 +217,14 @@ same as the Google Test name (i.e. ``suite.testcase``); see also
executable is being used in multiple calls to ``gtest_discover_tests()``.
Note that this variable is only available in CTest.
+ ``TIMEOUT num``
+ Specifies how long (in seconds) CMake will wait for the test to enumerate
+ available tests. If the test takes longer than this, discovery (and your
+ build) will fail. Most test executables will enumerate their tests very
+ quickly, but under some exceptional circumstances, a test may require a
+ longer timeout. The default is 5. See also the ``TIMEOUT`` option of
+ :command:`execute_process`.
+
#]=======================================================================]
#------------------------------------------------------------------------------
@@ -349,7 +357,7 @@ function(gtest_discover_tests TARGET)
cmake_parse_arguments(
""
"NO_PRETTY_TYPES;NO_PRETTY_VALUES"
- "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST"
+ "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST;TIMEOUT"
"EXTRA_ARGS;PROPERTIES"
${ARGN}
)
@@ -360,6 +368,9 @@ function(gtest_discover_tests TARGET)
if(NOT _TEST_LIST)
set(_TEST_LIST ${TARGET}_TESTS)
endif()
+ if(NOT _TIMEOUT)
+ set(_TIMEOUT 5)
+ endif()
get_property(
has_counter
@@ -407,6 +418,7 @@ function(gtest_discover_tests TARGET)
-D "NO_PRETTY_VALUES=${_NO_PRETTY_VALUES}"
-D "TEST_LIST=${_TEST_LIST}"
-D "CTEST_FILE=${ctest_tests_file}"
+ -D "TEST_DISCOVERY_TIMEOUT=${_TIMEOUT}"
-P "${_GOOGLETEST_DISCOVER_TESTS_SCRIPT}"
VERBATIM
)
diff --git a/Modules/GoogleTestAddTests.cmake b/Modules/GoogleTestAddTests.cmake
index 7d0d9097b1..5a4bdcad39 100644
--- a/Modules/GoogleTestAddTests.cmake
+++ b/Modules/GoogleTestAddTests.cmake
@@ -24,19 +24,24 @@ endfunction()
# Run test executable to get list of available tests
if(NOT EXISTS "${TEST_EXECUTABLE}")
message(FATAL_ERROR
- "Specified test executable '${TEST_EXECUTABLE}' does not exist"
+ "Specified test executable does not exist.\n"
+ " Path: '${TEST_EXECUTABLE}'"
)
endif()
execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" --gtest_list_tests
+ TIMEOUT ${TEST_DISCOVERY_TIMEOUT}
OUTPUT_VARIABLE output
RESULT_VARIABLE result
)
if(NOT ${result} EQUAL 0)
+ string(REPLACE "\n" "\n " output "${output}")
message(FATAL_ERROR
- "Error running test executable '${TEST_EXECUTABLE}':\n"
+ "Error running test executable.\n"
+ " Path: '${TEST_EXECUTABLE}'\n"
" Result: ${result}\n"
- " Output: ${output}\n"
+ " Output:\n"
+ " ${output}\n"
)
endif()
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-result.txt
new file mode 100644
index 0000000000..d197c913c2
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-result.txt
@@ -0,0 +1 @@
+[^0]
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-stderr.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-stderr.txt
new file mode 100644
index 0000000000..55a4a7aa4a
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-stderr.txt
@@ -0,0 +1,2 @@
+Unable to find executable: timeout_test_NOT_BUILT
+Errors while running CTest
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-timeout-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-timeout-result.txt
new file mode 100644
index 0000000000..d197c913c2
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest-timeout-result.txt
@@ -0,0 +1 @@
+[^0]
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-timeout-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-timeout-stdout.txt
new file mode 100644
index 0000000000..8464c80342
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest-timeout-stdout.txt
@@ -0,0 +1,7 @@
+( *|[0-9]+>)CMake Error at .*GoogleTestAddTests.cmake:[0-9]+ \(message\):
+( *|[0-9]+>) Error running test executable.
+?( *|[0-9]+>)
+( *|[0-9]+>) Path: '.*timeout_test(\.exe)?'
+( *|[0-9]+>) Result: Process terminated due to timeout
+( *|[0-9]+>) Output:
+( *|[0-9]+>) +
diff --git a/Tests/RunCMake/GoogleTest/GoogleTest.cmake b/Tests/RunCMake/GoogleTest/GoogleTest.cmake
index 58f4196ffb..5e4b8ef069 100644
--- a/Tests/RunCMake/GoogleTest/GoogleTest.cmake
+++ b/Tests/RunCMake/GoogleTest/GoogleTest.cmake
@@ -21,3 +21,9 @@ gtest_discover_tests(
EXTRA_ARGS how now "\"brown\" cow"
PROPERTIES LABELS TEST2
)
+
+add_executable(timeout_test timeout_test.cpp)
+
+gtest_discover_tests(
+ timeout_test
+)
diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake
index b79af26c34..73014d1438 100644
--- a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake
+++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake
@@ -9,24 +9,45 @@ function(run_GoogleTest)
endif()
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
run_cmake(GoogleTest)
+
run_cmake_command(GoogleTest-build
${CMAKE_COMMAND}
--build .
--config Debug
+ --target fake_gtest
+ )
+
+ set(RunCMake_TEST_OUTPUT_MERGE 1)
+ run_cmake_command(GoogleTest-timeout
+ ${CMAKE_COMMAND}
+ --build .
+ --config Debug
+ --target timeout_test
)
+ set(RunCMake_TEST_OUTPUT_MERGE 0)
+
run_cmake_command(GoogleTest-test1
${CMAKE_CTEST_COMMAND}
-C Debug
-L TEST1
--no-label-summary
)
+
run_cmake_command(GoogleTest-test2
${CMAKE_CTEST_COMMAND}
-C Debug
-L TEST2
--no-label-summary
)
+
+ run_cmake_command(GoogleTest-test-missing
+ ${CMAKE_CTEST_COMMAND}
+ -C Debug
+ -R timeout
+ --no-label-summary
+ )
endfunction()
run_GoogleTest()
diff --git a/Tests/RunCMake/GoogleTest/timeout_test.cpp b/Tests/RunCMake/GoogleTest/timeout_test.cpp
new file mode 100644
index 0000000000..a8e5c1ce4a
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/timeout_test.cpp
@@ -0,0 +1,15 @@
+#if defined(_WIN32)
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+int main()
+{
+#if defined(_WIN32)
+ Sleep(10000);
+#else
+ sleep(10);
+#endif
+ return 0;
+}