1#!/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 22source build/envsetup.sh >&/dev/null # for get_build_var, setpaths 23setpaths # include platform prebuilt java, javac, etc in $PATH. 24 25if [ -z "$ANDROID_HOST_OUT" ] ; then 26 ANDROID_HOST_OUT=${OUT_DIR-$ANDROID_BUILD_TOP/out}/host/linux-x86 27fi 28 29java_lib_location="${ANDROID_HOST_OUT}/../common/obj/JAVA_LIBRARIES" 30make_target_name="apache-harmony-jdwp-tests-hostdex" 31 32vm_args="" 33art="/data/local/tmp/system/bin/art" 34art_debugee="sh /data/local/tmp/system/bin/art" 35args=$@ 36debuggee_args="-Xcompiler-option --debuggable" 37device_dir="--device-dir=/data/local/tmp" 38# We use the art script on target to ensure the runner and the debuggee share the same 39# image. 40vm_command="--vm-command=$art" 41image_compiler_option="" 42plugin="" 43debug="no" 44explicit_debug="no" 45verbose="no" 46image="-Ximage:/data/art-test/core.art" 47with_jdwp_path="" 48agent_wrapper="" 49vm_args="" 50# By default, we run the whole JDWP test suite. 51has_specific_test="no" 52test="org.apache.harmony.jpda.tests.share.AllTests" 53mode="target" 54# Use JIT compiling by default. 55use_jit=true 56variant_cmdline_parameter="--variant=X32" 57dump_command="/bin/true" 58# 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 64 65gdb_target= 66has_gdb="no" 67 68while true; do 69 if [[ "$1" == "--mode=host" ]]; then 70 mode="host" 71 # Specify bash explicitly since the art script cannot, since it has to run on the device 72 # with mksh. 73 art="bash ${OUT_DIR-out}/host/linux-x86/bin/art" 74 art_debugee="bash ${OUT_DIR-out}/host/linux-x86/bin/art" 75 # We force generation of a new image to avoid build-time and run-time classpath differences. 76 image="-Ximage:/system/non/existent/vogar.art" 77 # We do not need a device directory on host. 78 device_dir="" 79 # Vogar knows which VM to use on host. 80 vm_command="" 81 shift 82 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 98 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 106 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 114 elif [[ $1 == -Ximage:* ]]; then 115 image="$1" 116 shift 117 elif [[ "$1" == "--no-jit" ]]; then 118 use_jit=false 119 # Remove the --no-jit from the arguments. 120 args=${args/$1} 121 shift 122 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 128 elif [[ $1 == "--debug" ]]; then 129 explicit_debug="yes" 130 debug="yes" 131 # Remove the --debug from the arguments. 132 args=${args/$1} 133 shift 134 elif [[ $1 == "--verbose" ]]; then 135 verbose="yes" 136 # Remove the --verbose from the arguments. 137 args=${args/$1} 138 shift 139 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 148 elif [[ $1 == "--test" ]]; then 149 # Remove the --test from the arguments. 150 args=${args/$1} 151 shift 152 has_specific_test="yes" 153 test=$1 154 # Remove the test from the arguments. 155 args=${args/$1} 156 shift 157 elif [[ "$1" == "--jdwp-path" ]]; then 158 # Remove the --jdwp-path from the arguments. 159 args=${args/$1} 160 shift 161 with_jdwp_path=$1 162 # Remove the path from the arguments. 163 args=${args/$1} 164 shift 165 elif [[ "$1" == "" ]]; then 166 break 167 elif [[ $1 == --variant=* ]]; then 168 variant_cmdline_parameter=$1 169 shift 170 elif [[ $1 == -Xplugin:* ]]; then 171 plugin="$1" 172 args=${args/$1} 173 shift 174 else 175 shift 176 fi 177done 178 179if [[ $has_gdb = "yes" ]]; then 180 if [[ $explicit_debug = "no" ]]; then 181 debug="yes" 182 fi 183fi 184 185if [[ $mode == "ri" ]]; then 186 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 190 if [[ "x$image" != "x" ]]; then 191 echo "Cannot use -Ximage: with --mode=jvm" 192 exit 1 193 elif [[ $has_gdb = "yes" ]]; then 194 echo "Cannot use --gdbserver with --mode=jvm" 195 exit 1 196 elif [[ $debug == "yes" ]]; then 197 echo "Cannot use --debug with --mode=jvm" 198 exit 1 199 fi 200else 201 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 209 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 220 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 224 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 234 str="javalib" 235 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 247 248# 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. 256if [[ $mode == "host" ]]; then 257 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 268if [[ "$image" != "" ]]; then 269 vm_args="$vm_args --vm-arg $image" 270fi 271 272if [[ "$plugin" != "" ]]; then 273 vm_args="$vm_args --vm-arg $plugin" 274fi 275 276if $use_jit; then 277 vm_args="$vm_args --vm-arg -Xcompiler-option --vm-arg --compiler-filter=quicken" 278 debuggee_args="$debuggee_args -Xcompiler-option --compiler-filter=quicken" 279fi 280 281if [[ $mode != "ri" ]]; then 282 vm_args="$vm_args --vm-arg -Xusejit:$use_jit" 283 debuggee_args="$debuggee_args -Xusejit:$use_jit" 284fi 285 286if [[ $debug == "yes" ]]; then 287 art="$art -d" 288 art_debugee="$art_debugee -d" 289 vm_args="$vm_args --vm-arg -XXlib:libartd.so --vm-arg -XX:SlowDebug=true" 290fi 291if [[ $verbose == "yes" ]]; then 292 # Enable JDWP logs in the debuggee. 293 art_debugee="$art_debugee -verbose:jdwp" 294fi 295 296if [[ $mode != "ri" ]]; then 297 toolchain_args="--toolchain d8 --language CUR" 298 if [[ "x$with_jdwp_path" == "x" ]]; then 299 # Need to enable the internal jdwp implementation. 300 art_debugee="${art_debugee} -XjdwpProvider:internal" 301 fi 302else 303 toolchain_args="--toolchain javac --language CUR" 304fi 305 306# Run the tests using vogar. 307vogar $vm_command \ 308 $vm_args \ 309 --verbose \ 310 $args \ 311 $device_dir \ 312 $image_compiler_option \ 313 --timeout 800 \ 314 --vm-arg -Djpda.settings.verbose=true \ 315 --vm-arg -Djpda.settings.timeout=$jdwp_test_timeout \ 316 --vm-arg -Djpda.settings.waitingTime=$jdwp_test_timeout \ 317 --vm-arg -Djpda.settings.transportAddress=127.0.0.1:55107 \ 318 --vm-arg -Djpda.settings.dumpProcess="$dump_command" \ 319 --vm-arg -Djpda.settings.debuggeeJavaPath="$art_debugee $plugin $image $debuggee_args" \ 320 --classpath "$test_jar" \ 321 $toolchain_args \ 322 $test 323 324vogar_exit_status=$? 325 326echo "Killing stalled dalvikvm processes..." 327if [[ $mode == "host" ]]; then 328 pkill -9 -f /bin/dalvikvm 329else 330 adb shell pkill -9 -f /bin/dalvikvm 331fi 332echo "Done." 333 334exit $vogar_exit_status 335