diff options
Diffstat (limited to 'tests')
10 files changed, 368 insertions, 225 deletions
diff --git a/tests/BootImageProfileTest/AndroidTest.xml b/tests/BootImageProfileTest/AndroidTest.xml index b4f2663585cc..d7f820411f27 100644 --- a/tests/BootImageProfileTest/AndroidTest.xml +++ b/tests/BootImageProfileTest/AndroidTest.xml @@ -19,18 +19,8 @@ --> <target_preparer class="com.android.tradefed.targetprep.DeviceSetup"> - <!-- we need this magic flag, otherwise it always reboots and breaks the selinux --> + <!-- we need this magic flag, otherwise it always reboots and breaks selinux --> <option name="force-skip-system-props" value="true" /> - - <option name="run-command" value="device_config put runtime_native_boot profilesystemserver true" /> - <option name="run-command" value="device_config put runtime_native_boot profilebootclasspath true" /> - - <!-- Profiling does not pick up the above changes we restart the shell --> - <option name="run-command" value="stop" /> - <option name="run-command" value="start" /> - - <!-- give it some time to restart the shell; otherwise the first unit test might fail --> - <option name="run-command" value="sleep 2" /> </target_preparer> <test class="com.android.tradefed.testtype.HostTest" > diff --git a/tests/BootImageProfileTest/OWNERS b/tests/BootImageProfileTest/OWNERS new file mode 100644 index 000000000000..657b3f2add2e --- /dev/null +++ b/tests/BootImageProfileTest/OWNERS @@ -0,0 +1,4 @@ +mathieuc@google.com +calin@google.com +yawanng@google.com +sehr@google.com diff --git a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java index 10f3e54a5f96..1c8b6be49547 100644 --- a/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java +++ b/tests/BootImageProfileTest/src/com/android/bootimageprofile/BootImageProfileTest.java @@ -42,10 +42,9 @@ public class BootImageProfileTest implements IDeviceTest { } /** - * Test that the boot image profile properties are set. + * Validate that the boot image profile properties are set. */ - @Test - public void testProperties() throws Exception { + public void validateProperties() throws Exception { String res = mTestDevice.getProperty( "persist.device_config.runtime_native_boot.profilebootclasspath"); assertTrue("profile boot class path not enabled", res != null && res.equals("true")); @@ -67,13 +66,37 @@ public class BootImageProfileTest implements IDeviceTest { @Test public void testSystemServerProfile() throws Exception { + final int numIterations = 20; + for (int i = 1; i <= numIterations; ++i) { + String res; + res = mTestDevice.getProperty( + "persist.device_config.runtime_native_boot.profilebootclasspath"); + boolean profileBootClassPath = res != null && res.equals("true"); + res = mTestDevice.getProperty( + "persist.device_config.runtime_native_boot.profilesystemserver"); + boolean profileSystemServer = res != null && res.equals("true"); + if (profileBootClassPath && profileSystemServer) { + break; + } + if (i == numIterations) { + assertTrue("profile system server not enabled", profileSystemServer); + assertTrue("profile boot class path not enabled", profileSystemServer); + } + + res = mTestDevice.executeShellCommand( + "device_config put runtime_native_boot profilebootclasspath true"); + res = mTestDevice.executeShellCommand( + "device_config put runtime_native_boot profilesystemserver true"); + res = mTestDevice.executeShellCommand("stop"); + res = mTestDevice.executeShellCommand("start"); + Thread.sleep(5000); + } // Trunacte the profile before force it to be saved to prevent previous profiles // causing the test to pass. String res; res = mTestDevice.executeShellCommand("truncate -s 0 " + SYSTEM_SERVER_PROFILE).trim(); assertTrue(res, res.length() == 0); // Wait up to 20 seconds for the profile to be saved. - final int numIterations = 20; for (int i = 1; i <= numIterations; ++i) { // Force save the profile since we truncated it. if (forceSaveProfile("system_server")) { @@ -89,6 +112,9 @@ public class BootImageProfileTest implements IDeviceTest { // In case the profile is partially saved, wait an extra second. Thread.sleep(1000); + // Validate that properties are still set. + validateProperties(); + // Validate that the profile is non empty. res = mTestDevice.executeShellCommand("profman --dump-only --profile-file=" + SYSTEM_SERVER_PROFILE); diff --git a/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java index 59049160e885..1361df30e9d7 100644 --- a/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java +++ b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java @@ -321,8 +321,7 @@ public class MemoryUsageTest extends InstrumentationTestCase { } mAtm.startActivityAndWait(null, - getInstrumentation().getContext().getBasePackageName(), - getInstrumentation().getContext().getFeatureId(), mLaunchIntent, + getInstrumentation().getContext().getBasePackageName(), mLaunchIntent, mimeType, null, null, 0, mLaunchIntent.getFlags(), null, null, UserHandle.USER_CURRENT_OR_SELF); } catch (RemoteException e) { diff --git a/tests/PlatformCompatGating/Android.bp b/tests/PlatformCompatGating/Android.bp index 74dfde848191..342c47de755a 100644 --- a/tests/PlatformCompatGating/Android.bp +++ b/tests/PlatformCompatGating/Android.bp @@ -18,6 +18,7 @@ android_test { name: "PlatformCompatGating", // Only compile source java files in this apk. srcs: ["src/**/*.java"], + test_suites: ["device-tests"], static_libs: [ "junit", "androidx.test.runner", diff --git a/tests/RollbackTest/NetworkStagedRollbackTest/src/com/android/tests/rollback/host/NetworkStagedRollbackTest.java b/tests/RollbackTest/NetworkStagedRollbackTest/src/com/android/tests/rollback/host/NetworkStagedRollbackTest.java index 2c2e8282ff51..a72bd38e5a83 100644 --- a/tests/RollbackTest/NetworkStagedRollbackTest/src/com/android/tests/rollback/host/NetworkStagedRollbackTest.java +++ b/tests/RollbackTest/NetworkStagedRollbackTest/src/com/android/tests/rollback/host/NetworkStagedRollbackTest.java @@ -16,22 +16,99 @@ package com.android.tests.rollback.host; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.testng.Assert.assertThrows; + +import com.android.tradefed.device.LogcatReceiver; +import com.android.tradefed.result.InputStreamSource; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + /** * Runs the network rollback tests. */ @RunWith(DeviceJUnit4ClassRunner.class) public class NetworkStagedRollbackTest 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("testApkOnlyEnableRollback");</code> + */ + private void runPhase(String phase) throws Exception { + assertTrue(runDeviceTests("com.android.tests.rollback", + "com.android.tests.rollback.NetworkStagedRollbackTest", + phase)); + } + + private static final String REASON_EXPLICIT_HEALTH_CHECK = "REASON_EXPLICIT_HEALTH_CHECK"; + + private static final String ROLLBACK_INITIATE = "ROLLBACK_INITIATE"; + private static final String ROLLBACK_BOOT_TRIGGERED = "ROLLBACK_BOOT_TRIGGERED"; + + private LogcatReceiver mReceiver; + + @Before + public void setUp() throws Exception { + mReceiver = new LogcatReceiver(getDevice(), "logcat -s WatchdogRollbackLogger", + getDevice().getOptions().getMaxLogcatDataSize(), 0); + mReceiver.start(); + } + + @After + public void tearDown() throws Exception { + mReceiver.stop(); + mReceiver.clear(); + } + + /** * Tests failed network health check triggers watchdog staged rollbacks. */ @Test public void testNetworkFailedRollback() throws Exception { + try { + // Disconnect internet so we can test network health triggered rollbacks + getDevice().executeShellCommand("svc wifi disable"); + getDevice().executeShellCommand("svc data disable"); + + runPhase("testNetworkFailedRollback_Phase1"); + // Reboot device to activate staged package + getDevice().reboot(); + + // Verify rollback was enabled + runPhase("testNetworkFailedRollback_Phase2"); + assertThrows(AssertionError.class, () -> runPhase("testNetworkFailedRollback_Phase3")); + + getDevice().waitForDeviceAvailable(); + // Verify rollback was executed after health check deadline + runPhase("testNetworkFailedRollback_Phase4"); + InputStreamSource logcatStream = mReceiver.getLogcatData(); + try { + List<String> watchdogEvents = getWatchdogLoggingEvents(logcatStream); + assertTrue(watchdogEventOccurred(watchdogEvents, ROLLBACK_INITIATE, null, + REASON_EXPLICIT_HEALTH_CHECK, null)); + assertTrue(watchdogEventOccurred(watchdogEvents, ROLLBACK_BOOT_TRIGGERED, null, + null, null)); + } finally { + logcatStream.close(); + } + } finally { + // Reconnect internet again so we won't break tests which assume internet available + getDevice().executeShellCommand("svc wifi enable"); + getDevice().executeShellCommand("svc data enable"); + } } /** @@ -39,5 +116,83 @@ public class NetworkStagedRollbackTest extends BaseHostJUnit4Test { */ @Test public void testNetworkPassedDoesNotRollback() throws Exception { + runPhase("testNetworkPassedDoesNotRollback_Phase1"); + // Reboot device to activate staged package + getDevice().reboot(); + + // Verify rollback was enabled + runPhase("testNetworkPassedDoesNotRollback_Phase2"); + + // Connect to internet so network health check passes + getDevice().executeShellCommand("svc wifi enable"); + getDevice().executeShellCommand("svc data enable"); + + // Wait for device available because emulator device may restart after turning + // on mobile data + getDevice().waitForDeviceAvailable(); + + // Verify rollback was not executed after health check deadline + runPhase("testNetworkPassedDoesNotRollback_Phase3"); + InputStreamSource logcatStream = mReceiver.getLogcatData(); + try { + List<String> watchdogEvents = getWatchdogLoggingEvents(logcatStream); + assertEquals(watchdogEventOccurred(watchdogEvents, null, null, + REASON_EXPLICIT_HEALTH_CHECK, null), false); + } finally { + logcatStream.close(); + } + } + + /** + * Returns a list of all Watchdog logging events which have occurred. + */ + private List<String> getWatchdogLoggingEvents(InputStreamSource inputStreamSource) + throws Exception { + List<String> watchdogEvents = new ArrayList<>(); + InputStream inputStream = inputStreamSource.createInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + String line; + while ((line = reader.readLine()) != null) { + if (line.contains("Watchdog event occurred")) { + watchdogEvents.add(line); + } + } + return watchdogEvents; + } + + /** + * Returns whether a Watchdog event has occurred that matches the given criteria. + * + * Check the value of all non-null parameters against the list of Watchdog events that have + * occurred, and return {@code true} if an event exists which matches all criteria. + */ + private boolean watchdogEventOccurred(List<String> loggingEvents, + String type, String logPackage, + String rollbackReason, String failedPackageName) throws Exception { + List<String> eventCriteria = new ArrayList<>(); + if (type != null) { + eventCriteria.add("type: " + type); + } + if (logPackage != null) { + eventCriteria.add("logPackage: " + logPackage); + } + if (rollbackReason != null) { + eventCriteria.add("rollbackReason: " + rollbackReason); + } + if (failedPackageName != null) { + eventCriteria.add("failedPackageName: " + failedPackageName); + } + for (String loggingEvent: loggingEvents) { + boolean matchesCriteria = true; + for (String criterion: eventCriteria) { + if (!loggingEvent.contains(criterion)) { + matchesCriteria = false; + } + } + if (matchesCriteria) { + return true; + } + } + return false; } } diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/NetworkStagedRollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/NetworkStagedRollbackTest.java index 04004d6abb5a..35bc65a24d63 100644 --- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/NetworkStagedRollbackTest.java +++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/NetworkStagedRollbackTest.java @@ -16,9 +16,182 @@ package com.android.tests.rollback; +import static com.android.cts.rollback.lib.RollbackInfoSubject.assertThat; +import static com.android.cts.rollback.lib.RollbackUtils.getUniqueRollbackInfoForPackage; + +import android.Manifest; +import android.content.ComponentName; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.rollback.RollbackManager; +import android.os.ParcelFileDescriptor; +import android.provider.DeviceConfig; + +import androidx.test.platform.app.InstrumentationRegistry; + +import com.android.cts.install.lib.Install; +import com.android.cts.install.lib.InstallUtils; +import com.android.cts.install.lib.TestApp; +import com.android.cts.rollback.lib.RollbackUtils; + +import libcore.io.IoUtils; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import java.io.File; +import java.util.concurrent.TimeUnit; + @RunWith(JUnit4.class) public class NetworkStagedRollbackTest { + private static final String NETWORK_STACK_CONNECTOR_CLASS = + "android.net.INetworkStackConnector"; + private static final String PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS = + "watchdog_request_timeout_millis"; + + private static final TestApp NETWORK_STACK = new TestApp("NetworkStack", + getNetworkStackPackageName(), -1, false, findNetworkStackApk()); + + private static File findNetworkStackApk() { + final File apk = new File("/system/priv-app/NetworkStack/NetworkStack.apk"); + if (apk.isFile()) { + return apk; + } + return new File("/system/priv-app/NetworkStackNext/NetworkStackNext.apk"); + } + + /** + * Adopts common shell permissions needed for rollback tests. + */ + @Before + public void adoptShellPermissions() { + InstallUtils.adoptShellPermissionIdentity( + Manifest.permission.INSTALL_PACKAGES, + Manifest.permission.DELETE_PACKAGES, + Manifest.permission.TEST_MANAGE_ROLLBACKS, + Manifest.permission.FORCE_STOP_PACKAGES, + Manifest.permission.WRITE_DEVICE_CONFIG); + } + + /** + * Drops shell permissions needed for rollback tests. + */ + @After + public void dropShellPermissions() { + InstallUtils.dropShellPermissionIdentity(); + } + + @Test + public void testNetworkFailedRollback_Phase1() throws Exception { + // Remove available rollbacks and uninstall NetworkStack on /data/ + RollbackManager rm = RollbackUtils.getRollbackManager(); + String networkStack = getNetworkStackPackageName(); + + rm.expireRollbackForPackage(networkStack); + uninstallNetworkStackPackage(); + + assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), + networkStack)).isNull(); + + // Reduce health check deadline + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK, + PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS, + Integer.toString(120000), false); + // Simulate re-installation of new NetworkStack with rollbacks enabled + installNetworkStackPackage(); + } + + @Test + public void testNetworkFailedRollback_Phase2() throws Exception { + RollbackManager rm = RollbackUtils.getRollbackManager(); + assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), + getNetworkStackPackageName())).isNotNull(); + + // Sleep for < health check deadline + Thread.sleep(TimeUnit.SECONDS.toMillis(5)); + // Verify rollback was not executed before health check deadline + assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), + getNetworkStackPackageName())).isNull(); + } + + @Test + public void testNetworkFailedRollback_Phase3() throws Exception { + // Sleep for > health check deadline (120s to trigger rollback + 120s to reboot) + // The device is expected to reboot during sleeping. This device method will fail and + // the host will catch the assertion. If reboot doesn't happen, the host will fail the + // assertion. + Thread.sleep(TimeUnit.SECONDS.toMillis(240)); + } + + @Test + public void testNetworkFailedRollback_Phase4() throws Exception { + RollbackManager rm = RollbackUtils.getRollbackManager(); + assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), + getNetworkStackPackageName())).isNotNull(); + } + + private static String getNetworkStackPackageName() { + Intent intent = new Intent(NETWORK_STACK_CONNECTOR_CLASS); + ComponentName comp = intent.resolveSystemService( + InstrumentationRegistry.getInstrumentation().getContext().getPackageManager(), 0); + return comp.getPackageName(); + } + + private static void installNetworkStackPackage() throws Exception { + Install.single(NETWORK_STACK).setStaged().setEnableRollback() + .addInstallFlags(PackageManager.INSTALL_REPLACE_EXISTING).commit(); + } + + private static void uninstallNetworkStackPackage() { + // Uninstall the package as a privileged user so we won't fail due to permission. + runShellCommand("pm uninstall " + getNetworkStackPackageName()); + } + + @Test + public void testNetworkPassedDoesNotRollback_Phase1() throws Exception { + // Remove available rollbacks and uninstall NetworkStack on /data/ + RollbackManager rm = RollbackUtils.getRollbackManager(); + String networkStack = getNetworkStackPackageName(); + + rm.expireRollbackForPackage(networkStack); + uninstallNetworkStackPackage(); + + assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), + networkStack)).isNull(); + + // Reduce health check deadline, here unlike the network failed case, we use + // a longer deadline because joining a network can take a much longer time for + // reasons external to the device than 'not joining' + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK, + PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS, + Integer.toString(300000), false); + // Simulate re-installation of new NetworkStack with rollbacks enabled + installNetworkStackPackage(); + } + + @Test + public void testNetworkPassedDoesNotRollback_Phase2() throws Exception { + RollbackManager rm = RollbackUtils.getRollbackManager(); + assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), + getNetworkStackPackageName())).isNotNull(); + } + + @Test + public void testNetworkPassedDoesNotRollback_Phase3() throws Exception { + // Sleep for > health check deadline. We expect no rollback should happen during sleeping. + // If the device reboots for rollback, this device test will fail as well as the host test. + Thread.sleep(TimeUnit.SECONDS.toMillis(310)); + RollbackManager rm = RollbackUtils.getRollbackManager(); + assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), + getNetworkStackPackageName())).isNull(); + } + + private static void runShellCommand(String cmd) { + ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation() + .executeShellCommand(cmd); + IoUtils.closeQuietly(pfd); + } } diff --git a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java index 0fdcbc52bffa..70be83f216da 100644 --- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java +++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java @@ -22,14 +22,11 @@ import static com.android.cts.rollback.lib.RollbackUtils.getUniqueRollbackInfoFo import static com.google.common.truth.Truth.assertThat; import android.Manifest; -import android.content.ComponentName; import android.content.Context; -import android.content.Intent; import android.content.pm.PackageInstaller; import android.content.pm.PackageManager; import android.content.rollback.RollbackInfo; import android.content.rollback.RollbackManager; -import android.os.ParcelFileDescriptor; import android.os.storage.StorageManager; import android.provider.DeviceConfig; @@ -44,8 +41,6 @@ import com.android.cts.rollback.lib.Rollback; import com.android.cts.rollback.lib.RollbackUtils; import com.android.internal.R; -import libcore.io.IoUtils; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -65,24 +60,8 @@ import java.util.concurrent.TimeUnit; */ @RunWith(JUnit4.class) public class StagedRollbackTest { - - private static final String NETWORK_STACK_CONNECTOR_CLASS = - "android.net.INetworkStackConnector"; private static final String PROPERTY_WATCHDOG_TRIGGER_FAILURE_COUNT = "watchdog_trigger_failure_count"; - private static final String PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS = - "watchdog_request_timeout_millis"; - - private static final TestApp NETWORK_STACK = new TestApp("NetworkStack", - getNetworkStackPackageName(), -1, false, findNetworkStackApk()); - - private static File findNetworkStackApk() { - final File apk = new File("/system/priv-app/NetworkStack/NetworkStack.apk"); - if (apk.isFile()) { - return apk; - } - return new File("/system/priv-app/NetworkStackNext/NetworkStackNext.apk"); - } /** * Adopts common shell permissions needed for rollback tests. @@ -275,72 +254,6 @@ public class StagedRollbackTest { } @Test - public void testNetworkFailedRollback_Phase1() throws Exception { - // Remove available rollbacks and uninstall NetworkStack on /data/ - RollbackManager rm = RollbackUtils.getRollbackManager(); - String networkStack = getNetworkStackPackageName(); - - rm.expireRollbackForPackage(networkStack); - uninstallNetworkStackPackage(); - - assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), - networkStack)).isNull(); - - // Reduce health check deadline - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK, - PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS, - Integer.toString(120000), false); - // Simulate re-installation of new NetworkStack with rollbacks enabled - installNetworkStackPackage(); - } - - @Test - public void testNetworkFailedRollback_Phase2() throws Exception { - RollbackManager rm = RollbackUtils.getRollbackManager(); - assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), - getNetworkStackPackageName())).isNotNull(); - - // Sleep for < health check deadline - Thread.sleep(TimeUnit.SECONDS.toMillis(5)); - // Verify rollback was not executed before health check deadline - assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), - getNetworkStackPackageName())).isNull(); - } - - @Test - public void testNetworkFailedRollback_Phase3() throws Exception { - // Sleep for > health check deadline (120s to trigger rollback + 120s to reboot) - // The device is expected to reboot during sleeping. This device method will fail and - // the host will catch the assertion. If reboot doesn't happen, the host will fail the - // assertion. - Thread.sleep(TimeUnit.SECONDS.toMillis(240)); - } - - @Test - public void testNetworkFailedRollback_Phase4() throws Exception { - RollbackManager rm = RollbackUtils.getRollbackManager(); - assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), - getNetworkStackPackageName())).isNotNull(); - } - - private static String getNetworkStackPackageName() { - Intent intent = new Intent(NETWORK_STACK_CONNECTOR_CLASS); - ComponentName comp = intent.resolveSystemService( - InstrumentationRegistry.getInstrumentation().getContext().getPackageManager(), 0); - return comp.getPackageName(); - } - - private static void installNetworkStackPackage() throws Exception { - Install.single(NETWORK_STACK).setStaged().setEnableRollback() - .addInstallFlags(PackageManager.INSTALL_REPLACE_EXISTING).commit(); - } - - private static void uninstallNetworkStackPackage() { - // Uninstall the package as a privileged user so we won't fail due to permission. - runShellCommand("pm uninstall " + getNetworkStackPackageName()); - } - - @Test public void testPreviouslyAbandonedRollbacks_Phase1() throws Exception { Uninstall.packages(TestApp.A); Install.single(TestApp.A1).commit(); @@ -376,45 +289,6 @@ public class StagedRollbackTest { Uninstall.packages(TestApp.A); } - @Test - public void testNetworkPassedDoesNotRollback_Phase1() throws Exception { - // Remove available rollbacks and uninstall NetworkStack on /data/ - RollbackManager rm = RollbackUtils.getRollbackManager(); - String networkStack = getNetworkStackPackageName(); - - rm.expireRollbackForPackage(networkStack); - uninstallNetworkStackPackage(); - - assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), - networkStack)).isNull(); - - // Reduce health check deadline, here unlike the network failed case, we use - // a longer deadline because joining a network can take a much longer time for - // reasons external to the device than 'not joining' - DeviceConfig.setProperty(DeviceConfig.NAMESPACE_ROLLBACK, - PROPERTY_WATCHDOG_REQUEST_TIMEOUT_MILLIS, - Integer.toString(300000), false); - // Simulate re-installation of new NetworkStack with rollbacks enabled - installNetworkStackPackage(); - } - - @Test - public void testNetworkPassedDoesNotRollback_Phase2() throws Exception { - RollbackManager rm = RollbackUtils.getRollbackManager(); - assertThat(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), - getNetworkStackPackageName())).isNotNull(); - } - - @Test - public void testNetworkPassedDoesNotRollback_Phase3() throws Exception { - // Sleep for > health check deadline. We expect no rollback should happen during sleeping. - // If the device reboots for rollback, this device test will fail as well as the host test. - Thread.sleep(TimeUnit.SECONDS.toMillis(310)); - RollbackManager rm = RollbackUtils.getRollbackManager(); - assertThat(getUniqueRollbackInfoForPackage(rm.getRecentlyCommittedRollbacks(), - getNetworkStackPackageName())).isNull(); - } - private static String getModuleMetadataPackageName() { return InstrumentationRegistry.getInstrumentation().getContext() .getResources().getString(R.string.config_defaultModuleMetadataProvider); @@ -603,12 +477,6 @@ public class StagedRollbackTest { InstallUtils.waitForSessionReady(committed.getCommittedSessionId()); } - private static void runShellCommand(String cmd) { - ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation() - .executeShellCommand(cmd); - IoUtils.closeQuietly(pfd); - } - @Test public void isCheckpointSupported() { Context context = InstrumentationRegistry.getInstrumentation().getContext(); diff --git a/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java b/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java index 032f18240a55..c3fd962ffa6d 100644 --- a/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +++ b/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java @@ -228,77 +228,6 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } /** - * Tests failed network health check triggers watchdog staged rollbacks. - */ - @Test - public void testNetworkFailedRollback() throws Exception { - try { - // Disconnect internet so we can test network health triggered rollbacks - getDevice().executeShellCommand("svc wifi disable"); - getDevice().executeShellCommand("svc data disable"); - - runPhase("testNetworkFailedRollback_Phase1"); - // Reboot device to activate staged package - getDevice().reboot(); - - // Verify rollback was enabled - runPhase("testNetworkFailedRollback_Phase2"); - assertThrows(AssertionError.class, () -> runPhase("testNetworkFailedRollback_Phase3")); - - getDevice().waitForDeviceAvailable(); - // Verify rollback was executed after health check deadline - runPhase("testNetworkFailedRollback_Phase4"); - InputStreamSource logcatStream = mReceiver.getLogcatData(); - try { - List<String> watchdogEvents = getWatchdogLoggingEvents(logcatStream); - assertTrue(watchdogEventOccurred(watchdogEvents, ROLLBACK_INITIATE, null, - REASON_EXPLICIT_HEALTH_CHECK, null)); - assertTrue(watchdogEventOccurred(watchdogEvents, ROLLBACK_BOOT_TRIGGERED, null, - null, null)); - } finally { - logcatStream.close(); - } - } finally { - // Reconnect internet again so we won't break tests which assume internet available - getDevice().executeShellCommand("svc wifi enable"); - getDevice().executeShellCommand("svc data enable"); - } - } - - /** - * Tests passed network health check does not trigger watchdog staged rollbacks. - */ - @Test - public void testNetworkPassedDoesNotRollback() throws Exception { - runPhase("testNetworkPassedDoesNotRollback_Phase1"); - // Reboot device to activate staged package - getDevice().reboot(); - - // Verify rollback was enabled - runPhase("testNetworkPassedDoesNotRollback_Phase2"); - - // Connect to internet so network health check passes - getDevice().executeShellCommand("svc wifi enable"); - getDevice().executeShellCommand("svc data enable"); - - // Wait for device available because emulator device may restart after turning - // on mobile data - getDevice().waitForDeviceAvailable(); - - // Verify rollback was not executed after health check deadline - runPhase("testNetworkPassedDoesNotRollback_Phase3"); - InputStreamSource logcatStream = mReceiver.getLogcatData(); - try { - List<String> watchdogEvents = getWatchdogLoggingEvents(logcatStream); - assertEquals(watchdogEventOccurred(watchdogEvents, null, null, - REASON_EXPLICIT_HEALTH_CHECK, null), false); - } finally { - logcatStream.close(); - } - - } - - /** * Tests rolling back user data where there are multiple rollbacks for that package. */ @Test @@ -527,11 +456,6 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { } } - private String getNetworkStackPath() throws Exception { - // Find the NetworkStack path (can be NetworkStack.apk or NetworkStackNext.apk) - return getDevice().executeShellCommand("ls /system/priv-app/NetworkStack*/*.apk"); - } - private boolean isCheckpointSupported() throws Exception { try { runPhase("isCheckpointSupported"); diff --git a/tests/RollbackTest/TEST_MAPPING b/tests/RollbackTest/TEST_MAPPING index fefde5b4be12..0f4c4603f9b4 100644 --- a/tests/RollbackTest/TEST_MAPPING +++ b/tests/RollbackTest/TEST_MAPPING @@ -7,6 +7,9 @@ "name": "StagedRollbackTest" }, { + "name": "NetworkStagedRollbackTest" + }, + { "name": "MultiUserRollbackTest" } ] |