Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfc08041 authored by Mathieu Chartier's avatar Mathieu Chartier Committed by Gerrit Code Review
Browse files

Merge changes I52ac80f1,Iba48c173,If0a71607

* changes:
  Make BootImageProfileTest less flaky
  Use shell commands instead of ITestDevice for BootImageProfile test
  Make BootImageProfileTest less flaky
parents 8977dd0b 6f44bd04
Loading
Loading
Loading
Loading
+58 −26
Original line number Diff line number Diff line
@@ -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,16 +42,33 @@ 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.executeShellCommand("getprop dalvik.vm." + property).trim();
        }
    }

    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");
        assertTrue("profile boot class path not enabled", res != null && res.equals("true"));
        res = mTestDevice.getProperty(
                "persist.device_config.runtime_native_boot.profilesystemserver");
        assertTrue("profile system server not enabled", res != null && res.equals("true"));
        String res = getProperty("profilebootclasspath");
        assertTrue("profile boot class path not enabled: " + res, "true".equals(res));
        res = getProperty("profilesystemserver");
        assertTrue("profile system server not enabled: " + res, "true".equals(res));
    }

    private boolean forceSaveProfile(String pkg) throws Exception {
@@ -60,40 +78,54 @@ 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;
        for (int i = 1; i <= numIterations; ++i) {
        final int numIterations = 30;
        String res;
            res = mTestDevice.getProperty(
                    "persist.device_config.runtime_native_boot.profilebootclasspath");
            boolean profileBootClassPath = res != null && res.equals("true");
            res = mTestDevice.getProperty(
                    "persist.device_config.runtime_native_boot.profilesystemserver");
            boolean profileSystemServer = res != null && res.equals("true");
        // Set properties and wait for them to be readable.
        for (int i = 1; i <= numIterations; ++i) {
            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 = mTestDevice.executeShellCommand(
                    "device_config put runtime_native_boot profilebootclasspath true");
            res = mTestDevice.executeShellCommand(
                    "device_config put runtime_native_boot profilesystemserver true");
            setProperty("profilebootclasspath", "true");
            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");
            Thread.sleep(5000);
        assertTrue("start shell: " + res, res.length() == 0);
        for (int i = 1; i <= numIterations; ++i) {
            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: " + pss, profileSystemServer);
                assertTrue("profile boot class path not enabled: " + pbcp, profileBootClassPath);
            }
            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.