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