1#!/bin/bash 2# 3# Copyright (C) 2007 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# Set up prog to be the path of this script, including following symlinks, 18# and set up progdir to be the fully-qualified pathname of its directory. 19prog="$0" 20args="$@" 21while [ -h "${prog}" ]; do 22 newProg=`/bin/ls -ld "${prog}"` 23 newProg=`expr "${newProg}" : ".* -> \(.*\)$"` 24 if expr "x${newProg}" : 'x/' >/dev/null; then 25 prog="${newProg}" 26 else 27 progdir=`dirname "${prog}"` 28 prog="${progdir}/${newProg}" 29 fi 30done 31oldwd=`pwd` 32progdir=`dirname "${prog}"` 33cd "${progdir}" 34progdir=`pwd` 35prog="${progdir}"/`basename "${prog}"` 36test_dir="test-$$" 37if [ -z "$TMPDIR" ]; then 38 tmp_dir="/tmp/$USER/${test_dir}" 39else 40 tmp_dir="${TMPDIR}/${test_dir}" 41fi 42checker="${progdir}/../tools/checker/checker.py" 43export JAVA="java" 44export JAVAC="javac -g -Xlint:-options -source 1.8 -target 1.8" 45export RUN="${progdir}/etc/run-test-jar" 46export DEX_LOCATION=/data/run-test/${test_dir} 47 48# ANDROID_BUILD_TOP is not set in a build environment. 49if [ -z "$ANDROID_BUILD_TOP" ]; then 50 export ANDROID_BUILD_TOP=$oldwd 51fi 52 53# OUT_DIR defaults to out, and may be relative to $ANDROID_BUILD_TOP. 54# Convert it to an absolute path, since we cd into the tmp_dir to run the tests. 55export OUT_DIR=${OUT_DIR:-out} 56if [[ "$OUT_DIR" != /* ]]; then 57 export OUT_DIR=$ANDROID_BUILD_TOP/$OUT_DIR 58fi 59 60# ANDROID_HOST_OUT is not set in a build environment. 61if [ -z "$ANDROID_HOST_OUT" ]; then 62 export ANDROID_HOST_OUT=${OUT_DIR}/host/linux-x86 63fi 64 65host_lib_root=${ANDROID_HOST_OUT} 66chroot= 67info="info.txt" 68run="run" 69expected_stdout="expected-stdout.txt" 70expected_stderr="expected-stderr.txt" 71check_cmd="check" 72test_stdout="test-stdout.txt" 73test_stderr="test-stderr.txt" 74cfg_output="graph.cfg" 75strace_output="strace-output.txt" 76lib="libartd.so" 77testlib="arttestd" 78run_args=(--quiet) 79 80quiet="no" 81debuggable="no" 82prebuild_mode="yes" 83target_mode="yes" 84dev_mode="no" 85create_runner="no" 86update_mode="no" 87debug_mode="no" 88relocate="no" 89runtime="art" 90usage="no" 91suffix64="" 92trace="false" 93trace_stream="false" 94basic_verify="false" 95gc_verify="false" 96gc_stress="false" 97jvmti_trace_stress="false" 98jvmti_field_stress="false" 99jvmti_step_stress="false" 100jvmti_redefine_stress="false" 101strace="false" 102always_clean="no" 103never_clean="no" 104have_image="yes" 105android_root="/system" 106bisection_search="no" 107timeout="" 108suspend_timeout="500000" 109run_optimizing="false" 110dump_cfg="false" 111dump_cfg_path="" 112# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and 113# ART output to approximately 128MB. This should be more than sufficient 114# for any test while still catching cases of runaway output. 115# Set a hard limit to encourage ART developers to increase the ulimit here if 116# needed to support a test case rather than resetting the limit in the run 117# script for the particular test in question. Adjust this if needed for 118# particular configurations. 119file_ulimit=128000 120 121 122while true; do 123 if [ "x$1" = "x--host" ]; then 124 target_mode="no" 125 DEX_LOCATION=$tmp_dir 126 run_args+=(--host) 127 shift 128 elif [ "x$1" = "x--quiet" ]; then 129 quiet="yes" 130 shift 131 elif [ "x$1" = "x--use-java-home" ]; then 132 if [ -n "${JAVA_HOME}" ]; then 133 export JAVA="${JAVA_HOME}/bin/java" 134 export JAVAC="${JAVA_HOME}/bin/javac -g" 135 else 136 echo "Passed --use-java-home without JAVA_HOME variable set!" 137 usage="yes" 138 fi 139 shift 140 elif [ "x$1" = "x--jvm" ]; then 141 target_mode="no" 142 DEX_LOCATION="$tmp_dir" 143 runtime="jvm" 144 prebuild_mode="no" 145 run_args+=(--jvm) 146 shift 147 elif [ "x$1" = "x-O" ]; then 148 lib="libart.so" 149 testlib="arttest" 150 run_args+=(-O) 151 shift 152 elif [ "x$1" = "x--dalvik" ]; then 153 lib="libdvm.so" 154 runtime="dalvik" 155 shift 156 elif [ "x$1" = "x--no-image" ]; then 157 have_image="no" 158 shift 159 elif [ "x$1" = "x--relocate" ]; then 160 relocate="yes" 161 shift 162 elif [ "x$1" = "x--no-relocate" ]; then 163 relocate="no" 164 shift 165 elif [ "x$1" = "x--prebuild" ]; then 166 run_args+=(--prebuild) 167 prebuild_mode="yes" 168 shift; 169 elif [ "x$1" = "x--compact-dex-level" ]; then 170 option="$1" 171 shift 172 run_args+=("$option" "$1") 173 shift; 174 elif [ "x$1" = "x--strip-dex" ]; then 175 run_args+=(--strip-dex) 176 shift; 177 elif [ "x$1" = "x--debuggable" ]; then 178 run_args+=(-Xcompiler-option --debuggable) 179 debuggable="yes" 180 shift; 181 elif [ "x$1" = "x--no-prebuild" ]; then 182 run_args+=(--no-prebuild) 183 prebuild_mode="no" 184 shift; 185 elif [ "x$1" = "x--gcverify" ]; then 186 basic_verify="true" 187 gc_verify="true" 188 shift 189 elif [ "x$1" = "x--gcstress" ]; then 190 basic_verify="true" 191 gc_stress="true" 192 shift 193 elif [ "x$1" = "x--jvmti-step-stress" ]; then 194 jvmti_step_stress="true" 195 shift 196 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then 197 jvmti_redefine_stress="true" 198 shift 199 elif [ "x$1" = "x--jvmti-field-stress" ]; then 200 jvmti_field_stress="true" 201 shift 202 elif [ "x$1" = "x--jvmti-trace-stress" ]; then 203 jvmti_trace_stress="true" 204 shift 205 elif [ "x$1" = "x--suspend-timeout" ]; then 206 shift 207 suspend_timeout="$1" 208 shift 209 elif [ "x$1" = "x--image" ]; then 210 shift 211 image="$1" 212 run_args+=(--image "$image") 213 shift 214 elif [ "x$1" = "x-Xcompiler-option" ]; then 215 shift 216 option="$1" 217 run_args+=(-Xcompiler-option "$option") 218 shift 219 elif [ "x$1" = "x--runtime-option" ]; then 220 shift 221 option="$1" 222 run_args+=(--runtime-option "$option") 223 shift 224 elif [ "x$1" = "x--gdb-arg" ]; then 225 shift 226 gdb_arg="$1" 227 run_args+=(--gdb-arg "$gdb_arg") 228 shift 229 elif [ "x$1" = "x--gdb-dex2oat-args" ]; then 230 shift 231 gdb_dex2oat_args="$1" 232 run_args+=(--gdb-dex2oat-args "$gdb_dex2oat_args") 233 shift 234 elif [ "x$1" = "x--debug" ]; then 235 run_args+=(--debug) 236 shift 237 elif [ "x$1" = "x--debug-wrap-agent" ]; then 238 run_args+=(--debug-wrap-agent) 239 shift 240 elif [ "x$1" = "x--with-agent" ]; then 241 shift 242 option="$1" 243 run_args+=(--with-agent "$1") 244 shift 245 elif [ "x$1" = "x--debug-agent" ]; then 246 shift 247 option="$1" 248 run_args+=(--debug-agent "$1") 249 shift 250 elif [ "x$1" = "x--dump-cfg" ]; then 251 shift 252 dump_cfg="true" 253 dump_cfg_path="$1" 254 shift 255 elif [ "x$1" = "x--gdb" ]; then 256 run_args+=(--gdb) 257 dev_mode="yes" 258 shift 259 elif [ "x$1" = "x--gdb-dex2oat" ]; then 260 run_args+=(--gdb-dex2oat) 261 dev_mode="yes" 262 shift 263 elif [ "x$1" = "x--gdbserver-bin" ]; then 264 shift 265 run_args+=(--gdbserver-bin "$1") 266 shift 267 elif [ "x$1" = "x--gdbserver-port" ]; then 268 shift 269 run_args+=(--gdbserver-port "$1") 270 shift 271 elif [ "x$1" = "x--gdbserver" ]; then 272 run_args+=(--gdbserver) 273 dev_mode="yes" 274 shift 275 elif [ "x$1" = "x--strace" ]; then 276 strace="yes" 277 run_args+=(--invoke-with strace --invoke-with -o --invoke-with "$tmp_dir/$strace_output") 278 timeout="${timeout:-1800}" 279 shift 280 elif [ "x$1" = "x--zygote" ]; then 281 run_args+=(--zygote) 282 shift 283 elif [ "x$1" = "x--interpreter" ]; then 284 run_args+=(--interpreter) 285 shift 286 elif [ "x$1" = "x--jit" ]; then 287 run_args+=(--jit) 288 shift 289 elif [ "x$1" = "x--baseline" ]; then 290 run_args+=(--baseline) 291 shift 292 elif [ "x$1" = "x--optimizing" ]; then 293 run_optimizing="true" 294 shift 295 elif [ "x$1" = "x--no-verify" ]; then 296 run_args+=(--no-verify) 297 shift 298 elif [ "x$1" = "x--verify-soft-fail" ]; then 299 run_args+=(--verify-soft-fail) 300 shift 301 elif [ "x$1" = "x--no-optimize" ]; then 302 run_args+=(--no-optimize) 303 shift 304 elif [ "x$1" = "x--no-precise" ]; then 305 run_args+=(--no-precise) 306 shift 307 elif [ "x$1" = "x--external-log-tags" ]; then 308 run_args+=(--external-log-tags) 309 shift 310 elif [ "x$1" = "x--invoke-with" ]; then 311 shift 312 what="$1" 313 if [ "x$what" = "x" ]; then 314 echo "$0 missing argument to --invoke-with" 1>&2 315 usage="yes" 316 break 317 fi 318 run_args+=(--invoke-with "${what}") 319 shift 320 elif [ "x$1" = "x--create-runner" ]; then 321 run_args+=(--create-runner --dry-run) 322 dev_mode="yes" 323 never_clean="yes" 324 create_runner="yes" 325 shift 326 elif [ "x$1" = "x--dev" ]; then 327 run_args+=(--dev) 328 dev_mode="yes" 329 shift 330 elif [ "x$1" = "x--temp-path" ]; then 331 shift 332 tmp_dir=$1 333 if [ "x$tmp_dir" = "x" ]; then 334 echo "$0 missing argument to --temp-path" 1>&2 335 usage="yes" 336 break 337 fi 338 shift 339 elif [ "x$1" = "x--chroot" ]; then 340 shift 341 if [ "x$1" = "x" ]; then 342 echo "$0 missing argument to --chroot" 1>&2 343 usage="yes" 344 break 345 fi 346 chroot="$1" 347 run_args+=(--chroot "$1") 348 shift 349 elif [ "x$1" = "x--simpleperf" ]; then 350 run_args+=(--simpleperf) 351 shift 352 elif [ "x$1" = "x--android-root" ]; then 353 shift 354 if [ "x$1" = "x" ]; then 355 echo "$0 missing argument to --android-root" 1>&2 356 usage="yes" 357 break 358 fi 359 android_root="$1" 360 run_args+=(--android-root "$1") 361 shift 362 elif [ "x$1" = "x--android-art-root" ]; then 363 shift 364 if [ "x$1" = "x" ]; then 365 echo "$0 missing argument to --android-art-root" 1>&2 366 usage="yes" 367 break 368 fi 369 run_args+=(--android-art-root "$1") 370 shift 371 elif [ "x$1" = "x--android-tzdata-root" ]; then 372 shift 373 if [ "x$1" = "x" ]; then 374 echo "$0 missing argument to --android-tzdata-root" 1>&2 375 usage="yes" 376 break 377 fi 378 run_args+=(--android-tzdata-root "$1") 379 shift 380 elif [ "x$1" = "x--update" ]; then 381 update_mode="yes" 382 shift 383 elif [ "x$1" = "x--help" ]; then 384 usage="yes" 385 shift 386 elif [ "x$1" = "x--64" ]; then 387 run_args+=(--64) 388 suffix64="64" 389 shift 390 elif [ "x$1" = "x--bionic" ]; then 391 # soong linux_bionic builds are 64bit only. 392 run_args+=(--bionic --host --64) 393 suffix64="64" 394 target_mode="no" 395 DEX_LOCATION=$tmp_dir 396 host_lib_root=$OUT_DIR/soong/host/linux_bionic-x86 397 shift 398 elif [ "x$1" = "x--runtime-extracted-zipapex" ]; then 399 shift 400 # TODO Should we allow the java.library.path to search the zipapex too? 401 # Not needed at the moment and adding it will be complicated so for now 402 # we'll ignore this. 403 run_args+=(--host --runtime-extracted-zipapex "$1") 404 target_mode="no" 405 DEX_LOCATION=$tmp_dir 406 shift 407 elif [ "x$1" = "x--runtime-zipapex" ]; then 408 shift 409 # TODO Should we allow the java.library.path to search the zipapex too? 410 # Not needed at the moment and adding it will be complicated so for now 411 # we'll ignore this. 412 run_args+=(--host --runtime-zipapex "$1") 413 target_mode="no" 414 DEX_LOCATION=$tmp_dir 415 # apex_payload.zip is quite large we need a high enough ulimit to 416 # extract it. 512mb should be good enough. 417 file_ulimit=512000 418 shift 419 elif [ "x$1" = "x--timeout" ]; then 420 shift 421 if [ "x$1" = "x" ]; then 422 echo "$0 missing argument to --timeout" 1>&2 423 usage="yes" 424 break 425 fi 426 timeout="$1" 427 shift 428 elif [ "x$1" = "x--trace" ]; then 429 trace="true" 430 shift 431 elif [ "x$1" = "x--stream" ]; then 432 trace_stream="true" 433 shift 434 elif [ "x$1" = "x--always-clean" ]; then 435 always_clean="yes" 436 shift 437 elif [ "x$1" = "x--never-clean" ]; then 438 never_clean="yes" 439 shift 440 elif [ "x$1" = "x--dex2oat-swap" ]; then 441 run_args+=(--dex2oat-swap) 442 shift 443 elif [ "x$1" = "x--instruction-set-features" ]; then 444 shift 445 run_args+=(--instruction-set-features "$1") 446 shift 447 elif [ "x$1" = "x--bisection-search" ]; then 448 bisection_search="yes" 449 shift 450 elif [ "x$1" = "x--vdex" ]; then 451 run_args+=(--vdex) 452 shift 453 elif [ "x$1" = "x--dm" ]; then 454 run_args+=(--dm) 455 shift 456 elif [ "x$1" = "x--vdex-filter" ]; then 457 shift 458 filter=$1 459 run_args+=(--vdex-filter "$filter") 460 shift 461 elif [ "x$1" = "x--random-profile" ]; then 462 run_args+=(--random-profile) 463 shift 464 elif [ "x$1" = "x--dex2oat-jobs" ]; then 465 shift 466 run_args+=(-Xcompiler-option "-j$1") 467 shift 468 elif expr "x$1" : "x--" >/dev/null 2>&1; then 469 echo "unknown $0 option: $1" 1>&2 470 usage="yes" 471 break 472 else 473 break 474 fi 475done 476 477if [ "$usage" = "no" -a "x$1" = "x" ]; then 478 echo "missing test to run" 1>&2 479 usage="yes" 480fi 481 482# The DEX_LOCATION with the chroot prefix, if any. 483chroot_dex_location="$chroot$DEX_LOCATION" 484 485# Allocate file descriptor real_stderr and redirect it to the shell's error 486# output (fd 2). 487if [ ${BASH_VERSINFO[1]} -ge 4 ] && [ ${BASH_VERSINFO[2]} -ge 1 ]; then 488 exec {real_stderr}>&2 489else 490 # In bash before version 4.1 we need to do a manual search for free file 491 # descriptors. 492 FD=3 493 while [ -e /dev/fd/$FD ]; do FD=$((FD + 1)); done 494 real_stderr=$FD 495 eval "exec ${real_stderr}>&2" 496fi 497if [ "$quiet" = "yes" ]; then 498 # Force the default standard output and error to go to /dev/null so we will 499 # not print them. 500 exec 1>/dev/null 501 exec 2>/dev/null 502fi 503 504function err_echo() { 505 echo "$@" 1>&${real_stderr} 506} 507 508# tmp_dir may be relative, resolve. 509# 510# Cannot use realpath, as it does not exist on Mac. 511# Cannot use a simple "cd", as the path might not be created yet. 512# Cannot use readlink -m, as it does not exist on Mac. 513# Fallback to nuclear option: 514noncanonical_tmp_dir=$tmp_dir 515tmp_dir="`cd $oldwd ; python3 -c "import os; import sys; sys.stdout.write(os.path.realpath('$tmp_dir'))"`" 516if [ -z $tmp_dir ] ; then 517 err_echo "Failed to resolve $tmp_dir" 518 exit 1 519fi 520mkdir -p $tmp_dir 521 522# Add thread suspend timeout flag 523if [ ! "$runtime" = "jvm" ]; then 524 run_args+=(--runtime-option "-XX:ThreadSuspendTimeout=$suspend_timeout") 525fi 526 527if [ "$basic_verify" = "true" ]; then 528 # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests. 529 run_args+=(--runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0) 530fi 531if [ "$gc_verify" = "true" ]; then 532 run_args+=(--runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc) 533fi 534if [ "$gc_stress" = "true" ]; then 535 run_args+=(--gc-stress --runtime-option -Xgc:gcstress --runtime-option -Xms2m --runtime-option -Xmx16m) 536fi 537if [ "$jvmti_redefine_stress" = "true" ]; then 538 run_args+=(--no-app-image --jvmti-redefine-stress) 539fi 540if [ "$jvmti_step_stress" = "true" ]; then 541 run_args+=(--no-app-image --jvmti-step-stress) 542fi 543if [ "$jvmti_field_stress" = "true" ]; then 544 run_args+=(--no-app-image --jvmti-field-stress) 545fi 546if [ "$jvmti_trace_stress" = "true" ]; then 547 run_args+=(--no-app-image --jvmti-trace-stress) 548fi 549if [ "$trace" = "true" ]; then 550 run_args+=(--runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file-size:2000000) 551 if [ "$trace_stream" = "true" ]; then 552 # Streaming mode uses the file size as the buffer size. So output gets really large. Drop 553 # the ability to analyze the file and just write to /dev/null. 554 run_args+=(--runtime-option -Xmethod-trace-file:/dev/null) 555 # Enable streaming mode. 556 run_args+=(--runtime-option -Xmethod-trace-stream) 557 else 558 run_args+=(--runtime-option "-Xmethod-trace-file:${DEX_LOCATION}/trace.bin") 559 fi 560elif [ "$trace_stream" = "true" ]; then 561 err_echo "Cannot use --stream without --trace." 562 exit 1 563fi 564if [ -n "$timeout" ]; then 565 run_args+=(--timeout "$timeout") 566fi 567 568# Most interesting target architecture variables are Makefile variables, not environment variables. 569# Try to map the suffix64 flag and what we find in ${ANDROID_PRODUCT_OUT}/data/art-test to an architecture name. 570function guess_target_arch_name() { 571 # Check whether this is a device with native bridge. Currently this is hardcoded 572 # to x86 + arm. 573 local guess_path=$chroot/system/framework/art_boot_images 574 local x86_arm=`adb shell ls ${guess_path} | sort | grep -E '^(arm|x86)$'` 575 # Collapse line-breaks into spaces 576 x86_arm=$(echo $x86_arm) 577 if [ "x$x86_arm" = "xarm x86" ] ; then 578 err_echo "Native-bridge configuration detected." 579 # We only support the main arch for tests. 580 if [ "x${suffix64}" = "x64" ]; then 581 target_arch_name="" 582 else 583 target_arch_name=x86 584 fi 585 else 586 local grep32bit=`adb shell ls ${guess_path} | grep -E '^(arm|x86)$'` 587 local grep64bit=`adb shell ls ${guess_path} | grep -E '^(arm64|x86_64)$'` 588 if [ "x${suffix64}" = "x64" ]; then 589 target_arch_name=${grep64bit} 590 else 591 target_arch_name=${grep32bit} 592 fi 593 fi 594} 595 596function guess_host_arch_name() { 597 if [ "x${suffix64}" = "x64" ]; then 598 host_arch_name="x86_64" 599 else 600 host_arch_name="x86" 601 fi 602} 603 604if [ "$target_mode" = "no" ]; then 605 if [ "$runtime" = "jvm" ]; then 606 if [ "$prebuild_mode" = "yes" ]; then 607 err_echo "--prebuild with --jvm is unsupported" 608 exit 1 609 fi 610 else 611 # ART/Dalvik host mode. 612 if [ -n "$chroot" ]; then 613 err_echo "--chroot with --host is unsupported" 614 exit 1 615 fi 616 fi 617fi 618 619if [ ! "$runtime" = "jvm" ]; then 620 run_args+=(--lib "$lib") 621fi 622 623if [ "$runtime" = "dalvik" ]; then 624 if [ "$target_mode" = "no" ]; then 625 framework="${ANDROID_PRODUCT_OUT}/system/framework" 626 bpath="${framework}/core-icu4j.jar:${framework}/core-libart.jar:${framework}/core-oj.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/bouncycastle.jar:${framework}/ext.jar" 627 run_args+=(--boot --runtime-option "-Xbootclasspath:${bpath}") 628 else 629 true # defaults to using target BOOTCLASSPATH 630 fi 631elif [ "$runtime" = "art" ]; then 632 if [ "$target_mode" = "no" ]; then 633 guess_host_arch_name 634 run_args+=(--boot "${ANDROID_HOST_OUT}/apex/art_boot_images/javalib/boot.art") 635 run_args+=(--runtime-option "-Djava.library.path=${host_lib_root}/lib${suffix64}:${host_lib_root}/nativetest${suffix64}") 636 else 637 guess_target_arch_name 638 # Note that libarttest(d).so and other test libraries that depend on ART 639 # internal libraries must not be in this path for JNI libraries - they 640 # need to be loaded through LD_LIBRARY_PATH and 641 # NATIVELOADER_DEFAULT_NAMESPACE_LIBS instead. 642 run_args+=(--runtime-option "-Djava.library.path=/data/nativetest${suffix64}/art/${target_arch_name}") 643 run_args+=(--boot "/system/framework/art_boot_images/boot.art") 644 fi 645 if [ "$relocate" = "yes" ]; then 646 run_args+=(--relocate) 647 else 648 run_args+=(--no-relocate) 649 fi 650elif [ "$runtime" = "jvm" ]; then 651 # TODO: Detect whether the host is 32-bit or 64-bit. 652 run_args+=(--runtime-option "-Djava.library.path=${ANDROID_HOST_OUT}/lib64:${ANDROID_HOST_OUT}/nativetest64") 653fi 654 655if [ "$have_image" = "no" ]; then 656 if [ "$runtime" != "art" ]; then 657 err_echo "--no-image is only supported on the art runtime" 658 exit 1 659 fi 660 run_args+=(--no-image) 661fi 662 663if [ "$create_runner" = "yes" -a "$target_mode" = "yes" ]; then 664 err_echo "--create-runner does not function for non --host tests" 665 usage="yes" 666fi 667 668if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then 669 err_echo "--dev and --update are mutually exclusive" 670 usage="yes" 671fi 672 673if [ "$dev_mode" = "yes" -a "$quiet" = "yes" ]; then 674 err_echo "--dev and --quiet are mutually exclusive" 675 usage="yes" 676fi 677 678if [ "$bisection_search" = "yes" -a "$prebuild_mode" = "yes" ]; then 679 err_echo "--bisection-search and --prebuild are mutually exclusive" 680 usage="yes" 681fi 682 683# TODO: Chroot-based bisection search is not supported yet (see below); implement it. 684if [ "$bisection_search" = "yes" -a -n "$chroot" ]; then 685 err_echo "--chroot with --bisection-search is unsupported" 686 exit 1 687fi 688 689if [ "$usage" = "no" ]; then 690 if [ "x$1" = "x" -o "x$1" = "x-" ]; then 691 test_dir=`basename "$oldwd"` 692 else 693 test_dir="$1" 694 fi 695 696 if [ '!' -d "$test_dir" ]; then 697 td2=`echo ${test_dir}-*` 698 if [ '!' -d "$td2" ]; then 699 err_echo "${test_dir}: no such test directory" 700 usage="yes" 701 fi 702 test_dir="$td2" 703 fi 704 # Shift to get rid of the test name argument. The rest of the arguments 705 # will get passed to the test run. 706 shift 707fi 708 709if [ "$usage" = "yes" ]; then 710 prog=`basename $prog` 711 ( 712 echo "usage:" 713 echo " $prog --help Print this message." 714 echo " $prog [options] [test-name] Run test normally." 715 echo " $prog --dev [options] [test-name] Development mode" \ 716 "(dumps to stdout)." 717 echo " $prog --create-runner [options] [test-name]" 718 echo " Creates a runner script for use with other " \ 719 "tools (e.g. parallel_run.py)." 720 echo " The script will only run the test portion, and " \ 721 "share oat and dex files." 722 echo " $prog --update [options] [test-name] Update mode" \ 723 "(replaces expected-stdout.txt and expected-stderr.txt)." 724 echo ' Omitting the test name or specifying "-" will use the' \ 725 "current directory." 726 echo " Runtime Options:" 727 echo " -O Run non-debug rather than debug build (off by default)." 728 echo " -Xcompiler-option Pass an option to the compiler." 729 echo " --runtime-option Pass an option to the runtime." 730 echo " --compact-dex-level Specify a compact dex level to the compiler." 731 echo " --debug Wait for the default debugger to attach." 732 echo " --debug-agent <agent-path>" 733 echo " Wait for the given debugger agent to attach. Currently" 734 echo " only supported on host." 735 echo " --debug-wrap-agent use libwrapagentproperties and tools/libjdwp-compat.props" 736 echo " to load the debugger agent specified by --debug-agent." 737 echo " --with-agent <agent> Run the test with the given agent loaded with -agentpath:" 738 echo " --debuggable Whether to compile Java code for a debugger." 739 echo " --gdb Run under gdb; incompatible with some tests." 740 echo " --gdb-dex2oat Run dex2oat under the prebuilt lldb." 741 echo " --gdbserver Start gdbserver (defaults to port :5039)." 742 echo " --gdbserver-port <port>" 743 echo " Start gdbserver with the given COMM (see man gdbserver)." 744 echo " --gdbserver-bin <binary>" 745 echo " Use the given binary as gdbserver." 746 echo " --gdb-arg Pass an option to gdb or gdbserver." 747 echo " --gdb-dex2oat-args Pass options separated by ';' to lldb for dex2oat." 748 echo " --simpleperf Wraps the dalvikvm invocation in 'simpleperf record ..." 749 echo " ... simpleperf report' and dumps stats to stdout." 750 echo " --temp-path [path] Location where to execute the tests." 751 echo " --interpreter Enable interpreter only mode (off by default)." 752 echo " --jit Enable jit (off by default)." 753 echo " --optimizing Enable optimizing compiler (default)." 754 echo " --no-verify Turn off verification (on by default)." 755 echo " --verify-soft-fail Force soft fail verification (off by default)." 756 echo " Verification is enabled if neither --no-verify" 757 echo " nor --verify-soft-fail is specified." 758 echo " --no-optimize Turn off optimization (on by default)." 759 echo " --no-precise Turn off precise GC (on by default)." 760 echo " --zygote Spawn the process from the Zygote." \ 761 "If used, then the" 762 echo " other runtime options are ignored." 763 echo " --prebuild Run dex2oat on the files before starting test. (default)" 764 echo " --no-prebuild Do not run dex2oat on the files before starting" 765 echo " the test." 766 echo " --strip-dex Strip the dex files before starting test." 767 echo " --relocate Force the use of relocating in the test, making" 768 echo " the image and oat files be relocated to a random" 769 echo " address before running." 770 echo " --no-relocate Force the use of no relocating in the test. (default)" 771 echo " --image Run the test using a precompiled boot image. (default)" 772 echo " --no-image Run the test without a precompiled boot image." 773 echo " --host Use the host-mode virtual machine." 774 echo " --invoke-with Pass --invoke-with option to runtime." 775 echo " --dalvik Use Dalvik (off by default)." 776 echo " --jvm Use a host-local RI virtual machine." 777 echo " --use-java-home Use the JAVA_HOME environment variable" 778 echo " to find the java compiler and runtime" 779 echo " (if applicable) to run the test with." 780 echo " --64 Run the test in 64-bit mode" 781 echo " --bionic Use the (host, 64-bit only) linux_bionic libc runtime" 782 echo " --runtime-zipapex [file]" 783 echo " Use the given zipapex file to provide runtime binaries" 784 echo " --runtime-extracted-zipapex [dir]" 785 echo " Use the given extracted zipapex directory to provide" 786 echo " runtime binaries" 787 echo " --timeout n Test timeout in seconds" 788 echo " --trace Run with method tracing" 789 echo " --strace Run with syscall tracing from strace." 790 echo " --stream Run method tracing in streaming mode (requires --trace)" 791 echo " --gcstress Run with gc stress testing" 792 echo " --gcverify Run with gc verification" 793 echo " --jvmti-trace-stress Run with jvmti method tracing stress testing" 794 echo " --jvmti-step-stress Run with jvmti single step stress testing" 795 echo " --jvmti-redefine-stress" 796 echo " Run with jvmti method redefinition stress testing" 797 echo " --always-clean Delete the test files even if the test fails." 798 echo " --never-clean Keep the test files even if the test succeeds." 799 echo " --chroot [newroot] Run with root directory set to newroot." 800 echo " --android-root [path] The path on target for the android root. (/system by default)." 801 echo " --android-i18n-root [path]" 802 echo " The path on target for the i18n module root." 803 echo " (/apex/com.android.i18n by default)." 804 echo " --android-art-root [path]" 805 echo " The path on target for the ART module root." 806 echo " (/apex/com.android.art by default)." 807 echo " --android-tzdata-root [path]" 808 echo " The path on target for the Android Time Zone Data root." 809 echo " (/apex/com.android.tzdata by default)." 810 echo " --dex2oat-swap Use a dex2oat swap file." 811 echo " --instruction-set-features [string]" 812 echo " Set instruction-set-features for compilation." 813 echo " --quiet Don't print anything except failure messages" 814 echo " --external-log-tags Use ANDROID_LOG_TAGS to set a custom logging level for" 815 echo " a test run." 816 echo " --bisection-search Perform bisection bug search." 817 echo " --vdex Test using vdex as in input to dex2oat. Only works with --prebuild." 818 echo " --suspend-timeout Change thread suspend timeout ms (default 500000)." 819 echo " --dex2oat-jobs Number of dex2oat jobs." 820 ) 1>&2 # Direct to stderr so usage is not printed if --quiet is set. 821 exit 1 822fi 823 824cd "$test_dir" 825test_dir=`pwd` 826 827td_info="${test_dir}/${info}" 828td_expected_stdout="${test_dir}/${expected_stdout}" 829td_expected_stderr="${test_dir}/${expected_stderr}" 830 831for td_file in "$td_info" "$td_expected_stdout" "$td_expected_stderr"; do 832 if [ ! -r "$td_file" ]; then 833 err_echo "${test_dir}: missing file $td_file" 834 exit 1 835 fi 836done 837 838export TEST_NAME=`basename ${test_dir}` 839 840# Tests named '<number>-checker-*' will also have their CFGs verified with 841# Checker when compiled with Optimizing on host. 842# Additionally, if the user specifies that the CFG must be dumped, it will 843# run the checker for any type of test to generate the CFG. 844if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]] || [ "$dump_cfg" = "true" ]; then 845 if [ "$runtime" = "art" -a "$run_optimizing" = "true" ]; then 846 # In no-prebuild or no-image mode, the compiler only quickens so disable the checker. 847 if [ "$prebuild_mode" = "yes" ]; then 848 run_checker="yes" 849 850 if [ "$target_mode" = "no" ]; then 851 cfg_output_dir="$tmp_dir" 852 checker_args="--arch=${host_arch_name^^}" 853 else 854 cfg_output_dir="$DEX_LOCATION" 855 checker_args="--arch=${target_arch_name^^}" 856 fi 857 858 if [ "$debuggable" = "yes" ]; then 859 checker_args="$checker_args --debuggable" 860 fi 861 862 run_args+=(-Xcompiler-option "--dump-cfg=$cfg_output_dir/$cfg_output" -Xcompiler-option -j1) 863 checker_args="$checker_args --print-cfg" 864 fi 865 fi 866fi 867 868run_args+=(--testlib "${testlib}") 869 870if ! ulimit -f ${file_ulimit}; then 871 err_echo "ulimit file size setting failed" 872fi 873 874# Extract run-test data from the zip file. 875rm -rf "$tmp_dir" 876mkdir -p "$tmp_dir/.unzipped" 877cd "$tmp_dir" 878if [[ "$target_mode" == "yes" ]]; then 879 zip_file="${ANDROID_HOST_OUT}/etc/art/art-run-test-target-data.zip" 880 zip_entry="target/${TEST_NAME}" 881elif [[ $runtime == "jvm" ]]; then 882 zip_file="${ANDROID_HOST_OUT}/etc/art/art-run-test-jvm-data.zip" 883 zip_entry="jvm/${TEST_NAME}" 884else 885 zip_file="${ANDROID_HOST_OUT}/etc/art/art-run-test-host-data.zip" 886 zip_entry="host/${TEST_NAME}" 887fi 888unzip -q "${zip_file}" "${zip_entry}/*" -d "$tmp_dir/.unzipped" 889mv "$tmp_dir"/.unzipped/${zip_entry}/* "$tmp_dir" 890 891good="no" 892good_run="yes" 893export TEST_RUNTIME="${runtime}" 894if [ "$dev_mode" = "yes" ]; then 895 echo "${test_dir}: running..." 1>&2 896 "./${run}" "${run_args[@]}" "$@" 897 run_exit="$?" 898 899 if [ "$run_exit" = "0" ]; then 900 if [ "$run_checker" = "yes" ]; then 901 if [ "$target_mode" = "yes" ]; then 902 adb pull "$chroot/$cfg_output_dir/$cfg_output" &> /dev/null 903 fi 904 "$checker" $checker_args "$cfg_output" "$tmp_dir" 2>&1 905 checker_exit="$?" 906 if [ "$checker_exit" = "0" ]; then 907 good="yes" 908 fi 909 err_echo "checker exit status: $checker_exit" 910 else 911 good="yes" 912 fi 913 fi 914 echo "run exit status: $run_exit" 1>&2 915elif [ "$update_mode" = "yes" ]; then 916 echo "${test_dir}: running..." 1>&2 917 "./${run}" "${run_args[@]}" "$@" >"$test_stdout" 2>"$test_stderr" 918 if [ "$run_checker" = "yes" ]; then 919 if [ "$target_mode" = "yes" ]; then 920 adb pull "$chroot/$cfg_output_dir/$cfg_output" &> /dev/null 921 fi 922 "$checker" -q $checker_args "$cfg_output" "$tmp_dir" >>"$test_stdout" 2>>"$test_stderr" 923 fi 924 sed -e 's/[[:cntrl:]]$//g' <"$test_stdout" >"${td_expected_stdout}" 925 sed -e 's/[[:cntrl:]]$//g' <"$test_stderr" >"${td_expected_stderr}" 926 good="yes" 927else 928 echo "${test_dir}: running..." 1>&2 929 "./${run}" "${run_args[@]}" "$@" >"$test_stdout" 2>"$test_stderr" 930 run_exit="$?" 931 if [ "$run_exit" != "0" ]; then 932 err_echo "run exit status: $run_exit" 933 good_run="no" 934 elif [ "$run_checker" = "yes" ]; then 935 if [ "$target_mode" = "yes" ]; then 936 adb pull "$chroot/$cfg_output_dir/$cfg_output" &> /dev/null 937 fi 938 "$checker" -q $checker_args "$cfg_output" "$tmp_dir" >>"$test_stdout" 2>>"$test_stderr" 939 checker_exit="$?" 940 if [ "$checker_exit" != "0" ]; then 941 err_echo "checker exit status: $checker_exit" 942 good_run="no" 943 else 944 good_run="yes" 945 fi 946 else 947 good_run="yes" 948 fi 949 ./$check_cmd "$expected_stdout" "$test_stdout" "$expected_stderr" "$test_stderr" 950 if [ "$?" = "0" ]; then 951 if [ "$good_run" = "yes" ]; then 952 # test_stdout == expected_stdout && test_stderr == expected_stderr 953 good="yes" 954 echo "${test_dir}: succeeded!" 1>&2 955 fi 956 fi 957fi 958 959( 960 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then 961 echo "${test_dir}: FAILED!" 962 echo ' ' 963 echo '#################### info' 964 cat "${td_info}" | sed 's/^/# /g' 965 echo '#################### stdout diffs' 966 if [ "$run_checker" == "yes" ]; then 967 # Checker failures dump the whole CFG, so we output the whole diff. 968 diff --strip-trailing-cr -u "$expected_stdout" "$test_stdout" 969 else 970 diff --strip-trailing-cr -u "$expected_stdout" "$test_stdout" | tail -n 10000 971 fi 972 echo '####################' 973 echo '#################### stderr diffs' 974 diff --strip-trailing-cr -u "$expected_stderr" "$test_stderr" | tail -n 10000 975 echo '####################' 976 if [ "$strace" = "yes" ]; then 977 echo '#################### strace output' 978 tail -n 3000 "$tmp_dir/$strace_output" 979 echo '####################' 980 fi 981 if [ "x$target_mode" = "xno" -a "x$SANITIZE_HOST" = "xaddress" ]; then 982 # Run the stack script to symbolize any ASAN aborts on the host for SANITIZE_HOST. The 983 # tools used by the given ABI work for both x86 and x86-64. 984 echo "ABI: 'x86_64'" | cat - "$test_stdout" "$test_stderr" \ 985 | $ANDROID_BUILD_TOP/development/scripts/stack | tail -n 3000 986 fi 987 echo ' ' 988 fi 989 990) 2>&${real_stderr} 1>&2 991 992# Copy the generated CFG to the specified path. 993if [ $dump_cfg = "true" ]; then 994 if [ $run_optimizing != "true" ]; then 995 err_echo "Can't dump the .cfg if the compiler type isn't set to \"optimizing\"." 996 else 997 if [ "$target_mode" = "yes" ]; then 998 adb pull $chroot/$cfg_output_dir/$cfg_output $dump_cfg_path 999 else 1000 cp $cfg_output_dir/$cfg_output $dump_cfg_path 1001 fi 1002 fi 1003fi 1004 1005# Attempt bisection only if the test failed. 1006# TODO: Implement support for chroot-based bisection search. 1007if [ "$bisection_search" = "yes" -a "$good" != "yes" ]; then 1008 # Bisecting works by skipping different optimization passes which breaks checker assertions. 1009 if [ "$run_checker" == "yes" ]; then 1010 echo "${test_dir}: not bisecting, checker test." 1>&2 1011 else 1012 # Increase file size limit, bisection search can generate large logfiles. 1013 echo "${test_dir}: bisecting..." 1>&2 1014 cwd=`pwd` 1015 maybe_device_mode="" 1016 raw_cmd="" 1017 if [ "$target_mode" = "yes" ]; then 1018 # Produce cmdline.sh in $chroot_dex_location. "$@" is passed as a runtime option 1019 # so that cmdline.sh forwards its arguments to dalvikvm. invoke-with is set 1020 # to exec in order to preserve pid when calling dalvikvm. This is required 1021 # for bisection search to correctly retrieve logs from device. 1022 "./${run}" "${run_args[@]}" --runtime-option '"$@"' --invoke-with exec --dry-run "$@" &> /dev/null 1023 adb shell chmod u+x "$chroot_dex_location/cmdline.sh" 1024 maybe_device_mode="--device" 1025 raw_cmd="$DEX_LOCATION/cmdline.sh" 1026 else 1027 raw_cmd="$cwd/${run} --external-log-tags "${run_args[@]}" $@" 1028 fi 1029 # TODO: Pass a `--chroot` option to the bisection_search.py script and use it there. 1030 $ANDROID_BUILD_TOP/art/tools/bisection_search/bisection_search.py \ 1031 $maybe_device_mode \ 1032 --raw-cmd="$raw_cmd" \ 1033 --check-script="$cwd/check" \ 1034 --expected-output="$cwd/expected-stdout.txt" \ 1035 --logfile="$cwd/bisection_log.txt" \ 1036 --timeout=${timeout:-300} 1037 fi 1038fi 1039 1040# Clean up test files. 1041if [ "$always_clean" = "yes" -o "$good" = "yes" ] && [ "$never_clean" = "no" ]; then 1042 cd "$oldwd" 1043 rm -rf "$tmp_dir" 1044 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then 1045 adb shell rm -rf $chroot_dex_location 1046 fi 1047 if [ "$good" = "yes" ]; then 1048 exit 0 1049 fi 1050fi 1051 1052 1053( 1054 if [ "$always_clean" = "yes" ]; then 1055 echo "${TEST_NAME} files deleted from host " 1056 if [ "$target_mode" == "yes" ]; then 1057 echo "and from target" 1058 fi 1059 else 1060 echo "${TEST_NAME} files left in ${tmp_dir} on host" 1061 if [ "$target_mode" == "yes" ]; then 1062 echo "and in ${chroot_dex_location} on target" 1063 fi 1064 fi 1065 1066) 2>&${real_stderr} 1>&2 1067 1068if [ "$never_clean" = "yes" ] && [ "$good" = "yes" ]; then 1069 exit 0 1070else 1071 exit 1 1072fi 1073