mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
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).
This commit is contained in:
parent
37c91e1836
commit
72c0bbe2bd
@ -519,10 +519,7 @@ message(STATUS "")
|
|||||||
message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
|
message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}")
|
||||||
message(STATUS "")
|
message(STATUS "")
|
||||||
|
|
||||||
option(EIGEN_FAILTEST "Enable failtests." OFF)
|
|
||||||
if(EIGEN_FAILTEST)
|
|
||||||
add_subdirectory(failtest)
|
add_subdirectory(failtest)
|
||||||
endif()
|
|
||||||
|
|
||||||
string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
|
string(TOLOWER "${CMAKE_GENERATOR}" cmake_generator_tolower)
|
||||||
if(cmake_generator_tolower MATCHES "makefile")
|
if(cmake_generator_tolower MATCHES "makefile")
|
||||||
|
@ -334,37 +334,32 @@ endmacro(ei_add_test_sycl)
|
|||||||
# note that the test runner for these is CMake itself, when passed -DEIGEN_FAILTEST=ON
|
# 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.
|
# so here we're just running CMake commands immediately, we're not adding any targets.
|
||||||
macro(ei_add_failtest testname)
|
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(test_target_ok ${testname}_ok)
|
||||||
set(filename "${testname}.cpp")
|
set(test_target_ko ${testname}_ko)
|
||||||
file(READ "${filename}" test_source)
|
|
||||||
|
|
||||||
try_compile(succeeds_when_it_should_fail
|
# Add executables
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
add_executable(${test_target_ok} ${testname}.cpp)
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${filename}"
|
add_executable(${test_target_ko} ${testname}.cpp)
|
||||||
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()
|
|
||||||
|
|
||||||
try_compile(succeeds_when_it_should_succeed
|
# Remove them from the normal build process
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
set_target_properties(${test_target_ok} ${test_target_ko} PROPERTIES
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${filename}"
|
EXCLUDE_FROM_ALL TRUE
|
||||||
COMPILE_DEFINITIONS)
|
EXCLUDE_FROM_DEFAULT_BUILD TRUE)
|
||||||
if (NOT succeeds_when_it_should_succeed)
|
|
||||||
message(STATUS "FAILED: ${testname} build failed when it should have succeeded")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (succeeds_when_it_should_fail OR NOT succeeds_when_it_should_succeed)
|
# Configure the failing test
|
||||||
math(EXPR EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT}+1)
|
target_compile_definitions(${test_target_ko} PRIVATE EIGEN_SHOULD_FAIL_TO_BUILD)
|
||||||
endif()
|
|
||||||
|
|
||||||
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})
|
# Expect the second test to fail
|
||||||
set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT})
|
set_tests_properties(${test_target_ko} PROPERTIES WILL_FAIL TRUE)
|
||||||
endmacro(ei_add_failtest)
|
endmacro(ei_add_failtest)
|
||||||
|
|
||||||
# print a summary of the different options
|
# print a summary of the different options
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
message(STATUS "Running the failtests")
|
|
||||||
|
|
||||||
ei_add_failtest("failtest_sanity_check")
|
ei_add_failtest("failtest_sanity_check")
|
||||||
|
|
||||||
@ -64,12 +63,3 @@ ei_add_failtest("bdcsvd_int")
|
|||||||
ei_add_failtest("eigensolver_int")
|
ei_add_failtest("eigensolver_int")
|
||||||
ei_add_failtest("eigensolver_cplx")
|
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()
|
|
||||||
|
@ -439,11 +439,6 @@ if (EIGEN_TEST_HIP)
|
|||||||
|
|
||||||
endif(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)
|
option(EIGEN_TEST_BUILD_DOCUMENTATION "Test building the doxygen documentation" OFF)
|
||||||
IF(EIGEN_TEST_BUILD_DOCUMENTATION)
|
IF(EIGEN_TEST_BUILD_DOCUMENTATION)
|
||||||
add_dependencies(buildtests doc)
|
add_dependencies(buildtests doc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user