From 8f2f4ad4688df4963982c489c80b84e115cda29d Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Fri, 3 Jan 2025 17:57:53 +0100 Subject: [PATCH] Add `*_check` build targets for auto cmake tests Similar `*_check` targets are created in `qt_internal_add_test`. This change extends that implementation to auto cmake tests. Note: These generated targets do not have additional dependencies, on the build targets, unlike those generated by `qt_internal_add_test`. You would need to (re-)run the build first separately and then run the `*_check` target. Fixes: QTBUG-98640 Pick-to: 6.8 6.9 Change-Id: I387f09570b6a4a345756133870c2eb9ef1cf3cf8 Reviewed-by: Alexandru Croitor --- cmake/QtPublicTestHelpers.cmake | 32 ++++++++++++++++++++++++++++++++ cmake/QtTestHelpers.cmake | 16 ++++------------ src/corelib/Qt6CTestMacros.cmake | 3 +++ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/cmake/QtPublicTestHelpers.cmake b/cmake/QtPublicTestHelpers.cmake index af59bc168b5..1912ec95dfe 100644 --- a/cmake/QtPublicTestHelpers.cmake +++ b/cmake/QtPublicTestHelpers.cmake @@ -121,3 +121,35 @@ endfunction() function(_qt_internal_test_batch_target_name out) set(${out} "test_batch" PARENT_SCOPE) endfunction() + +# Create a *_check target of the ctest execution for alternative execution +# Arguments: +# : CTEST_TEST_NAME: (default: ${testname}) +# name of the ctest test used +function(_qt_internal_make_check_target testname) + set(options "") + set(singleOpts CTEST_TEST_NAME) + set(multiOpts "") + + cmake_parse_arguments(PARSE_ARGV 0 arg + "${options}" "${singleOpts}" "${multiOpts}" + ) + if(NOT arg_CTEST_TEST_NAME) + set(arg_CTEST_TEST_NAME ${testname}) + endif() + + set(test_config_options "") + get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG) + if(is_multi_config) + set(test_config_options -C $) + endif() + # Note: By default the working directory here is CMAKE_CURRENT_BINARY_DIR, which will + # work as long as this is called anywhere up or down the path where the equivalent + # `add_test` is called (not down a different branch path). + add_custom_target(${testname}_check + VERBATIM + COMMENT "Running ctest -V -R \"^${arg_CTEST_TEST_NAME}$\" ${test_config_options}" + COMMAND + "${CMAKE_CTEST_COMMAND}" -V -R "^${arg_CTEST_TEST_NAME}$" ${test_config_options} + ) +endfunction() diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index 94cd99cd6df..1e4c3754bb8 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -794,18 +794,10 @@ function(qt_internal_add_test name) ) endif() - # Add a ${target}/check makefile target, to more easily test one test. - - set(test_config_options "") - get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG) - if(is_multi_config) - set(test_config_options -C $) - endif() - add_custom_target("${testname}_check" - VERBATIM - COMMENT "Running ${CMAKE_CTEST_COMMAND} -V -R \"^${name}$\" ${test_config_options}" - COMMAND "${CMAKE_CTEST_COMMAND}" -V -R "^${name}$" ${test_config_options} - ) + # Add a ${target}_check makefile target, to more easily test one test. + # TODO: Note in batch mode testname tests would execute all batched tests defined in name + _qt_internal_make_check_target(${testname} CTEST_TEST_NAME ${name}) + # Add appropriate dependencies to the targets as needed if(TARGET "${name}") add_dependencies("${testname}_check" "${name}") if(ANDROID) diff --git a/src/corelib/Qt6CTestMacros.cmake b/src/corelib/Qt6CTestMacros.cmake index f6bdb3b3cc8..613bff9cabe 100644 --- a/src/corelib/Qt6CTestMacros.cmake +++ b/src/corelib/Qt6CTestMacros.cmake @@ -482,6 +482,7 @@ macro(_qt_internal_test_expect_pass _dir) ) endif() set_tests_properties(${testname} PROPERTIES ENVIRONMENT "ASAN_OPTIONS=detect_leaks=0") + _qt_internal_make_check_target(${testname}) if(_ARGS_BINARY) set(run_env_args "") @@ -703,6 +704,7 @@ list(APPEND CMAKE_PREFIX_PATH \"${__expect_fail_prefixes}\") add_test(${testname} "${CMAKE_COMMAND}" "-P" "${wrapper_file}") set_tests_properties(${testname} PROPERTIES SKIP_REGULAR_EXPRESSION "${_qt_internal_skip_build_test_regex}") + _qt_internal_make_check_target(${testname}) unset(__expect_fail_prefixes) endmacro() @@ -826,4 +828,5 @@ function(_qt_internal_test_module_includes) add_test(module_includes "${CMAKE_COMMAND}" "-P" "${wrapper_file}") set_tests_properties(module_includes PROPERTIES SKIP_REGULAR_EXPRESSION "${_qt_internal_skip_build_test_regex}") + _qt_internal_make_check_target(module_includes) endfunction()