Changeset View
Changeset View
Standalone View
Standalone View
cmake/modules/TestSuite.cmake
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
include(Coverage) | include(Coverage) | ||||
function(create_test_suite_with_parent_targets NAME) | function(create_test_suite_with_parent_targets NAME) | ||||
get_target_from_suite(${NAME} TARGET) | get_target_from_suite(${NAME} TARGET) | ||||
add_custom_target(${TARGET} | add_custom_target(${TARGET} | ||||
COMMENT "Running ${NAME} test suite" | COMMENT "Running ${NAME} test suite" | ||||
COMMAND cmake -E echo "PASSED: ${NAME} test suite" | COMMAND "${CMAKE_COMMAND}" -E echo "PASSED: ${NAME} test suite" | ||||
) | ) | ||||
foreach(PARENT_TARGET ${ARGN}) | foreach(PARENT_TARGET ${ARGN}) | ||||
if(TARGET ${PARENT_TARGET}) | if(TARGET ${PARENT_TARGET}) | ||||
add_dependencies(${PARENT_TARGET} ${TARGET}) | add_dependencies(${PARENT_TARGET} ${TARGET}) | ||||
endif() | endif() | ||||
endforeach() | endforeach() | ||||
add_custom_target_coverage(${TARGET}) | add_custom_target_coverage(${TARGET}) | ||||
endfunction() | endfunction() | ||||
macro(create_test_suite NAME) | macro(create_test_suite NAME) | ||||
create_test_suite_with_parent_targets(${NAME} check-all check-extended) | create_test_suite_with_parent_targets(${NAME} check-all check-extended) | ||||
endmacro() | endmacro() | ||||
# After this call, all the tests added to the suite will also be added to the | # After this call, all the tests added to the suite will also be added to the | ||||
# pool. Works only with the Ninja generators. | # pool. Works only with the Ninja generators. | ||||
function(test_suite_create_pool SUITE JOBS) | function(test_suite_create_pool SUITE JOBS) | ||||
# Create a pool for the test suite | # Create a pool for the test suite | ||||
get_pool_from_suite(${SUITE} POOL) | get_pool_from_suite(${SUITE} POOL) | ||||
set_property(GLOBAL APPEND PROPERTY JOB_POOLS ${POOL}=${JOBS}) | set_property(GLOBAL APPEND PROPERTY JOB_POOLS ${POOL}=${JOBS}) | ||||
endfunction() | endfunction() | ||||
include(InstallationHelper) | |||||
function(install_test SUITE NAME) | |||||
# Allow for installing all tests ... | |||||
if(NOT TARGET install-tests) | |||||
add_custom_target(install-tests) | |||||
endif() | |||||
# ... a complete test suite ... | |||||
if(NOT TARGET install-test-suite-${SUITE}) | |||||
add_custom_target(install-test-suite-${SUITE}) | |||||
endif() | |||||
if(NOT TARGET install-${SUITE}-${NAME}) | |||||
install_target(${NAME} COMPONENT ${SUITE}-${NAME} EXCLUDE_FROM_ALL) | |||||
# ... or a single test | |||||
add_custom_target(install-${SUITE}-${NAME} | |||||
COMMENT "Installing ${NAME} from test suite ${SUITE}" | |||||
COMMAND | |||||
"${CMAKE_COMMAND}" | |||||
-DCOMPONENT="${SUITE}-${NAME}" | |||||
-DCMAKE_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" | |||||
-P cmake_install.cmake | |||||
DEPENDS ${NAME} | |||||
) | |||||
add_dependencies(install-test-suite-${SUITE} install-${SUITE}-${NAME}) | |||||
add_dependencies(install-tests install-${SUITE}-${NAME}) | |||||
endif() | |||||
endfunction() | |||||
set(TEST_RUNNER_TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/../templates/TestRunner.cmake.in") | set(TEST_RUNNER_TEMPLATE "${CMAKE_CURRENT_LIST_DIR}/../templates/TestRunner.cmake.in") | ||||
function(add_test_runner SUITE NAME EXECUTABLE) | function(add_test_runner SUITE NAME EXECUTABLE) | ||||
cmake_parse_arguments(ARG "JUNIT" "" "" ${ARGN}) | cmake_parse_arguments(ARG "JUNIT" "" "" ${ARGN}) | ||||
get_target_from_suite(${SUITE} SUITE_TARGET) | get_target_from_suite(${SUITE} SUITE_TARGET) | ||||
set(TARGET "${SUITE_TARGET}-${NAME}") | set(TARGET "${SUITE_TARGET}-${NAME}") | ||||
# If there is a pool associated to the test suite, then add the test to the | # If there is a pool associated to the test suite, then add the test to the | ||||
Show All 24 Lines | add_custom_command(TARGET ${TARGET} POST_BUILD | ||||
COMMAND | COMMAND | ||||
"${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/cmake/utils/junit-reports-merge.py" | "${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/cmake/utils/junit-reports-merge.py" | ||||
"${JUNIT_REPORT_DIRECTORY}" | "${JUNIT_REPORT_DIRECTORY}" | ||||
"${CMAKE_BINARY_DIR}/test/tmp" | "${CMAKE_BINARY_DIR}/test/tmp" | ||||
"${SUITE}" | "${SUITE}" | ||||
"${NAME}" | "${NAME}" | ||||
) | ) | ||||
endif() | endif() | ||||
install_test(${SUITE} ${EXECUTABLE}) | |||||
endfunction() | endfunction() | ||||
function(add_test_to_suite SUITE NAME) | function(add_test_to_suite SUITE NAME) | ||||
add_executable(${NAME} EXCLUDE_FROM_ALL ${ARGN}) | add_executable(${NAME} EXCLUDE_FROM_ALL ${ARGN}) | ||||
add_test_runner(${SUITE} ${NAME} ${NAME}) | add_test_runner(${SUITE} ${NAME} ${NAME}) | ||||
get_target_from_suite(${SUITE} TARGET) | get_target_from_suite(${SUITE} TARGET) | ||||
set_property( | set_property( | ||||
▲ Show 20 Lines • Show All 58 Lines • Show Last 20 Lines |