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

Commit f0a42771 authored by JW Wang's avatar JW Wang
Browse files

Code cleanup: StagedRollbackTest (2/n)

Rename device side methods to testNativeWatchdogTriggersRollback_PhaseN
to show that they are grouped and coordinated by the same host side method.

Also put related methods together for readability.

Bug: 142697546
Test: atest StagedRollbackTest
Change-Id: I3186d27c4d3c5176f72d72f1682ed46ae0cb62ea
parent fa4c6710
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -170,8 +170,11 @@ public class StagedRollbackTest {
                        networkStack)).isNull();
    }

    /**
     * Stage install ModuleMetadata package to simulate a Mainline module update.
     */
    @Test
    public void installModuleMetadataPackage() throws Exception {
    public void testNativeWatchdogTriggersRollback_Phase1() throws Exception {
        resetModuleMetadataPackage();
        Context context = InstrumentationRegistry.getContext();
        PackageInfo metadataPackageInfo = context.getPackageManager().getPackageInfo(
@@ -185,39 +188,45 @@ public class StagedRollbackTest {
                + metadataApkPath);
    }

    /**
     * Verify the rollback is available.
     */
    @Test
    public void assertNetworkStackRollbackAvailable() throws Exception {
    public void testNativeWatchdogTriggersRollback_Phase2() throws Exception {
        RollbackManager rm = RollbackUtils.getRollbackManager();
        assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
                        getNetworkStackPackageName())).isNotNull();
                        MODULE_META_DATA_PACKAGE)).isNotNull();
    }

    /**
     * Verify the rollback is committed after crashing.
     */
    @Test
    public void assertNetworkStackRollbackCommitted() throws Exception {
    public void testNativeWatchdogTriggersRollback_Phase3() throws Exception {
        RollbackManager rm = RollbackUtils.getRollbackManager();
        assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
                        getNetworkStackPackageName())).isNotNull();
                        MODULE_META_DATA_PACKAGE)).isNotNull();
    }

    @Test
    public void assertNoNetworkStackRollbackCommitted() throws Exception {
    public void assertNetworkStackRollbackAvailable() throws Exception {
        RollbackManager rm = RollbackUtils.getRollbackManager();
        assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
                        getNetworkStackPackageName())).isNull();
        assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
                        getNetworkStackPackageName())).isNotNull();
    }

    @Test
    public void assertModuleMetadataRollbackAvailable() throws Exception {
    public void assertNetworkStackRollbackCommitted() throws Exception {
        RollbackManager rm = RollbackUtils.getRollbackManager();
        assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
                        MODULE_META_DATA_PACKAGE)).isNotNull();
        assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
                        getNetworkStackPackageName())).isNotNull();
    }

    @Test
    public void assertModuleMetadataRollbackCommitted() throws Exception {
    public void assertNoNetworkStackRollbackCommitted() throws Exception {
        RollbackManager rm = RollbackUtils.getRollbackManager();
        assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
                        MODULE_META_DATA_PACKAGE)).isNotNull();
                        getNetworkStackPackageName())).isNull();
    }

    private String getNetworkStackPackageName() {
+3 −3
Original line number Diff line number Diff line
@@ -90,13 +90,13 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
    @Test
    public void testNativeWatchdogTriggersRollback() throws Exception {
        //Stage install ModuleMetadata package - this simulates a Mainline module update
        runPhase("installModuleMetadataPackage");
        runPhase("testNativeWatchdogTriggersRollback_Phase1");

        // Reboot device to activate staged package
        getDevice().reboot();
        getDevice().waitForDeviceAvailable();

        runPhase("assertModuleMetadataRollbackAvailable");
        runPhase("testNativeWatchdogTriggersRollback_Phase2");

        // crash system_server enough times to trigger a rollback
        crashProcess("system_server", NATIVE_CRASHES_THRESHOLD);
@@ -113,7 +113,7 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
        getDevice().waitForDeviceAvailable();

        // verify rollback committed
        runPhase("assertModuleMetadataRollbackCommitted");
        runPhase("testNativeWatchdogTriggersRollback_Phase3");
    }

    /**