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