summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2023-11-28 12:25:44 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-12-01 10:46:52 +0000
commit85bc2522243c2f368815273a5df40f0d3098abc4 (patch)
tree17a57a6d6a10333e0ecde400e0047a0ba8a20991 /cmake
parent4874dd826bd456288a4f04b58a04ece0710671db (diff)
CMake: Compute dynamic timeout for androidtestrunner
Pass a CMake test TIMEOUT argument to androidtestrunner, using a value of 95% of that timeout to allow time for the test runner to do any cleanup before being killed. If no test argument is provided, use the value from CMake property DART_TESTING_TIMEOUT or CTEST_TEST_TIMEOUT. If that's not provided default to 25 minutes which is the default for DART_TESTING_TIMEOUT. Along the way set the default androidtestrunner timeout to 10 minutes and fix the wrong timeout in the help menu. Fixes: QTBUG-106479 Pick-to: 6.5 Change-Id: I12cd531583dd94954caf8044c37c22382d53d43c Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Dimitrios Apostolou <jimis@qt.io> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit d2c29aee41d06d59024ef72eb50bb9f25909e922) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtPlatformAndroid.cmake4
-rw-r--r--cmake/QtTestHelpers.cmake32
2 files changed, 33 insertions, 3 deletions
diff --git a/cmake/QtPlatformAndroid.cmake b/cmake/QtPlatformAndroid.cmake
index 65095de329..b396b76881 100644
--- a/cmake/QtPlatformAndroid.cmake
+++ b/cmake/QtPlatformAndroid.cmake
@@ -185,7 +185,7 @@ define_property(TARGET
)
# Returns test execution arguments for Android targets
-function(qt_internal_android_test_arguments target out_test_runner out_test_arguments)
+function(qt_internal_android_test_arguments target timeout out_test_runner out_test_arguments)
set(${out_test_runner} "${QT_HOST_PATH}/${QT${PROJECT_VERSION_MAJOR}_HOST_INFO_BINDIR}/androidtestrunner" PARENT_SCOPE)
set(deployment_tool "${QT_HOST_PATH}/${QT${PROJECT_VERSION_MAJOR}_HOST_INFO_BINDIR}/androiddeployqt")
@@ -203,7 +203,7 @@ function(qt_internal_android_test_arguments target out_test_runner out_test_argu
"--skip-install-root"
"--make" "${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target}_make_apk"
"--apk" "${apk_dir}/${target}.apk"
- "--timeout" "-1"
+ "--timeout" "${timeout}"
"--verbose"
PARENT_SCOPE
)
diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake
index 4978f95538..9bde392077 100644
--- a/cmake/QtTestHelpers.cmake
+++ b/cmake/QtTestHelpers.cmake
@@ -579,6 +579,11 @@ function(qt_internal_add_test name)
endif()
endif()
+ # Pass 95% of the timeout to allow the test runner time to do any cleanup
+ # before being killed.
+ set(percentage "95")
+ qt_internal_get_android_test_timeout("${arg_TIMEOUT}" "${percentage}" android_timeout)
+
if (ANDROID)
if(arg_BUNDLE_ANDROID_OPENSSL_LIBS)
if(NOT OPENSSL_ROOT_DIR)
@@ -595,7 +600,8 @@ function(qt_internal_add_test name)
endif()
endif()
endif()
- qt_internal_android_test_arguments("${name}" test_executable extra_test_args)
+ qt_internal_android_test_arguments(
+ "${name}" "${android_timeout}" test_executable extra_test_args)
set(test_working_dir "${CMAKE_CURRENT_BINARY_DIR}")
elseif(QNX)
set(test_working_dir "")
@@ -788,6 +794,30 @@ function(qt_internal_add_test name)
qt_internal_add_test_finalizers("${name}")
endfunction()
+# Given an optional test timeout value (specified via qt_internal_add_test's TIMEOUT option)
+# returns a percentage of the final timeout to be passed to the androidtestrunner executable.
+#
+# When the optional timeout is empty, default to cmake's defaults for getting the timeout.
+function(qt_internal_get_android_test_timeout input_timeout percentage output_timeout_var)
+ set(actual_timeout "${input_timeout}")
+ if(NOT actual_timeout)
+ # Related: https://gitlab.kitware.com/cmake/cmake/-/issues/20450
+ if(DART_TESTING_TIMEOUT)
+ set(actual_timeout "${DART_TESTING_TIMEOUT}")
+ elseif(CTEST_TEST_TIMEOUT)
+ set(actual_timeout "${CTEST_TEST_TIMEOUT}")
+ else()
+ # Default DART_TESTING_TIMEOUT is 25 minutes, specified in seconds
+ # https://github.com/Kitware/CMake/blob/master/Modules/CTest.cmake#L167C16-L167C16
+ set(actual_timeout "1500")
+ endif()
+ endif()
+
+ math(EXPR calculated_timeout "${actual_timeout} * ${percentage} / 100")
+
+ set(${output_timeout_var} "${calculated_timeout}" PARENT_SCOPE)
+endfunction()
+
# This function adds test with specified NAME and wraps given test COMMAND with standalone cmake
# script.
#