From 44e771cf3b83ed2ab1c2993c741c284c7ffbf6bf Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Tue, 18 Feb 2020 15:31:29 -0800 Subject: [PATCH 1/3] Make BootImageProfileTest less flaky Use the system properties instead of phenotype since GMS can change the values more arbitrarily for PH properties. Test: manual Bug: 149645847 (cherry-picked from commit 599079b3814535b098fde9ffa8589dae1adecede) Merged-In: If0a716075597f45e95b8357480e4b4a7c52fbb2a Change-Id: If0a716075597f45e95b8357480e4b4a7c52fbb2a --- .../BootImageProfileTest.java | 67 ++++++++++++++----- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java index 6684515ec8359..ea6b527b5042a 100644 --- a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java +++ b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java @@ -30,6 +30,7 @@ public class BootImageProfileTest implements IDeviceTest { private ITestDevice mTestDevice; private static final String SYSTEM_SERVER_PROFILE = "/data/misc/profiles/cur/0/android/primary.prof"; + private static final boolean USE_PHENOTYPE = false; @Override public void setDevice(ITestDevice testDevice) { @@ -41,15 +42,32 @@ public class BootImageProfileTest implements IDeviceTest { return mTestDevice; } + private String getProperty(String property) throws Exception { + if (USE_PHENOTYPE) { + return mTestDevice.getProperty("persist.device_config.runtime_native_boot." + + property); + } else { + return mTestDevice.getProperty("dalvik.vm." + property); + } + } + + private String setProperty(String property, String value) throws Exception { + if (USE_PHENOTYPE) { + return mTestDevice.executeShellCommand( + "device_config put runtime_native_boot " + property + " " + value); + } else { + return mTestDevice.executeShellCommand( + "setprop dalvik.vm." + property + " " + value); + } + } + /** * Validate that the boot image profile properties are set. */ public void validateProperties() throws Exception { - String res = mTestDevice.getProperty( - "persist.device_config.runtime_native_boot.profilebootclasspath"); + String res = getProperty("profilebootclasspath"); assertTrue("profile boot class path not enabled", res != null && res.equals("true")); - res = mTestDevice.getProperty( - "persist.device_config.runtime_native_boot.profilesystemserver"); + res = getProperty("profilesystemserver"); assertTrue("profile system server not enabled", res != null && res.equals("true")); } @@ -67,13 +85,12 @@ public class BootImageProfileTest implements IDeviceTest { @Test public void testSystemServerProfile() throws Exception { final int numIterations = 20; + String res; + // Set properties and wait for them to be readable. for (int i = 1; i <= numIterations; ++i) { - String res; - res = mTestDevice.getProperty( - "persist.device_config.runtime_native_boot.profilebootclasspath"); + res = getProperty("profilebootclasspath"); boolean profileBootClassPath = res != null && res.equals("true"); - res = mTestDevice.getProperty( - "persist.device_config.runtime_native_boot.profilesystemserver"); + res = getProperty("profilesystemserver"); boolean profileSystemServer = res != null && res.equals("true"); if (profileBootClassPath && profileSystemServer) { break; @@ -83,17 +100,33 @@ public class BootImageProfileTest implements IDeviceTest { assertTrue("profile boot class path not enabled", profileSystemServer); } - res = mTestDevice.executeShellCommand( - "device_config put runtime_native_boot profilebootclasspath true"); - res = mTestDevice.executeShellCommand( - "device_config put runtime_native_boot profilesystemserver true"); - res = mTestDevice.executeShellCommand("stop"); - res = mTestDevice.executeShellCommand("start"); - Thread.sleep(5000); + res = setProperty("profilebootclasspath", "true"); + res = setProperty("profilesystemserver", "true"); + Thread.sleep(1000); } + + // Restart shell and wait for system boot. + res = mTestDevice.executeShellCommand("stop"); + assertTrue("stop shell: " + res, res.length() == 0); + res = mTestDevice.executeShellCommand("start"); + assertTrue("start shell: " + res, res.length() == 0); + for (int i = 1; i <= numIterations; ++i) { + res = getProperty("profilebootclasspath"); + boolean profileBootClassPath = res != null && res.equals("true"); + res = getProperty("profilesystemserver"); + boolean profileSystemServer = res != null && res.equals("true"); + if (profileBootClassPath && profileSystemServer) { + break; + } + if (i == numIterations) { + assertTrue("profile system server not enabled", profileSystemServer); + assertTrue("profile boot class path not enabled", profileSystemServer); + } + Thread.sleep(1000); + } + // Trunacte the profile before force it to be saved to prevent previous profiles // causing the test to pass. - String res; 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. From a37afa406721c44de4c0ca8c7afcc44d780ae5d4 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Mon, 24 Feb 2020 23:39:42 -0800 Subject: [PATCH 2/3] Use shell commands instead of ITestDevice for BootImageProfile test For some reason, ITestDevice property getting and setting is flaky on GCE. This causes frequent test failures. Test: tested on cuddlefish device Bug: 149802360 (cherry-picked from commit 94d9a21ccb34ab2567ef173e460350220c8ac658) Merged-In: Iba48c173bdea2d55d8f2aa7f0fa382628582fe1c Change-Id: Iba48c173bdea2d55d8f2aa7f0fa382628582fe1c --- .../BootImageProfileTest.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java index ea6b527b5042a..34e6a4b42ac8a 100644 --- a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java +++ b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java @@ -47,7 +47,7 @@ public class BootImageProfileTest implements IDeviceTest { return mTestDevice.getProperty("persist.device_config.runtime_native_boot." + property); } else { - return mTestDevice.getProperty("dalvik.vm." + property); + return mTestDevice.executeShellCommand("getprop dalvik.vm." + property).trim(); } } @@ -66,9 +66,9 @@ public class BootImageProfileTest implements IDeviceTest { */ public void validateProperties() throws Exception { String res = getProperty("profilebootclasspath"); - assertTrue("profile boot class path not enabled", res != null && res.equals("true")); + assertTrue("profile boot class path not enabled: " + res, "true".equals(res)); res = getProperty("profilesystemserver"); - assertTrue("profile system server not enabled", res != null && res.equals("true")); + assertTrue("profile system server not enabled: " + res, "true".equals(res)); } private boolean forceSaveProfile(String pkg) throws Exception { @@ -88,20 +88,20 @@ public class BootImageProfileTest implements IDeviceTest { String res; // Set properties and wait for them to be readable. for (int i = 1; i <= numIterations; ++i) { - res = getProperty("profilebootclasspath"); - boolean profileBootClassPath = res != null && res.equals("true"); - res = getProperty("profilesystemserver"); - boolean profileSystemServer = res != null && res.equals("true"); + String pbcp = getProperty("profilebootclasspath"); + boolean profileBootClassPath = "true".equals(pbcp); + String pss = getProperty("profilesystemserver"); + boolean profileSystemServer = "true".equals(pss); if (profileBootClassPath && profileSystemServer) { break; } if (i == numIterations) { - assertTrue("profile system server not enabled", profileSystemServer); - assertTrue("profile boot class path not enabled", profileSystemServer); + assertTrue("profile system server not enabled: " + pss, profileSystemServer); + assertTrue("profile boot class path not enabled: " + pbcp, profileBootClassPath); } - res = setProperty("profilebootclasspath", "true"); - res = setProperty("profilesystemserver", "true"); + setProperty("profilebootclasspath", "true"); + setProperty("profilesystemserver", "true"); Thread.sleep(1000); } @@ -111,16 +111,16 @@ public class BootImageProfileTest implements IDeviceTest { res = mTestDevice.executeShellCommand("start"); assertTrue("start shell: " + res, res.length() == 0); for (int i = 1; i <= numIterations; ++i) { - res = getProperty("profilebootclasspath"); - boolean profileBootClassPath = res != null && res.equals("true"); - res = getProperty("profilesystemserver"); - boolean profileSystemServer = res != null && res.equals("true"); + String pbcp = getProperty("profilebootclasspath"); + boolean profileBootClassPath = "true".equals(pbcp); + String pss = getProperty("profilesystemserver"); + boolean profileSystemServer = "true".equals(pss); if (profileBootClassPath && profileSystemServer) { break; } if (i == numIterations) { - assertTrue("profile system server not enabled", profileSystemServer); - assertTrue("profile boot class path not enabled", profileSystemServer); + assertTrue("profile system server not enabled: " + pss, profileSystemServer); + assertTrue("profile boot class path not enabled: " + pbcp, profileBootClassPath); } Thread.sleep(1000); } From 6f44bd04927acc92e3f7ccadbc580a7da33f96a9 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Fri, 6 Mar 2020 09:19:42 -0800 Subject: [PATCH 3/3] Make BootImageProfileTest less flaky Number one flake is when the system server process is killed before SIGUSR1. Change this case to be non fatal. Increase number of retry iterations in case the package manager is very slow to start and get a JIT sample. Hopefully fixes the other flake where PackageManagerService. is not seen in the profile. (cherry-picked from commit d5d442ddd9b59528f84ae84b27b05795c04ef7cb) Test: atest BootImageProfileTest Bug: 149802360 Merged-In: I52ac80f15d8efe152dea81b75a82faa4da1b8600 Change-Id: I52ac80f15d8efe152dea81b75a82faa4da1b8600 --- .../com/android/bootimageprofile/BootImageProfileTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java index 34e6a4b42ac8a..9a02bd4054174 100644 --- a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java +++ b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java @@ -78,13 +78,12 @@ public class BootImageProfileTest implements IDeviceTest { return false; } String res = mTestDevice.executeShellCommand("kill -s SIGUSR1 " + pid).trim(); - assertTrue("kill SIGUSR1: " + res, res.length() == 0); - return true; + return res.length() == 0; } @Test public void testSystemServerProfile() throws Exception { - final int numIterations = 20; + final int numIterations = 30; String res; // Set properties and wait for them to be readable. for (int i = 1; i <= numIterations; ++i) {