From d2c29aee41d06d59024ef72eb50bb9f25909e922 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 28 Nov 2023 12:25:44 +0100 Subject: 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.6 6.5 Change-Id: I12cd531583dd94954caf8044c37c22382d53d43c Reviewed-by: Alexandru Croitor Reviewed-by: Dimitrios Apostolou Reviewed-by: Axel Spoerl --- cmake/QtPlatformAndroid.cmake | 4 ++-- cmake/QtTestHelpers.cmake | 32 +++++++++++++++++++++++++++++++- src/tools/androidtestrunner/main.cpp | 4 ++-- 3 files changed, 35 insertions(+), 5 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 991c38bc57..7ac7058131 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -606,6 +606,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(EXISTS "${OPENSSL_ROOT_DIR}/${CMAKE_ANDROID_ARCH_ABI}/libcrypto_3.so") @@ -637,7 +642,8 @@ function(qt_internal_add_test name) "This is fine if OpenSSL was built statically.") 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 "") @@ -842,6 +848,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. # diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index 79506e10cb..defa7500ae 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -118,7 +118,7 @@ struct Options bool helpRequested = false; bool verbose = false; bool skipAddInstallRoot = false; - int timeoutSecs = 480; // 8 minutes + int timeoutSecs = 600; // 10 minutes QString buildPath; QString adbCommand{QStringLiteral("adb")}; QString makeCommand; @@ -270,7 +270,7 @@ static void printHelp() " --activity : The Activity to run. If missing the first\n" " activity from AndroidManifest.qml file will be used.\n" "\n" - " --timeout : Timeout to run the test. Default is 5 minutes.\n" + " --timeout : Timeout to run the test. Default is 10 minutes.\n" "\n" " --skip-install-root: Do not append INSTALL_ROOT=... to the make command.\n" "\n" -- cgit v1.2.3