Loading tests/RollbackTest/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -76,13 +76,13 @@ LOCAL_PACKAGE_NAME := RollbackTest LOCAL_MODULE_TAGS := tests LOCAL_STATIC_JAVA_LIBRARIES := android-support-test LOCAL_COMPATIBILITY_SUITE := general-tests LOCAL_COMPATIBILITY_SUPPORT_FILES := $(ROLLBACK_TEST_APEX_V1) LOCAL_JAVA_RESOURCE_FILES := \ $(ROLLBACK_TEST_APP_AV1) \ $(ROLLBACK_TEST_APP_AV2) \ $(ROLLBACK_TEST_APP_A_CRASHING_V2) \ $(ROLLBACK_TEST_APP_BV1) \ $(ROLLBACK_TEST_APP_BV2) \ $(ROLLBACK_TEST_APEX_V1) \ $(ROLLBACK_TEST_APEX_V2) LOCAL_MANIFEST_FILE := RollbackTest/AndroidManifest.xml LOCAL_SDK_VERSION := system_current Loading tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTestUtils.java +11 −5 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ class RollbackTestUtils { Context context = InstrumentationRegistry.getContext(); PackageManager pm = context.getPackageManager(); try { PackageInfo info = pm.getPackageInfo(packageName, 0); PackageInfo info = pm.getPackageInfo(packageName, PackageManager.MATCH_APEX); return info.getLongVersionCode(); } catch (PackageManager.NameNotFoundException e) { return -1; Loading Loading @@ -142,7 +142,7 @@ class RollbackTestUtils { session = packageInstaller.openSession(sessionId); ClassLoader loader = RollbackTest.class.getClassLoader(); try (OutputStream packageInSession = session.openWrite("package", 0, -1); try (OutputStream packageInSession = session.openWrite(resourceName, 0, -1); InputStream is = loader.getResourceAsStream(resourceName);) { byte[] buffer = new byte[4096]; int n; Loading @@ -168,7 +168,8 @@ class RollbackTestUtils { } /** * Installs the apks with the given resource names as an atomic set. * Installs the APKs or APEXs with the given resource names as an atomic * set. A resource is assumed to be an APEX if it has the .apex extension. * <p> * In case of staged installs, this function will return succesfully after * the staged install has been committed and is ready for the device to Loading Loading @@ -206,6 +207,9 @@ class RollbackTestUtils { if (staged) { params.setStaged(); } if (resourceName.endsWith(".apex")) { params.setInstallAsApex(); } if (enableRollback) { params.setEnableRollback(); } Loading @@ -213,7 +217,7 @@ class RollbackTestUtils { session = packageInstaller.openSession(sessionId); ClassLoader loader = RollbackTest.class.getClassLoader(); try (OutputStream packageInSession = session.openWrite("package", 0, -1); try (OutputStream packageInSession = session.openWrite(resourceName, 0, -1); InputStream is = loader.getResourceAsStream(resourceName);) { byte[] buffer = new byte[4096]; int n; Loading Loading @@ -247,7 +251,9 @@ class RollbackTestUtils { } /** * Installs the apks with the given resource names as a staged atomic set. * Installs the APKs or APEXs with the given resource names as a staged * atomic set. A resource is assumed to be an APEX if it has the .apex * extension. * * @param enableRollback if rollback should be enabled. * @param resourceNames names of the class loader resource for the apks to Loading tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +96 −8 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ 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 @@ -46,6 +47,11 @@ 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_APEX_PKG = "com.android.tests.rollback.testapex"; private static final String TEST_APEX_V1 = "com.android.tests.rollback.testapex.RollbackTestApexV1.apex"; private static final String TEST_APEX_V2 = "com.android.tests.rollback.testapex.RollbackTestApexV2.apex"; /** * Adopts common shell permissions needed for rollback tests. Loading @@ -68,10 +74,11 @@ public class StagedRollbackTest { /** * Test basic rollbacks. Enable rollback phase. * Test rollbacks of staged installs involving only apks. * Enable rollback phase. */ @Test public void testBasicEnableRollback() throws Exception { public void testApkOnlyEnableRollback() throws Exception { RollbackTestUtils.uninstall(TEST_APP_A); assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); Loading @@ -81,14 +88,15 @@ public class StagedRollbackTest { RollbackTestUtils.installStaged(true, "RollbackTestAppAv2.apk"); // At this point, the host test driver will reboot the device and run // testBasicCommitRollback(). // testApkOnlyCommitRollback(). } /** * Test basic rollbacks. Commit rollback phase. * Test rollbacks of staged installs involving only apks. * Commit rollback phase. */ @Test public void testBasicCommitRollback() throws Exception { public void testApkOnlyCommitRollback() throws Exception { assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackManager rm = RollbackTestUtils.getRollbackManager(); Loading @@ -111,14 +119,15 @@ public class StagedRollbackTest { assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); // At this point, the host test driver will reboot the device and run // testBasicConfirmRollback(). // testApkOnlyConfirmRollback(). } /** * Test basic rollbacks. Confirm rollback phase. * Test rollbacks of staged installs involving only apks. * Confirm rollback phase. */ @Test public void testBasicConfirmRollback() throws Exception { public void testApkOnlyConfirmRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackManager rm = RollbackTestUtils.getRollbackManager(); Loading @@ -128,4 +137,83 @@ public class StagedRollbackTest { assertTrue(rollback.isStaged()); assertNotEquals(-1, rollback.getCommittedSessionId()); } /** * Test rollbacks of staged installs involving only apex. * Prepare apex phase. */ @Test public void testApexOnlyPrepareApex() throws Exception { // Note: We can't uninstall the apex if it is already on device, // because that isn't supported yet (b/123667725). As long as nothing // is failing, this should be fine because we don't expect the tests // to leave the device with v2 of the apex installed. RollbackTestUtils.installStaged(false, TEST_APEX_V1); // At this point, the host test driver will reboot the device and run // testApexOnlyEnableRollback(). } /** * Test rollbacks of staged installs involving only apex. * Enable rollback phase. */ @Test public void testApexOnlyEnableRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); RollbackTestUtils.installStaged(true, TEST_APEX_V2); // At this point, the host test driver will reboot the device and run // testApexOnlyCommitRollback(). } /** * Test rollbacks of staged installs involving only apks. * Commit rollback phase. */ @Test public void testApexOnlyCommitRollback() throws Exception { assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); RollbackManager rm = RollbackTestUtils.getRollbackManager(); RollbackInfo rollback = getUniqueRollbackInfoForPackage( rm.getAvailableRollbacks(), TEST_APEX_PKG); assertRollbackInfoEquals(TEST_APEX_PKG, 2, 1, rollback); assertTrue(rollback.isStaged()); 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; } } assertRollbackInfoEquals(TEST_APEX_PKG, 2, 1, committed); assertTrue(committed.isStaged()); assertNotEquals(-1, committed.getCommittedSessionId()); RollbackTestUtils.waitForSessionReady(committed.getCommittedSessionId()); // The apex should not be rolled back until after reboot. assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); // At this point, the host test driver will reboot the device and run // testApexOnlyConfirmRollback(). } /** * Test rollbacks of staged installs involving only apks. * Confirm rollback phase. */ @Test public void testApexOnlyConfirmRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); } } tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +20 −6 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { * Runs the given phase of a test by calling into the device. * Throws an exception if the test phase fails. * <p> * For example, <code>runPhase("testBasicEnableRollback");</code> * For example, <code>runPhase("testApkOnlyEnableRollback");</code> */ private void runPhase(String phase) throws Exception { assertTrue(runDeviceTests("com.android.tests.rollback", Loading @@ -43,14 +43,28 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } /** * Tests staged rollbacks. * Tests staged rollbacks involving only apks. */ @Test public void testBasic() throws Exception { runPhase("testBasicEnableRollback"); public void testApkOnly() throws Exception { runPhase("testApkOnlyEnableRollback"); getDevice().reboot(); runPhase("testBasicCommitRollback"); runPhase("testApkOnlyCommitRollback"); getDevice().reboot(); runPhase("testBasicConfirmRollback"); runPhase("testApkOnlyConfirmRollback"); } /** * Tests staged rollbacks involving only apex. */ @Test public void testApexOnly() throws Exception { runPhase("testApexOnlyPrepareApex"); getDevice().reboot(); runPhase("testApexOnlyEnableRollback"); getDevice().reboot(); runPhase("testApexOnlyCommitRollback"); getDevice().reboot(); runPhase("testApexOnlyConfirmRollback"); } } Loading
tests/RollbackTest/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -76,13 +76,13 @@ LOCAL_PACKAGE_NAME := RollbackTest LOCAL_MODULE_TAGS := tests LOCAL_STATIC_JAVA_LIBRARIES := android-support-test LOCAL_COMPATIBILITY_SUITE := general-tests LOCAL_COMPATIBILITY_SUPPORT_FILES := $(ROLLBACK_TEST_APEX_V1) LOCAL_JAVA_RESOURCE_FILES := \ $(ROLLBACK_TEST_APP_AV1) \ $(ROLLBACK_TEST_APP_AV2) \ $(ROLLBACK_TEST_APP_A_CRASHING_V2) \ $(ROLLBACK_TEST_APP_BV1) \ $(ROLLBACK_TEST_APP_BV2) \ $(ROLLBACK_TEST_APEX_V1) \ $(ROLLBACK_TEST_APEX_V2) LOCAL_MANIFEST_FILE := RollbackTest/AndroidManifest.xml LOCAL_SDK_VERSION := system_current Loading
tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTestUtils.java +11 −5 Original line number Diff line number Diff line Loading @@ -66,7 +66,7 @@ class RollbackTestUtils { Context context = InstrumentationRegistry.getContext(); PackageManager pm = context.getPackageManager(); try { PackageInfo info = pm.getPackageInfo(packageName, 0); PackageInfo info = pm.getPackageInfo(packageName, PackageManager.MATCH_APEX); return info.getLongVersionCode(); } catch (PackageManager.NameNotFoundException e) { return -1; Loading Loading @@ -142,7 +142,7 @@ class RollbackTestUtils { session = packageInstaller.openSession(sessionId); ClassLoader loader = RollbackTest.class.getClassLoader(); try (OutputStream packageInSession = session.openWrite("package", 0, -1); try (OutputStream packageInSession = session.openWrite(resourceName, 0, -1); InputStream is = loader.getResourceAsStream(resourceName);) { byte[] buffer = new byte[4096]; int n; Loading @@ -168,7 +168,8 @@ class RollbackTestUtils { } /** * Installs the apks with the given resource names as an atomic set. * Installs the APKs or APEXs with the given resource names as an atomic * set. A resource is assumed to be an APEX if it has the .apex extension. * <p> * In case of staged installs, this function will return succesfully after * the staged install has been committed and is ready for the device to Loading Loading @@ -206,6 +207,9 @@ class RollbackTestUtils { if (staged) { params.setStaged(); } if (resourceName.endsWith(".apex")) { params.setInstallAsApex(); } if (enableRollback) { params.setEnableRollback(); } Loading @@ -213,7 +217,7 @@ class RollbackTestUtils { session = packageInstaller.openSession(sessionId); ClassLoader loader = RollbackTest.class.getClassLoader(); try (OutputStream packageInSession = session.openWrite("package", 0, -1); try (OutputStream packageInSession = session.openWrite(resourceName, 0, -1); InputStream is = loader.getResourceAsStream(resourceName);) { byte[] buffer = new byte[4096]; int n; Loading Loading @@ -247,7 +251,9 @@ class RollbackTestUtils { } /** * Installs the apks with the given resource names as a staged atomic set. * Installs the APKs or APEXs with the given resource names as a staged * atomic set. A resource is assumed to be an APEX if it has the .apex * extension. * * @param enableRollback if rollback should be enabled. * @param resourceNames names of the class loader resource for the apks to Loading
tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +96 −8 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ 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 @@ -46,6 +47,11 @@ 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_APEX_PKG = "com.android.tests.rollback.testapex"; private static final String TEST_APEX_V1 = "com.android.tests.rollback.testapex.RollbackTestApexV1.apex"; private static final String TEST_APEX_V2 = "com.android.tests.rollback.testapex.RollbackTestApexV2.apex"; /** * Adopts common shell permissions needed for rollback tests. Loading @@ -68,10 +74,11 @@ public class StagedRollbackTest { /** * Test basic rollbacks. Enable rollback phase. * Test rollbacks of staged installs involving only apks. * Enable rollback phase. */ @Test public void testBasicEnableRollback() throws Exception { public void testApkOnlyEnableRollback() throws Exception { RollbackTestUtils.uninstall(TEST_APP_A); assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); Loading @@ -81,14 +88,15 @@ public class StagedRollbackTest { RollbackTestUtils.installStaged(true, "RollbackTestAppAv2.apk"); // At this point, the host test driver will reboot the device and run // testBasicCommitRollback(). // testApkOnlyCommitRollback(). } /** * Test basic rollbacks. Commit rollback phase. * Test rollbacks of staged installs involving only apks. * Commit rollback phase. */ @Test public void testBasicCommitRollback() throws Exception { public void testApkOnlyCommitRollback() throws Exception { assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackManager rm = RollbackTestUtils.getRollbackManager(); Loading @@ -111,14 +119,15 @@ public class StagedRollbackTest { assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); // At this point, the host test driver will reboot the device and run // testBasicConfirmRollback(). // testApkOnlyConfirmRollback(). } /** * Test basic rollbacks. Confirm rollback phase. * Test rollbacks of staged installs involving only apks. * Confirm rollback phase. */ @Test public void testBasicConfirmRollback() throws Exception { public void testApkOnlyConfirmRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A)); RollbackManager rm = RollbackTestUtils.getRollbackManager(); Loading @@ -128,4 +137,83 @@ public class StagedRollbackTest { assertTrue(rollback.isStaged()); assertNotEquals(-1, rollback.getCommittedSessionId()); } /** * Test rollbacks of staged installs involving only apex. * Prepare apex phase. */ @Test public void testApexOnlyPrepareApex() throws Exception { // Note: We can't uninstall the apex if it is already on device, // because that isn't supported yet (b/123667725). As long as nothing // is failing, this should be fine because we don't expect the tests // to leave the device with v2 of the apex installed. RollbackTestUtils.installStaged(false, TEST_APEX_V1); // At this point, the host test driver will reboot the device and run // testApexOnlyEnableRollback(). } /** * Test rollbacks of staged installs involving only apex. * Enable rollback phase. */ @Test public void testApexOnlyEnableRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); RollbackTestUtils.installStaged(true, TEST_APEX_V2); // At this point, the host test driver will reboot the device and run // testApexOnlyCommitRollback(). } /** * Test rollbacks of staged installs involving only apks. * Commit rollback phase. */ @Test public void testApexOnlyCommitRollback() throws Exception { assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); RollbackManager rm = RollbackTestUtils.getRollbackManager(); RollbackInfo rollback = getUniqueRollbackInfoForPackage( rm.getAvailableRollbacks(), TEST_APEX_PKG); assertRollbackInfoEquals(TEST_APEX_PKG, 2, 1, rollback); assertTrue(rollback.isStaged()); 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; } } assertRollbackInfoEquals(TEST_APEX_PKG, 2, 1, committed); assertTrue(committed.isStaged()); assertNotEquals(-1, committed.getCommittedSessionId()); RollbackTestUtils.waitForSessionReady(committed.getCommittedSessionId()); // The apex should not be rolled back until after reboot. assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); // At this point, the host test driver will reboot the device and run // testApexOnlyConfirmRollback(). } /** * Test rollbacks of staged installs involving only apks. * Confirm rollback phase. */ @Test public void testApexOnlyConfirmRollback() throws Exception { assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APEX_PKG)); } }
tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +20 −6 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { * Runs the given phase of a test by calling into the device. * Throws an exception if the test phase fails. * <p> * For example, <code>runPhase("testBasicEnableRollback");</code> * For example, <code>runPhase("testApkOnlyEnableRollback");</code> */ private void runPhase(String phase) throws Exception { assertTrue(runDeviceTests("com.android.tests.rollback", Loading @@ -43,14 +43,28 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } /** * Tests staged rollbacks. * Tests staged rollbacks involving only apks. */ @Test public void testBasic() throws Exception { runPhase("testBasicEnableRollback"); public void testApkOnly() throws Exception { runPhase("testApkOnlyEnableRollback"); getDevice().reboot(); runPhase("testBasicCommitRollback"); runPhase("testApkOnlyCommitRollback"); getDevice().reboot(); runPhase("testBasicConfirmRollback"); runPhase("testApkOnlyConfirmRollback"); } /** * Tests staged rollbacks involving only apex. */ @Test public void testApexOnly() throws Exception { runPhase("testApexOnlyPrepareApex"); getDevice().reboot(); runPhase("testApexOnlyEnableRollback"); getDevice().reboot(); runPhase("testApexOnlyCommitRollback"); getDevice().reboot(); runPhase("testApexOnlyConfirmRollback"); } }