AndroidTestRunner: retry check for running device few times

Try to check if the device is running few times while waiting
for the app to finish, just in case the adb ps command fails
for some reason while the app is actually still running.

Also, use ps -p <pid> to directly return only pid and avoiding
to filter out all the other processes with grep. grep can be then
used to only filter out the test package name and leaving out the
ps header.

Pick-to: 6.8
Fixes: QTBUG-127488
Change-Id: I85fe61106381fd1a7a26ef6347f8ab4a4a6678bb
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
Assam Boudjelthia 2024-10-23 17:13:01 +03:00
parent 1347ca99a3
commit 03006555ec

View File

@ -455,12 +455,21 @@ static bool obtainPid() {
}
static bool isRunning() {
QByteArray output;
const QStringList psArgs = { "shell"_L1, "ps | grep ' %1'"_L1.arg(g_options.package) };
if (!execAdbCommand(psArgs, &output, false))
if (g_testInfo.pid < 1)
return false;
return output.indexOf(QLatin1StringView(" " + g_options.package.toUtf8())) > -1;
QByteArray output;
const QStringList psArgs = { "shell"_L1, "ps"_L1, "-p"_L1, QString::number(g_testInfo.pid),
"|"_L1, "grep"_L1, "-o"_L1, " %1$"_L1.arg(g_options.package) };
bool psSuccess = false;
for (int i = 1; i <= 3; ++i) {
psSuccess = execAdbCommand(psArgs, &output, false);
if (psSuccess)
break;
QThread::msleep(250);
}
return psSuccess && output.trimmed() == g_options.package.toUtf8();
}
static void waitForStartedAndFinished()