From 55a1ef3ee303190f1da8d32d56a872273e3eb0a5 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 16 Jan 2025 16:17:28 +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 Change-Id: I387f09570b6a4a345756133870c2eb9ef1cf3cf8 Reviewed-by: Alexandru Croitor (cherry picked from commit 8f2f4ad4688df4963982c489c80b84e115cda29d) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 566db56dd3c3d1ed6697f2774054533aa2329d91) --- cmake/QtPublicTestHelpers.cmake | 32 ++++++++++++++++++++++++++++++++ cmake/QtTestHelpers.cmake | 16 ++++------------ src/corelib/Qt6CTestMacros.cmake | 6 ++++++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/cmake/QtPublicTestHelpers.cmake b/cmake/QtPublicTestHelpers.cmake index 2c1c3f2b271..09ba70ee747 100644 --- a/cmake/QtPublicTestHelpers.cmake +++ b/cmake/QtPublicTestHelpers.cmake @@ -109,3 +109,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 a195289c44b..db1bbc84c26 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -765,18 +765,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 3924894f8f7..12689dcd287 100644 --- a/src/corelib/Qt6CTestMacros.cmake +++ b/src/corelib/Qt6CTestMacros.cmake @@ -457,6 +457,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 "") @@ -663,6 +664,9 @@ list(APPEND CMAKE_PREFIX_PATH \"${__expect_fail_prefixes}\") --build-project "${_dir}" --build-options ${option_list} ) + + _qt_internal_make_check_target(${testname}) + unset(__expect_fail_prefixes) endmacro() @@ -776,4 +780,6 @@ function(_qt_internal_test_module_includes) --build-project module_includes --build-options ${option_list} ) + + _qt_internal_make_check_target(module_includes) endfunction()