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

Commit 6d9107a4 authored by Samiul Islam's avatar Samiul Islam
Browse files

Test apexd behaves correctly when not in fs-checkpoint mode

This CL contains two tests:
1) When fs-checkpoint-mode is false, but fs-rollback-mode is true
2) When both modes are false

Bug: 193648282
Test: atest StagedInstallInternalTest
Change-Id: I9c96296343a7f39a65de9e06e8a07d765f832044
parent 0077afd8
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
@@ -195,6 +195,47 @@ public class StagedInstallInternalTest {
        assertSessionFailedWithMessage(sessionId, "has unexpected SHA512 hash");
    }

    @Test
    public void testActiveApexIsRevertedOnCheckpointRollback_Prepare() throws Exception {
        int sessionId = Install.single(TestApp.Apex2).setStaged().commit();
        assertSessionReady(sessionId);
        storeSessionId(sessionId);
    }

    @Test
    public void testActiveApexIsRevertedOnCheckpointRollback_Commit() throws Exception {
        // Verify apex installed during preparation was successful
        int sessionId = retrieveLastSessionId();
        assertSessionApplied(sessionId);
        assertThat(InstallUtils.getInstalledVersion(SHIM_APEX_PACKAGE_NAME)).isEqualTo(2);
        // Commit a new staged session
        sessionId = Install.single(TestApp.Apex3).setStaged().commit();
        assertSessionReady(sessionId);
        storeSessionId(sessionId);
    }

    @Test
    public void testActiveApexIsRevertedOnCheckpointRollback_VerifyPostReboot() throws Exception {
        int sessionId = retrieveLastSessionId();
        assertSessionFailed(sessionId);
        assertThat(InstallUtils.getInstalledVersion(SHIM_APEX_PACKAGE_NAME)).isEqualTo(2);
    }

    @Test
    public void testApexIsNotActivatedIfNotInCheckpointMode_Commit() throws Exception {
        int sessionId = Install.single(TestApp.Apex2).setStaged().commit();
        assertSessionReady(sessionId);
        storeSessionId(sessionId);
        assertThat(InstallUtils.getInstalledVersion(SHIM_APEX_PACKAGE_NAME)).isEqualTo(1);
    }

    @Test
    public void testApexIsNotActivatedIfNotInCheckpointMode_VerifyPostReboot() throws Exception {
        int sessionId = retrieveLastSessionId();
        assertSessionFailed(sessionId);
        assertThat(InstallUtils.getInstalledVersion(SHIM_APEX_PACKAGE_NAME)).isEqualTo(1);
    }

    @Test
    public void testRebootlessUpdates() throws Exception {
        InstallUtils.dropShellPermissionIdentity();
@@ -257,6 +298,18 @@ public class StagedInstallInternalTest {
        }
    }

    private static void assertSessionApplied(int sessionId) {
        assertSessionState(sessionId, (session) -> {
            assertThat(session.isStagedSessionApplied()).isTrue();
        });
    }

    private static void assertSessionFailed(int sessionId) {
        assertSessionState(sessionId, (session) -> {
            assertThat(session.isStagedSessionFailed()).isTrue();
        });
    }

    private static void assertSessionFailedWithMessage(int sessionId, String msg) {
        assertSessionState(sessionId, (session) -> {
            assertThat(session.isStagedSessionFailed()).isTrue();
+43 −0
Original line number Diff line number Diff line
@@ -345,6 +345,49 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        runPhase("testApexActivationFailureIsCapturedInSession_Verify");
    }

    @Test
    public void testActiveApexIsRevertedOnCheckpointRollback() throws Exception {
        assumeTrue("Device does not support updating APEX",
                mHostUtils.isApexUpdateSupported());
        assumeTrue("Device does not support file-system checkpoint",
                mHostUtils.isCheckpointSupported());

        // Install something so that /data/apex/active is not empty
        runPhase("testActiveApexIsRevertedOnCheckpointRollback_Prepare");
        getDevice().reboot();

        // Stage another session which will be installed during fs-rollback mode
        runPhase("testActiveApexIsRevertedOnCheckpointRollback_Commit");

        // Set checkpoint to 0 so that we enter fs-rollback mode immediately on reboot
        getDevice().enableAdbRoot();
        getDevice().executeShellCommand("vdc checkpoint startCheckpoint 0");
        getDevice().disableAdbRoot();
        getDevice().reboot();

        // Verify that session was reverted and we have fallen back to
        // apex installed during preparation stage.
        runPhase("testActiveApexIsRevertedOnCheckpointRollback_VerifyPostReboot");
    }

    @Test
    public void testApexIsNotActivatedIfNotInCheckpointMode() throws Exception {
        assumeTrue("Device does not support updating APEX",
                mHostUtils.isApexUpdateSupported());
        assumeTrue("Device does not support file-system checkpoint",
                mHostUtils.isCheckpointSupported());

        runPhase("testApexIsNotActivatedIfNotInCheckpointMode_Commit");
        // Delete checkpoint file in /metadata so that device thinks
        // fs-checkpointing was never activated
        getDevice().enableAdbRoot();
        getDevice().executeShellCommand("rm /metadata/vold/checkpoint");
        getDevice().disableAdbRoot();
        getDevice().reboot();
        // Verify that session was not installed when not in fs-checkpoint mode
        runPhase("testApexIsNotActivatedIfNotInCheckpointMode_VerifyPostReboot");
    }

    @Test
    public void testRebootlessUpdates() throws Exception {
        pushTestApex("test.rebootless_apex_v1.apex");