diff --git a/tests/hostside/helper/java/android/virt/test/VirtualizationTestCaseBase.java b/tests/hostside/helper/java/android/virt/test/VirtualizationTestCaseBase.java index df3e247a..440ae18c 100644 --- a/tests/hostside/helper/java/android/virt/test/VirtualizationTestCaseBase.java +++ b/tests/hostside/helper/java/android/virt/test/VirtualizationTestCaseBase.java @@ -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