Split odsign_e2e_tests into two modules.

odsign_e2e_tests is in CTS. We cannot keep all test cases in this module
because some test cases don't meet to quaility bar. Besides, those tests
verify module behavior rather than platform behavior, so they should not
be in CTS anyway.

This change adds `include-filter`s to odsign_e2e_tests to filter out
test cases that shouldn't be in CTS. It adds a separate module
`odsign_e2e_tests_full` that contains all test cases.

Also, this change removes manual `enableAdbRoot` calls and adds
`RootTargetPreparer` to `odsign_e2e_tests_full`.

Bug: 219695818
Bug: 219698071
Bug: 219697768
Bug: 220604681
Bug: 218721247
Test: atest --collect-tests-only odsign_e2e_tests
Test: atest --collect-tests-only odsign_e2e_tests_full
Change-Id: I0eb47caa3d720e3063a6dd56a7f9ecb8ec2f30bd
diff --git a/test/odsign/Android.bp b/test/odsign/Android.bp
index 40676d5..c3cccd3 100644
--- a/test/odsign/Android.bp
+++ b/test/odsign/Android.bp
@@ -16,8 +16,15 @@
     default_applicable_licenses: ["art_license"],
 }
 
-java_test_host {
-    name: "odsign_e2e_tests",
+soong_config_module_type_import {
+    from: "art/build/SoongConfig.bp",
+    module_types: [
+        "art_module_java_defaults",
+    ],
+}
+
+art_module_java_defaults {
+    name: "odsign_e2e_tests_defaults",
     defaults: ["art_module_source_build_java_defaults"],
     srcs: ["test-src/**/*.java"],
     libs: ["tradefed"],
@@ -28,13 +35,27 @@
     data: [
         ":odsign_e2e_test_app",
     ],
+}
+
+java_test_host {
+    name: "odsign_e2e_tests",
+    defaults: ["odsign_e2e_tests_defaults"],
     test_config: "odsign-e2e-tests.xml",
     test_suites: [
-        "device-tests",
+        "general-tests",
         "cts",
     ],
 }
 
+java_test_host {
+    name: "odsign_e2e_tests_full",
+    defaults: ["odsign_e2e_tests_defaults"],
+    test_config: "odsign-e2e-tests-full.xml",
+    test_suites: [
+        "general-tests",
+    ],
+}
+
 cc_library_shared {
     name: "libOdsignTestAppJni",
     defaults: ["art_defaults"],
diff --git a/test/odsign/odsign-e2e-tests-full.xml b/test/odsign/odsign-e2e-tests-full.xml
new file mode 100644
index 0000000..a674721
--- /dev/null
+++ b/test/odsign/odsign-e2e-tests-full.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2022 The Android Open Source Project
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<configuration description="Config for all on-device signing ART e2e test cases">
+    <option name="test-suite-tag" value="odsign_e2e_tests_full" />
+    <option name="test-suite-tag" value="apct" />
+
+    <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer" />
+
+    <test class="com.android.tradefed.testtype.HostTest" >
+        <option name="jar" value="odsign_e2e_tests_full.jar" />
+    </test>
+
+    <!-- Only run tests if the device under test is SDK version 31 (Android 12) or above. -->
+    <object type="module_controller" class="com.android.tradefed.testtype.suite.module.Sdk31ModuleController" />
+</configuration>
diff --git a/test/odsign/odsign-e2e-tests.xml b/test/odsign/odsign-e2e-tests.xml
index 6dd31e2..3114b1e 100644
--- a/test/odsign/odsign-e2e-tests.xml
+++ b/test/odsign/odsign-e2e-tests.xml
@@ -13,7 +13,7 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-<configuration description="Config for on-device signing ART e2e test cases">
+<configuration description="Config for a subset of on-device signing ART e2e test cases that run in CTS">
     <option name="test-suite-tag" value="odsign_e2e_tests" />
     <option name="test-suite-tag" value="apct" />
     <option name="test-suite-tag" value="cts" />
@@ -25,6 +25,7 @@
 
     <test class="com.android.tradefed.testtype.HostTest" >
         <option name="jar" value="odsign_e2e_tests.jar" />
+        <option name="include-annotation" value="com.android.tests.odsign.annotation.CtsTestCase" />
     </test>
 
     <!-- Only run tests if the device under test is SDK version 31 (Android 12) or above. -->
diff --git a/test/odsign/test-src/com/android/tests/odsign/ActivationTest.java b/test/odsign/test-src/com/android/tests/odsign/ActivationTest.java
index b5101ae..05db530 100644
--- a/test/odsign/test-src/com/android/tests/odsign/ActivationTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/ActivationTest.java
@@ -18,6 +18,7 @@
 
 import static org.junit.Assert.assertTrue;
 
+import com.android.tests.odsign.annotation.CtsTestCase;
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
 import com.android.tradefed.testtype.junit4.DeviceTestRunOptions;
@@ -46,6 +47,7 @@
     }
 
     @Test
+    @CtsTestCase
     public void verifyArtUpgradeSignsFiles() throws Exception {
         installPackage(TEST_APP_APK);
         DeviceTestRunOptions options = new DeviceTestRunOptions(TEST_APP_PACKAGE_NAME);
@@ -55,6 +57,7 @@
     }
 
     @Test
+    @CtsTestCase
     public void verifyArtUpgradeGeneratesAnyArtifacts() throws Exception {
         installPackage(TEST_APP_APK);
         DeviceTestRunOptions options = new DeviceTestRunOptions(TEST_APP_PACKAGE_NAME);
@@ -65,11 +68,6 @@
 
     @Test
     public void verifyArtUpgradeGeneratesRequiredArtifacts() throws Exception {
-        // This test does not actually require root access, but we use `enableAdbRootOrSkipTest` as
-        // a way to skip the test in CTS. This test should not run in CTS because it has assumptions
-        // on the ART module's behavior.
-        mTestUtils.enableAdbRootOrSkipTest();
-
         installPackage(TEST_APP_APK);
         DeviceTestRunOptions options = new DeviceTestRunOptions(TEST_APP_PACKAGE_NAME);
         options.setTestClassName(TEST_APP_PACKAGE_NAME + ".ArtifactsSignedTest");
@@ -79,9 +77,6 @@
 
     @Test
     public void verifyGeneratedArtifactsLoaded() throws Exception {
-        // Checking zygote and system_server need the device have adb root to walk process maps.
-        mTestUtils.enableAdbRootOrSkipTest();
-
         // Check both zygote and system_server processes to see that they have loaded the
         // artifacts compiled and signed by odrefresh and odsign. We check both here rather than
         // having a separate test because the device reboots between each @Test method and
@@ -92,16 +87,12 @@
 
     @Test
     public void verifyGeneratedArtifactsLoadedAfterReboot() throws Exception {
-        mTestUtils.enableAdbRootOrSkipTest();
-
         mTestUtils.reboot();
         verifyGeneratedArtifactsLoaded();
     }
 
     @Test
     public void verifyGeneratedArtifactsLoadedAfterPartialCompilation() throws Exception {
-        mTestUtils.enableAdbRootOrSkipTest();
-
         Set<String> mappedArtifacts = mTestUtils.getSystemServerLoadedArtifacts();
         // Delete an arbitrary artifact.
         getDevice().deleteFile(mappedArtifacts.iterator().next());
diff --git a/test/odsign/test-src/com/android/tests/odsign/CompOsDenialHostTest.java b/test/odsign/test-src/com/android/tests/odsign/CompOsDenialHostTest.java
index 442e190..16ef562 100644
--- a/test/odsign/test-src/com/android/tests/odsign/CompOsDenialHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/CompOsDenialHostTest.java
@@ -57,7 +57,6 @@
         CompOsTestUtils compOsTestUtils = new CompOsTestUtils(device);
 
         compOsTestUtils.assumeCompOsPresent();
-        testUtils.enableAdbRootOrSkipTest();
 
         testUtils.installTestApex();
 
@@ -82,7 +81,6 @@
 
         // Reboot should restore the device back to a good state.
         testUtils.reboot();
-        testUtils.restoreAdbRoot();
     }
 
     @Before
diff --git a/test/odsign/test-src/com/android/tests/odsign/CompOsSigningHostTest.java b/test/odsign/test-src/com/android/tests/odsign/CompOsSigningHostTest.java
index cd6fe18..bb382d6 100644
--- a/test/odsign/test-src/com/android/tests/odsign/CompOsSigningHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/CompOsSigningHostTest.java
@@ -24,6 +24,7 @@
 
 import static org.junit.Assume.assumeTrue;
 
+import com.android.tests.odsign.annotation.CtsTestCase;
 import com.android.tradefed.device.DeviceNotAvailableException;
 import com.android.tradefed.device.ITestDevice;
 import com.android.tradefed.invoker.TestInformation;
@@ -85,7 +86,6 @@
         OdsignTestUtils testUtils = new OdsignTestUtils(testInfo);
         testUtils.uninstallTestApex();
         testUtils.reboot();
-        testUtils.restoreAdbRoot();
     }
 
     @Test
@@ -96,7 +96,6 @@
 
         // The log files are currently only available through a rooted shell.
         OdsignTestUtils testUtils = new OdsignTestUtils(getTestInformation());
-        testUtils.enableAdbRootOrSkipTest();
 
         testUtils.archiveLogThenDelete(mTestLogs, CompOsTestUtils.APEXDATA_DIR + "/vm.log",
                         "vm.log-CompOsSigningHostTest");
@@ -105,6 +104,7 @@
     }
 
     @Test
+    @CtsTestCase
     public void checkFileChecksums() throws Exception {
         CompOsTestUtils compOsTestUtils = new CompOsTestUtils(getDevice());
         String actualChecksums = compOsTestUtils.checksumDirectoryContentPartial(
@@ -119,6 +119,7 @@
     }
 
     @Test
+    @CtsTestCase
     public void checkFileCreationTimeAfterVmStartAndBeforeReboot() throws Exception {
         OdsignTestUtils testUtils = new OdsignTestUtils(getTestInformation());
 
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 833a44e..d27902f 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdrefreshHostTest.java
@@ -60,7 +60,6 @@
     @BeforeClassWithInfo
     public static void beforeClassWithDevice(TestInformation testInfo) throws Exception {
         OdsignTestUtils testUtils = new OdsignTestUtils(testInfo);
-        testUtils.enableAdbRootOrSkipTest();
         testUtils.installTestApex();
         testUtils.reboot();
 
@@ -81,7 +80,6 @@
         OdsignTestUtils testUtils = new OdsignTestUtils(testInfo);
         testUtils.uninstallTestApex();
         testUtils.reboot();
-        testUtils.restoreAdbRoot();
     }
 
     @Before
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 162ad72..7905660 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OdsignTestUtils.java
@@ -66,8 +66,6 @@
     private static final Duration RESTART_ZYGOTE_COMPLETE_TIMEOUT = Duration.ofMinutes(3);
 
     private static final String TAG = "OdsignTestUtils";
-    private static final String WAS_ADB_ROOT_KEY = TAG + ":WAS_ADB_ROOT";
-    private static final String ADB_ROOT_ENABLED_KEY = TAG + ":ADB_ROOT_ENABLED";
     private static final String PACKAGE_NAME_KEY = TAG + ":PACKAGE_NAME";
 
     private final InstallUtilsHost mInstallUtils;
@@ -274,25 +272,6 @@
     }
 
     /**
-     * Enables adb root or skips the test if adb root is not supported.
-     */
-    public void enableAdbRootOrSkipTest() throws Exception {
-        setBoolean(WAS_ADB_ROOT_KEY, mTestInfo.getDevice().isAdbRoot());
-        boolean adbRootEnabled = mTestInfo.getDevice().enableAdbRoot();
-        assumeTrue("ADB root failed and required to get process maps", adbRootEnabled);
-        setBoolean(ADB_ROOT_ENABLED_KEY, adbRootEnabled);
-    }
-
-    /**
-     * Restores the device to the state before {@link enableAdbRootOrSkipTest} was called.
-     */
-    public void restoreAdbRoot() throws Exception {
-        if (getBooleanOrDefault(ADB_ROOT_ENABLED_KEY) && !getBooleanOrDefault(WAS_ADB_ROOT_KEY)) {
-            mTestInfo.getDevice().disableAdbRoot();
-        }
-    }
-
-    /**
      * Returns the value of a boolean test property, or false if it does not exist.
      */
     private boolean getBooleanOrDefault(String key) {
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 cf83b0b..13faf55 100644
--- a/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java
+++ b/test/odsign/test-src/com/android/tests/odsign/OnDeviceSigningHostTest.java
@@ -48,13 +48,11 @@
         OdsignTestUtils testUtils = new OdsignTestUtils(testInfo);
         testUtils.uninstallTestApex();
         testUtils.reboot();
-        testUtils.restoreAdbRoot();
     }
 
     @Test
     public void verifyCompilationLogGenerated() throws Exception {
         OdsignTestUtils testUtils = new OdsignTestUtils(getTestInformation());
-        testUtils.enableAdbRootOrSkipTest();
 
         // Check there is a compilation log, we expect compilation to have occurred.
         assertTrue("Compilation log not found", testUtils.haveCompilationLog());
diff --git a/test/odsign/test-src/com/android/tests/odsign/annotation/CtsTestCase.java b/test/odsign/test-src/com/android/tests/odsign/annotation/CtsTestCase.java
new file mode 100644
index 0000000..37e44c0
--- /dev/null
+++ b/test/odsign/test-src/com/android/tests/odsign/annotation/CtsTestCase.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tests.odsign.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used for a set of test cases that are suitable to run in CTS.
+ * A test case running in CTS must not require root access, and it must meet the quality bar on
+ * failure rate and average runtime.
+ */
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface CtsTestCase {}