diff options
author | Bartlomiej Moskal <[email protected]> | 2025-01-30 11:02:21 +0100 |
---|---|---|
committer | Bartlomiej Moskal <[email protected]> | 2025-02-11 22:03:57 +0100 |
commit | b4c82eba03388aa4f9e5b56f633e0e679a3b0123 (patch) | |
tree | 3c2b5f3df2072d27a5384767f8872470df3d4d45 | |
parent | d7a739bde116116ec6cacdb99c3a235705017529 (diff) |
AndroidTestRunner: allow to call additional/extra adb call
This commit adds a new parameter (--pre-test-adb-command) to
AndroidTestRunner. The new parameter allows to pass an extra adb command
which will be called by AndroidTestRunner after installation and before
running the test.
To set the mentioned argument the new parameter for qt_internal_add_test
was proposed: ANDROID_TESTRUNNER_PRE_TEST_ADB_COMMANDS.
The new parameter is needed especially for multimedia screen capture
tests. ScreenCapture feature needs an acceptation of Security Popup. It
can be automatically accepted with additional adb command.
Fixes: QTBUG-132249
Pick-to: 6.9 6.8
Change-Id: Ib70cd05d60d4594961ca68b554c7aae11cf42240
Reviewed-by: Assam Boudjelthia <[email protected]>
-rw-r--r-- | cmake/QtTestHelpers.cmake | 10 | ||||
-rw-r--r-- | src/tools/androidtestrunner/doc/androidtestrunner.qdoc | 2 | ||||
-rw-r--r-- | src/tools/androidtestrunner/main.cpp | 20 |
3 files changed, 32 insertions, 0 deletions
diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index 9cc7c24ef1a..1a3a08f5209 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -232,6 +232,7 @@ function(qt_internal_get_test_arg_definitions optional_args single_value_args mu QML_IMPORTPATH TESTDATA QT_TEST_SERVER_LIST + ANDROID_TESTRUNNER_PRE_TEST_ADB_COMMANDS ${__default_private_args} ${__default_public_args} PARENT_SCOPE @@ -456,6 +457,8 @@ endfunction() # The option forces adding the provided TESTDATA to resources. # MANUAL # The option indicates that the test is a manual test. +# ANDROID_TESTRUNNER_PRE_TEST_ADB_COMMANDS +# Passes --pre-test-adb-command <command> to androidTestRunner. Android specific argument. function(qt_internal_add_test name) qt_internal_get_test_arg_definitions(optional_args single_value_args multi_value_args) @@ -684,6 +687,13 @@ function(qt_internal_add_test name) if(QT_ENABLE_VERBOSE_DEPLOYMENT OR build_environment STREQUAL "ci") list(APPEND extra_test_args "--verbose") endif() + + if(arg_ANDROID_TESTRUNNER_PRE_TEST_ADB_COMMANDS) + foreach(command IN LISTS arg_ANDROID_TESTRUNNER_PRE_TEST_ADB_COMMANDS) + list(APPEND extra_test_args "--pre-test-adb-command" "${command}") + endforeach() + endif() + set(test_working_dir "${CMAKE_CURRENT_BINARY_DIR}") elseif(QNX) set(test_working_dir "") diff --git a/src/tools/androidtestrunner/doc/androidtestrunner.qdoc b/src/tools/androidtestrunner/doc/androidtestrunner.qdoc index 21f231868a4..28c5516b22a 100644 --- a/src/tools/androidtestrunner/doc/androidtestrunner.qdoc +++ b/src/tools/androidtestrunner/doc/androidtestrunner.qdoc @@ -106,6 +106,8 @@ \li \c {--ndk-stack <command-path>}: Specifies the path to the \l {Android: ndk-stack}{ndk-stack} tool for symbolizing crash stack traces. Defaults to the tool path found under \c $ANDROID_NDK_ROOT. + \li \c {--pre-test-adb-command <command>}: call the adb <command> after + installation and before the test run. \li \c {-- <arguments>}: Passes anything after the dashes as test arguments. \li \c --verbose: Prints verbose output. \li \c --help: Displays the help information. diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index 01a20f524bb..ae057a3f0c7 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -49,6 +49,7 @@ struct Options QStringList amStarttestArgs; QString apkPath; QString ndkStackPath; + QList<QStringList> preTestRunAdbCommands; bool showLogcatOutput = false; std::optional<QProcess> stdoutLogger; }; @@ -169,6 +170,12 @@ static bool parseOptions() g_options.helpRequested = true; } else if (argument.compare("--verbose"_L1, Qt::CaseInsensitive) == 0) { g_options.verbose = true; + } else if (argument.compare("--pre-test-adb-command"_L1, Qt::CaseInsensitive) == 0) { + if (i + 1 == arguments.size()) + g_options.helpRequested = true; + else { + g_options.preTestRunAdbCommands += QProcess::splitCommand(arguments.at(++i)); + } } else if (argument.compare("--"_L1, Qt::CaseInsensitive) == 0) { ++i; break; @@ -244,6 +251,9 @@ static void printHelp() "\n" " --verbose: Prints out information during processing.\n" "\n" + " --pre-test-adb-command <command>: call the adb <command> after\n" + " installation and before the test run.\n" + "\n" " --help: Displays this information.\n", qPrintable(QCoreApplication::arguments().at(0)) ); @@ -867,6 +877,16 @@ int main(int argc, char *argv[]) if (!g_testInfo.isPackageInstalled) return EXIT_ERROR; + // Call additional adb command if set after installation and before starting the test + for (const auto &command : g_options.preTestRunAdbCommands) { + QByteArray output; + if (!execAdbCommand(command, &output)) { + qCritical("The pre test ADB command \"%s\" failed with output:\n%s", + qUtf8Printable(command.join(u' ')), output.constData()); + return EXIT_ERROR; + } + } + // Pre test start const QString formattedStartTime = getCurrentTimeString(); |