Rewrite testNetworkFailedRollback
This is an effort to fix flaky StagedRollbackTest.
ag/9614192 adds support for native file path to TestApp so now we can
install network stack package using install.lib which provides better
tools for logging and synchronization than shell commands. This will
facilitate debugging flakiness.
Also move other code to device tests for the same reason.
Bug: 143211397
Test: atest StagedRollbackTest
Change-Id: I971618da3defade4693be154ab523f1cbfea5b7c
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 bfb4968..82eef7f 100644
--- a/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java
+++ b/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java
@@ -30,6 +30,7 @@
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
+import android.content.pm.PackageManager;
import android.content.rollback.RollbackInfo;
import android.content.rollback.RollbackManager;
import android.os.ParcelFileDescriptor;
@@ -55,6 +56,7 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import java.io.File;
import java.util.concurrent.TimeUnit;
/**
@@ -72,8 +74,13 @@
"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 String MODULE_META_DATA_PACKAGE = getModuleMetadataPackageName();
+ private static final TestApp NETWORK_STACK = new TestApp("NetworkStack",
+ getNetworkStackPackageName(), -1, false,
+ new File("/system/priv-app/NetworkStack/NetworkStack.apk"));
/**
* Adopts common shell permissions needed for rollback tests.
@@ -214,6 +221,7 @@
@Test
public void testNetworkFailedRollback_Phase1() throws Exception {
+ // Remove available rollbacks and uninstall NetworkStack on /data/
RollbackManager rm = RollbackUtils.getRollbackManager();
String networkStack = getNetworkStackPackageName();
@@ -222,6 +230,15 @@
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();
+ // Sleep to allow writes to disk before reboot
+ Thread.sleep(TimeUnit.SECONDS.toMillis(5));
}
@Test
@@ -253,16 +270,20 @@
getNetworkStackPackageName())).isNotNull();
}
- private String getNetworkStackPackageName() {
+ private static String getNetworkStackPackageName() {
Intent intent = new Intent(NETWORK_STACK_CONNECTOR_CLASS);
ComponentName comp = intent.resolveSystemService(
InstrumentationRegistry.getContext().getPackageManager(), 0);
return comp.getPackageName();
}
- private void uninstallNetworkStackPackage() {
- // Since the host side use shell command to install the network stack package, uninstall
- // must be done by shell command as well. Otherwise uninstall by a different user will fail.
+ 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());
}
@@ -348,7 +369,7 @@
MODULE_META_DATA_PACKAGE)).isNull();
}
- private void runShellCommand(String cmd) {
+ private static void runShellCommand(String cmd) {
ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation().getUiAutomation()
.executeShellCommand(cmd);
IoUtils.closeQuietly(pfd);
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 e3d9c35..2e6875a 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
@@ -110,17 +110,7 @@
getDevice().executeShellCommand("svc wifi disable");
getDevice().executeShellCommand("svc data disable");
- // Remove available rollbacks and uninstall NetworkStack on /data/
runPhase("testNetworkFailedRollback_Phase1");
- // Reduce health check deadline
- getDevice().executeShellCommand("device_config put rollback "
- + "watchdog_request_timeout_millis 120000");
- // Simulate re-installation of new NetworkStack with rollbacks enabled
- getDevice().executeShellCommand("pm install -r --staged --enable-rollback "
- + "/system/priv-app/NetworkStack/NetworkStack.apk");
-
- // Sleep to allow writes to disk before reboot
- Thread.sleep(5000);
// Reboot device to activate staged package
getDevice().reboot();