summaryrefslogtreecommitdiff
path: root/tests/BootImageProfileTest
diff options
context:
space:
mode:
authorMathieu Chartier <mathieuc@google.com>2019-11-05 10:15:45 -0800
committerMathieu Chartier <mathieuc@google.com>2019-11-11 10:52:40 -0800
commit233c33956bab083650b7ef608e8ac9d446dba75a (patch)
tree295f57bb22768b2d5a475cba18e2a65a9bf5f0e2 /tests/BootImageProfileTest
parente619f7ac5144ca4087bac7195e9be5c724cc925f (diff)
Add retry loop for BootImageProfileTest
In case the package manager is not yet started, retry saving the profile up to 20 times to give it time. Should fix test flakiness. Also addresses previous review comment. Bug: 144048260 Bug: 139883463 Test: atest BootImageProfileTest Change-Id: I12e101447d2a42fb0fcad7ad3427750c3ce89a79
Diffstat (limited to 'tests/BootImageProfileTest')
-rw-r--r--tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java84
1 files changed, 49 insertions, 35 deletions
diff --git a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java
index 74aaec1eee34..10f3e54a5f96 100644
--- a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java
+++ b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java
@@ -73,53 +73,67 @@ public class BootImageProfileTest implements IDeviceTest {
res = mTestDevice.executeShellCommand("truncate -s 0 " + SYSTEM_SERVER_PROFILE).trim();
assertTrue(res, res.length() == 0);
// Wait up to 20 seconds for the profile to be saved.
- for (int i = 0; i < 20; ++i) {
+ final int numIterations = 20;
+ for (int i = 1; i <= numIterations; ++i) {
// Force save the profile since we truncated it.
if (forceSaveProfile("system_server")) {
// Might fail if system server is not yet running.
String s = mTestDevice.executeShellCommand(
"wc -c <" + SYSTEM_SERVER_PROFILE).trim();
- if (!"0".equals(s)) {
- break;
+ if ("0".equals(s)) {
+ Thread.sleep(1000);
+ continue;
}
}
+
+ // In case the profile is partially saved, wait an extra second.
Thread.sleep(1000);
- }
- // In case the profile is partially saved, wait an extra second.
- Thread.sleep(1000);
- // Validate that the profile is non empty.
- res = mTestDevice.executeShellCommand("profman --dump-only --profile-file="
- + SYSTEM_SERVER_PROFILE);
- boolean sawFramework = false;
- boolean sawServices = false;
- for (String line : res.split("\n")) {
- if (line.contains("framework.jar")) {
- sawFramework = true; // Legacy
- } else if (line.contains("framework-minus-apex.jar")) {
- sawFramework = true;
- } else if (line.contains("services.jar")) {
- sawServices = true;
+
+ // Validate that the profile is non empty.
+ res = mTestDevice.executeShellCommand("profman --dump-only --profile-file="
+ + SYSTEM_SERVER_PROFILE);
+ boolean sawFramework = false;
+ boolean sawServices = false;
+ for (String line : res.split("\n")) {
+ if (line.contains("framework.jar")) {
+ sawFramework = true;
+ } else if (line.contains("framework-minus-apex.jar")) {
+ sawFramework = true;
+ } else if (line.contains("services.jar")) {
+ sawServices = true;
+ }
+ }
+ if (i == numIterations) {
+ // Only assert for last iteration since there are race conditions where the package
+ // manager might not be started whewn the profile saves.
+ assertTrue("Did not see framework.jar in " + res, sawFramework);
+ assertTrue("Did not see services.jar in " + res, sawServices);
}
- }
- assertTrue("Did not see framework.jar in " + res, sawFramework);
- assertTrue("Did not see services.jar in " + res, sawServices);
+ // Test the profile contents contain common methods for core-oj that would normally be
+ // AOT compiled. Also test that services.jar has PackageManagerService.<init> since the
+ // package manager service should always be created during boot.
+ res = mTestDevice.executeShellCommand(
+ "profman --dump-classes-and-methods --profile-file="
+ + SYSTEM_SERVER_PROFILE + " --apk=/apex/com.android.art/javalib/core-oj.jar"
+ + " --apk=/system/framework/services.jar");
+ boolean sawObjectInit = false;
+ boolean sawPmInit = false;
+ for (String line : res.split("\n")) {
+ if (line.contains("Ljava/lang/Object;-><init>()V")) {
+ sawObjectInit = true;
+ } else if (line.contains("Lcom/android/server/pm/PackageManagerService;-><init>")) {
+ sawPmInit = true;
+ }
+ }
+ if (i == numIterations) {
+ assertTrue("Did not see Object.<init> in " + res, sawObjectInit);
+ assertTrue("Did not see PackageManagerService.<init> in " + res, sawPmInit);
+ }
- // Test the profile contents contain common methods for core-oj that would normally be AOT
- // compiled.
- res = mTestDevice.executeShellCommand("profman --dump-classes-and-methods --profile-file="
- + SYSTEM_SERVER_PROFILE + " --apk=/apex/com.android.art/javalib/core-oj.jar"
- + " --apk=/system/framework/services.jar");
- boolean sawObjectInit = false;
- boolean sawPmInit = false;
- for (String line : res.split("\n")) {
- if (line.contains("Ljava/lang/Object;-><init>()V")) {
- sawObjectInit = true;
- } else if (line.contains("Lcom/android/server/pm/PackageManagerService;-><init>")) {
- sawPmInit = true;
+ if (sawFramework && sawServices && sawObjectInit && sawPmInit) {
+ break; // Asserts passed, exit.
}
}
- assertTrue("Did not see Object.<init> in " + res, sawObjectInit);
- assertTrue("Did not see PackageManagerService.<init> in " + res, sawPmInit);
}
}