Rewrite run-test scripts for `src-dex2oat-unresolved`.

Rename `src-dex2oat-unresolved/` to `src-aotex/` and compile
to `$TEST_NAME-aotex.jar`, so that it can be used together
with `src-ex/` which is compiled to `$TEST_NAME-ex.jar`.

Introduce `src-bcpex/`, compiled to `$TEST_NAME-bcpex.jar,
that is added to the boot class path at runtime but not for
AOT compilation.

Test: testrunner.py --host --jvm
Test: testrunner.py --target --optimizing
Bug: 203171409
Change-Id: Ic4751b743c2f53c8f4567ed35a4b14d0e7cac05a
diff --git a/test/529-checker-unresolved/run b/test/529-checker-unresolved/run
deleted file mode 100644
index 63fdb8c..0000000
--- a/test/529-checker-unresolved/run
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2015 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.
-
-# Use secondary switch to add secondary dex file to class path.
-exec ${RUN} "${@}" --secondary
diff --git a/test/529-checker-unresolved/src-dex2oat-unresolved/UnresolvedClass.java b/test/529-checker-unresolved/src-aotex/UnresolvedClass.java
similarity index 100%
rename from test/529-checker-unresolved/src-dex2oat-unresolved/UnresolvedClass.java
rename to test/529-checker-unresolved/src-aotex/UnresolvedClass.java
diff --git a/test/529-checker-unresolved/src-dex2oat-unresolved/UnresolvedInterface.java b/test/529-checker-unresolved/src-aotex/UnresolvedInterface.java
similarity index 100%
rename from test/529-checker-unresolved/src-dex2oat-unresolved/UnresolvedInterface.java
rename to test/529-checker-unresolved/src-aotex/UnresolvedInterface.java
diff --git a/test/529-checker-unresolved/src-dex2oat-unresolved/UnresolvedSuperClass.java b/test/529-checker-unresolved/src-aotex/UnresolvedSuperClass.java
similarity index 100%
rename from test/529-checker-unresolved/src-dex2oat-unresolved/UnresolvedSuperClass.java
rename to test/529-checker-unresolved/src-aotex/UnresolvedSuperClass.java
diff --git a/test/608-checker-unresolved-lse/run b/test/608-checker-unresolved-lse/run
deleted file mode 100644
index 226891f..0000000
--- a/test/608-checker-unresolved-lse/run
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2016 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.
-
-# Use secondary switch to add secondary dex file to class path.
-exec ${RUN} "${@}" --secondary
diff --git a/test/608-checker-unresolved-lse/src-dex2oat-unresolved/MissingInterface.java b/test/608-checker-unresolved-lse/src-aotex/MissingInterface.java
similarity index 100%
rename from test/608-checker-unresolved-lse/src-dex2oat-unresolved/MissingInterface.java
rename to test/608-checker-unresolved-lse/src-aotex/MissingInterface.java
diff --git a/test/648-inline-caches-unresolved/run b/test/648-inline-caches-unresolved/run
index fb70d22..d24ef42 100644
--- a/test/648-inline-caches-unresolved/run
+++ b/test/648-inline-caches-unresolved/run
@@ -14,4 +14,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-exec ${RUN} $@ --secondary --profile
+exec ${RUN} $@ --profile
diff --git a/test/648-inline-caches-unresolved/src-dex2oat-unresolved/UnresolvedSuperClass.java b/test/648-inline-caches-unresolved/src-aotex/UnresolvedSuperClass.java
similarity index 100%
rename from test/648-inline-caches-unresolved/src-dex2oat-unresolved/UnresolvedSuperClass.java
rename to test/648-inline-caches-unresolved/src-aotex/UnresolvedSuperClass.java
diff --git a/test/706-checker-scheduler/run b/test/706-checker-scheduler/run
deleted file mode 100644
index 5ffc303..0000000
--- a/test/706-checker-scheduler/run
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2017 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.
-
-# Use secondary switch to add secondary dex file to class path.
-exec ${RUN} "${@}" --secondary
diff --git a/test/706-checker-scheduler/src-dex2oat-unresolved/UnresolvedClass.java b/test/706-checker-scheduler/src-aotex/UnresolvedClass.java
similarity index 100%
rename from test/706-checker-scheduler/src-dex2oat-unresolved/UnresolvedClass.java
rename to test/706-checker-scheduler/src-aotex/UnresolvedClass.java
diff --git a/test/831-unresolved-field/run b/test/831-unresolved-field/run
deleted file mode 100644
index 23424f6..0000000
--- a/test/831-unresolved-field/run
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2021 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.
-
-# Use secondary switch to add secondary dex file to class path.
-exec ${RUN} "${@}" --secondary
diff --git a/test/831-unresolved-field/src-dex2oat-unresolved/UnresolvedClass.java b/test/831-unresolved-field/src-aotex/UnresolvedClass.java
similarity index 100%
rename from test/831-unresolved-field/src-dex2oat-unresolved/UnresolvedClass.java
rename to test/831-unresolved-field/src-aotex/UnresolvedClass.java
diff --git a/test/etc/default-build b/test/etc/default-build
index c48eff5..0702930 100755
--- a/test/etc/default-build
+++ b/test/etc/default-build
@@ -59,7 +59,8 @@
 HAS_SMALI_EX = path.exists("smali-ex")
 HAS_SRC_EX = path.exists("src-ex")
 HAS_SRC_EX2 = path.exists("src-ex2")
-HAS_SRC_DEX2OAT_UNRESOLVED = path.exists("src-dex2oat-unresolved")
+HAS_SRC_AOTEX = path.exists("src-aotex")
+HAS_SRC_BCPEX = path.exists("src-bcpex")
 HAS_HIDDENAPI_SPEC = path.exists("hiddenapi-flags.csv")
 
 # USE_HIDDENAPI=false run-test... will disable hiddenapi.
@@ -251,62 +252,71 @@
   return HAS_SRC_MULTIDEX or HAS_JASMIN_MULTIDEX or HAS_SMALI_MULTIDEX
 
 
-if HAS_SRC_DEX2OAT_UNRESOLVED:
-  os.makedirs("classes", exist_ok=True)
-  os.makedirs("classes-ex")
-  javac_with_bootclasspath([
-      "-implicit:none", "-sourcepath", "src-dex2oat-unresolved", "-d", "classes"
-  ] + find("src", "*.java"))
-  javac_with_bootclasspath(
-      ["-implicit:none", "-sourcepath", "src", "-d", "classes-ex"] +
-      find("src-dex2oat-unresolved", "*.java"))
+src_tmp_all = []
+if HAS_SRC and (HAS_SRC_MULTIDEX or HAS_SRC_AOTEX or HAS_SRC_BCPEX):
+  # To allow circular references, compile src/, src-multidex/, src-aotex/ and
+  # src-bcpex/ together and pass the output as class path argument.
+  # Replacement sources in src-art/ and src2 can replace symbols used by the
+  # other src-* sources we compile here but everything needed to compile the
+  # other src-* sources should be present in src/.
+  os.makedirs("classes-tmp-all")
+  javac_with_bootclasspath(["-implicit:none", "-d", "classes-tmp-all"] +
+                           find("src", "*.java") +
+                           find("src-multidex", "*.java") +
+                           find("src-aotex", "*.java") +
+                           find("src-bcpex", "*.java"))
+  src_tmp_all = ["-cp", "classes-tmp-all"]
+
+if HAS_SRC_AOTEX:
+  os.makedirs("classes-aotex")
+  javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
+                           ["-d", "classes-aotex"] +
+                           find("src-aotex", "*.java"))
   if NEED_DEX:
-    make_dex("classes-ex")
+    make_dex("classes-aotex")
     # rename it so it shows up as "classes.dex" in the zip file.
-    os.rename("classes-ex.dex", "classes.dex")
-    zip(TEST_NAME + "-ex.jar", "classes.dex")
+    os.rename("classes-aotex.dex", "classes.dex")
+    zip(TEST_NAME + "-aotex.jar", "classes.dex")
+
+if HAS_SRC_BCPEX:
+  os.makedirs("classes-bcpex")
+  javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
+                           ["-d", "classes-bcpex"] +
+                           find("src-bcpex", "*.java"))
+  if NEED_DEX:
+    make_dex("classes-bcpex")
+    # rename it so it shows up as "classes.dex" in the zip file.
+    os.rename("classes-bcpex.dex", "classes.dex")
+    zip(TEST_NAME + "-bcpex.jar", "classes.dex")
+
+if HAS_SRC:
+  os.makedirs("classes", exist_ok=True)
+  javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
+                           ["-d", "classes"] + find("src", "*.java"))
+
+if HAS_SRC_ART:
+  os.makedirs("classes", exist_ok=True)
+  javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
+                           ["-d", "classes"] + find("src-art", "*.java"))
+
+if HAS_SRC_MULTIDEX:
+  os.makedirs("classes2")
+  javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
+                           ["-d", "classes2"] +
+                           find("src-multidex", "*.java"))
+  if NEED_DEX:
+    make_dex("classes2")
+
+if HAS_SRC2:
+  os.makedirs("classes", exist_ok=True)
+  javac_with_bootclasspath(["-classpath", "classes", "-d", "classes"] +
+                           find("src2", "*.java"))
+
+# If the classes directory is not-empty, package classes in a DEX file.
+# NB: some tests provide classes rather than java files.
+if find("classes", "*"):
+  if NEED_DEX:
     make_dex("classes")
-else:
-  src_tmp_all = []
-  if HAS_SRC and HAS_SRC_MULTIDEX:
-    # To allow circular references, compile src/ and src-multidex/ together
-    # and pass the output as class path argument. Replacement sources
-    # in src-art/ can replace symbols used by src-multidex but everything
-    # needed to compile src-multidex should be present in src/.
-    os.makedirs("classes-tmp-all")
-    javac_with_bootclasspath(["-implicit:none", "-d", "classes-tmp-all"] +
-                             find("src", "*.java") +
-                             find("src-multidex", "*.java"))
-    src_tmp_all = ["-cp", "classes-tmp-all"]
-
-  if HAS_SRC:
-    os.makedirs("classes", exist_ok=True)
-    javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
-                             ["-d", "classes"] + find("src", "*.java"))
-
-  if HAS_SRC_ART:
-    os.makedirs("classes", exist_ok=True)
-    javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
-                             ["-d", "classes"] + find("src-art", "*.java"))
-
-  if HAS_SRC_MULTIDEX:
-    os.makedirs("classes2")
-    javac_with_bootclasspath(["-implicit:none"] + src_tmp_all +
-                             ["-d", "classes2"] +
-                             find("src-multidex", "*.java"))
-    if NEED_DEX:
-      make_dex("classes2")
-
-  if HAS_SRC2:
-    os.makedirs("classes", exist_ok=True)
-    javac_with_bootclasspath(["-classpath", "classes", "-d", "classes"] +
-                             find("src2", "*.java"))
-
-  # If the classes directory is not-empty, package classes in a DEX file.
-  # NB: some tests provide classes rather than java files.
-  if find("classes", "*"):
-    if NEED_DEX:
-      make_dex("classes")
 
 if HAS_JASMIN:
   # Compile Jasmin classes as if they were part of the classes.dex file.
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index e67fa42..1275743 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -741,9 +741,14 @@
 readonly b_path=$(get_apex_bootclasspath ${HOST})
 readonly b_path_locations=$(get_apex_bootclasspath_locations ${HOST})
 
+BCPEX=
+if [ -f "$TEST_NAME-bcpex.jar" ] ; then
+  BCPEX=":$DEX_LOCATION/$TEST_NAME-bcpex.jar"
+fi
+
 # Pass down the bootclasspath
-FLAGS="${FLAGS} -Xbootclasspath:${b_path}"
-FLAGS="${FLAGS} -Xbootclasspath-locations:${b_path_locations}"
+FLAGS="${FLAGS} -Xbootclasspath:${b_path}${BCPEX}"
+FLAGS="${FLAGS} -Xbootclasspath-locations:${b_path_locations}${BCPEX}"
 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath:${b_path}"
 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath-locations:${b_path_locations}"
 
@@ -1139,6 +1144,12 @@
   QUOTED_DALVIKVM_BOOT_OPT="$DALVIKVM_BOOT_OPT"
 fi
 
+DALVIKVM_CLASSPATH=$DEX_LOCATION/$TEST_NAME.jar
+if [ -f "$TEST_NAME-aotex.jar" ] ; then
+  DALVIKVM_CLASSPATH=$DALVIKVM_CLASSPATH:$DEX_LOCATION/$TEST_NAME-aotex.jar
+fi
+DALVIKVM_CLASSPATH=$DALVIKVM_CLASSPATH$SECONDARY_DEX
+
 # We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
 # b/27185632
 # b/24664297
@@ -1157,7 +1168,7 @@
                   ${QUOTED_DALVIKVM_BOOT_OPT} \
                   $TMP_DIR_OPTION \
                   -XX:DumpNativeStackOnSigQuit:false \
-                  -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
+                  -cp $DALVIKVM_CLASSPATH $MAIN $ARGS"
 
 if [ "x$SIMPLEPERF" == xyes ]; then
   dalvikvm_cmdline="simpleperf record ${dalvikvm_cmdline} && simpleperf report"
@@ -1214,6 +1225,8 @@
       adb shell mkdir -p $CHROOT_DEX_LOCATION
       adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION
       adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION
+      adb push $TEST_NAME-aotex.jar $CHROOT_DEX_LOCATION
+      adb push $TEST_NAME-bcpex.jar $CHROOT_DEX_LOCATION
       if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
         adb push profile $CHROOT_DEX_LOCATION
       fi
@@ -1226,6 +1239,8 @@
       adb shell mkdir -p $CHROOT_DEX_LOCATION >/dev/null 2>&1
       adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
       adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
+      adb push $TEST_NAME-aotex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
+      adb push $TEST_NAME-bcpex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
       if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
         adb push profile $CHROOT_DEX_LOCATION >/dev/null 2>&1
       fi
diff --git a/test/utils/regen-test-files b/test/utils/regen-test-files
index 4de6653..ee1c184 100755
--- a/test/utils/regen-test-files
+++ b/test/utils/regen-test-files
@@ -373,7 +373,8 @@
                    "smali",
                    "smali-ex",
                    "smali-multidex",
-                   "src-dex2oat-unresolved",
+                   "src-aotex",
+                   "src-bcpex",
                    "src-ex",
                    "src-ex2",
                    "src-multidex",