Loading tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTestUtils.java +41 −6 Original line number Diff line number Diff line Loading @@ -340,16 +340,26 @@ class RollbackTestUtils { } /** * Asserts that the given RollbackInfo has a single package with expected * package name and versions. * Asserts that the given RollbackInfo has the given packages with expected * package names and all are rolled to and from the same given versions. */ static void assertRollbackInfoEquals(String packageName, static void assertRollbackInfoEquals(String[] packageNames, long versionRolledBackFrom, long versionRolledBackTo, RollbackInfo info, VersionedPackage... causePackages) { assertNotNull(info); assertEquals(1, info.getPackages().size()); assertPackageRollbackInfoEquals(packageName, versionRolledBackFrom, versionRolledBackTo, info.getPackages().get(0)); assertEquals(packageNames.length, info.getPackages().size()); int foundPackages = 0; for (String packageName : packageNames) { for (PackageRollbackInfo pkgRollbackInfo : info.getPackages()) { if (packageName.equals(pkgRollbackInfo.getPackageName())) { foundPackages++; assertPackageRollbackInfoEquals(packageName, versionRolledBackFrom, versionRolledBackTo, pkgRollbackInfo); break; } } } assertEquals(packageNames.length, foundPackages); assertEquals(causePackages.length, info.getCausePackages().size()); for (int i = 0; i < causePackages.length; ++i) { assertEquals(causePackages[i].getPackageName(), Loading @@ -359,6 +369,18 @@ class RollbackTestUtils { } } /** * Asserts that the given RollbackInfo has a single package with expected * package name and versions. */ static void assertRollbackInfoEquals(String packageName, long versionRolledBackFrom, long versionRolledBackTo, RollbackInfo info, VersionedPackage... causePackages) { String[] packageNames = {packageName}; assertRollbackInfoEquals(packageNames, versionRolledBackFrom, versionRolledBackTo, info, causePackages); } /** * Waits for the given session to be marked as ready. * Throws an assertion if the session fails. Loading Loading @@ -453,4 +475,17 @@ class RollbackTestUtils { fail(result); } } /** * Return the rollback info for a recently committed rollback, by matching the rollback id, or * return null if no matching rollback is found. */ static RollbackInfo getRecentlyCommittedRollbackInfoById(int getRollbackId) { for (RollbackInfo info : getRollbackManager().getRecentlyCommittedRollbacks()) { if (info.getRollbackId() == getRollbackId) { return info; } } return null; } } tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +89 −17 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.tests.rollback; import static com.android.tests.rollback.RollbackTestUtils.assertRollbackInfoEquals; import static com.android.tests.rollback.RollbackTestUtils.getRecentlyCommittedRollbackInfoById; import static com.android.tests.rollback.RollbackTestUtils.getUniqueRollbackInfoForPackage; import android.Manifest; Loading @@ -25,7 +26,6 @@ import android.content.rollback.RollbackManager; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.After; Loading @@ -47,6 +47,8 @@ public class StagedRollbackTest { private static final String TAG = "RollbackTest"; private static final String TEST_APP_A = "com.android.tests.rollback.testapp.A"; private static final String TEST_APP_A_V1 = "RollbackTestAppAv1.apk"; private static final String TEST_APP_A_V2 = "RollbackTestAppAv2.apk"; private static final String TEST_APEX_PKG = "com.android.tests.rollback.testapex"; private static final String TEST_APEX_V1 = "com.android.tests.rollback.testapex.RollbackTestApexV1.apex"; Loading Loading @@ -82,11 +84,11 @@ public class StagedRollbackTest { RollbackTestUtils.uninstall(TEST_APP_A); assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.install("RollbackTestAppAv1.apk", false); RollbackTestUtils.install(TEST_APP_A_V1, false); assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.processUserData(TEST_APP_A); RollbackTestUtils.installStaged(true, "RollbackTestAppAv2.apk"); RollbackTestUtils.installStaged(true, TEST_APP_A_V2); // At this point, the host test driver will reboot the device and run // testApkOnlyCommitRollback(). Loading Loading @@ -141,6 +143,86 @@ public class StagedRollbackTest { assertNotEquals(-1, rollback.getCommittedSessionId()); } /** * Test rollbacks of staged installs an apk and an apex. * Prepare apex (and apk) phase. */ @Test public void testApkAndApexPrepare() throws Exception { RollbackTestUtils.uninstall(TEST_APP_A); assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); // Note: can't uninstall the apex. See note in #testApexOnlyPrepareApex(). RollbackTestUtils.installStaged(false, TEST_APP_A_V1, TEST_APEX_V1); // At this point, the host test driver will reboot the device and run // testApkAndApexEnableRollback(). } /** * Test rollbacks of staged installs an apk and an apex. * Enable rollback phase. */ @Test public void testApkAndApexEnableRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.installStaged(true, TEST_APP_A_V2, TEST_APEX_V2); // At this point, the host test driver will reboot the device and run // testApkAndApexCommitRollback(). } /** * Test rollbacks of staged installs an apk and an apex. * Commit rollback phase. */ @Test public void testApkAndApexCommitRollback() throws Exception { assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.processUserData(TEST_APP_A); RollbackManager rm = RollbackTestUtils.getRollbackManager(); RollbackInfo rollback = getUniqueRollbackInfoForPackage( rm.getAvailableRollbacks(), TEST_APP_A); String[] packagesNames = {TEST_APEX_PKG, TEST_APP_A}; assertRollbackInfoEquals(packagesNames, 2, 1, rollback); assertTrue(rollback.isStaged()); RollbackTestUtils.rollback(rollback.getRollbackId()); RollbackInfo committed = getRecentlyCommittedRollbackInfoById(rollback.getRollbackId()); assertRollbackInfoEquals(packagesNames, 2, 1, committed); assertTrue(committed.isStaged()); assertNotEquals(-1, committed.getCommittedSessionId()); RollbackTestUtils.waitForSessionReady(committed.getCommittedSessionId()); // The apex and apk should not be rolled back until after reboot. assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); // At this point, the host test driver will reboot the device and run // testApkAndApexConfirmRollback(). } /** * Test rollbacks of staged installs an apk and an apex. * Confirm rollback phase. */ @Test public void testApkAndApexConfirmRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.processUserData(TEST_APP_A); } /** * Test rollbacks of staged installs involving only apex. * Prepare apex phase. Loading Loading @@ -171,7 +253,7 @@ public class StagedRollbackTest { } /** * Test rollbacks of staged installs involving only apks. * Test rollbacks of staged installs involving only apex. * Commit rollback phase. */ @Test Loading @@ -186,18 +268,8 @@ public class StagedRollbackTest { RollbackTestUtils.rollback(rollback.getRollbackId()); // Note: We can't use getUniqueRollbackInfoForPackage for the apex, // because we can't uninstall the apex (b/123667725), which means // there's no way to clear info about rollbacks from previous tests // run on the device. Look up the info by rollback id instead. RollbackInfo committed = null; for (RollbackInfo info : rm.getRecentlyCommittedRollbacks()) { if (info.getRollbackId() == rollback.getRollbackId()) { assertNull(committed); committed = info; break; } } RollbackInfo committed = getRecentlyCommittedRollbackInfoById(rollback.getRollbackId()); assertRollbackInfoEquals(TEST_APEX_PKG, 2, 1, committed); assertTrue(committed.isStaged()); assertNotEquals(-1, committed.getCommittedSessionId()); Loading @@ -212,7 +284,7 @@ public class StagedRollbackTest { } /** * Test rollbacks of staged installs involving only apks. * Test rollbacks of staged installs involving only apex. * Confirm rollback phase. */ @Test Loading tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -67,4 +67,18 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { getDevice().reboot(); runPhase("testApexOnlyConfirmRollback"); } /** * Tests staged rollbacks involving apk and apex. */ @Test public void testApkAndApex() throws Exception { runPhase("testApkAndApexPrepare"); getDevice().reboot(); runPhase("testApkAndApexEnableRollback"); getDevice().reboot(); runPhase("testApkAndApexCommitRollback"); getDevice().reboot(); runPhase("testApkAndApexConfirmRollback"); } } Loading
tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTestUtils.java +41 −6 Original line number Diff line number Diff line Loading @@ -340,16 +340,26 @@ class RollbackTestUtils { } /** * Asserts that the given RollbackInfo has a single package with expected * package name and versions. * Asserts that the given RollbackInfo has the given packages with expected * package names and all are rolled to and from the same given versions. */ static void assertRollbackInfoEquals(String packageName, static void assertRollbackInfoEquals(String[] packageNames, long versionRolledBackFrom, long versionRolledBackTo, RollbackInfo info, VersionedPackage... causePackages) { assertNotNull(info); assertEquals(1, info.getPackages().size()); assertPackageRollbackInfoEquals(packageName, versionRolledBackFrom, versionRolledBackTo, info.getPackages().get(0)); assertEquals(packageNames.length, info.getPackages().size()); int foundPackages = 0; for (String packageName : packageNames) { for (PackageRollbackInfo pkgRollbackInfo : info.getPackages()) { if (packageName.equals(pkgRollbackInfo.getPackageName())) { foundPackages++; assertPackageRollbackInfoEquals(packageName, versionRolledBackFrom, versionRolledBackTo, pkgRollbackInfo); break; } } } assertEquals(packageNames.length, foundPackages); assertEquals(causePackages.length, info.getCausePackages().size()); for (int i = 0; i < causePackages.length; ++i) { assertEquals(causePackages[i].getPackageName(), Loading @@ -359,6 +369,18 @@ class RollbackTestUtils { } } /** * Asserts that the given RollbackInfo has a single package with expected * package name and versions. */ static void assertRollbackInfoEquals(String packageName, long versionRolledBackFrom, long versionRolledBackTo, RollbackInfo info, VersionedPackage... causePackages) { String[] packageNames = {packageName}; assertRollbackInfoEquals(packageNames, versionRolledBackFrom, versionRolledBackTo, info, causePackages); } /** * Waits for the given session to be marked as ready. * Throws an assertion if the session fails. Loading Loading @@ -453,4 +475,17 @@ class RollbackTestUtils { fail(result); } } /** * Return the rollback info for a recently committed rollback, by matching the rollback id, or * return null if no matching rollback is found. */ static RollbackInfo getRecentlyCommittedRollbackInfoById(int getRollbackId) { for (RollbackInfo info : getRollbackManager().getRecentlyCommittedRollbacks()) { if (info.getRollbackId() == getRollbackId) { return info; } } return null; } }
tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +89 −17 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.tests.rollback; import static com.android.tests.rollback.RollbackTestUtils.assertRollbackInfoEquals; import static com.android.tests.rollback.RollbackTestUtils.getRecentlyCommittedRollbackInfoById; import static com.android.tests.rollback.RollbackTestUtils.getUniqueRollbackInfoForPackage; import android.Manifest; Loading @@ -25,7 +26,6 @@ import android.content.rollback.RollbackManager; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.After; Loading @@ -47,6 +47,8 @@ public class StagedRollbackTest { private static final String TAG = "RollbackTest"; private static final String TEST_APP_A = "com.android.tests.rollback.testapp.A"; private static final String TEST_APP_A_V1 = "RollbackTestAppAv1.apk"; private static final String TEST_APP_A_V2 = "RollbackTestAppAv2.apk"; private static final String TEST_APEX_PKG = "com.android.tests.rollback.testapex"; private static final String TEST_APEX_V1 = "com.android.tests.rollback.testapex.RollbackTestApexV1.apex"; Loading Loading @@ -82,11 +84,11 @@ public class StagedRollbackTest { RollbackTestUtils.uninstall(TEST_APP_A); assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.install("RollbackTestAppAv1.apk", false); RollbackTestUtils.install(TEST_APP_A_V1, false); assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.processUserData(TEST_APP_A); RollbackTestUtils.installStaged(true, "RollbackTestAppAv2.apk"); RollbackTestUtils.installStaged(true, TEST_APP_A_V2); // At this point, the host test driver will reboot the device and run // testApkOnlyCommitRollback(). Loading Loading @@ -141,6 +143,86 @@ public class StagedRollbackTest { assertNotEquals(-1, rollback.getCommittedSessionId()); } /** * Test rollbacks of staged installs an apk and an apex. * Prepare apex (and apk) phase. */ @Test public void testApkAndApexPrepare() throws Exception { RollbackTestUtils.uninstall(TEST_APP_A); assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); // Note: can't uninstall the apex. See note in #testApexOnlyPrepareApex(). RollbackTestUtils.installStaged(false, TEST_APP_A_V1, TEST_APEX_V1); // At this point, the host test driver will reboot the device and run // testApkAndApexEnableRollback(). } /** * Test rollbacks of staged installs an apk and an apex. * Enable rollback phase. */ @Test public void testApkAndApexEnableRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.installStaged(true, TEST_APP_A_V2, TEST_APEX_V2); // At this point, the host test driver will reboot the device and run // testApkAndApexCommitRollback(). } /** * Test rollbacks of staged installs an apk and an apex. * Commit rollback phase. */ @Test public void testApkAndApexCommitRollback() throws Exception { assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.processUserData(TEST_APP_A); RollbackManager rm = RollbackTestUtils.getRollbackManager(); RollbackInfo rollback = getUniqueRollbackInfoForPackage( rm.getAvailableRollbacks(), TEST_APP_A); String[] packagesNames = {TEST_APEX_PKG, TEST_APP_A}; assertRollbackInfoEquals(packagesNames, 2, 1, rollback); assertTrue(rollback.isStaged()); RollbackTestUtils.rollback(rollback.getRollbackId()); RollbackInfo committed = getRecentlyCommittedRollbackInfoById(rollback.getRollbackId()); assertRollbackInfoEquals(packagesNames, 2, 1, committed); assertTrue(committed.isStaged()); assertNotEquals(-1, committed.getCommittedSessionId()); RollbackTestUtils.waitForSessionReady(committed.getCommittedSessionId()); // The apex and apk should not be rolled back until after reboot. assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); // At this point, the host test driver will reboot the device and run // testApkAndApexConfirmRollback(). } /** * Test rollbacks of staged installs an apk and an apex. * Confirm rollback phase. */ @Test public void testApkAndApexConfirmRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackTestUtils.processUserData(TEST_APP_A); } /** * Test rollbacks of staged installs involving only apex. * Prepare apex phase. Loading Loading @@ -171,7 +253,7 @@ public class StagedRollbackTest { } /** * Test rollbacks of staged installs involving only apks. * Test rollbacks of staged installs involving only apex. * Commit rollback phase. */ @Test Loading @@ -186,18 +268,8 @@ public class StagedRollbackTest { RollbackTestUtils.rollback(rollback.getRollbackId()); // Note: We can't use getUniqueRollbackInfoForPackage for the apex, // because we can't uninstall the apex (b/123667725), which means // there's no way to clear info about rollbacks from previous tests // run on the device. Look up the info by rollback id instead. RollbackInfo committed = null; for (RollbackInfo info : rm.getRecentlyCommittedRollbacks()) { if (info.getRollbackId() == rollback.getRollbackId()) { assertNull(committed); committed = info; break; } } RollbackInfo committed = getRecentlyCommittedRollbackInfoById(rollback.getRollbackId()); assertRollbackInfoEquals(TEST_APEX_PKG, 2, 1, committed); assertTrue(committed.isStaged()); assertNotEquals(-1, committed.getCommittedSessionId()); Loading @@ -212,7 +284,7 @@ public class StagedRollbackTest { } /** * Test rollbacks of staged installs involving only apks. * Test rollbacks of staged installs involving only apex. * Confirm rollback phase. */ @Test Loading
tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -67,4 +67,18 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { getDevice().reboot(); runPhase("testApexOnlyConfirmRollback"); } /** * Tests staged rollbacks involving apk and apex. */ @Test public void testApkAndApex() throws Exception { runPhase("testApkAndApexPrepare"); getDevice().reboot(); runPhase("testApkAndApexEnableRollback"); getDevice().reboot(); runPhase("testApkAndApexCommitRollback"); getDevice().reboot(); runPhase("testApkAndApexConfirmRollback"); } }