Home | History | Annotate | Download | only in tools
      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 
     17 if [ ! -d libcore ]; then
     18   echo "Script needs to be run at the root of the android tree"
     19   exit 1
     20 fi
     21 
     22 source build/envsetup.sh >&/dev/null # for get_build_var, setpaths
     23 setpaths # include platform prebuilt java, javac, etc in $PATH.
     24 
     25 if [ -z "$ANDROID_HOST_OUT" ] ; then
     26   ANDROID_HOST_OUT=${OUT_DIR-$ANDROID_BUILD_TOP/out}/host/linux-x86
     27 fi
     28 
     29 java_lib_location="${ANDROID_HOST_OUT}/../common/obj/JAVA_LIBRARIES"
     30 make_target_name="apache-harmony-jdwp-tests-hostdex"
     31 
     32 vm_args=""
     33 art="/data/local/tmp/system/bin/art"
     34 art_debugee="sh /data/local/tmp/system/bin/art"
     35 args=$@
     36 debuggee_args="-Xcompiler-option --debuggable"
     37 device_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.
     40 vm_command="--vm-command=$art"
     41 image_compiler_option=""
     42 plugin=""
     43 debug="no"
     44 explicit_debug="no"
     45 verbose="no"
     46 image="-Ximage:/data/art-test/core.art"
     47 with_jdwp_path=""
     48 agent_wrapper=""
     49 vm_args=""
     50 # By default, we run the whole JDWP test suite.
     51 has_specific_test="no"
     52 test="org.apache.harmony.jpda.tests.share.AllTests"
     53 mode="target"
     54 # Use JIT compiling by default.
     55 use_jit=true
     56 variant_cmdline_parameter="--variant=X32"
     57 dump_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).
     63 jdwp_test_timeout=10000
     64 
     65 gdb_target=
     66 has_gdb="no"
     67 
     68 while 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
    177 done
    178 
    179 if [[ $has_gdb = "yes" ]]; then
    180   if [[ $explicit_debug = "no" ]]; then
    181     debug="yes"
    182   fi
    183 fi
    184 
    185 if [[ $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
    200 else
    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"
    227 fi
    228 
    229 function 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.
    240 test_jar=$(jlib_name "${java_lib_location}/${make_target_name}_intermediates")
    241 
    242 if [[ ! -f $test_jar ]]; then
    243   echo "Before running, you must build jdwp tests and vogar:" \
    244        "make ${make_target_name} vogar"
    245   exit 1
    246 fi
    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.
    256 if [[ $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
    266 fi
    267 
    268 if [[ "$image" != "" ]]; then
    269   vm_args="$vm_args --vm-arg $image"
    270 fi
    271 
    272 if [[ "$plugin" != "" ]]; then
    273   vm_args="$vm_args --vm-arg $plugin"
    274 fi
    275 
    276 if $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"
    279 fi
    280 
    281 if [[ $mode != "ri" ]]; then
    282   vm_args="$vm_args --vm-arg -Xusejit:$use_jit"
    283   debuggee_args="$debuggee_args -Xusejit:$use_jit"
    284 fi
    285 
    286 if [[ $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"
    290 fi
    291 if [[ $verbose == "yes" ]]; then
    292   # Enable JDWP logs in the debuggee.
    293   art_debugee="$art_debugee -verbose:jdwp"
    294 fi
    295 
    296 if [[ $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
    302 else
    303   toolchain_args="--toolchain javac --language CUR"
    304 fi
    305 
    306 # Run the tests using vogar.
    307 vogar $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 
    324 vogar_exit_status=$?
    325 
    326 echo "Killing stalled dalvikvm processes..."
    327 if [[ $mode == "host" ]]; then
    328   pkill -9 -f /bin/dalvikvm
    329 else
    330   adb shell pkill -9 -f /bin/dalvikvm
    331 fi
    332 echo "Done."
    333 
    334 exit $vogar_exit_status
    335