Remove `RootTargetPreparer` from odsign_e2e_tests.
Instead, we enable ADB root for individual test cases, and skip the test
case if ADB root is not supported. This allows us to run some test cases
that don't require root access on devices that don't support ADB root.
Bug: 214016309
Test: Run `odsign_e2e_tests` on a userdebug build and see all test cases
pass.
Test: Run `odsign_e2e_tests` on a user build and see 2 test cases pass,
while others are skipped.
Change-Id: I3d74800f5ce25555fec52ef65cbe57fcfe711907
diff --git a/test/odsign/odsign-e2e-tests.xml b/test/odsign/odsign-e2e-tests.xml
index 37dc513..6dd31e2 100644
--- a/test/odsign/odsign-e2e-tests.xml
+++ b/test/odsign/odsign-e2e-tests.xml
@@ -23,7 +23,6 @@
<!-- odsign runs on early boot, so multi-user doesn't apply. -->
<option name="config-descriptor:metadata" key="parameter" value="not_secondary_user" />
- <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/>
<test class="com.android.tradefed.testtype.HostTest" >
<option name="jar" value="odsign_e2e_tests.jar" />
</test>
diff --git a/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java b/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
index fc8e57f..0a907f2 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
@@ -58,6 +58,7 @@
public static void beforeClassWithDevice(TestInformation testInfo) throws Exception {
sTestUtils = new OdsignTestUtils(testInfo);
sTestUtils.installTestApex();
+ sTestUtils.enableAdbRootOrSkipTest();
sZygoteArtifacts = new HashSet<>();
for (String zygoteName : sTestUtils.ZYGOTE_NAMES) {
@@ -70,6 +71,7 @@
@AfterClassWithInfo
public static void afterClassWithDevice(TestInformation testInfo) throws Exception {
sTestUtils.uninstallTestApex();
+ sTestUtils.restoreAdbRoot();
}
@Test
diff --git a/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java b/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
index f00ff14..e3a2eaa 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
@@ -53,6 +53,9 @@
private final InstallUtilsHost mInstallUtils;
private final TestInformation mTestInfo;
+ private boolean mWasAdbRoot = false;
+ private boolean mAdbRootEnabled = false;
+
public OdsignTestUtils(TestInformation testInfo) throws Exception {
assertNotNull(testInfo.getDevice());
mInstallUtils = new InstallUtilsHost(testInfo);
@@ -143,4 +146,22 @@
mTestInfo.getDevice().waitForBootComplete(BOOT_COMPLETE_TIMEOUT.toMillis());
assertWithMessage("Device didn't boot in %s", BOOT_COMPLETE_TIMEOUT).that(success).isTrue();
}
+
+ /**
+ * Enables adb root or skips the test if adb root is not supported.
+ */
+ public void enableAdbRootOrSkipTest() throws Exception {
+ mWasAdbRoot = mTestInfo.getDevice().isAdbRoot();
+ mAdbRootEnabled = mTestInfo.getDevice().enableAdbRoot();
+ assumeTrue("ADB root failed and required to get process maps", mAdbRootEnabled);
+ }
+
+ /**
+ * Restores the device to the state before {@link enableAdbRootOrSkipTest} was called.
+ */
+ public void restoreAdbRoot() throws Exception {
+ if (mAdbRootEnabled && !mWasAdbRoot) {
+ mTestInfo.getDevice().disableAdbRoot();
+ }
+ }
}
diff --git a/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java b/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java
index 9c1949c..fe8465a 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java
@@ -48,12 +48,13 @@
@BeforeClassWithInfo
public static void beforeClassWithDevice(TestInformation testInfo) throws Exception {
sTestUtils = new OdsignTestUtils(testInfo);
- sTestUtils.installTestApex();;
+ sTestUtils.installTestApex();
}
@AfterClassWithInfo
public static void afterClassWithDevice(TestInformation testInfo) throws Exception {
sTestUtils.uninstallTestApex();
+ sTestUtils.restoreAdbRoot();
}
@Test
@@ -77,8 +78,7 @@
@Test
public void verifyGeneratedArtifactsLoaded() throws Exception {
// Checking zygote and system_server need the device have adb root to walk process maps.
- final boolean adbEnabled = getDevice().enableAdbRoot();
- assertTrue("ADB root failed and required to get process maps", adbEnabled);
+ sTestUtils.enableAdbRootOrSkipTest();
// Check there is a compilation log, we expect compilation to have occurred.
assertTrue("Compilation log not found", sTestUtils.haveCompilationLog());
@@ -93,12 +93,16 @@
@Test
public void verifyGeneratedArtifactsLoadedAfterReboot() throws Exception {
+ sTestUtils.enableAdbRootOrSkipTest();
+
sTestUtils.reboot();
verifyGeneratedArtifactsLoaded();
}
@Test
public void verifyGeneratedArtifactsLoadedAfterPartialCompilation() throws Exception {
+ sTestUtils.enableAdbRootOrSkipTest();
+
Set<String> mappedArtifacts = sTestUtils.getSystemServerLoadedArtifacts();
// Delete an arbitrary artifact.
getDevice().deleteFile(mappedArtifacts.iterator().next());