summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dan Zimmerman <danzimm@fb.com> 2019-12-22 15:26:39 -0800
committer Mathieu Chartier <mathieuc@google.com> 2020-02-07 22:37:33 +0000
commit73b6aa9fd182603cee4baad16adab66d2f63ef78 (patch)
treee15be5d2a68ac7f3f238cca9785f2f61f960aac8
parent4cbb51a0c057249a500ca7fe3947401978f165d2 (diff)
[art] Enable compilation of secondary dexes by default in tests
Previously tests used unoptimized secondary dex files (if they used a secondary dex file). After this change all tests will use optimized secondary dex files unless they explicitly opt out. Right now the only tests that opt out of optimized secondary dex files are: - 130-hprof - At the moment unloading app images is not implemented (or it is and I couldn't find it / it's not working for this test), and this test relies on dex files properly getting unloaded. - 141-class-unload - See explanation for 130-hprof - 674-hiddenapi - Compilation skirts hidden API checks - 719-dm-verify-redefinition - This test seems to compile secondary dex files itself, so we should disable the "automatic" compilation Test: test/testrunner/testrunner.py -b --host Bug: 149098478 Change-Id: I73592c597df629717db6d75eb977bf943bb6de72
-rw-r--r--test/130-hprof/run18
-rw-r--r--test/138-duplicate-classes-check/src-art/Main.java5
-rw-r--r--test/141-class-unload/run18
-rwxr-xr-xtest/674-hiddenapi/run5
-rw-r--r--test/719-dm-verify-redefinition/run1
-rwxr-xr-xtest/etc/run-test-jar110
6 files changed, 131 insertions, 26 deletions
diff --git a/test/130-hprof/run b/test/130-hprof/run
new file mode 100644
index 0000000000..73a984e082
--- /dev/null
+++ b/test/130-hprof/run
@@ -0,0 +1,18 @@
+#!/bin/bash
+#
+# Copyright (C) 2020 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.
+
+# Currently app images aren't unloaded when dex files are unloaded.
+exec ${RUN} $@ --no-secondary-app-image
diff --git a/test/138-duplicate-classes-check/src-art/Main.java b/test/138-duplicate-classes-check/src-art/Main.java
index b32f0bcc46..35d0209af8 100644
--- a/test/138-duplicate-classes-check/src-art/Main.java
+++ b/test/138-duplicate-classes-check/src-art/Main.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import dalvik.system.DexClassLoader;
+import dalvik.system.PathClassLoader;
import java.io.File;
import java.lang.reflect.Method;
@@ -32,9 +32,8 @@ public class Main {
// Now run the class from the -ex file.
String dexPath = System.getenv("DEX_LOCATION") + "/138-duplicate-classes-check-ex.jar";
- String optimizedDirectory = System.getenv("DEX_LOCATION");
String librarySearchPath = null;
- DexClassLoader loader = new DexClassLoader(dexPath, optimizedDirectory, librarySearchPath,
+ PathClassLoader loader = new PathClassLoader(dexPath, librarySearchPath,
getClass().getClassLoader());
try {
diff --git a/test/141-class-unload/run b/test/141-class-unload/run
new file mode 100644
index 0000000000..73a984e082
--- /dev/null
+++ b/test/141-class-unload/run
@@ -0,0 +1,18 @@
+#!/bin/bash
+#
+# Copyright (C) 2020 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.
+
+# Currently app images aren't unloaded when dex files are unloaded.
+exec ${RUN} $@ --no-secondary-app-image
diff --git a/test/674-hiddenapi/run b/test/674-hiddenapi/run
index 2babeefbe5..b57d10a905 100755
--- a/test/674-hiddenapi/run
+++ b/test/674-hiddenapi/run
@@ -16,4 +16,7 @@
# Make verification soft fail so that we can re-verify boot classpath
# methods at runtime.
-exec ${RUN} $@ --verify-soft-fail \ No newline at end of file
+#
+# N.B. Compilation of secondary dexes can prevent hidden API checks, e.g. if
+# a blacklisted field get is inlined.
+exec ${RUN} $@ --verify-soft-fail --no-secondary-compilation
diff --git a/test/719-dm-verify-redefinition/run b/test/719-dm-verify-redefinition/run
index f4e9d7124c..26e10e1151 100644
--- a/test/719-dm-verify-redefinition/run
+++ b/test/719-dm-verify-redefinition/run
@@ -23,4 +23,5 @@ exec ${RUN} \
--dm \
--vdex-arg \
--class-loader-context=PCL[$DEX_LOCATION/719-dm-verify-redefinition-ex.jar] \
+ --no-secondary-compilation \
"${@}"
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index d593677a84..abe50c9756 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -84,6 +84,9 @@ TEST_VDEX="n"
TEST_DM="n"
TEST_IS_NDEBUG="n"
APP_IMAGE="y"
+SECONDARY_APP_IMAGE="y"
+SECONDARY_CLASS_LOADER_CONTEXT=""
+SECONDARY_COMPILATION="y"
JVMTI_STRESS="n"
JVMTI_STEP_STRESS="n"
JVMTI_FIELD_STRESS="n"
@@ -233,6 +236,16 @@ while true; do
elif [ "x$1" = "x--no-app-image" ]; then
APP_IMAGE="n"
shift
+ elif [ "x$1" = "x--no-secondary-app-image" ]; then
+ SECONDARY_APP_IMAGE="n"
+ shift
+ elif [ "x$1" = "x--secondary-class-loader-context" ]; then
+ shift
+ SECONDARY_CLASS_LOADER_CONTEXT="$1"
+ shift
+ elif [ "x$1" = "x--no-secondary-compilation" ]; then
+ SECONDARY_COMPILATION="n"
+ shift
elif [ "x$1" = "x--strip-dex" ]; then
STRIP_DEX="y"
shift
@@ -902,13 +915,27 @@ if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
fi
fi
-if [ "$PREBUILD" = "y" ]; then
- mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
+function write_dex2oat_cmdlines {
+ local name="$1"
+
+ local class_loader_context=""
+ local enable_app_image=false
if [ "$APP_IMAGE" = "y" ]; then
- # Pick a base that will force the app image to get relocated.
- app_image="--app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art --resolve-startup-const-strings=true"
+ enable_app_image=true
fi
+ # If the name ends in -ex then this is a secondary dex file
+ if [ "${name:${#name}-3}" = "-ex" ]; then
+ # Lazily realize the default value in case DEX_LOCATION/TEST_NAME change
+ [ -z "$SECONDARY_CLASS_LOADER_CONTEXT" ] && SECONDARY_CLASS_LOADER_CONTEXT="PCL[];PCL[$DEX_LOCATION/$TEST_NAME.jar]"
+ class_loader_context="'--class-loader-context=$SECONDARY_CLASS_LOADER_CONTEXT'"
+ $enable_app_image && [ "$SECONDARY_APP_IMAGE" = "y" ] || enable_app_image=false
+ fi
+
+ local app_image=""
+ $enable_app_image && app_image="--app-image-file=$DEX_LOCATION/oat/$ISA/$name.art --resolve-startup-const-strings=true"
+
+ local dex2oat_binary
dex2oat_binary=${DEX2OAT_DEBUG_BINARY}
if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
dex2oat_binary=${DEX2OAT_NDEBUG_BINARY}
@@ -916,18 +943,16 @@ if [ "$PREBUILD" = "y" ]; then
dex2oat_cmdline="$INVOKE_WITH $ANDROID_ART_BIN_DIR/$dex2oat_binary \
$COMPILE_FLAGS \
--boot-image=${BOOT_IMAGE} \
- --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
- --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
- ${app_image} \
+ --dex-file=$DEX_LOCATION/$name.jar \
+ --oat-file=$DEX_LOCATION/oat/$ISA/$name.odex \
+ "$app_image" \
--generate-mini-debug-info \
- --instruction-set=$ISA"
+ --instruction-set=$ISA \
+ $class_loader_context"
if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
fi
- # Enable mini-debug-info for JIT (if JIT is used).
- FLAGS="$FLAGS -Xcompiler-option --generate-mini-debug-info"
-
# Add in a timeout. This is important for testing the compilation/verification time of
# pathological cases.
# Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
@@ -940,15 +965,45 @@ if [ "$PREBUILD" = "y" ]; then
dex2oat_cmdline="timeout -k ${DEX2OAT_TIMEOUT}s -s SIGRTMIN+2 ${DEX2OAT_RT_TIMEOUT}s ${dex2oat_cmdline} --watchdog-timeout=${DEX2OAT_TIMEOUT}000"
fi
if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
- vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
+ vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex"
elif [ "$TEST_VDEX" = "y" ]; then
- vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
+ vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex"
elif [ "$TEST_DM" = "y" ]; then
dex2oat_cmdline="${dex2oat_cmdline} --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
- dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$TEST_NAME.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
- vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.dm"
- elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
- vdex_cmdline="${dex2oat_cmdline} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
+ dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$name.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
+ vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$name.dm"
+ fi
+}
+
+if [ "$PREBUILD" = "y" ]; then
+ mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
+
+ # "Primary".
+ write_dex2oat_cmdlines "$TEST_NAME"
+ dex2oat_cmdline=$(echo $dex2oat_cmdline)
+ dm_cmdline=$(echo $dm_cmdline)
+ vdex_cmdline=$(echo $vdex_cmdline)
+
+ # Enable mini-debug-info for JIT (if JIT is used).
+ FLAGS="$FLAGS -Xcompiler-option --generate-mini-debug-info"
+
+ if [ -f "$TEST_NAME-ex.jar" ] && [ "$SECONDARY_COMPILATION" = "y" ] ; then
+ # "Secondary" for test coverage.
+
+ # Store primary values.
+ base_dex2oat_cmdline="$dex2oat_cmdline"
+ base_dm_cmdline="$dm_cmdline"
+ base_vdex_cmdline="$vdex_cmdline"
+
+ write_dex2oat_cmdlines "$TEST_NAME-ex"
+ dex2oat_cmdline=$(echo $dex2oat_cmdline)
+ dm_cmdline=$(echo $dm_cmdline)
+ vdex_cmdline=$(echo $vdex_cmdline)
+
+ # Concatenate.
+ dex2oat_cmdline="$base_dex2oat_cmdline && $dex2oat_cmdline"
+ dm_cmdline="$base_dm_cmdline" # Only use primary dm.
+ vdex_cmdline="$base_vdex_cmdline && $vdex_cmdline"
fi
fi
@@ -997,11 +1052,22 @@ dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ART_BIN_DIR/$DALVIKVM \
-XX:DumpNativeStackOnSigQuit:false \
-cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
+sanitize_dex2oat_cmdline() {
+ local args=()
+ for arg in "$@"; do
+ if [ "$arg" = "--class-loader-context=&" ]; then
+ arg="--class-loader-context=\&"
+ fi
+ args+=("$arg")
+ done
+ echo -n "${args[@]}"
+}
+
# Remove whitespace.
-dex2oat_cmdline=$(echo $dex2oat_cmdline)
+dex2oat_cmdline=$(sanitize_dex2oat_cmdline $(echo $dex2oat_cmdline))
dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
dm_cmdline=$(echo $dm_cmdline)
-vdex_cmdline=$(echo $vdex_cmdline)
+vdex_cmdline=$(sanitize_dex2oat_cmdline $(echo $vdex_cmdline))
profman_cmdline=$(echo $profman_cmdline)
# Use an empty ASAN_OPTIONS to enable defaults.
@@ -1262,9 +1328,9 @@ else
$linkroot_cmdline || { echo "create symlink android-root failed." >&2 ; exit 2; }
$linkroot_overlay_cmdline || { echo "overlay android-root failed." >&2 ; exit 2; }
$profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
- $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
- $dm_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
- $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
+ eval "$dex2oat_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
+ eval "$dm_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
+ eval "$vdex_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
$strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
$sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }