Add new default option EIGEN_SPLIT_LARGE_TESTS and cmake macro ei_add_test_multi.

When enabled, large tests are split into smaller executables.
This needs minimal changes in the unit tests.
Updated the LU test to use it.
This commit is contained in:
Benoit Jacob 2009-10-19 13:29:00 -04:00
parent 9a700c2974
commit 580672ea43
3 changed files with 111 additions and 50 deletions

View File

@ -18,30 +18,11 @@ macro(ei_add_property prop value)
set_property(GLOBAL PROPERTY ${prop} "${previous} ${value}")
endmacro(ei_add_property)
# Macro to add a test
#
# the unique parameter testname must correspond to a file
# <testname>.cpp which follows this pattern:
#
# #include "main.h"
# void test_<testname>() { ... }
#
# this macro add an executable test_<testname> as well as a ctest test
# named <testname>.
#
# it also adds another executable debug_<testname> that compiles in full debug mode
# and is not added to the test target. The idea is that when a test fails you want
# a quick way of rebuilding this specific test in full debug mode.
#
# On platforms with bash simply run:
# "ctest -V" or "ctest -V -R <testname>"
# On other platform use ctest as usual
#
macro(ei_add_test testname)
set(targetname test_${testname})
#internal. See documentation of ei_add_test for details.
macro(ei_add_test_internal testname testname_with_suffix)
set(targetname test_${testname_with_suffix})
if(NOT MSVC_IDE)
set(debug_targetname debug_${testname})
set(debug_targetname debug_${testname_with_suffix})
endif(NOT MSVC_IDE)
set(filename ${testname}.cpp)
@ -80,10 +61,14 @@ macro(ei_add_test testname)
endif(NOT EIGEN_NO_ASSERTION_CHECKING)
# let the user pass e.g. optimization flags, but don't apply them to the debug target
if(${ARGC} GREATER 1)
ei_add_target_property(${targetname} COMPILE_FLAGS "${ARGV1}")
endif(${ARGC} GREATER 1)
# let the user pass flags. Note that if the user passes an optimization flag here, it's important that
# we counter it by a no-optimization flag!
if(${ARGC} GREATER 2)
ei_add_target_property(${targetname} COMPILE_FLAGS "${ARGV2}")
if(NOT MSVC_IDE)
ei_add_target_property(${debug_targetname} COMPILE_FLAGS "${ARGV2} ${EI_NO_OPTIMIZATION_FLAG}")
endif(NOT MSVC_IDE)
endif(${ARGC} GREATER 2)
# for the debug target, add full debug options
if(CMAKE_COMPILER_IS_GNUCXX)
@ -101,29 +86,94 @@ macro(ei_add_test testname)
endif(NOT MSVC_IDE)
target_link_libraries(${targetname} ${EXTERNAL_LIBS})
if(${ARGC} GREATER 2)
string(STRIP "${ARGV2}" ARGV2_stripped)
string(LENGTH "${ARGV2_stripped}" ARGV2_stripped_length)
if(${ARGV2_stripped_length} GREATER 0)
target_link_libraries(${targetname} ${ARGV2})
if(${ARGC} GREATER 3)
string(STRIP "${ARGV3}" ARGV3_stripped)
string(LENGTH "${ARGV3_stripped}" ARGV3_stripped_length)
if(${ARGV3_stripped_length} GREATER 0)
target_link_libraries(${targetname} ${ARGV3})
if(NOT MSVC_IDE)
target_link_libraries(${debug_targetname} ${ARGV2})
target_link_libraries(${debug_targetname} ${ARGV3})
endif(NOT MSVC_IDE)
endif(${ARGV2_stripped_length} GREATER 0)
endif(${ARGC} GREATER 2)
endif(${ARGV3_stripped_length} GREATER 0)
endif(${ARGC} GREATER 3)
if(WIN32)
if(CYGWIN)
add_test(${testname} "${Eigen_SOURCE_DIR}/test/runtest.sh" "${testname}")
add_test(${testname_with_suffix} "${Eigen_SOURCE_DIR}/test/runtest.sh" "${testname_with_suffix}")
else(CYGWIN)
add_test(${testname} "${targetname}")
add_test(${testname_with_suffix} "${targetname}")
endif(CYGWIN)
else(WIN32)
add_test(${testname} "${Eigen_SOURCE_DIR}/test/runtest.sh" "${testname}")
add_test(${testname_with_suffix} "${Eigen_SOURCE_DIR}/test/runtest.sh" "${testname_with_suffix}")
endif(WIN32)
endmacro(ei_add_test_internal)
# Macro to add a test
#
# the unique parameter testname must correspond to a file
# <testname>.cpp which follows this pattern:
#
# #include "main.h"
# void test_<testname>() { ... }
#
# this macro add an executable test_<testname> as well as a ctest test
# named <testname>.
#
# it also adds another executable debug_<testname> that compiles in full debug mode
# and is not added to the test target. The idea is that when a test fails you want
# a quick way of rebuilding this specific test in full debug mode.
#
# On platforms with bash simply run:
# "ctest -V" or "ctest -V -R <testname>"
# On other platform use ctest as usual
#
macro(ei_add_test testname)
ei_add_test_internal(${testname} ${testname} "${ARGV1}" "${ARGV2}")
endmacro(ei_add_test)
# Macro to add a multi-part test. Allows to split large tests into multiple executables.
#
# The first parameter is the number of parts.
#
# the second parameter testname must correspond to a file
# <testname>.cpp which follows this pattern:
#
# #include "main.h"
# void test_<testname>() { ... }
#
# this macro adds executables test_<testname>_N for N ranging from 1 to the number of parts
# (first parameter) as well as corresponding ctest tests named <testname_N>.
#
# it also adds corresponding debug targets and ctest tests, see the documentation of ei_add_test.
#
# On platforms with bash simply run:
# "ctest -V" or "ctest -V -R <testname>"
# On other platforms use ctest as usual
macro(ei_add_test_multi parts testname)
if(EIGEN_SPLIT_LARGE_TESTS)
add_custom_target(test_${testname})
if(NOT MSVC_IDE)
add_custom_target(debug_${testname})
endif(NOT MSVC_IDE)
foreach(part RANGE 1 ${parts})
message("multipart argv2 ${ARGV2} argv3 ${ARGV3}")
ei_add_test_internal(${testname} ${testname}_${part} "${ARGV2} -DEIGEN_TEST_PART_${part}" "${ARGV3}")
add_dependencies(test_${testname} test_${testname}_${part})
if(NOT MSVC_IDE)
add_dependencies(debug_${testname} debug_${testname}_${part})
endif(NOT MSVC_IDE)
endforeach(part)
else(EIGEN_SPLIT_LARGE_TESTS)
set(symbols_to_enable_all_parts "")
foreach(part RANGE 1 ${parts})
set(symbols_to_enable_all_parts "${symbols_to_enable_all_parts} -DEIGEN_TEST_PART_${part}")
endforeach(part)
ei_add_test_internal(${testname} ${testname} "${ARGV2} ${symbols_to_enable_all_parts}" "${ARGV3}")
endif(EIGEN_SPLIT_LARGE_TESTS)
endmacro(ei_add_test_multi)
# print a summary of the different options
macro(ei_testing_print_summary)
@ -204,12 +254,15 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COVERAGE_FLAGS} -fno-inline-functions")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g3")
endif(CMAKE_SYSTEM_NAME MATCHES Linux)
set(EI_OFLAG "-O2")
set(EI_NO_OPTIMIZATION_FLAG "-O0")
elseif(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "/D_DEBUG /MDd /Zi /Ob0 /Od" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
set(EI_OFLAG "/O2")
set(EI_NO_OPTIMIZATION_FLAG "/O0")
else(CMAKE_COMPILER_IS_GNUCXX)
set(EI_OFLAG "")
set(EI_NO_OPTIMIZATION_FLAG "")
endif(CMAKE_COMPILER_IS_GNUCXX)

View File

@ -3,6 +3,8 @@ add_custom_target(btest)
include(EigenTesting)
ei_init_testing()
option(EIGEN_SPLIT_LARGE_TESTS "Split large tests into smaller executables" ON)
find_package(GSL)
if(GSL_FOUND AND GSL_VERSION_MINOR LESS 9)
set(GSL_FOUND "")
@ -119,7 +121,7 @@ ei_add_test(product_notemporary ${EI_OFLAG})
ei_add_test(stable_norm)
ei_add_test(bandmatrix)
ei_add_test(cholesky " " "${GSL_LIBRARIES}")
ei_add_test(lu ${EI_OFLAG})
ei_add_test_multi(6 lu ${EI_OFLAG})
ei_add_test(determinant)
ei_add_test(inverse ${EI_OFLAG})
ei_add_test(qr)

View File

@ -153,22 +153,28 @@ template<typename MatrixType> void lu_verify_assert()
void test_lu()
{
for(int i = 0; i < g_repeat; i++) {
#if defined EIGEN_TEST_PART_1
CALL_SUBTEST( lu_non_invertible<Matrix3f>() );
CALL_SUBTEST( lu_verify_assert<Matrix3f>() );
#elif defined EIGEN_TEST_PART_2
CALL_SUBTEST( (lu_non_invertible<Matrix<double, 4, 6> >()) );
CALL_SUBTEST( (lu_verify_assert<Matrix<double, 4, 6> >()) );
#elif defined EIGEN_TEST_PART_3
CALL_SUBTEST( lu_non_invertible<MatrixXf>() );
CALL_SUBTEST( lu_non_invertible<MatrixXd>() );
CALL_SUBTEST( lu_non_invertible<MatrixXcf>() );
CALL_SUBTEST( lu_non_invertible<MatrixXcd>() );
CALL_SUBTEST( lu_invertible<MatrixXf>() );
CALL_SUBTEST( lu_verify_assert<MatrixXf>() );
#elif defined EIGEN_TEST_PART_4
CALL_SUBTEST( lu_non_invertible<MatrixXd>() );
CALL_SUBTEST( lu_invertible<MatrixXd>() );
CALL_SUBTEST( lu_verify_assert<MatrixXd>() );
#elif defined EIGEN_TEST_PART_5
CALL_SUBTEST( lu_non_invertible<MatrixXcf>() );
CALL_SUBTEST( lu_invertible<MatrixXcf>() );
CALL_SUBTEST( lu_verify_assert<MatrixXcf>() );
#elif defined EIGEN_TEST_PART_6
CALL_SUBTEST( lu_non_invertible<MatrixXcd>() );
CALL_SUBTEST( lu_invertible<MatrixXcd>() );
CALL_SUBTEST( lu_verify_assert<MatrixXcd>() );
#endif
}
CALL_SUBTEST( lu_verify_assert<Matrix3f>() );
CALL_SUBTEST( lu_verify_assert<Matrix3d>() );
CALL_SUBTEST( lu_verify_assert<MatrixXf>() );
CALL_SUBTEST( lu_verify_assert<MatrixXd>() );
CALL_SUBTEST( lu_verify_assert<MatrixXcf>() );
CALL_SUBTEST( lu_verify_assert<MatrixXcd>() );
}