xref: /aosp_15_r20/art/tools/run-jdwp-tests.sh (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker#!/bin/bash
2*795d594fSAndroid Build Coastguard Worker#
3*795d594fSAndroid Build Coastguard Worker# Copyright (C) 2015 The Android Open Source Project
4*795d594fSAndroid Build Coastguard Worker#
5*795d594fSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*795d594fSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*795d594fSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*795d594fSAndroid Build Coastguard Worker#
9*795d594fSAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
10*795d594fSAndroid Build Coastguard Worker#
11*795d594fSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*795d594fSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*795d594fSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*795d594fSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*795d594fSAndroid Build Coastguard Worker# limitations under the License.
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Workerif [ ! -d libcore ]; then
18*795d594fSAndroid Build Coastguard Worker  echo "Script needs to be run at the root of the android tree"
19*795d594fSAndroid Build Coastguard Worker  exit 1
20*795d594fSAndroid Build Coastguard Workerfi
21*795d594fSAndroid Build Coastguard Worker
22*795d594fSAndroid Build Coastguard Workersource build/envsetup.sh >&/dev/null # for get_build_var, setpaths
23*795d594fSAndroid Build Coastguard Workerset_lunch_paths # include platform prebuilt java, javac, etc in $PATH.
24*795d594fSAndroid Build Coastguard Worker
25*795d594fSAndroid Build Coastguard Workerif [ -z "$ANDROID_HOST_OUT" ] ; then
26*795d594fSAndroid Build Coastguard Worker  ANDROID_HOST_OUT=${OUT_DIR-$ANDROID_BUILD_TOP/out}/host/linux-x86
27*795d594fSAndroid Build Coastguard Workerfi
28*795d594fSAndroid Build Coastguard Worker
29*795d594fSAndroid Build Coastguard Worker# "Root" (actually "system") directory on device (in the case of
30*795d594fSAndroid Build Coastguard Worker# target testing).
31*795d594fSAndroid Build Coastguard Workerandroid_root=${ART_TEST_ANDROID_ROOT:-/system}
32*795d594fSAndroid Build Coastguard Worker
33*795d594fSAndroid Build Coastguard Workerjava_lib_location="${ANDROID_HOST_OUT}/../common/obj/JAVA_LIBRARIES"
34*795d594fSAndroid Build Coastguard Workermake_target_name="apache-harmony-jdwp-tests-hostdex"
35*795d594fSAndroid Build Coastguard Worker
36*795d594fSAndroid Build Coastguard Workerfunction boot_classpath_arg {
37*795d594fSAndroid Build Coastguard Worker  local dir="$1"
38*795d594fSAndroid Build Coastguard Worker  local suffix="$2"
39*795d594fSAndroid Build Coastguard Worker  shift 2
40*795d594fSAndroid Build Coastguard Worker  local separator=""
41*795d594fSAndroid Build Coastguard Worker  for var
42*795d594fSAndroid Build Coastguard Worker  do
43*795d594fSAndroid Build Coastguard Worker    if [ "$var" = "conscrypt" ] && [ "$mode" = "target" ]; then
44*795d594fSAndroid Build Coastguard Worker      printf -- "${separator}/apex/com.android.conscrypt/javalib/conscrypt.jar";
45*795d594fSAndroid Build Coastguard Worker    elif [ "$var" = "core-icu4j" ] && [ "$mode" = "target" ]; then
46*795d594fSAndroid Build Coastguard Worker      printf -- "${separator}/apex/com.android.i18n/javalib/core-icu4j.jar";
47*795d594fSAndroid Build Coastguard Worker    else
48*795d594fSAndroid Build Coastguard Worker      printf -- "${separator}${dir}/${var}${suffix}.jar";
49*795d594fSAndroid Build Coastguard Worker    fi
50*795d594fSAndroid Build Coastguard Worker    separator=":"
51*795d594fSAndroid Build Coastguard Worker  done
52*795d594fSAndroid Build Coastguard Worker}
53*795d594fSAndroid Build Coastguard Worker
54*795d594fSAndroid Build Coastguard Worker# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
55*795d594fSAndroid Build Coastguard Worker# because that's what we use for compiling the boot.art image.
56*795d594fSAndroid Build Coastguard Worker# It may contain additional modules from TEST_CORE_JARS.
57*795d594fSAndroid Build Coastguard WorkerBOOT_CLASSPATH_JARS="core-oj core-libart okhttp bouncycastle apache-xml core-icu4j conscrypt"
58*795d594fSAndroid Build Coastguard Worker
59*795d594fSAndroid Build Coastguard Workervm_args=""
60*795d594fSAndroid Build Coastguard Workerart="$android_root/bin/art"
61*795d594fSAndroid Build Coastguard Workermode="target"
62*795d594fSAndroid Build Coastguard Workerart_debugee="sh $android_root/bin/art"
63*795d594fSAndroid Build Coastguard Workerargs=$@
64*795d594fSAndroid Build Coastguard Workerchroot_option=
65*795d594fSAndroid Build Coastguard Workerdebuggee_args="-Xcompiler-option --debuggable"
66*795d594fSAndroid Build Coastguard Workerdevice_dir="--device-dir=/data/local/tmp"
67*795d594fSAndroid Build Coastguard Worker# We use the art script on target to ensure the runner and the debuggee share the same
68*795d594fSAndroid Build Coastguard Worker# image.
69*795d594fSAndroid Build Coastguard Workervm_command="--vm-command=$art"
70*795d594fSAndroid Build Coastguard Workerimage_compiler_option=""
71*795d594fSAndroid Build Coastguard Workerplugin=""
72*795d594fSAndroid Build Coastguard Workerdebug="no"
73*795d594fSAndroid Build Coastguard Workerexplicit_debug="no"
74*795d594fSAndroid Build Coastguard Workerverbose="no"
75*795d594fSAndroid Build Coastguard Workerimage="-Ximage:/system/framework/art_boot_images/boot.art"
76*795d594fSAndroid Build Coastguard Workerboot_classpath="$(boot_classpath_arg /apex/com.android.art/javalib "" $BOOT_CLASSPATH_JARS)"
77*795d594fSAndroid Build Coastguard Workerboot_classpath_locations=""
78*795d594fSAndroid Build Coastguard Workerwith_jdwp_path=""
79*795d594fSAndroid Build Coastguard Workeragent_wrapper=""
80*795d594fSAndroid Build Coastguard Workervm_args=""
81*795d594fSAndroid Build Coastguard Worker# By default, we run the whole JDWP test suite.
82*795d594fSAndroid Build Coastguard Workerhas_specific_test="no"
83*795d594fSAndroid Build Coastguard Workertest="org.apache.harmony.jpda.tests.share.AllTests"
84*795d594fSAndroid Build Coastguard Worker# Use JIT compiling by default.
85*795d594fSAndroid Build Coastguard Workeruse_jit=true
86*795d594fSAndroid Build Coastguard Workerinstant_jit=false
87*795d594fSAndroid Build Coastguard Workervariant_cmdline_parameter="--variant=X32"
88*795d594fSAndroid Build Coastguard Workerdump_command="/bin/true"
89*795d594fSAndroid Build Coastguard Workercalled_from_libjdwp=${RUN_JDWP_TESTS_CALLED_FROM_LIBJDWP:-false}
90*795d594fSAndroid Build Coastguard Workerrun_internal_jdwp_test=false
91*795d594fSAndroid Build Coastguard Worker# Let LUCI bots do what they want.
92*795d594fSAndroid Build Coastguard Workerif test -v LUCI_CONTEXT; then
93*795d594fSAndroid Build Coastguard Worker  run_internal_jdwp_test=true
94*795d594fSAndroid Build Coastguard Workerfi
95*795d594fSAndroid Build Coastguard Worker# Timeout of JDWP test in ms.
96*795d594fSAndroid Build Coastguard Worker#
97*795d594fSAndroid Build Coastguard Worker# Note: some tests expect a timeout to check that *no* reply/event is received for a specific case.
98*795d594fSAndroid Build Coastguard Worker# A lower timeout can save up several minutes when running the whole test suite, especially for
99*795d594fSAndroid Build Coastguard Worker# continuous testing. This value can be adjusted to fit the configuration of the host machine(s).
100*795d594fSAndroid Build Coastguard Workerjdwp_test_timeout=10000
101*795d594fSAndroid Build Coastguard Worker
102*795d594fSAndroid Build Coastguard Workerskip_tests=
103*795d594fSAndroid Build Coastguard Workergdb_target=
104*795d594fSAndroid Build Coastguard Workerhas_gdb="no"
105*795d594fSAndroid Build Coastguard Worker
106*795d594fSAndroid Build Coastguard Workerwhile true; do
107*795d594fSAndroid Build Coastguard Worker  if [[ "$1" == "--mode=host" ]]; then
108*795d594fSAndroid Build Coastguard Worker    mode="host"
109*795d594fSAndroid Build Coastguard Worker    # Specify bash explicitly since the art script cannot, since it has to run on the device
110*795d594fSAndroid Build Coastguard Worker    # with mksh.
111*795d594fSAndroid Build Coastguard Worker    art="bash ${OUT_DIR-out}/host/linux-x86/bin/art"
112*795d594fSAndroid Build Coastguard Worker    art_debugee="bash ${OUT_DIR-out}/host/linux-x86/bin/art"
113*795d594fSAndroid Build Coastguard Worker    # We force generation of a new image to avoid build-time and run-time classpath differences.
114*795d594fSAndroid Build Coastguard Worker    image="-Ximage:/system/non/existent/vogar.art"
115*795d594fSAndroid Build Coastguard Worker    # Pass the host boot classpath.
116*795d594fSAndroid Build Coastguard Worker    if [ "${ANDROID_HOST_OUT:0:${#ANDROID_BUILD_TOP}+1}" = "${ANDROID_BUILD_TOP}/" ]; then
117*795d594fSAndroid Build Coastguard Worker      framework_location="${ANDROID_HOST_OUT:${#ANDROID_BUILD_TOP}+1}/framework"
118*795d594fSAndroid Build Coastguard Worker    else
119*795d594fSAndroid Build Coastguard Worker      echo "error: ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"
120*795d594fSAndroid Build Coastguard Worker      echo "ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP}"
121*795d594fSAndroid Build Coastguard Worker      echo "ANDROID_HOST_OUT=${ANDROID_HOST_OUT}"
122*795d594fSAndroid Build Coastguard Worker      exit
123*795d594fSAndroid Build Coastguard Worker    fi
124*795d594fSAndroid Build Coastguard Worker    boot_classpath="$(boot_classpath_arg ${ANDROID_HOST_OUT}/framework -hostdex $BOOT_CLASSPATH_JARS)"
125*795d594fSAndroid Build Coastguard Worker    boot_classpath_locations="$(boot_classpath_arg ${framework_location} -hostdex $BOOT_CLASSPATH_JARS)"
126*795d594fSAndroid Build Coastguard Worker    # We do not need a device directory on host.
127*795d594fSAndroid Build Coastguard Worker    device_dir=""
128*795d594fSAndroid Build Coastguard Worker    # Vogar knows which VM to use on host.
129*795d594fSAndroid Build Coastguard Worker    vm_command=""
130*795d594fSAndroid Build Coastguard Worker    shift
131*795d594fSAndroid Build Coastguard Worker  elif [[ "$1" == "--mode=jvm" ]]; then
132*795d594fSAndroid Build Coastguard Worker    mode="ri"
133*795d594fSAndroid Build Coastguard Worker    make_target_name="apache-harmony-jdwp-tests"
134*795d594fSAndroid Build Coastguard Worker    run_internal_jdwp_test=true
135*795d594fSAndroid Build Coastguard Worker    art="$(which java)"
136*795d594fSAndroid Build Coastguard Worker    art_debugee="$(which java)"
137*795d594fSAndroid Build Coastguard Worker    # No need for extra args.
138*795d594fSAndroid Build Coastguard Worker    debuggee_args=""
139*795d594fSAndroid Build Coastguard Worker    # No image. On the RI.
140*795d594fSAndroid Build Coastguard Worker    image=""
141*795d594fSAndroid Build Coastguard Worker    boot_classpath=""
142*795d594fSAndroid Build Coastguard Worker    boot_classpath_locations=""
143*795d594fSAndroid Build Coastguard Worker    # We do not need a device directory on RI.
144*795d594fSAndroid Build Coastguard Worker    device_dir=""
145*795d594fSAndroid Build Coastguard Worker    # Vogar knows which VM to use on RI.
146*795d594fSAndroid Build Coastguard Worker    vm_command=""
147*795d594fSAndroid Build Coastguard Worker    # We don't care about jit with the RI
148*795d594fSAndroid Build Coastguard Worker    use_jit=false
149*795d594fSAndroid Build Coastguard Worker    shift
150*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == --skip-test ]]; then
151*795d594fSAndroid Build Coastguard Worker    skip_tests="${skip_tests},${2}"
152*795d594fSAndroid Build Coastguard Worker    # remove the --skip-test
153*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
154*795d594fSAndroid Build Coastguard Worker    shift
155*795d594fSAndroid Build Coastguard Worker    # remove the arg
156*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
157*795d594fSAndroid Build Coastguard Worker    shift
158*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == --force-run-test ]]; then
159*795d594fSAndroid Build Coastguard Worker    run_internal_jdwp_test=true
160*795d594fSAndroid Build Coastguard Worker    # remove the --force-run-test
161*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
162*795d594fSAndroid Build Coastguard Worker    shift
163*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == --test-timeout-ms ]]; then
164*795d594fSAndroid Build Coastguard Worker    # Remove the --test-timeout-ms from the arguments.
165*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
166*795d594fSAndroid Build Coastguard Worker    shift
167*795d594fSAndroid Build Coastguard Worker    jdwp_test_timeout=$1
168*795d594fSAndroid Build Coastguard Worker    # Remove the argument
169*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
170*795d594fSAndroid Build Coastguard Worker    shift
171*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == --agent-wrapper ]]; then
172*795d594fSAndroid Build Coastguard Worker    # Remove the --agent-wrapper from the arguments.
173*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
174*795d594fSAndroid Build Coastguard Worker    shift
175*795d594fSAndroid Build Coastguard Worker    agent_wrapper=${agent_wrapper}${1},
176*795d594fSAndroid Build Coastguard Worker    # Remove the argument
177*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
178*795d594fSAndroid Build Coastguard Worker    shift
179*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == -Ximage:* ]]; then
180*795d594fSAndroid Build Coastguard Worker    image="$1"
181*795d594fSAndroid Build Coastguard Worker    shift
182*795d594fSAndroid Build Coastguard Worker  elif [[ "$1" == "--instant-jit" ]]; then
183*795d594fSAndroid Build Coastguard Worker    instant_jit=true
184*795d594fSAndroid Build Coastguard Worker    # Remove the --instant-jit from the arguments.
185*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
186*795d594fSAndroid Build Coastguard Worker    shift
187*795d594fSAndroid Build Coastguard Worker  elif [[ "$1" == "--no-jit" ]]; then
188*795d594fSAndroid Build Coastguard Worker    use_jit=false
189*795d594fSAndroid Build Coastguard Worker    # Remove the --no-jit from the arguments.
190*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
191*795d594fSAndroid Build Coastguard Worker    shift
192*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == "--no-debug" ]]; then
193*795d594fSAndroid Build Coastguard Worker    explicit_debug="yes"
194*795d594fSAndroid Build Coastguard Worker    debug="no"
195*795d594fSAndroid Build Coastguard Worker    # Remove the --no-debug from the arguments.
196*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
197*795d594fSAndroid Build Coastguard Worker    shift
198*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == "--debug" ]]; then
199*795d594fSAndroid Build Coastguard Worker    explicit_debug="yes"
200*795d594fSAndroid Build Coastguard Worker    debug="yes"
201*795d594fSAndroid Build Coastguard Worker    # Remove the --debug from the arguments.
202*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
203*795d594fSAndroid Build Coastguard Worker    shift
204*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == "--verbose" ]]; then
205*795d594fSAndroid Build Coastguard Worker    verbose="yes"
206*795d594fSAndroid Build Coastguard Worker    # Remove the --verbose from the arguments.
207*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
208*795d594fSAndroid Build Coastguard Worker    shift
209*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == "--gdbserver" ]]; then
210*795d594fSAndroid Build Coastguard Worker    # Remove the --gdbserver from the arguments.
211*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
212*795d594fSAndroid Build Coastguard Worker    has_gdb="yes"
213*795d594fSAndroid Build Coastguard Worker    shift
214*795d594fSAndroid Build Coastguard Worker    gdb_target=$1
215*795d594fSAndroid Build Coastguard Worker    # Remove the target from the arguments.
216*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
217*795d594fSAndroid Build Coastguard Worker    shift
218*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == "--test" ]]; then
219*795d594fSAndroid Build Coastguard Worker    # Remove the --test from the arguments.
220*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
221*795d594fSAndroid Build Coastguard Worker    shift
222*795d594fSAndroid Build Coastguard Worker    has_specific_test="yes"
223*795d594fSAndroid Build Coastguard Worker    test=$1
224*795d594fSAndroid Build Coastguard Worker    # Remove the test from the arguments.
225*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
226*795d594fSAndroid Build Coastguard Worker    shift
227*795d594fSAndroid Build Coastguard Worker  elif [[ "$1" == "--jdwp-path" ]]; then
228*795d594fSAndroid Build Coastguard Worker    # Remove the --jdwp-path from the arguments.
229*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
230*795d594fSAndroid Build Coastguard Worker    shift
231*795d594fSAndroid Build Coastguard Worker    with_jdwp_path=$1
232*795d594fSAndroid Build Coastguard Worker    # Remove the path from the arguments.
233*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
234*795d594fSAndroid Build Coastguard Worker    shift
235*795d594fSAndroid Build Coastguard Worker  elif [[ "$1" == "" ]]; then
236*795d594fSAndroid Build Coastguard Worker    break
237*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == --variant=* ]]; then
238*795d594fSAndroid Build Coastguard Worker    variant_cmdline_parameter=$1
239*795d594fSAndroid Build Coastguard Worker    shift
240*795d594fSAndroid Build Coastguard Worker  elif [[ $1 == -Xplugin:* ]]; then
241*795d594fSAndroid Build Coastguard Worker    plugin="$1"
242*795d594fSAndroid Build Coastguard Worker    args=${args/$1}
243*795d594fSAndroid Build Coastguard Worker    shift
244*795d594fSAndroid Build Coastguard Worker  else
245*795d594fSAndroid Build Coastguard Worker    shift
246*795d594fSAndroid Build Coastguard Worker  fi
247*795d594fSAndroid Build Coastguard Workerdone
248*795d594fSAndroid Build Coastguard Worker
249*795d594fSAndroid Build Coastguard Workerif [ ! -t 1 ] ; then
250*795d594fSAndroid Build Coastguard Worker  # Suppress color codes if not attached to a terminal
251*795d594fSAndroid Build Coastguard Worker  args="$args --no-color"
252*795d594fSAndroid Build Coastguard Workerfi
253*795d594fSAndroid Build Coastguard Worker
254*795d594fSAndroid Build Coastguard Workerif [[ $mode == "target" ]]; then
255*795d594fSAndroid Build Coastguard Worker  # Honor environment variable ART_TEST_CHROOT.
256*795d594fSAndroid Build Coastguard Worker  if [[ -n "$ART_TEST_CHROOT" ]]; then
257*795d594fSAndroid Build Coastguard Worker    # Set Vogar's `--chroot` option.
258*795d594fSAndroid Build Coastguard Worker    chroot_option="--chroot $ART_TEST_CHROOT"
259*795d594fSAndroid Build Coastguard Worker    # Adjust settings for chroot environment.
260*795d594fSAndroid Build Coastguard Worker    art="/system/bin/art"
261*795d594fSAndroid Build Coastguard Worker    art_debugee="sh /system/bin/art"
262*795d594fSAndroid Build Coastguard Worker    vm_command="--vm-command=$art"
263*795d594fSAndroid Build Coastguard Worker    device_dir="--device-dir=/tmp"
264*795d594fSAndroid Build Coastguard Worker  fi
265*795d594fSAndroid Build Coastguard Workerfi
266*795d594fSAndroid Build Coastguard Worker
267*795d594fSAndroid Build Coastguard Workerif [[ $called_from_libjdwp != "true" ]]; then
268*795d594fSAndroid Build Coastguard Worker  if [[ $run_internal_jdwp_test = "false" ]]; then
269*795d594fSAndroid Build Coastguard Worker    echo "Calling run_jdwp_tests.sh directly is probably not what you want. You probably want to"
270*795d594fSAndroid Build Coastguard Worker    echo "run ./art/tools/run-libjdwp-tests.sh instead in order to test the JDWP implementation"
271*795d594fSAndroid Build Coastguard Worker    echo "used by apps. If you really wish to run these tests using the deprecated internal JDWP"
272*795d594fSAndroid Build Coastguard Worker    echo "implementation pass the '--force-run-test' flag."
273*795d594fSAndroid Build Coastguard Worker    exit 1
274*795d594fSAndroid Build Coastguard Worker  fi
275*795d594fSAndroid Build Coastguard Workerfi
276*795d594fSAndroid Build Coastguard Worker
277*795d594fSAndroid Build Coastguard Workerif [[ $has_gdb = "yes" ]]; then
278*795d594fSAndroid Build Coastguard Worker  if [[ $explicit_debug = "no" ]]; then
279*795d594fSAndroid Build Coastguard Worker    debug="yes"
280*795d594fSAndroid Build Coastguard Worker  fi
281*795d594fSAndroid Build Coastguard Workerfi
282*795d594fSAndroid Build Coastguard Worker
283*795d594fSAndroid Build Coastguard Workerif [[ $mode == "ri" ]]; then
284*795d594fSAndroid Build Coastguard Worker  if [[ "x$with_jdwp_path" != "x" ]]; then
285*795d594fSAndroid Build Coastguard Worker    vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentArgument=-agentpath:${agent_wrapper}"
286*795d594fSAndroid Build Coastguard Worker    vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentName=$with_jdwp_path"
287*795d594fSAndroid Build Coastguard Worker  fi
288*795d594fSAndroid Build Coastguard Worker  if [[ "x$image" != "x" ]]; then
289*795d594fSAndroid Build Coastguard Worker    echo "Cannot use -Ximage: with --mode=jvm"
290*795d594fSAndroid Build Coastguard Worker    exit 1
291*795d594fSAndroid Build Coastguard Worker  elif [[ $has_gdb = "yes" ]]; then
292*795d594fSAndroid Build Coastguard Worker    echo "Cannot use --gdbserver with --mode=jvm"
293*795d594fSAndroid Build Coastguard Worker    exit 1
294*795d594fSAndroid Build Coastguard Worker  elif [[ $debug == "yes" ]]; then
295*795d594fSAndroid Build Coastguard Worker    echo "Cannot use --debug with --mode=jvm"
296*795d594fSAndroid Build Coastguard Worker    exit 1
297*795d594fSAndroid Build Coastguard Worker  fi
298*795d594fSAndroid Build Coastguard Workerelse
299*795d594fSAndroid Build Coastguard Worker  if [[ "$mode" == "host" ]]; then
300*795d594fSAndroid Build Coastguard Worker    dump_command="/bin/kill -3"
301*795d594fSAndroid Build Coastguard Worker  else
302*795d594fSAndroid Build Coastguard Worker    # Note that this dumping command won't work when `$android_root`
303*795d594fSAndroid Build Coastguard Worker    # is different from `/system` (e.g. on ART Buildbot devices) when
304*795d594fSAndroid Build Coastguard Worker    # the device is running Android N, as the debuggerd protocol
305*795d594fSAndroid Build Coastguard Worker    # changed in an incompatible way in Android O (see b/32466479).
306*795d594fSAndroid Build Coastguard Worker    dump_command="$android_root/xbin/su root $android_root/bin/debuggerd"
307*795d594fSAndroid Build Coastguard Worker  fi
308*795d594fSAndroid Build Coastguard Worker  if [[ $has_gdb = "yes" ]]; then
309*795d594fSAndroid Build Coastguard Worker    if [[ $mode == "target" ]]; then
310*795d594fSAndroid Build Coastguard Worker      echo "Cannot use --gdbserver with --mode=target"
311*795d594fSAndroid Build Coastguard Worker      exit 1
312*795d594fSAndroid Build Coastguard Worker    else
313*795d594fSAndroid Build Coastguard Worker      art_debugee="$art_debugee --gdbserver $gdb_target"
314*795d594fSAndroid Build Coastguard Worker      # The tests absolutely require some timeout. We set a ~2 week timeout since we can kill the
315*795d594fSAndroid Build Coastguard Worker      # test with gdb if it goes on too long.
316*795d594fSAndroid Build Coastguard Worker      jdwp_test_timeout="1000000000"
317*795d594fSAndroid Build Coastguard Worker    fi
318*795d594fSAndroid Build Coastguard Worker  fi
319*795d594fSAndroid Build Coastguard Worker  if [[ "x$with_jdwp_path" != "x" ]]; then
320*795d594fSAndroid Build Coastguard Worker    vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentArgument=-agentpath:${agent_wrapper}"
321*795d594fSAndroid Build Coastguard Worker    vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentName=${with_jdwp_path}"
322*795d594fSAndroid Build Coastguard Worker  fi
323*795d594fSAndroid Build Coastguard Worker  vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --debuggable"
324*795d594fSAndroid Build Coastguard Worker  # we don't want to be trying to connect to adbconnection which might not have
325*795d594fSAndroid Build Coastguard Worker  # been built.
326*795d594fSAndroid Build Coastguard Worker  vm_args="${vm_args} --vm-arg -XjdwpProvider:none"
327*795d594fSAndroid Build Coastguard Worker  # Make sure the debuggee doesn't re-generate, nor clean up what the debugger has generated.
328*795d594fSAndroid Build Coastguard Worker  art_debugee="$art_debugee --no-compile --no-clean"
329*795d594fSAndroid Build Coastguard Workerfi
330*795d594fSAndroid Build Coastguard Worker
331*795d594fSAndroid Build Coastguard Workerfunction jlib_name {
332*795d594fSAndroid Build Coastguard Worker  local path=$1
333*795d594fSAndroid Build Coastguard Worker  local str="classes"
334*795d594fSAndroid Build Coastguard Worker  local suffix="jar"
335*795d594fSAndroid Build Coastguard Worker  if [[ $mode == "ri" ]]; then
336*795d594fSAndroid Build Coastguard Worker    str="javalib"
337*795d594fSAndroid Build Coastguard Worker  fi
338*795d594fSAndroid Build Coastguard Worker  echo "$path/$str.$suffix"
339*795d594fSAndroid Build Coastguard Worker}
340*795d594fSAndroid Build Coastguard Worker
341*795d594fSAndroid Build Coastguard Worker# Jar containing all the tests.
342*795d594fSAndroid Build Coastguard Workertest_jar=$(jlib_name "${java_lib_location}/${make_target_name}_intermediates")
343*795d594fSAndroid Build Coastguard Worker
344*795d594fSAndroid Build Coastguard Workerif [[ ! -f $test_jar ]]; then
345*795d594fSAndroid Build Coastguard Worker  echo "Before running, you must build jdwp tests and vogar:" \
346*795d594fSAndroid Build Coastguard Worker       "m ${make_target_name} vogar"
347*795d594fSAndroid Build Coastguard Worker  exit 1
348*795d594fSAndroid Build Coastguard Workerfi
349*795d594fSAndroid Build Coastguard Worker
350*795d594fSAndroid Build Coastguard Worker# For the host:
351*795d594fSAndroid Build Coastguard Worker#
352*795d594fSAndroid Build Coastguard Worker# If, on the other hand, there is a variant set, use it to modify the art_debugee parameter to
353*795d594fSAndroid Build Coastguard Worker# force the fork to have the same bitness as the controller. This should be fine and not impact
354*795d594fSAndroid Build Coastguard Worker# testing (cross-bitness), as the protocol is always 64-bit anyways (our implementation).
355*795d594fSAndroid Build Coastguard Worker#
356*795d594fSAndroid Build Coastguard Worker# Note: this isn't necessary for the device as the BOOTCLASSPATH environment variable is set there
357*795d594fSAndroid Build Coastguard Worker#       and used as a fallback.
358*795d594fSAndroid Build Coastguard Workerif [[ $mode == "host" ]]; then
359*795d594fSAndroid Build Coastguard Worker  variant=${variant_cmdline_parameter:10}
360*795d594fSAndroid Build Coastguard Worker  if [[ $variant == "x32" || $variant == "X32" ]]; then
361*795d594fSAndroid Build Coastguard Worker    art_debugee="$art_debugee --32"
362*795d594fSAndroid Build Coastguard Worker  elif [[ $variant == "x64" || $variant == "X64" ]]; then
363*795d594fSAndroid Build Coastguard Worker    art_debugee="$art_debugee --64"
364*795d594fSAndroid Build Coastguard Worker  else
365*795d594fSAndroid Build Coastguard Worker    echo "Error, do not understand variant $variant_cmdline_parameter."
366*795d594fSAndroid Build Coastguard Worker    exit 1
367*795d594fSAndroid Build Coastguard Worker  fi
368*795d594fSAndroid Build Coastguard Workerfi
369*795d594fSAndroid Build Coastguard Worker
370*795d594fSAndroid Build Coastguard Workerif [[ "$image" != "" ]]; then
371*795d594fSAndroid Build Coastguard Worker  vm_args="$vm_args --vm-arg $image"
372*795d594fSAndroid Build Coastguard Worker  debuggee_args="$debuggee_args $image"
373*795d594fSAndroid Build Coastguard Workerfi
374*795d594fSAndroid Build Coastguard Workerif [[ "$boot_classpath" != "" ]]; then
375*795d594fSAndroid Build Coastguard Worker  vm_args="$vm_args --vm-arg -Xbootclasspath:${boot_classpath}"
376*795d594fSAndroid Build Coastguard Worker  debuggee_args="$debuggee_args -Xbootclasspath:${boot_classpath}"
377*795d594fSAndroid Build Coastguard Workerfi
378*795d594fSAndroid Build Coastguard Workerif [[ "$boot_classpath_locations" != "" ]]; then
379*795d594fSAndroid Build Coastguard Worker  vm_args="$vm_args --vm-arg -Xbootclasspath-locations:${boot_classpath_locations}"
380*795d594fSAndroid Build Coastguard Worker  debuggee_args="$debuggee_args -Xbootclasspath-locations:${boot_classpath_locations}"
381*795d594fSAndroid Build Coastguard Workerfi
382*795d594fSAndroid Build Coastguard Worker
383*795d594fSAndroid Build Coastguard Workerif [[ "$plugin" != "" ]]; then
384*795d594fSAndroid Build Coastguard Worker  vm_args="$vm_args --vm-arg $plugin"
385*795d594fSAndroid Build Coastguard Workerfi
386*795d594fSAndroid Build Coastguard Worker
387*795d594fSAndroid Build Coastguard Workerif [[ $mode != "ri" ]]; then
388*795d594fSAndroid Build Coastguard Worker  # Because we're running debuggable, we discard any AOT code.
389*795d594fSAndroid Build Coastguard Worker  # Therefore we run dex2oat with 'verify' to avoid spending time compiling.
390*795d594fSAndroid Build Coastguard Worker  vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --compiler-filter=verify"
391*795d594fSAndroid Build Coastguard Worker  debuggee_args="$debuggee_args -Xcompiler-option --compiler-filter=verify"
392*795d594fSAndroid Build Coastguard Worker
393*795d594fSAndroid Build Coastguard Worker  if $instant_jit; then
394*795d594fSAndroid Build Coastguard Worker    debuggee_args="$debuggee_args -Xjitthreshold:0"
395*795d594fSAndroid Build Coastguard Worker  fi
396*795d594fSAndroid Build Coastguard Worker
397*795d594fSAndroid Build Coastguard Worker  vm_args="$vm_args --vm-arg -Xusejit:$use_jit"
398*795d594fSAndroid Build Coastguard Worker  debuggee_args="$debuggee_args -Xusejit:$use_jit"
399*795d594fSAndroid Build Coastguard Workerfi
400*795d594fSAndroid Build Coastguard Worker
401*795d594fSAndroid Build Coastguard Workerif [[ $debug == "yes" ]]; then
402*795d594fSAndroid Build Coastguard Worker  art="$art -d"
403*795d594fSAndroid Build Coastguard Worker  art_debugee="$art_debugee -d"
404*795d594fSAndroid Build Coastguard Worker  vm_args="$vm_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
405*795d594fSAndroid Build Coastguard Workerfi
406*795d594fSAndroid Build Coastguard Workerif [[ $verbose == "yes" ]]; then
407*795d594fSAndroid Build Coastguard Worker  # Enable JDWP logs in the debuggee.
408*795d594fSAndroid Build Coastguard Worker  art_debugee="$art_debugee -verbose:jdwp"
409*795d594fSAndroid Build Coastguard Workerfi
410*795d594fSAndroid Build Coastguard Worker
411*795d594fSAndroid Build Coastguard Workerif [[ $mode != "ri" ]]; then
412*795d594fSAndroid Build Coastguard Worker  toolchain_args="--toolchain d8 --language CUR"
413*795d594fSAndroid Build Coastguard Worker  if [[ "x$with_jdwp_path" == "x" ]]; then
414*795d594fSAndroid Build Coastguard Worker    # Need to enable the internal jdwp implementation.
415*795d594fSAndroid Build Coastguard Worker    art_debugee="${art_debugee} -XjdwpProvider:internal"
416*795d594fSAndroid Build Coastguard Worker  else
417*795d594fSAndroid Build Coastguard Worker    # need to disable the jdwpProvider since we give the agent explicitly on the
418*795d594fSAndroid Build Coastguard Worker    # cmdline.
419*795d594fSAndroid Build Coastguard Worker    art_debugee="${art_debugee} -XjdwpProvider:none"
420*795d594fSAndroid Build Coastguard Worker  fi
421*795d594fSAndroid Build Coastguard Workerelse
422*795d594fSAndroid Build Coastguard Worker  toolchain_args="--toolchain javac --language CUR"
423*795d594fSAndroid Build Coastguard Workerfi
424*795d594fSAndroid Build Coastguard Worker
425*795d594fSAndroid Build Coastguard Worker# Run the tests using vogar.
426*795d594fSAndroid Build Coastguard Workervogar $vm_command \
427*795d594fSAndroid Build Coastguard Worker      $vm_args \
428*795d594fSAndroid Build Coastguard Worker      --verbose \
429*795d594fSAndroid Build Coastguard Worker      $args \
430*795d594fSAndroid Build Coastguard Worker      $chroot_option \
431*795d594fSAndroid Build Coastguard Worker      $device_dir \
432*795d594fSAndroid Build Coastguard Worker      $image_compiler_option \
433*795d594fSAndroid Build Coastguard Worker      --timeout 800 \
434*795d594fSAndroid Build Coastguard Worker      --vm-arg -Djpda.settings.verbose=true \
435*795d594fSAndroid Build Coastguard Worker      --vm-arg -Djpda.settings.timeout=$jdwp_test_timeout \
436*795d594fSAndroid Build Coastguard Worker      --vm-arg -Djpda.settings.waitingTime=$jdwp_test_timeout \
437*795d594fSAndroid Build Coastguard Worker      --vm-arg -Djpda.settings.transportAddress=127.0.0.1:55107 \
438*795d594fSAndroid Build Coastguard Worker      --vm-arg -Djpda.settings.dumpProcess="$dump_command" \
439*795d594fSAndroid Build Coastguard Worker      --vm-arg -Djpda.settings.debuggeeJavaPath="$art_debugee $plugin $debuggee_args" \
440*795d594fSAndroid Build Coastguard Worker      --vm-arg -Djpda.settings.badTestCases="$skip_tests" \
441*795d594fSAndroid Build Coastguard Worker      --classpath "$test_jar" \
442*795d594fSAndroid Build Coastguard Worker      $toolchain_args \
443*795d594fSAndroid Build Coastguard Worker      $test
444*795d594fSAndroid Build Coastguard Worker
445*795d594fSAndroid Build Coastguard Workervogar_exit_status=$?
446*795d594fSAndroid Build Coastguard Worker
447*795d594fSAndroid Build Coastguard Workerecho "Killing stalled dalvikvm processes..."
448*795d594fSAndroid Build Coastguard Workerif [[ $mode == "host" ]]; then
449*795d594fSAndroid Build Coastguard Worker  pkill -9 -f /bin/dalvikvm
450*795d594fSAndroid Build Coastguard Workerelse
451*795d594fSAndroid Build Coastguard Worker  # Tests may run on older Android versions where pkill requires "-l SIGNAL"
452*795d594fSAndroid Build Coastguard Worker  # rather than "-SIGNAL".
453*795d594fSAndroid Build Coastguard Worker  adb shell pkill -l 9 -f /bin/dalvikvm
454*795d594fSAndroid Build Coastguard Workerfi
455*795d594fSAndroid Build Coastguard Workerecho "Done."
456*795d594fSAndroid Build Coastguard Worker
457*795d594fSAndroid Build Coastguard Workerexit $vogar_exit_status
458