diff options
author | Samiul Islam <samiul@google.com> | 2021-07-16 11:12:59 +0100 |
---|---|---|
committer | Samiul Islam <samiul@google.com> | 2021-07-19 13:54:57 +0100 |
commit | 6d9107a468dac4a963891e62234dbe3b0b463692 (patch) | |
tree | b4fb7e76480c77ab0c455233b0250b08d4637004 /tests | |
parent | 0077afd88a42326767982d18812ccb5aa6de64ae (diff) |
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
Diffstat (limited to 'tests')
2 files changed, 96 insertions, 0 deletions
diff --git a/tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java b/tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java index 9cdaef75c491..738e68e33674 100644 --- a/tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java +++ b/tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java @@ -196,6 +196,47 @@ public class StagedInstallInternalTest { } @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(); InstallUtils.adoptShellPermissionIdentity(Manifest.permission.INSTALL_PACKAGE_UPDATES); @@ -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(); diff --git a/tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java b/tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java index e19f97b6c045..3bd3767ac6d9 100644 --- a/tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java +++ b/tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java @@ -346,6 +346,49 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test { } @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"); runPhase("testRebootlessUpdates"); |