blob: c58411c60b68272d3776693ec2d1e5873fd9257e [file] [log] [blame]
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +00001#!/bin/bash
2#
3# Copyright (C) 2015 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17if [ ! -d libcore ]; then
18 echo "Script needs to be run at the root of the android tree"
19 exit 1
20fi
21
Colin Crosse0ef0a82017-07-27 21:29:18 +000022source build/envsetup.sh >&/dev/null # for get_build_var, setpaths
23setpaths # include platform prebuilt java, javac, etc in $PATH.
Shubham Ajmerac33c0872017-07-20 18:41:52 -070024
Andreas Gampeebd089d2016-07-18 14:56:56 -070025if [ -z "$ANDROID_HOST_OUT" ] ; then
26 ANDROID_HOST_OUT=${OUT_DIR-$ANDROID_BUILD_TOP/out}/host/linux-x86
27fi
28
Alex Light617c9c52017-08-18 11:52:25 -070029java_lib_location="${ANDROID_HOST_OUT}/../common/obj/JAVA_LIBRARIES"
30make_target_name="apache-harmony-jdwp-tests-hostdex"
Igor Murashkin84f26322017-06-06 11:36:33 -070031
Alex Light617c9c52017-08-18 11:52:25 -070032vm_args=""
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000033art="/data/local/tmp/system/bin/art"
Nicolas Geoffray33e1f8f2015-04-24 14:37:29 +010034art_debugee="sh /data/local/tmp/system/bin/art"
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000035args=$@
Nicolas Geoffrayd553b432015-07-13 14:35:17 +010036debuggee_args="-Xcompiler-option --debuggable"
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000037device_dir="--device-dir=/data/local/tmp"
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +010038# We use the art script on target to ensure the runner and the debuggee share the same
39# image.
40vm_command="--vm-command=$art"
Nicolas Geoffraya2c18612015-03-30 23:01:28 +010041image_compiler_option=""
Alex Light617c9c52017-08-18 11:52:25 -070042plugin=""
Nicolas Geoffray9648a632015-06-15 14:35:01 +010043debug="no"
Alex Light84b92e02017-09-29 13:46:14 -070044explicit_debug="no"
Sebastien Hertza646aaf2015-09-10 12:03:51 +020045verbose="no"
Nicolas Geoffrayb76bc782016-09-14 12:33:34 +000046image="-Ximage:/data/art-test/core.art"
Alex Light0ac2e5c2017-09-19 15:35:20 -070047with_jdwp_path=""
48agent_wrapper=""
Nicolas Geoffray95186552015-10-28 13:06:21 +000049vm_args=""
Sebastien Hertza646aaf2015-09-10 12:03:51 +020050# By default, we run the whole JDWP test suite.
Alex Light84b92e02017-09-29 13:46:14 -070051has_specific_test="no"
Sebastien Hertza646aaf2015-09-10 12:03:51 +020052test="org.apache.harmony.jpda.tests.share.AllTests"
Alex Light617c9c52017-08-18 11:52:25 -070053mode="target"
Roland Levillain5db109b2016-05-19 12:24:17 +010054# Use JIT compiling by default.
55use_jit=true
Andreas Gampe85b286b2015-12-30 19:37:48 -080056variant_cmdline_parameter="--variant=X32"
Alex Light878f33f2018-02-08 11:16:39 -080057dump_command="/bin/true"
Sebastien Hertzc3b208c2017-03-27 11:35:54 +020058# Timeout of JDWP test in ms.
59#
60# Note: some tests expect a timeout to check that *no* reply/event is received for a specific case.
61# A lower timeout can save up several minutes when running the whole test suite, especially for
62# continuous testing. This value can be adjusted to fit the configuration of the host machine(s).
63jdwp_test_timeout=10000
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000064
Alex Light84b92e02017-09-29 13:46:14 -070065gdb_target=
66has_gdb="no"
67
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000068while true; do
69 if [[ "$1" == "--mode=host" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -070070 mode="host"
Nicolas Geoffray59786902015-03-30 16:34:16 +010071 # Specify bash explicitly since the art script cannot, since it has to run on the device
72 # with mksh.
Alex Lightb15fea22015-09-17 16:59:09 -070073 art="bash ${OUT_DIR-out}/host/linux-x86/bin/art"
74 art_debugee="bash ${OUT_DIR-out}/host/linux-x86/bin/art"
Andreas Gampe8994a042015-12-30 19:03:17 +000075 # We force generation of a new image to avoid build-time and run-time classpath differences.
76 image="-Ximage:/system/non/existent/vogar.art"
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +010077 # We do not need a device directory on host.
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000078 device_dir=""
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +010079 # Vogar knows which VM to use on host.
80 vm_command=""
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000081 shift
Alex Light617c9c52017-08-18 11:52:25 -070082 elif [[ "$1" == "--mode=jvm" ]]; then
83 mode="ri"
84 make_target_name="apache-harmony-jdwp-tests-host"
85 art="$(which java)"
86 art_debugee="$(which java)"
87 # No need for extra args.
88 debuggee_args=""
89 # No image. On the RI.
90 image=""
91 # We do not need a device directory on RI.
92 device_dir=""
93 # Vogar knows which VM to use on RI.
94 vm_command=""
95 # We don't care about jit with the RI
96 use_jit=false
97 shift
Alex Lightec4a10c2017-11-17 09:06:26 -080098 elif [[ $1 == --test-timeout-ms ]]; then
99 # Remove the --test-timeout-ms from the arguments.
100 args=${args/$1}
101 shift
102 jdwp_test_timeout=$1
103 # Remove the argument
104 args=${args/$1}
105 shift
Alex Light0ac2e5c2017-09-19 15:35:20 -0700106 elif [[ $1 == --agent-wrapper ]]; then
107 # Remove the --agent-wrapper from the arguments.
108 args=${args/$1}
109 shift
110 agent_wrapper=${agent_wrapper}${1},
111 # Remove the argument
112 args=${args/$1}
113 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000114 elif [[ $1 == -Ximage:* ]]; then
115 image="$1"
116 shift
Roland Levillain5db109b2016-05-19 12:24:17 +0100117 elif [[ "$1" == "--no-jit" ]]; then
118 use_jit=false
119 # Remove the --no-jit from the arguments.
120 args=${args/$1}
121 shift
Alex Light84b92e02017-09-29 13:46:14 -0700122 elif [[ $1 == "--no-debug" ]]; then
123 explicit_debug="yes"
124 debug="no"
125 # Remove the --no-debug from the arguments.
126 args=${args/$1}
127 shift
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100128 elif [[ $1 == "--debug" ]]; then
Alex Light84b92e02017-09-29 13:46:14 -0700129 explicit_debug="yes"
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100130 debug="yes"
131 # Remove the --debug from the arguments.
132 args=${args/$1}
133 shift
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200134 elif [[ $1 == "--verbose" ]]; then
135 verbose="yes"
136 # Remove the --verbose from the arguments.
137 args=${args/$1}
138 shift
Alex Light84b92e02017-09-29 13:46:14 -0700139 elif [[ $1 == "--gdbserver" ]]; then
140 # Remove the --gdbserver from the arguments.
141 args=${args/$1}
142 has_gdb="yes"
143 shift
144 gdb_target=$1
145 # Remove the target from the arguments.
146 args=${args/$1}
147 shift
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200148 elif [[ $1 == "--test" ]]; then
149 # Remove the --test from the arguments.
150 args=${args/$1}
151 shift
Alex Light84b92e02017-09-29 13:46:14 -0700152 has_specific_test="yes"
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200153 test=$1
154 # Remove the test from the arguments.
155 args=${args/$1}
156 shift
Alex Light617c9c52017-08-18 11:52:25 -0700157 elif [[ "$1" == "--jdwp-path" ]]; then
158 # Remove the --jdwp-path from the arguments.
159 args=${args/$1}
160 shift
Alex Light0ac2e5c2017-09-19 15:35:20 -0700161 with_jdwp_path=$1
Alex Light617c9c52017-08-18 11:52:25 -0700162 # Remove the path from the arguments.
163 args=${args/$1}
164 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000165 elif [[ "$1" == "" ]]; then
166 break
Andreas Gampe85b286b2015-12-30 19:37:48 -0800167 elif [[ $1 == --variant=* ]]; then
168 variant_cmdline_parameter=$1
169 shift
Alex Light617c9c52017-08-18 11:52:25 -0700170 elif [[ $1 == -Xplugin:* ]]; then
171 plugin="$1"
172 args=${args/$1}
173 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000174 else
175 shift
176 fi
177done
178
Alex Light84b92e02017-09-29 13:46:14 -0700179if [[ $has_gdb = "yes" ]]; then
180 if [[ $explicit_debug = "no" ]]; then
181 debug="yes"
182 fi
183fi
184
Alex Light617c9c52017-08-18 11:52:25 -0700185if [[ $mode == "ri" ]]; then
Alex Light0ac2e5c2017-09-19 15:35:20 -0700186 if [[ "x$with_jdwp_path" != "x" ]]; then
187 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentArgument=-agentpath:${agent_wrapper}"
188 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentName=$with_jdwp_path"
189 fi
Alex Light617c9c52017-08-18 11:52:25 -0700190 if [[ "x$image" != "x" ]]; then
191 echo "Cannot use -Ximage: with --mode=jvm"
192 exit 1
Alex Light84b92e02017-09-29 13:46:14 -0700193 elif [[ $has_gdb = "yes" ]]; then
194 echo "Cannot use --gdbserver with --mode=jvm"
195 exit 1
Alex Light617c9c52017-08-18 11:52:25 -0700196 elif [[ $debug == "yes" ]]; then
197 echo "Cannot use --debug with --mode=jvm"
198 exit 1
199 fi
200else
Alex Light878f33f2018-02-08 11:16:39 -0800201 if [[ "$mode" == "host" ]]; then
202 dump_command="/bin/kill -3"
203 else
204 # TODO It would be great to be able to use this on target too but we need to
205 # be able to walk /proc to figure out what the actual child pid is.
206 dump_command="/system/bin/true"
207 # dump_command="/system/xbin/su root /data/local/tmp/system/bin/debuggerd -b"
208 fi
Alex Light84b92e02017-09-29 13:46:14 -0700209 if [[ $has_gdb = "yes" ]]; then
210 if [[ $mode == "target" ]]; then
211 echo "Cannot use --gdbserver with --mode=target"
212 exit 1
213 else
214 art_debugee="$art_debugee --gdbserver $gdb_target"
215 # The tests absolutely require some timeout. We set a ~2 week timeout since we can kill the
216 # test with gdb if it goes on too long.
217 jdwp_test_timeout="1000000000"
218 fi
219 fi
Alex Light0ac2e5c2017-09-19 15:35:20 -0700220 if [[ "x$with_jdwp_path" != "x" ]]; then
221 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentArgument=-agentpath:${agent_wrapper}"
222 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentName=${with_jdwp_path}"
223 fi
Alex Light617c9c52017-08-18 11:52:25 -0700224 vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --debuggable"
225 # Make sure the debuggee doesn't clean up what the debugger has generated.
226 art_debugee="$art_debugee --no-clean"
227fi
228
229function jlib_name {
230 local path=$1
231 local str="classes"
232 local suffix="jar"
233 if [[ $mode == "ri" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -0700234 str="javalib"
Alex Light617c9c52017-08-18 11:52:25 -0700235 fi
236 echo "$path/$str.$suffix"
237}
238
239# Jar containing all the tests.
240test_jar=$(jlib_name "${java_lib_location}/${make_target_name}_intermediates")
241
242if [[ ! -f $test_jar ]]; then
243 echo "Before running, you must build jdwp tests and vogar:" \
244 "make ${make_target_name} vogar"
245 exit 1
246fi
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100247
Andreas Gampe85b286b2015-12-30 19:37:48 -0800248# For the host:
249#
250# If, on the other hand, there is a variant set, use it to modify the art_debugee parameter to
251# force the fork to have the same bitness as the controller. This should be fine and not impact
252# testing (cross-bitness), as the protocol is always 64-bit anyways (our implementation).
253#
254# Note: this isn't necessary for the device as the BOOTCLASSPATH environment variable is set there
255# and used as a fallback.
Alex Light617c9c52017-08-18 11:52:25 -0700256if [[ $mode == "host" ]]; then
Andreas Gampe85b286b2015-12-30 19:37:48 -0800257 variant=${variant_cmdline_parameter:10}
258 if [[ $variant == "x32" || $variant == "X32" ]]; then
259 art_debugee="$art_debugee --32"
260 elif [[ $variant == "x64" || $variant == "X64" ]]; then
261 art_debugee="$art_debugee --64"
262 else
263 echo "Error, do not understand variant $variant_cmdline_parameter."
264 exit 1
265 fi
266fi
267
Nicolas Geoffray95186552015-10-28 13:06:21 +0000268if [[ "$image" != "" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -0700269 vm_args="$vm_args --vm-arg $image"
Nicolas Geoffray95186552015-10-28 13:06:21 +0000270fi
Alex Light617c9c52017-08-18 11:52:25 -0700271
272if [[ "$plugin" != "" ]]; then
273 vm_args="$vm_args --vm-arg $plugin"
274fi
275
Roland Levillain5db109b2016-05-19 12:24:17 +0100276if $use_jit; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100277 vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --compiler-filter=quicken"
278 debuggee_args="$debuggee_args -Xcompiler-option --compiler-filter=quicken"
Roland Levillain5db109b2016-05-19 12:24:17 +0100279fi
Alex Light617c9c52017-08-18 11:52:25 -0700280
281if [[ $mode != "ri" ]]; then
282 vm_args="$vm_args --vm-arg -Xusejit:$use_jit"
283 debuggee_args="$debuggee_args -Xusejit:$use_jit"
284fi
285
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100286if [[ $debug == "yes" ]]; then
287 art="$art -d"
288 art_debugee="$art_debugee -d"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700289 vm_args="$vm_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100290fi
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200291if [[ $verbose == "yes" ]]; then
292 # Enable JDWP logs in the debuggee.
293 art_debugee="$art_debugee -verbose:jdwp"
294fi
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100295
Neil Fuller239bdf62018-01-08 18:55:36 +0000296if [[ $mode != "ri" ]]; then
Neil Fullerc546ec92018-01-05 15:00:35 +0000297 toolchain_args="--toolchain d8 --language CUR"
Alex Light264a4862018-01-31 16:47:58 +0000298 if [[ "x$with_jdwp_path" == "x" ]]; then
299 # Need to enable the internal jdwp implementation.
300 art_debugee="${art_debugee} -XjdwpProvider:internal"
301 fi
Alex Light8d8299d2017-11-10 08:41:04 -0800302else
303 toolchain_args="--toolchain javac --language CUR"
Igor Murashkin84f26322017-06-06 11:36:33 -0700304fi
305
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000306# Run the tests using vogar.
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +0100307vogar $vm_command \
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100308 $vm_args \
Nicolas Geoffray9620b9d2015-03-30 12:28:26 +0100309 --verbose \
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000310 $args \
311 $device_dir \
Nicolas Geoffraya2c18612015-03-30 23:01:28 +0100312 $image_compiler_option \
Nicolas Geoffray472b00c2015-05-06 14:57:09 +0100313 --timeout 800 \
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000314 --vm-arg -Djpda.settings.verbose=true \
Sebastien Hertzc3b208c2017-03-27 11:35:54 +0200315 --vm-arg -Djpda.settings.timeout=$jdwp_test_timeout \
316 --vm-arg -Djpda.settings.waitingTime=$jdwp_test_timeout \
Nicolas Geoffraya2c18612015-03-30 23:01:28 +0100317 --vm-arg -Djpda.settings.transportAddress=127.0.0.1:55107 \
Alex Light878f33f2018-02-08 11:16:39 -0800318 --vm-arg -Djpda.settings.dumpProcess="$dump_command" \
Alex Light617c9c52017-08-18 11:52:25 -0700319 --vm-arg -Djpda.settings.debuggeeJavaPath="$art_debugee $plugin $image $debuggee_args" \
Igor Murashkin84f26322017-06-06 11:36:33 -0700320 --classpath "$test_jar" \
321 $toolchain_args \
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200322 $test
Hiroshi Yamauchia166bbb2015-11-19 16:24:31 -0800323
324vogar_exit_status=$?
325
326echo "Killing stalled dalvikvm processes..."
Alex Lightc611ffa2017-10-18 08:59:16 -0700327if [[ $mode == "host" ]]; then
Hiroshi Yamauchia166bbb2015-11-19 16:24:31 -0800328 pkill -9 -f /bin/dalvikvm
329else
330 adb shell pkill -9 -f /bin/dalvikvm
331fi
332echo "Done."
333
334exit $vogar_exit_status