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

Commit e70b85f0 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Make BootImageProfileTest less flaky am: 75446bc1 am: f12c84ae am: 3468c29f

Change-Id: Ic6d08ac490b65268df9483b2473ddf614997ac1f
parents 1aa03558 3468c29f
Loading
Loading
Loading
Loading
+50 −17
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ public class BootImageProfileTest implements IDeviceTest {
    private ITestDevice mTestDevice;
    private ITestDevice mTestDevice;
    private static final String SYSTEM_SERVER_PROFILE =
    private static final String SYSTEM_SERVER_PROFILE =
            "/data/misc/profiles/cur/0/android/primary.prof";
            "/data/misc/profiles/cur/0/android/primary.prof";
    private static final boolean USE_PHENOTYPE = false;


    @Override
    @Override
    public void setDevice(ITestDevice testDevice) {
    public void setDevice(ITestDevice testDevice) {
@@ -41,15 +42,32 @@ public class BootImageProfileTest implements IDeviceTest {
        return mTestDevice;
        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.
     * Validate that the boot image profile properties are set.
     */
     */
    public void validateProperties() throws Exception {
    public void validateProperties() throws Exception {
        String res = mTestDevice.getProperty(
        String res = getProperty("profilebootclasspath");
                "persist.device_config.runtime_native_boot.profilebootclasspath");
        assertTrue("profile boot class path not enabled", res != null && res.equals("true"));
        assertTrue("profile boot class path not enabled", res != null && res.equals("true"));
        res = mTestDevice.getProperty(
        res = getProperty("profilesystemserver");
                "persist.device_config.runtime_native_boot.profilesystemserver");
        assertTrue("profile system server not enabled", res != null && res.equals("true"));
        assertTrue("profile system server not enabled", res != null && res.equals("true"));
    }
    }


@@ -67,13 +85,12 @@ public class BootImageProfileTest implements IDeviceTest {
    @Test
    @Test
    public void testSystemServerProfile() throws Exception {
    public void testSystemServerProfile() throws Exception {
        final int numIterations = 20;
        final int numIterations = 20;
        for (int i = 1; i <= numIterations; ++i) {
        String res;
        String res;
            res = mTestDevice.getProperty(
        // Set properties and wait for them to be readable.
                    "persist.device_config.runtime_native_boot.profilebootclasspath");
        for (int i = 1; i <= numIterations; ++i) {
            res = getProperty("profilebootclasspath");
            boolean profileBootClassPath = res != null && res.equals("true");
            boolean profileBootClassPath = res != null && res.equals("true");
            res = mTestDevice.getProperty(
            res = getProperty("profilesystemserver");
                    "persist.device_config.runtime_native_boot.profilesystemserver");
            boolean profileSystemServer = res != null && res.equals("true");
            boolean profileSystemServer = res != null && res.equals("true");
            if (profileBootClassPath && profileSystemServer) {
            if (profileBootClassPath && profileSystemServer) {
                break;
                break;
@@ -83,17 +100,33 @@ public class BootImageProfileTest implements IDeviceTest {
                assertTrue("profile boot class path not enabled", profileSystemServer);
                assertTrue("profile boot class path not enabled", profileSystemServer);
            }
            }


            res = mTestDevice.executeShellCommand(
            res = setProperty("profilebootclasspath", "true");
                    "device_config put runtime_native_boot profilebootclasspath true");
            res = setProperty("profilesystemserver", "true");
            res = mTestDevice.executeShellCommand(
            Thread.sleep(1000);
                    "device_config put runtime_native_boot profilesystemserver true");
        }

        // Restart shell and wait for system boot.
        res = mTestDevice.executeShellCommand("stop");
        res = mTestDevice.executeShellCommand("stop");
        assertTrue("stop shell: " + res, res.length() == 0);
        res = mTestDevice.executeShellCommand("start");
        res = mTestDevice.executeShellCommand("start");
            Thread.sleep(5000);
        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
        // Trunacte the profile before force it to be saved to prevent previous profiles
        // causing the test to pass.
        // causing the test to pass.
        String res;
        res = mTestDevice.executeShellCommand("truncate -s 0 " + SYSTEM_SERVER_PROFILE).trim();
        res = mTestDevice.executeShellCommand("truncate -s 0 " + SYSTEM_SERVER_PROFILE).trim();
        assertTrue(res, res.length() == 0);
        assertTrue(res, res.length() == 0);
        // Wait up to 20 seconds for the profile to be saved.
        // Wait up to 20 seconds for the profile to be saved.