aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2018-12-12 15:48:36 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2018-12-12 15:48:36 +0100
commit72c0bbe2bd1c49c75b6efdb81d0558f8b62578d1 (patch)
tree0085849ac123593d69b5d53e6c11abcbee8f024b
parent37c91e18368e77a333afd2f5a1fd52026014fca5 (diff)
Simplify handling of tests that must fail to compile.
Each test is now a normal ctest target, and build properties (compiler+flags) are preserved (instead of starting a new build-dir from scratch).
-rw-r--r--CMakeLists.txt5
-rw-r--r--cmake/EigenTesting.cmake45
-rw-r--r--failtest/CMakeLists.txt10
-rw-r--r--test/CMakeLists.txt5
4 files changed, 21 insertions, 44 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e18428e50..5255e9600 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -519,10 +519,7 @@ message(STATUS "")
message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
message(STATUS "")
-option(EIGEN_FAILTEST "Enable failtests." OFF)
-if(EIGEN_FAILTEST)
- add_subdirectory(failtest)
-endif()
+add_subdirectory(failtest)
string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
if(cmake_generator_tolower MATCHES "makefile")
diff --git a/cmake/EigenTesting.cmake b/cmake/EigenTesting.cmake
index 35deed509..8cb2d5492 100644
--- a/cmake/EigenTesting.cmake
+++ b/cmake/EigenTesting.cmake
@@ -334,37 +334,32 @@ endmacro(ei_add_test_sycl)
# note that the test runner for these is CMake itself, when passed -DEIGEN_FAILTEST=ON
# so here we're just running CMake commands immediately, we're not adding any targets.
macro(ei_add_failtest testname)
- get_property(EIGEN_FAILTEST_FAILURE_COUNT GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT)
- get_property(EIGEN_FAILTEST_COUNT GLOBAL PROPERTY EIGEN_FAILTEST_COUNT)
- message(STATUS "Checking failtest: ${testname}")
- set(filename "${testname}.cpp")
- file(READ "${filename}" test_source)
+ set(test_target_ok ${testname}_ok)
+ set(test_target_ko ${testname}_ko)
- try_compile(succeeds_when_it_should_fail
- "${CMAKE_CURRENT_BINARY_DIR}"
- "${CMAKE_CURRENT_SOURCE_DIR}/${filename}"
- COMPILE_DEFINITIONS "-DEIGEN_SHOULD_FAIL_TO_BUILD")
- if (succeeds_when_it_should_fail)
- message(STATUS "FAILED: ${testname} build succeeded when it should have failed")
- endif()
+ # Add executables
+ add_executable(${test_target_ok} ${testname}.cpp)
+ add_executable(${test_target_ko} ${testname}.cpp)
- try_compile(succeeds_when_it_should_succeed
- "${CMAKE_CURRENT_BINARY_DIR}"
- "${CMAKE_CURRENT_SOURCE_DIR}/${filename}"
- COMPILE_DEFINITIONS)
- if (NOT succeeds_when_it_should_succeed)
- message(STATUS "FAILED: ${testname} build failed when it should have succeeded")
- endif()
+ # Remove them from the normal build process
+ set_target_properties(${test_target_ok} ${test_target_ko} PROPERTIES
+ EXCLUDE_FROM_ALL TRUE
+ EXCLUDE_FROM_DEFAULT_BUILD TRUE)
- if (succeeds_when_it_should_fail OR NOT succeeds_when_it_should_succeed)
- math(EXPR EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT}+1)
- endif()
+ # Configure the failing test
+ target_compile_definitions(${test_target_ko} PRIVATE EIGEN_SHOULD_FAIL_TO_BUILD)
- math(EXPR EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT}+1)
+ # Add the tests to ctest.
+ add_test(NAME ${test_target_ok}
+ COMMAND ${CMAKE_COMMAND} --build . --target ${test_target_ok} --config $<CONFIGURATION>
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
+ add_test(NAME ${test_target_ko}
+ COMMAND ${CMAKE_COMMAND} --build . --target ${test_target_ko} --config $<CONFIGURATION>
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
- set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT})
- set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT})
+ # Expect the second test to fail
+ set_tests_properties(${test_target_ko} PROPERTIES WILL_FAIL TRUE)
endmacro(ei_add_failtest)
# print a summary of the different options
diff --git a/failtest/CMakeLists.txt b/failtest/CMakeLists.txt
index 1a73f05e6..f95503d7e 100644
--- a/failtest/CMakeLists.txt
+++ b/failtest/CMakeLists.txt
@@ -1,4 +1,3 @@
-message(STATUS "Running the failtests")
ei_add_failtest("failtest_sanity_check")
@@ -64,12 +63,3 @@ ei_add_failtest("bdcsvd_int")
ei_add_failtest("eigensolver_int")
ei_add_failtest("eigensolver_cplx")
-if (EIGEN_FAILTEST_FAILURE_COUNT)
- message(FATAL_ERROR
- "${EIGEN_FAILTEST_FAILURE_COUNT} out of ${EIGEN_FAILTEST_COUNT} failtests FAILED. "
- "To debug these failures, manually compile these programs in ${CMAKE_CURRENT_SOURCE_DIR}, "
- "with and without #define EIGEN_SHOULD_FAIL_TO_BUILD.")
-else()
- message(STATUS "Failtest SUCCESS: all ${EIGEN_FAILTEST_COUNT} failtests passed.")
- message(STATUS "")
-endif()
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index f215d97cd..67b35a61e 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -439,11 +439,6 @@ if (EIGEN_TEST_HIP)
endif(EIGEN_TEST_HIP)
-
-
-file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/failtests)
-add_test(NAME failtests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/failtests COMMAND ${CMAKE_COMMAND} ${Eigen_SOURCE_DIR} -G "${CMAKE_GENERATOR}" -DEIGEN_FAILTEST=ON)
-
option(EIGEN_TEST_BUILD_DOCUMENTATION "Test building the doxygen documentation" OFF)
IF(EIGEN_TEST_BUILD_DOCUMENTATION)
add_dependencies(buildtests doc)