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 <assam.boudjelthia@qt.io>
This commit is contained in:
Bartlomiej Moskal 2025-01-30 11:02:21 +01:00
parent d7a739bde1
commit b4c82eba03
3 changed files with 32 additions and 0 deletions

View File

@ -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 "")

View File

@ -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.

View File

@ -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();