[test] Fix rootMicrodroid() to block till device is online.

rootMicrodroid() restarts the adbd, which can cause the following
commands to fail. Run `adb shell true` on microdroid with retries before
returning

b: b/227443903
Test: atest MicrodroidTestCase
Change-Id: I42ba4559191d9e16e9d47bb4d04bd346b3de6958
This commit is contained in:
Shikha Panwar 2022-04-08 16:58:20 +00:00
parent 4bdd2e837d
commit 1509817e72
1 changed files with 17 additions and 1 deletions

View File

@ -133,6 +133,19 @@ public abstract class VirtualizationTestCaseBase extends BaseHostJUnit4Test {
return result.getStdout().trim();
}
// Same as runOnMicrodroid, but keeps retrying on error till timeout
private static String runOnMicrodroidRetryingOnFailure(String... cmd) {
final long timeoutMs = 30000; // 30 sec. Microdroid is extremely slow on GCE-on-CF.
int attempts = (int) MICRODROID_ADB_CONNECT_TIMEOUT_MINUTES * 60 * 1000 / 500;
CommandResult result = RunUtil.getDefault()
.runTimedCmdRetry(timeoutMs, 500, attempts,
"adb", "-s", MICRODROID_SERIAL, "shell", join(cmd));
if (result.getStatus() != CommandStatus.SUCCESS) {
fail(join(cmd) + " has failed: " + result);
}
return result.getStdout().trim();
}
// Same as runOnMicrodroid, but returns null on error.
public static String tryRunOnMicrodroid(String... cmd) {
CommandResult result = runOnMicrodroidForResult(cmd);
@ -332,13 +345,16 @@ public abstract class VirtualizationTestCaseBase extends BaseHostJUnit4Test {
public static void rootMicrodroid() {
runOnHost("adb", "-s", MICRODROID_SERIAL, "root");
runOnHostWithTimeout(
MICRODROID_ADB_CONNECT_TIMEOUT_MINUTES * 60 * 1000,
"adb",
"-s",
MICRODROID_SERIAL,
"wait-for-device");
// There have been tests when adb wait-for-device succeeded but the following command
// fails with error: closed. Hence, we run adb shell true in microdroid with retries
// before returning.
runOnMicrodroidRetryingOnFailure("true");
}
// Establish an adb connection to microdroid by letting Android forward the connection to