Loading tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +59 −6 Original line number Diff line number Diff line Loading @@ -185,12 +185,6 @@ public class StagedRollbackTest { */ @Test public void testNativeWatchdogTriggersRollback_Phase1() throws Exception { // When multiple staged sessions are installed on a device which doesn't support checkpoint, // only the 1st one will prevail. We have to check no other rollbacks available to ensure // TestApp.A is always the 1st and the only one to commit so rollback can work as intended. // If there are leftover rollbacks from previous tests, this assertion will fail. assertThat(RollbackUtils.getRollbackManager().getAvailableRollbacks()).isEmpty(); Uninstall.packages(TestApp.A); Install.single(TestApp.A1).commit(); assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); Loading Loading @@ -220,6 +214,64 @@ public class StagedRollbackTest { TestApp.A)).isNotNull(); } /** * Stage install an apk with rollback that will be later triggered by unattributable crash. */ @Test public void testNativeWatchdogTriggersRollbackForAll_Phase1() throws Exception { Uninstall.packages(TestApp.A); Install.single(TestApp.A1).commit(); assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); Install.single(TestApp.A2).setEnableRollback().setStaged().commit(); } /** * Verify the rollback is available and then install another package with rollback. */ @Test public void testNativeWatchdogTriggersRollbackForAll_Phase2() throws Exception { assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNotNull(); // Install another package with rollback Uninstall.packages(TestApp.B); Install.single(TestApp.B1).commit(); assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1); Install.single(TestApp.B2).setEnableRollback().setStaged().commit(); } /** * Verify the rollbacks are available. */ @Test public void testNativeWatchdogTriggersRollbackForAll_Phase3() throws Exception { assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2); assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNotNull(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.B)).isNotNull(); } /** * Verify the rollbacks are committed after crashing. */ @Test public void testNativeWatchdogTriggersRollbackForAll_Phase4() throws Exception { assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), TestApp.A)).isNotNull(); assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), TestApp.B)).isNotNull(); } @Test public void testNetworkFailedRollback_Phase1() throws Exception { // Remove available rollbacks and uninstall NetworkStack on /data/ Loading Loading @@ -438,6 +490,7 @@ public class StagedRollbackTest { RollbackManager rm = RollbackUtils.getRollbackManager(); rm.getAvailableRollbacks().stream().flatMap(info -> info.getPackages().stream()) .map(info -> info.getPackageName()).forEach(rm::expireRollbackForPackage); assertThat(RollbackUtils.getRollbackManager().getAvailableRollbacks()).isEmpty(); } private static void runShellCommand(String cmd) { Loading tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +32 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { @Before public void setUp() throws Exception { getDevice().reboot(); runPhase("testCleanUp"); } @After Loading @@ -75,7 +76,6 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { @Test public void testNativeWatchdogTriggersRollback() throws Exception { //Stage install ModuleMetadata package - this simulates a Mainline module update runPhase("testNativeWatchdogTriggersRollback_Phase1"); // Reboot device to activate staged package Loading @@ -101,6 +101,37 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { runPhase("testNativeWatchdogTriggersRollback_Phase3"); } @Test public void testNativeWatchdogTriggersRollbackForAll() throws Exception { // Install a package with rollback enabled. runPhase("testNativeWatchdogTriggersRollbackForAll_Phase1"); getDevice().reboot(); // Once previous staged install is applied, install another package runPhase("testNativeWatchdogTriggersRollbackForAll_Phase2"); getDevice().reboot(); // Verify the new staged install has also been applied successfully. runPhase("testNativeWatchdogTriggersRollbackForAll_Phase3"); // crash system_server enough times to trigger a rollback crashProcess("system_server", NATIVE_CRASHES_THRESHOLD); // Rollback should be committed automatically now. // Give time for rollback to be committed. This could take a while, // because we need all of the following to happen: // 1. system_server comes back up and boot completes. // 2. Rollback health observer detects updatable crashing signal. // 3. Staged rollback session becomes ready. // 4. Device actually reboots. // So we give a generous timeout here. assertTrue(getDevice().waitForDeviceNotAvailable(TimeUnit.MINUTES.toMillis(5))); getDevice().waitForDeviceAvailable(); // verify all available rollbacks have been committed runPhase("testNativeWatchdogTriggersRollbackForAll_Phase4"); } /** * Tests failed network health check triggers watchdog staged rollbacks. */ Loading Loading
tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +59 −6 Original line number Diff line number Diff line Loading @@ -185,12 +185,6 @@ public class StagedRollbackTest { */ @Test public void testNativeWatchdogTriggersRollback_Phase1() throws Exception { // When multiple staged sessions are installed on a device which doesn't support checkpoint, // only the 1st one will prevail. We have to check no other rollbacks available to ensure // TestApp.A is always the 1st and the only one to commit so rollback can work as intended. // If there are leftover rollbacks from previous tests, this assertion will fail. assertThat(RollbackUtils.getRollbackManager().getAvailableRollbacks()).isEmpty(); Uninstall.packages(TestApp.A); Install.single(TestApp.A1).commit(); assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); Loading Loading @@ -220,6 +214,64 @@ public class StagedRollbackTest { TestApp.A)).isNotNull(); } /** * Stage install an apk with rollback that will be later triggered by unattributable crash. */ @Test public void testNativeWatchdogTriggersRollbackForAll_Phase1() throws Exception { Uninstall.packages(TestApp.A); Install.single(TestApp.A1).commit(); assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); Install.single(TestApp.A2).setEnableRollback().setStaged().commit(); } /** * Verify the rollback is available and then install another package with rollback. */ @Test public void testNativeWatchdogTriggersRollbackForAll_Phase2() throws Exception { assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNotNull(); // Install another package with rollback Uninstall.packages(TestApp.B); Install.single(TestApp.B1).commit(); assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1); Install.single(TestApp.B2).setEnableRollback().setStaged().commit(); } /** * Verify the rollbacks are available. */ @Test public void testNativeWatchdogTriggersRollbackForAll_Phase3() throws Exception { assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2); assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(2); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.A)).isNotNull(); assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TestApp.B)).isNotNull(); } /** * Verify the rollbacks are committed after crashing. */ @Test public void testNativeWatchdogTriggersRollbackForAll_Phase4() throws Exception { assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1); assertThat(InstallUtils.getInstalledVersion(TestApp.B)).isEqualTo(1); RollbackManager rm = RollbackUtils.getRollbackManager(); assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), TestApp.A)).isNotNull(); assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), TestApp.B)).isNotNull(); } @Test public void testNetworkFailedRollback_Phase1() throws Exception { // Remove available rollbacks and uninstall NetworkStack on /data/ Loading Loading @@ -438,6 +490,7 @@ public class StagedRollbackTest { RollbackManager rm = RollbackUtils.getRollbackManager(); rm.getAvailableRollbacks().stream().flatMap(info -> info.getPackages().stream()) .map(info -> info.getPackageName()).forEach(rm::expireRollbackForPackage); assertThat(RollbackUtils.getRollbackManager().getAvailableRollbacks()).isEmpty(); } private static void runShellCommand(String cmd) { Loading
tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +32 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { @Before public void setUp() throws Exception { getDevice().reboot(); runPhase("testCleanUp"); } @After Loading @@ -75,7 +76,6 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { @Test public void testNativeWatchdogTriggersRollback() throws Exception { //Stage install ModuleMetadata package - this simulates a Mainline module update runPhase("testNativeWatchdogTriggersRollback_Phase1"); // Reboot device to activate staged package Loading @@ -101,6 +101,37 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { runPhase("testNativeWatchdogTriggersRollback_Phase3"); } @Test public void testNativeWatchdogTriggersRollbackForAll() throws Exception { // Install a package with rollback enabled. runPhase("testNativeWatchdogTriggersRollbackForAll_Phase1"); getDevice().reboot(); // Once previous staged install is applied, install another package runPhase("testNativeWatchdogTriggersRollbackForAll_Phase2"); getDevice().reboot(); // Verify the new staged install has also been applied successfully. runPhase("testNativeWatchdogTriggersRollbackForAll_Phase3"); // crash system_server enough times to trigger a rollback crashProcess("system_server", NATIVE_CRASHES_THRESHOLD); // Rollback should be committed automatically now. // Give time for rollback to be committed. This could take a while, // because we need all of the following to happen: // 1. system_server comes back up and boot completes. // 2. Rollback health observer detects updatable crashing signal. // 3. Staged rollback session becomes ready. // 4. Device actually reboots. // So we give a generous timeout here. assertTrue(getDevice().waitForDeviceNotAvailable(TimeUnit.MINUTES.toMillis(5))); getDevice().waitForDeviceAvailable(); // verify all available rollbacks have been committed runPhase("testNativeWatchdogTriggersRollbackForAll_Phase4"); } /** * Tests failed network health check triggers watchdog staged rollbacks. */ Loading