Merge changes I3186d27c,I54f28f54

* changes:
  Code cleanup: StagedRollbackTest (2/n)
  Code cleanup: StagedRollbackTest (1/n)
This commit is contained in:
TreeHugger Robot
2019-10-16 12:24:42 +00:00
committed by Android (Google) Code Review
2 changed files with 37 additions and 35 deletions

View File

@@ -92,7 +92,7 @@ public class StagedRollbackTest {
* Enable rollback phase.
*/
@Test
public void testBadApkOnlyEnableRollback() throws Exception {
public void testBadApkOnly_Phase1() throws Exception {
Uninstall.packages(TestApp.A);
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(-1);
@@ -101,9 +101,6 @@ public class StagedRollbackTest {
InstallUtils.processUserData(TestApp.A);
Install.single(TestApp.ACrashing2).setEnableRollback().setStaged().commit();
// At this point, the host test driver will reboot the device and run
// testBadApkOnlyConfirmEnableRollback().
}
/**
@@ -111,7 +108,7 @@ public class StagedRollbackTest {
* Confirm that rollback was successfully enabled.
*/
@Test
public void testBadApkOnlyConfirmEnableRollback() throws Exception {
public void testBadApkOnly_Phase2() throws Exception {
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
InstallUtils.processUserData(TestApp.A);
@@ -122,9 +119,6 @@ public class StagedRollbackTest {
assertThat(rollback).packagesContainsExactly(
Rollback.from(TestApp.A2).to(TestApp.A1));
assertThat(rollback.isStaged()).isTrue();
// At this point, the host test driver will run
// testBadApkOnlyTriggerRollback().
}
/**
@@ -133,15 +127,14 @@ public class StagedRollbackTest {
* rebooting the test out from under it.
*/
@Test
public void testBadApkOnlyTriggerRollback() throws Exception {
public void testBadApkOnly_Phase3() throws Exception {
// Crash TestApp.A PackageWatchdog#TRIGGER_FAILURE_COUNT times to trigger rollback
RollbackUtils.sendCrashBroadcast(TestApp.A, 5);
// We expect the device to be rebooted automatically. Wait for that to
// happen. At that point, the host test driver will wait for the
// device to come back up and run testApkOnlyConfirmRollback().
// We expect the device to be rebooted automatically. Wait for that to happen.
Thread.sleep(30 * 1000);
// Raise an error anyway if reboot didn't happen.
fail("watchdog did not trigger reboot");
}
@@ -150,7 +143,7 @@ public class StagedRollbackTest {
* Confirm rollback phase.
*/
@Test
public void testBadApkOnlyConfirmRollback() throws Exception {
public void testBadApkOnly_Phase4() throws Exception {
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
InstallUtils.processUserData(TestApp.A);
@@ -177,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(
@@ -192,6 +188,26 @@ public class StagedRollbackTest {
+ metadataApkPath);
}
/**
* Verify the rollback is available.
*/
@Test
public void testNativeWatchdogTriggersRollback_Phase2() throws Exception {
RollbackManager rm = RollbackUtils.getRollbackManager();
assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
MODULE_META_DATA_PACKAGE)).isNotNull();
}
/**
* Verify the rollback is committed after crashing.
*/
@Test
public void testNativeWatchdogTriggersRollback_Phase3() throws Exception {
RollbackManager rm = RollbackUtils.getRollbackManager();
assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
MODULE_META_DATA_PACKAGE)).isNotNull();
}
@Test
public void assertNetworkStackRollbackAvailable() throws Exception {
RollbackManager rm = RollbackUtils.getRollbackManager();
@@ -213,20 +229,6 @@ public class StagedRollbackTest {
getNetworkStackPackageName())).isNull();
}
@Test
public void assertModuleMetadataRollbackAvailable() throws Exception {
RollbackManager rm = RollbackUtils.getRollbackManager();
assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(),
MODULE_META_DATA_PACKAGE)).isNotNull();
}
@Test
public void assertModuleMetadataRollbackCommitted() throws Exception {
RollbackManager rm = RollbackUtils.getRollbackManager();
assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(),
MODULE_META_DATA_PACKAGE)).isNotNull();
}
private String getNetworkStackPackageName() {
Intent intent = new Intent(NETWORK_STACK_CONNECTOR_CLASS);
ComponentName comp = intent.resolveSystemService(

View File

@@ -68,35 +68,35 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
*/
@Test
public void testBadApkOnly() throws Exception {
runPhase("testBadApkOnlyEnableRollback");
runPhase("testBadApkOnly_Phase1");
getDevice().reboot();
runPhase("testBadApkOnlyConfirmEnableRollback");
runPhase("testBadApkOnly_Phase2");
try {
// This is expected to fail due to the device being rebooted out
// from underneath the test. If this fails for reasons other than
// the device reboot, those failures should result in failure of
// the testApkOnlyConfirmRollback phase.
CLog.logAndDisplay(LogLevel.INFO, "testBadApkOnlyTriggerRollback is expected to fail");
runPhase("testBadApkOnlyTriggerRollback");
runPhase("testBadApkOnly_Phase3");
} catch (AssertionError e) {
// AssertionError is expected.
}
getDevice().waitForDeviceAvailable();
runPhase("testBadApkOnlyConfirmRollback");
runPhase("testBadApkOnly_Phase4");
}
@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");
}
/**