blob: 53c6fb63f945dda530556f0712fc5b1315d02f68 [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
Roland Levillain1c361882018-03-02 14:23:51 +000029android_root="/system"
30if [ -n "$ART_TEST_ANDROID_ROOT" ]; then
31 android_root="$ART_TEST_ANDROID_ROOT"
32fi
33
Alex Light617c9c52017-08-18 11:52:25 -070034java_lib_location="${ANDROID_HOST_OUT}/../common/obj/JAVA_LIBRARIES"
35make_target_name="apache-harmony-jdwp-tests-hostdex"
Igor Murashkin84f26322017-06-06 11:36:33 -070036
Alex Light617c9c52017-08-18 11:52:25 -070037vm_args=""
Roland Levillain1c361882018-03-02 14:23:51 +000038art="$android_root/bin/art"
39art_debugee="sh $android_root/bin/art"
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000040args=$@
Nicolas Geoffrayd553b432015-07-13 14:35:17 +010041debuggee_args="-Xcompiler-option --debuggable"
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000042device_dir="--device-dir=/data/local/tmp"
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +010043# We use the art script on target to ensure the runner and the debuggee share the same
44# image.
45vm_command="--vm-command=$art"
Nicolas Geoffraya2c18612015-03-30 23:01:28 +010046image_compiler_option=""
Alex Light617c9c52017-08-18 11:52:25 -070047plugin=""
Nicolas Geoffray9648a632015-06-15 14:35:01 +010048debug="no"
Alex Light84b92e02017-09-29 13:46:14 -070049explicit_debug="no"
Sebastien Hertza646aaf2015-09-10 12:03:51 +020050verbose="no"
Nicolas Geoffrayb76bc782016-09-14 12:33:34 +000051image="-Ximage:/data/art-test/core.art"
Alex Light0ac2e5c2017-09-19 15:35:20 -070052with_jdwp_path=""
53agent_wrapper=""
Nicolas Geoffray95186552015-10-28 13:06:21 +000054vm_args=""
Sebastien Hertza646aaf2015-09-10 12:03:51 +020055# By default, we run the whole JDWP test suite.
Alex Light84b92e02017-09-29 13:46:14 -070056has_specific_test="no"
Sebastien Hertza646aaf2015-09-10 12:03:51 +020057test="org.apache.harmony.jpda.tests.share.AllTests"
Alex Light617c9c52017-08-18 11:52:25 -070058mode="target"
Roland Levillain5db109b2016-05-19 12:24:17 +010059# Use JIT compiling by default.
60use_jit=true
Andreas Gampe85b286b2015-12-30 19:37:48 -080061variant_cmdline_parameter="--variant=X32"
Alex Light878f33f2018-02-08 11:16:39 -080062dump_command="/bin/true"
Sebastien Hertzc3b208c2017-03-27 11:35:54 +020063# Timeout of JDWP test in ms.
64#
65# Note: some tests expect a timeout to check that *no* reply/event is received for a specific case.
66# A lower timeout can save up several minutes when running the whole test suite, especially for
67# continuous testing. This value can be adjusted to fit the configuration of the host machine(s).
68jdwp_test_timeout=10000
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000069
Alex Light84b92e02017-09-29 13:46:14 -070070gdb_target=
71has_gdb="no"
72
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000073while true; do
74 if [[ "$1" == "--mode=host" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -070075 mode="host"
Nicolas Geoffray59786902015-03-30 16:34:16 +010076 # Specify bash explicitly since the art script cannot, since it has to run on the device
77 # with mksh.
Alex Lightb15fea22015-09-17 16:59:09 -070078 art="bash ${OUT_DIR-out}/host/linux-x86/bin/art"
79 art_debugee="bash ${OUT_DIR-out}/host/linux-x86/bin/art"
Andreas Gampe8994a042015-12-30 19:03:17 +000080 # We force generation of a new image to avoid build-time and run-time classpath differences.
81 image="-Ximage:/system/non/existent/vogar.art"
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +010082 # We do not need a device directory on host.
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000083 device_dir=""
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +010084 # Vogar knows which VM to use on host.
85 vm_command=""
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000086 shift
Alex Light617c9c52017-08-18 11:52:25 -070087 elif [[ "$1" == "--mode=jvm" ]]; then
88 mode="ri"
89 make_target_name="apache-harmony-jdwp-tests-host"
90 art="$(which java)"
91 art_debugee="$(which java)"
92 # No need for extra args.
93 debuggee_args=""
94 # No image. On the RI.
95 image=""
96 # We do not need a device directory on RI.
97 device_dir=""
98 # Vogar knows which VM to use on RI.
99 vm_command=""
100 # We don't care about jit with the RI
101 use_jit=false
102 shift
Alex Lightec4a10c2017-11-17 09:06:26 -0800103 elif [[ $1 == --test-timeout-ms ]]; then
104 # Remove the --test-timeout-ms from the arguments.
105 args=${args/$1}
106 shift
107 jdwp_test_timeout=$1
108 # Remove the argument
109 args=${args/$1}
110 shift
Alex Light0ac2e5c2017-09-19 15:35:20 -0700111 elif [[ $1 == --agent-wrapper ]]; then
112 # Remove the --agent-wrapper from the arguments.
113 args=${args/$1}
114 shift
115 agent_wrapper=${agent_wrapper}${1},
116 # Remove the argument
117 args=${args/$1}
118 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000119 elif [[ $1 == -Ximage:* ]]; then
120 image="$1"
121 shift
Roland Levillain5db109b2016-05-19 12:24:17 +0100122 elif [[ "$1" == "--no-jit" ]]; then
123 use_jit=false
124 # Remove the --no-jit from the arguments.
125 args=${args/$1}
126 shift
Alex Light84b92e02017-09-29 13:46:14 -0700127 elif [[ $1 == "--no-debug" ]]; then
128 explicit_debug="yes"
129 debug="no"
130 # Remove the --no-debug from the arguments.
131 args=${args/$1}
132 shift
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100133 elif [[ $1 == "--debug" ]]; then
Alex Light84b92e02017-09-29 13:46:14 -0700134 explicit_debug="yes"
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100135 debug="yes"
136 # Remove the --debug from the arguments.
137 args=${args/$1}
138 shift
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200139 elif [[ $1 == "--verbose" ]]; then
140 verbose="yes"
141 # Remove the --verbose from the arguments.
142 args=${args/$1}
143 shift
Alex Light84b92e02017-09-29 13:46:14 -0700144 elif [[ $1 == "--gdbserver" ]]; then
145 # Remove the --gdbserver from the arguments.
146 args=${args/$1}
147 has_gdb="yes"
148 shift
149 gdb_target=$1
150 # Remove the target from the arguments.
151 args=${args/$1}
152 shift
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200153 elif [[ $1 == "--test" ]]; then
154 # Remove the --test from the arguments.
155 args=${args/$1}
156 shift
Alex Light84b92e02017-09-29 13:46:14 -0700157 has_specific_test="yes"
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200158 test=$1
159 # Remove the test from the arguments.
160 args=${args/$1}
161 shift
Alex Light617c9c52017-08-18 11:52:25 -0700162 elif [[ "$1" == "--jdwp-path" ]]; then
163 # Remove the --jdwp-path from the arguments.
164 args=${args/$1}
165 shift
Alex Light0ac2e5c2017-09-19 15:35:20 -0700166 with_jdwp_path=$1
Alex Light617c9c52017-08-18 11:52:25 -0700167 # Remove the path from the arguments.
168 args=${args/$1}
169 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000170 elif [[ "$1" == "" ]]; then
171 break
Andreas Gampe85b286b2015-12-30 19:37:48 -0800172 elif [[ $1 == --variant=* ]]; then
173 variant_cmdline_parameter=$1
174 shift
Alex Light617c9c52017-08-18 11:52:25 -0700175 elif [[ $1 == -Xplugin:* ]]; then
176 plugin="$1"
177 args=${args/$1}
178 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000179 else
180 shift
181 fi
182done
183
Alex Light84b92e02017-09-29 13:46:14 -0700184if [[ $has_gdb = "yes" ]]; then
185 if [[ $explicit_debug = "no" ]]; then
186 debug="yes"
187 fi
188fi
189
Alex Light617c9c52017-08-18 11:52:25 -0700190if [[ $mode == "ri" ]]; then
Alex Light0ac2e5c2017-09-19 15:35:20 -0700191 if [[ "x$with_jdwp_path" != "x" ]]; then
192 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentArgument=-agentpath:${agent_wrapper}"
193 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentName=$with_jdwp_path"
194 fi
Alex Light617c9c52017-08-18 11:52:25 -0700195 if [[ "x$image" != "x" ]]; then
196 echo "Cannot use -Ximage: with --mode=jvm"
197 exit 1
Alex Light84b92e02017-09-29 13:46:14 -0700198 elif [[ $has_gdb = "yes" ]]; then
199 echo "Cannot use --gdbserver with --mode=jvm"
200 exit 1
Alex Light617c9c52017-08-18 11:52:25 -0700201 elif [[ $debug == "yes" ]]; then
202 echo "Cannot use --debug with --mode=jvm"
203 exit 1
204 fi
205else
Alex Light878f33f2018-02-08 11:16:39 -0800206 if [[ "$mode" == "host" ]]; then
207 dump_command="/bin/kill -3"
208 else
209 # TODO It would be great to be able to use this on target too but we need to
210 # be able to walk /proc to figure out what the actual child pid is.
211 dump_command="/system/bin/true"
212 # dump_command="/system/xbin/su root /data/local/tmp/system/bin/debuggerd -b"
213 fi
Alex Light84b92e02017-09-29 13:46:14 -0700214 if [[ $has_gdb = "yes" ]]; then
215 if [[ $mode == "target" ]]; then
216 echo "Cannot use --gdbserver with --mode=target"
217 exit 1
218 else
219 art_debugee="$art_debugee --gdbserver $gdb_target"
220 # The tests absolutely require some timeout. We set a ~2 week timeout since we can kill the
221 # test with gdb if it goes on too long.
222 jdwp_test_timeout="1000000000"
223 fi
224 fi
Alex Light0ac2e5c2017-09-19 15:35:20 -0700225 if [[ "x$with_jdwp_path" != "x" ]]; then
226 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentArgument=-agentpath:${agent_wrapper}"
227 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentName=${with_jdwp_path}"
228 fi
Alex Light617c9c52017-08-18 11:52:25 -0700229 vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --debuggable"
230 # Make sure the debuggee doesn't clean up what the debugger has generated.
231 art_debugee="$art_debugee --no-clean"
232fi
233
234function jlib_name {
235 local path=$1
236 local str="classes"
237 local suffix="jar"
238 if [[ $mode == "ri" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -0700239 str="javalib"
Alex Light617c9c52017-08-18 11:52:25 -0700240 fi
241 echo "$path/$str.$suffix"
242}
243
244# Jar containing all the tests.
245test_jar=$(jlib_name "${java_lib_location}/${make_target_name}_intermediates")
246
247if [[ ! -f $test_jar ]]; then
248 echo "Before running, you must build jdwp tests and vogar:" \
249 "make ${make_target_name} vogar"
250 exit 1
251fi
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100252
Andreas Gampe85b286b2015-12-30 19:37:48 -0800253# For the host:
254#
255# If, on the other hand, there is a variant set, use it to modify the art_debugee parameter to
256# force the fork to have the same bitness as the controller. This should be fine and not impact
257# testing (cross-bitness), as the protocol is always 64-bit anyways (our implementation).
258#
259# Note: this isn't necessary for the device as the BOOTCLASSPATH environment variable is set there
260# and used as a fallback.
Alex Light617c9c52017-08-18 11:52:25 -0700261if [[ $mode == "host" ]]; then
Andreas Gampe85b286b2015-12-30 19:37:48 -0800262 variant=${variant_cmdline_parameter:10}
263 if [[ $variant == "x32" || $variant == "X32" ]]; then
264 art_debugee="$art_debugee --32"
265 elif [[ $variant == "x64" || $variant == "X64" ]]; then
266 art_debugee="$art_debugee --64"
267 else
268 echo "Error, do not understand variant $variant_cmdline_parameter."
269 exit 1
270 fi
271fi
272
Nicolas Geoffray95186552015-10-28 13:06:21 +0000273if [[ "$image" != "" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -0700274 vm_args="$vm_args --vm-arg $image"
Nicolas Geoffray95186552015-10-28 13:06:21 +0000275fi
Alex Light617c9c52017-08-18 11:52:25 -0700276
277if [[ "$plugin" != "" ]]; then
278 vm_args="$vm_args --vm-arg $plugin"
279fi
280
Roland Levillain5db109b2016-05-19 12:24:17 +0100281if $use_jit; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100282 vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --compiler-filter=quicken"
283 debuggee_args="$debuggee_args -Xcompiler-option --compiler-filter=quicken"
Roland Levillain5db109b2016-05-19 12:24:17 +0100284fi
Alex Light617c9c52017-08-18 11:52:25 -0700285
286if [[ $mode != "ri" ]]; then
287 vm_args="$vm_args --vm-arg -Xusejit:$use_jit"
288 debuggee_args="$debuggee_args -Xusejit:$use_jit"
289fi
290
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100291if [[ $debug == "yes" ]]; then
292 art="$art -d"
293 art_debugee="$art_debugee -d"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700294 vm_args="$vm_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100295fi
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200296if [[ $verbose == "yes" ]]; then
297 # Enable JDWP logs in the debuggee.
298 art_debugee="$art_debugee -verbose:jdwp"
299fi
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100300
Neil Fuller239bdf62018-01-08 18:55:36 +0000301if [[ $mode != "ri" ]]; then
Neil Fullerc546ec92018-01-05 15:00:35 +0000302 toolchain_args="--toolchain d8 --language CUR"
Alex Light264a4862018-01-31 16:47:58 +0000303 if [[ "x$with_jdwp_path" == "x" ]]; then
304 # Need to enable the internal jdwp implementation.
305 art_debugee="${art_debugee} -XjdwpProvider:internal"
306 fi
Alex Light8d8299d2017-11-10 08:41:04 -0800307else
308 toolchain_args="--toolchain javac --language CUR"
Igor Murashkin84f26322017-06-06 11:36:33 -0700309fi
310
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000311# Run the tests using vogar.
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +0100312vogar $vm_command \
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100313 $vm_args \
Nicolas Geoffray9620b9d2015-03-30 12:28:26 +0100314 --verbose \
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000315 $args \
316 $device_dir \
Nicolas Geoffraya2c18612015-03-30 23:01:28 +0100317 $image_compiler_option \
Nicolas Geoffray472b00c2015-05-06 14:57:09 +0100318 --timeout 800 \
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000319 --vm-arg -Djpda.settings.verbose=true \
Sebastien Hertzc3b208c2017-03-27 11:35:54 +0200320 --vm-arg -Djpda.settings.timeout=$jdwp_test_timeout \
321 --vm-arg -Djpda.settings.waitingTime=$jdwp_test_timeout \
Nicolas Geoffraya2c18612015-03-30 23:01:28 +0100322 --vm-arg -Djpda.settings.transportAddress=127.0.0.1:55107 \
Alex Light878f33f2018-02-08 11:16:39 -0800323 --vm-arg -Djpda.settings.dumpProcess="$dump_command" \
Alex Light617c9c52017-08-18 11:52:25 -0700324 --vm-arg -Djpda.settings.debuggeeJavaPath="$art_debugee $plugin $image $debuggee_args" \
Igor Murashkin84f26322017-06-06 11:36:33 -0700325 --classpath "$test_jar" \
326 $toolchain_args \
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200327 $test
Hiroshi Yamauchia166bbb2015-11-19 16:24:31 -0800328
329vogar_exit_status=$?
330
331echo "Killing stalled dalvikvm processes..."
Alex Lightc611ffa2017-10-18 08:59:16 -0700332if [[ $mode == "host" ]]; then
Hiroshi Yamauchia166bbb2015-11-19 16:24:31 -0800333 pkill -9 -f /bin/dalvikvm
334else
335 adb shell pkill -9 -f /bin/dalvikvm
336fi
337echo "Done."
338
339exit $vogar_exit_status