summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author JW Wang <wangchun@google.com> 2019-10-31 10:41:52 +0800
committer JW Wang <wangchun@google.com> 2019-11-02 08:04:16 +0800
commiteae2c7cdbe20d40f58fa9fbf61710162d3574394 (patch)
tree1061f09944fa51103f53bfaee577a985c19d78ee
parenteef40f1152d8f30489009ac359b6e5c12563e9cc (diff)
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
-rw-r--r--tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java31
-rw-r--r--tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java10
2 files changed, 26 insertions, 15 deletions
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 bfb49689f98d..82eef7f0c9ca 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.Context;
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.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import java.io.File;
import java.util.concurrent.TimeUnit;
/**
@@ -72,8 +74,13 @@ public class StagedRollbackTest {
"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 @@ 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();
@@ -222,6 +230,15 @@ public class StagedRollbackTest {
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 @@ public class StagedRollbackTest {
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 @@ public class StagedRollbackTest {
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 e3d9c3586256..2e6875a80660 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 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
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();