blob: 2cf614d79555f073f6195aaf546fe79deb66f4e0 [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"
Sebastien Hertzc3b208c2017-03-27 11:35:54 +020057# Timeout of JDWP test in ms.
58#
59# Note: some tests expect a timeout to check that *no* reply/event is received for a specific case.
60# A lower timeout can save up several minutes when running the whole test suite, especially for
61# continuous testing. This value can be adjusted to fit the configuration of the host machine(s).
62jdwp_test_timeout=10000
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000063
Alex Light84b92e02017-09-29 13:46:14 -070064gdb_target=
65has_gdb="no"
66
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000067while true; do
68 if [[ "$1" == "--mode=host" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -070069 mode="host"
Nicolas Geoffray59786902015-03-30 16:34:16 +010070 # Specify bash explicitly since the art script cannot, since it has to run on the device
71 # with mksh.
Alex Lightb15fea22015-09-17 16:59:09 -070072 art="bash ${OUT_DIR-out}/host/linux-x86/bin/art"
73 art_debugee="bash ${OUT_DIR-out}/host/linux-x86/bin/art"
Andreas Gampe8994a042015-12-30 19:03:17 +000074 # We force generation of a new image to avoid build-time and run-time classpath differences.
75 image="-Ximage:/system/non/existent/vogar.art"
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +010076 # We do not need a device directory on host.
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000077 device_dir=""
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +010078 # Vogar knows which VM to use on host.
79 vm_command=""
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +000080 shift
Alex Light617c9c52017-08-18 11:52:25 -070081 elif [[ "$1" == "--mode=jvm" ]]; then
82 mode="ri"
83 make_target_name="apache-harmony-jdwp-tests-host"
84 art="$(which java)"
85 art_debugee="$(which java)"
86 # No need for extra args.
87 debuggee_args=""
88 # No image. On the RI.
89 image=""
90 # We do not need a device directory on RI.
91 device_dir=""
92 # Vogar knows which VM to use on RI.
93 vm_command=""
94 # We don't care about jit with the RI
95 use_jit=false
96 shift
Alex Lightec4a10c2017-11-17 09:06:26 -080097 elif [[ $1 == --test-timeout-ms ]]; then
98 # Remove the --test-timeout-ms from the arguments.
99 args=${args/$1}
100 shift
101 jdwp_test_timeout=$1
102 # Remove the argument
103 args=${args/$1}
104 shift
Alex Light0ac2e5c2017-09-19 15:35:20 -0700105 elif [[ $1 == --agent-wrapper ]]; then
106 # Remove the --agent-wrapper from the arguments.
107 args=${args/$1}
108 shift
109 agent_wrapper=${agent_wrapper}${1},
110 # Remove the argument
111 args=${args/$1}
112 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000113 elif [[ $1 == -Ximage:* ]]; then
114 image="$1"
115 shift
Roland Levillain5db109b2016-05-19 12:24:17 +0100116 elif [[ "$1" == "--no-jit" ]]; then
117 use_jit=false
118 # Remove the --no-jit from the arguments.
119 args=${args/$1}
120 shift
Alex Light84b92e02017-09-29 13:46:14 -0700121 elif [[ $1 == "--no-debug" ]]; then
122 explicit_debug="yes"
123 debug="no"
124 # Remove the --no-debug from the arguments.
125 args=${args/$1}
126 shift
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100127 elif [[ $1 == "--debug" ]]; then
Alex Light84b92e02017-09-29 13:46:14 -0700128 explicit_debug="yes"
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100129 debug="yes"
130 # Remove the --debug from the arguments.
131 args=${args/$1}
132 shift
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200133 elif [[ $1 == "--verbose" ]]; then
134 verbose="yes"
135 # Remove the --verbose from the arguments.
136 args=${args/$1}
137 shift
Alex Light84b92e02017-09-29 13:46:14 -0700138 elif [[ $1 == "--gdbserver" ]]; then
139 # Remove the --gdbserver from the arguments.
140 args=${args/$1}
141 has_gdb="yes"
142 shift
143 gdb_target=$1
144 # Remove the target from the arguments.
145 args=${args/$1}
146 shift
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200147 elif [[ $1 == "--test" ]]; then
148 # Remove the --test from the arguments.
149 args=${args/$1}
150 shift
Alex Light84b92e02017-09-29 13:46:14 -0700151 has_specific_test="yes"
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200152 test=$1
153 # Remove the test from the arguments.
154 args=${args/$1}
155 shift
Alex Light617c9c52017-08-18 11:52:25 -0700156 elif [[ "$1" == "--jdwp-path" ]]; then
157 # Remove the --jdwp-path from the arguments.
158 args=${args/$1}
159 shift
Alex Light0ac2e5c2017-09-19 15:35:20 -0700160 with_jdwp_path=$1
Alex Light617c9c52017-08-18 11:52:25 -0700161 # Remove the path from the arguments.
162 args=${args/$1}
163 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000164 elif [[ "$1" == "" ]]; then
165 break
Andreas Gampe85b286b2015-12-30 19:37:48 -0800166 elif [[ $1 == --variant=* ]]; then
167 variant_cmdline_parameter=$1
168 shift
Alex Light617c9c52017-08-18 11:52:25 -0700169 elif [[ $1 == -Xplugin:* ]]; then
170 plugin="$1"
171 args=${args/$1}
172 shift
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000173 else
174 shift
175 fi
176done
177
Alex Light84b92e02017-09-29 13:46:14 -0700178if [[ $has_gdb = "yes" ]]; then
179 if [[ $explicit_debug = "no" ]]; then
180 debug="yes"
181 fi
182fi
183
Alex Light617c9c52017-08-18 11:52:25 -0700184if [[ $mode == "ri" ]]; then
Alex Light0ac2e5c2017-09-19 15:35:20 -0700185 if [[ "x$with_jdwp_path" != "x" ]]; then
186 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentArgument=-agentpath:${agent_wrapper}"
187 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentName=$with_jdwp_path"
188 fi
Alex Light617c9c52017-08-18 11:52:25 -0700189 if [[ "x$image" != "x" ]]; then
190 echo "Cannot use -Ximage: with --mode=jvm"
191 exit 1
Alex Light84b92e02017-09-29 13:46:14 -0700192 elif [[ $has_gdb = "yes" ]]; then
193 echo "Cannot use --gdbserver with --mode=jvm"
194 exit 1
Alex Light617c9c52017-08-18 11:52:25 -0700195 elif [[ $debug == "yes" ]]; then
196 echo "Cannot use --debug with --mode=jvm"
197 exit 1
198 fi
199else
Alex Light84b92e02017-09-29 13:46:14 -0700200 if [[ $has_gdb = "yes" ]]; then
201 if [[ $mode == "target" ]]; then
202 echo "Cannot use --gdbserver with --mode=target"
203 exit 1
204 else
205 art_debugee="$art_debugee --gdbserver $gdb_target"
206 # The tests absolutely require some timeout. We set a ~2 week timeout since we can kill the
207 # test with gdb if it goes on too long.
208 jdwp_test_timeout="1000000000"
209 fi
210 fi
Alex Light0ac2e5c2017-09-19 15:35:20 -0700211 if [[ "x$with_jdwp_path" != "x" ]]; then
212 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentArgument=-agentpath:${agent_wrapper}"
213 vm_args="${vm_args} --vm-arg -Djpda.settings.debuggeeAgentName=${with_jdwp_path}"
214 fi
Alex Light617c9c52017-08-18 11:52:25 -0700215 vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --debuggable"
216 # Make sure the debuggee doesn't clean up what the debugger has generated.
217 art_debugee="$art_debugee --no-clean"
218fi
219
220function jlib_name {
221 local path=$1
222 local str="classes"
223 local suffix="jar"
224 if [[ $mode == "ri" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -0700225 str="javalib"
Alex Light617c9c52017-08-18 11:52:25 -0700226 fi
227 echo "$path/$str.$suffix"
228}
229
230# Jar containing all the tests.
231test_jar=$(jlib_name "${java_lib_location}/${make_target_name}_intermediates")
232
233if [[ ! -f $test_jar ]]; then
234 echo "Before running, you must build jdwp tests and vogar:" \
235 "make ${make_target_name} vogar"
236 exit 1
237fi
Nicolas Geoffrayc0c07852017-08-08 09:44:15 +0100238
Andreas Gampe85b286b2015-12-30 19:37:48 -0800239# For the host:
240#
241# If, on the other hand, there is a variant set, use it to modify the art_debugee parameter to
242# force the fork to have the same bitness as the controller. This should be fine and not impact
243# testing (cross-bitness), as the protocol is always 64-bit anyways (our implementation).
244#
245# Note: this isn't necessary for the device as the BOOTCLASSPATH environment variable is set there
246# and used as a fallback.
Alex Light617c9c52017-08-18 11:52:25 -0700247if [[ $mode == "host" ]]; then
Andreas Gampe85b286b2015-12-30 19:37:48 -0800248 variant=${variant_cmdline_parameter:10}
249 if [[ $variant == "x32" || $variant == "X32" ]]; then
250 art_debugee="$art_debugee --32"
251 elif [[ $variant == "x64" || $variant == "X64" ]]; then
252 art_debugee="$art_debugee --64"
253 else
254 echo "Error, do not understand variant $variant_cmdline_parameter."
255 exit 1
256 fi
257fi
258
Nicolas Geoffray95186552015-10-28 13:06:21 +0000259if [[ "$image" != "" ]]; then
Alex Light617c9c52017-08-18 11:52:25 -0700260 vm_args="$vm_args --vm-arg $image"
Nicolas Geoffray95186552015-10-28 13:06:21 +0000261fi
Alex Light617c9c52017-08-18 11:52:25 -0700262
263if [[ "$plugin" != "" ]]; then
264 vm_args="$vm_args --vm-arg $plugin"
265fi
266
Roland Levillain5db109b2016-05-19 12:24:17 +0100267if $use_jit; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100268 vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --compiler-filter=quicken"
269 debuggee_args="$debuggee_args -Xcompiler-option --compiler-filter=quicken"
Roland Levillain5db109b2016-05-19 12:24:17 +0100270fi
Alex Light617c9c52017-08-18 11:52:25 -0700271
272if [[ $mode != "ri" ]]; then
273 vm_args="$vm_args --vm-arg -Xusejit:$use_jit"
274 debuggee_args="$debuggee_args -Xusejit:$use_jit"
275fi
276
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100277if [[ $debug == "yes" ]]; then
278 art="$art -d"
279 art_debugee="$art_debugee -d"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700280 vm_args="$vm_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true"
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100281fi
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200282if [[ $verbose == "yes" ]]; then
283 # Enable JDWP logs in the debuggee.
284 art_debugee="$art_debugee -verbose:jdwp"
285fi
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100286
Neil Fuller239bdf62018-01-08 18:55:36 +0000287if [[ $mode != "ri" ]]; then
Neil Fullerc546ec92018-01-05 15:00:35 +0000288 toolchain_args="--toolchain d8 --language CUR"
Alex Light8d8299d2017-11-10 08:41:04 -0800289else
290 toolchain_args="--toolchain javac --language CUR"
Igor Murashkin84f26322017-06-06 11:36:33 -0700291fi
292
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000293# Run the tests using vogar.
Nicolas Geoffrayd06dc9c2015-03-30 15:30:26 +0100294vogar $vm_command \
Nicolas Geoffray9648a632015-06-15 14:35:01 +0100295 $vm_args \
Nicolas Geoffray9620b9d2015-03-30 12:28:26 +0100296 --verbose \
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000297 $args \
298 $device_dir \
Nicolas Geoffraya2c18612015-03-30 23:01:28 +0100299 $image_compiler_option \
Nicolas Geoffray472b00c2015-05-06 14:57:09 +0100300 --timeout 800 \
Nicolas Geoffray96cd87a2015-03-26 16:48:29 +0000301 --vm-arg -Djpda.settings.verbose=true \
Sebastien Hertzc3b208c2017-03-27 11:35:54 +0200302 --vm-arg -Djpda.settings.timeout=$jdwp_test_timeout \
303 --vm-arg -Djpda.settings.waitingTime=$jdwp_test_timeout \
Nicolas Geoffraya2c18612015-03-30 23:01:28 +0100304 --vm-arg -Djpda.settings.transportAddress=127.0.0.1:55107 \
Alex Light617c9c52017-08-18 11:52:25 -0700305 --vm-arg -Djpda.settings.debuggeeJavaPath="$art_debugee $plugin $image $debuggee_args" \
Igor Murashkin84f26322017-06-06 11:36:33 -0700306 --classpath "$test_jar" \
307 $toolchain_args \
Sebastien Hertza646aaf2015-09-10 12:03:51 +0200308 $test
Hiroshi Yamauchia166bbb2015-11-19 16:24:31 -0800309
310vogar_exit_status=$?
311
312echo "Killing stalled dalvikvm processes..."
Alex Lightc611ffa2017-10-18 08:59:16 -0700313if [[ $mode == "host" ]]; then
Hiroshi Yamauchia166bbb2015-11-19 16:24:31 -0800314 pkill -9 -f /bin/dalvikvm
315else
316 adb shell pkill -9 -f /bin/dalvikvm
317fi
318echo "Done."
319
320exit $vogar_exit_status