diff --git a/cmake/QtPlatformAndroid.cmake b/cmake/QtPlatformAndroid.cmake index 65095de3293..b396b76881a 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 4978f955382..9bde3920776 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. # diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index fb4e6413905..35a48c3ffcc 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -115,7 +115,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; @@ -267,7 +267,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"