summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author JW Wang <wangchun@google.com> 2020-02-20 12:15:20 +0800
committer JW Wang <wangchun@google.com> 2020-02-20 18:49:59 +0800
commitf2a75879d3b1bd7090b859b64dc9d725907e5a1d (patch)
tree58c81f61e9c063165c5edd626616cabc9a8929d0
parenteb908a9ee1269b29d3a62273241ce413b46cc032 (diff)
No need to switch users before running tests (2/n)
My local test shows that switch-user doesn't work on my physical device. In fact there are APIs to run tests against a particular user without switching. It also speeds up tests without switching users from time to time. Bug: 149876119 Test: atest MultiUserRollbackTest Change-Id: I34d26ddcb6a6e9cdc39228310830a3cd83212e4a
-rw-r--r--tests/RollbackTest/MultiUserRollbackTest/src/com/android/tests/rollback/host/MultiUserRollbackTest.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/tests/RollbackTest/MultiUserRollbackTest/src/com/android/tests/rollback/host/MultiUserRollbackTest.java b/tests/RollbackTest/MultiUserRollbackTest/src/com/android/tests/rollback/host/MultiUserRollbackTest.java
index 52f6eba4072b..f2064b9dac9b 100644
--- a/tests/RollbackTest/MultiUserRollbackTest/src/com/android/tests/rollback/host/MultiUserRollbackTest.java
+++ b/tests/RollbackTest/MultiUserRollbackTest/src/com/android/tests/rollback/host/MultiUserRollbackTest.java
@@ -27,6 +27,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.util.concurrent.TimeUnit;
+
/**
* Runs rollback tests for multiple users.
*/
@@ -41,7 +43,6 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
@After
public void tearDown() throws Exception {
- getDevice().switchUser(mOriginalUserId);
getDevice().executeShellCommand("pm uninstall com.android.cts.install.lib.testapp.A");
removeSecondaryUserIfNecessary();
}
@@ -49,8 +50,8 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
@Before
public void setup() throws Exception {
mOriginalUserId = getDevice().getCurrentUser();
+ createAndStartSecondaryUser();
installPackageAsUser("RollbackTest.apk", true, mOriginalUserId);
- createAndSwitchToSecondaryUserIfNecessary();
installPackageAsUser("RollbackTest.apk", true, mSecondaryUserId);
}
@@ -64,7 +65,6 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
runPhaseForUsers("testMultipleUsersInstallV1", mOriginalUserId, mSecondaryUserId);
runPhaseForUsers("testMultipleUsersUpgradeToV2", mOriginalUserId);
runPhaseForUsers("testMultipleUsersUpdateUserData", mOriginalUserId, mSecondaryUserId);
- switchToUser(mOriginalUserId);
getDevice().executeShellCommand("pm rollback-app com.android.cts.install.lib.testapp.A");
runPhaseForUsers("testMultipleUsersVerifyUserdataRollback", mOriginalUserId,
mSecondaryUserId);
@@ -74,11 +74,11 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
* Run the phase for the given user ids, in the order they are given.
*/
private void runPhaseForUsers(String phase, int... userIds) throws Exception {
+ final long timeout = TimeUnit.MINUTES.toMillis(10);
for (int userId: userIds) {
- switchToUser(userId);
- assertTrue(runDeviceTests("com.android.tests.rollback",
+ assertTrue(runDeviceTests(getDevice(), "com.android.tests.rollback",
"com.android.tests.rollback.MultiUserRollbackTest",
- phase));
+ phase, userId, timeout));
}
}
@@ -89,6 +89,26 @@ public class MultiUserRollbackTest extends BaseHostJUnit4Test {
}
}
+ private void awaitUserUnlocked(int userId) throws Exception {
+ for (int i = 0; i < SWITCH_USER_COMPLETED_NUMBER_OF_POLLS; ++i) {
+ String userState = getDevice().executeShellCommand("am get-started-user-state "
+ + userId);
+ if (userState.contains("RUNNING_UNLOCKED")) {
+ return;
+ }
+ Thread.sleep(SWITCH_USER_COMPLETED_POLL_INTERVAL_IN_MILLIS);
+ }
+ fail("Timed out in unlocking user: " + userId);
+ }
+
+ private void createAndStartSecondaryUser() throws Exception {
+ String name = "MultiUserRollbackTest_User" + System.currentTimeMillis();
+ mSecondaryUserId = getDevice().createUser(name);
+ getDevice().startUser(mSecondaryUserId);
+ // Note we can't install apps on a locked user
+ awaitUserUnlocked(mSecondaryUserId);
+ }
+
private void createAndSwitchToSecondaryUserIfNecessary() throws Exception {
if (mSecondaryUserId == -1) {
mOriginalUserId = getDevice().getCurrentUser();