From 03006555ec872935d78fbb41f02c4cef3a5cab51 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Wed, 23 Oct 2024 17:13:01 +0300 Subject: [PATCH] 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 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 --- src/tools/androidtestrunner/main.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index 8269a7e411e..5e867ce2f07 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -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()