run-test revision 57e863c3739c310380e19252ad5746ff08d219c7
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}/$USER/${test_dir}" 41fi 42checker="${progdir}/../tools/checker/checker.py" 43export JAVA="java" 44export JAVAC="javac -g -source 1.7 -target 1.7 -Xlint:-options" 45export RUN="${progdir}/etc/run-test-jar" 46export DEX_LOCATION=/data/run-test/${test_dir} 47export NEED_DEX="true" 48export USE_JACK="false" 49export SMALI_ARGS="--experimental --api-level 23" 50 51# If dx was not set by the environment variable, assume it is in the path. 52if [ -z "$DX" ]; then 53 export DX="dx" 54fi 55 56# If jasmin was not set by the environment variable, assume it is in the path. 57if [ -z "$JASMIN" ]; then 58 export JASMIN="jasmin" 59fi 60 61# If smali was not set by the environment variable, assume it is in the path. 62if [ -z "$SMALI" ]; then 63 export SMALI="smali" 64fi 65 66# If dexmerger was not set by the environment variable, assume it is in the path. 67if [ -z "$DXMERGER" ]; then 68 export DXMERGER="dexmerger" 69fi 70 71# If jack was not set by the environment variable, assume it is in the path. 72if [ -z "$JACK" ]; then 73 export JACK="jack" 74fi 75 76# If the tree is compiled with Jack, build test with Jack by default. 77if [ "$ANDROID_COMPILE_WITH_JACK" = "true" ]; then 78 USE_JACK="true" 79fi 80 81# ANDROID_BUILD_TOP is not set in a build environment. 82if [ -z "$ANDROID_BUILD_TOP" ]; then 83 export ANDROID_BUILD_TOP=$oldwd 84fi 85 86# If JACK_CLASSPATH is not set, assume it only contains core-libart. 87if [ -z "$JACK_CLASSPATH" ]; then 88 export JACK_CLASSPATH="${OUT_DIR:-$ANDROID_BUILD_TOP/out}/host/common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack:${OUT_DIR:-$ANDROID_BUILD_TOP/out}/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/classes.jack" 89fi 90 91# If JILL_JAR is not set, assume it is located in the prebuilts directory. 92if [ -z "$JILL_JAR" ]; then 93 export JILL_JAR="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/jill.jar" 94fi 95 96export JACK="$JACK -g -cp $JACK_CLASSPATH" 97export JILL="java -jar $JILL_JAR" 98 99info="info.txt" 100build="build" 101run="run" 102expected="expected.txt" 103check_cmd="check" 104output="output.txt" 105build_output="build-output.txt" 106cfg_output="graph.cfg" 107strace_output="strace-output.txt" 108lib="libartd.so" 109testlib="arttestd" 110run_args="--quiet" 111build_args="" 112 113quiet="no" 114debuggable="no" 115prebuild_mode="yes" 116target_mode="yes" 117dev_mode="no" 118update_mode="no" 119debug_mode="no" 120relocate="yes" 121runtime="art" 122usage="no" 123build_only="no" 124suffix64="" 125trace="false" 126trace_stream="false" 127basic_verify="false" 128gc_verify="false" 129gc_stress="false" 130strace="false" 131always_clean="no" 132never_clean="no" 133have_dex2oat="yes" 134have_patchoat="yes" 135have_image="yes" 136image_suffix="" 137pic_image_suffix="" 138multi_image_suffix="" 139android_root="/system" 140 141while true; do 142 if [ "x$1" = "x--host" ]; then 143 target_mode="no" 144 DEX_LOCATION=$tmp_dir 145 run_args="${run_args} --host" 146 shift 147 elif [ "x$1" = "x--quiet" ]; then 148 quiet="yes" 149 shift 150 elif [ "x$1" = "x--use-java-home" ]; then 151 if [ -n "${JAVA_HOME}" ]; then 152 export JAVA="${JAVA_HOME}/bin/java" 153 export JAVAC="${JAVA_HOME}/bin/javac -g" 154 else 155 echo "Passed --use-java-home without JAVA_HOME variable set!" 156 usage="yes" 157 fi 158 shift 159 elif [ "x$1" = "x--jvm" ]; then 160 target_mode="no" 161 runtime="jvm" 162 prebuild_mode="no" 163 NEED_DEX="false" 164 USE_JACK="false" 165 run_args="${run_args} --jvm" 166 build_args="${build_args} --jvm" 167 shift 168 elif [ "x$1" = "x-O" ]; then 169 lib="libart.so" 170 testlib="arttest" 171 shift 172 elif [ "x$1" = "x--dalvik" ]; then 173 lib="libdvm.so" 174 runtime="dalvik" 175 shift 176 elif [ "x$1" = "x--no-dex2oat" ]; then 177 have_dex2oat="no" 178 shift 179 elif [ "x$1" = "x--no-patchoat" ]; then 180 have_patchoat="no" 181 shift 182 elif [ "x$1" = "x--no-image" ]; then 183 have_image="no" 184 shift 185 elif [ "x$1" = "x--pic-image" ]; then 186 pic_image_suffix="-pic" 187 shift 188 elif [ "x$1" = "x--multi-image" ]; then 189 multi_image_suffix="-multi" 190 shift 191 elif [ "x$1" = "x--pic-test" ]; then 192 run_args="${run_args} --pic-test" 193 shift 194 elif [ "x$1" = "x--relocate" ]; then 195 relocate="yes" 196 shift 197 elif [ "x$1" = "x--no-relocate" ]; then 198 relocate="no" 199 shift 200 elif [ "x$1" = "x--prebuild" ]; then 201 run_args="${run_args} --prebuild" 202 prebuild_mode="yes" 203 shift; 204 elif [ "x$1" = "x--debuggable" ]; then 205 run_args="${run_args} -Xcompiler-option --debuggable" 206 debuggable="yes" 207 shift; 208 elif [ "x$1" = "x--no-prebuild" ]; then 209 run_args="${run_args} --no-prebuild" 210 prebuild_mode="no" 211 shift; 212 elif [ "x$1" = "x--gcverify" ]; then 213 basic_verify="true" 214 gc_verify="true" 215 shift 216 elif [ "x$1" = "x--gcstress" ]; then 217 basic_verify="true" 218 gc_stress="true" 219 shift 220 elif [ "x$1" = "x--image" ]; then 221 shift 222 image="$1" 223 run_args="${run_args} --image $image" 224 shift 225 elif [ "x$1" = "x-Xcompiler-option" ]; then 226 shift 227 option="$1" 228 run_args="${run_args} -Xcompiler-option $option" 229 shift 230 elif [ "x$1" = "x--runtime-option" ]; then 231 shift 232 option="$1" 233 run_args="${run_args} --runtime-option $option" 234 shift 235 elif [ "x$1" = "x--gdb-arg" ]; then 236 shift 237 gdb_arg="$1" 238 run_args="${run_args} --gdb-arg $gdb_arg" 239 shift 240 elif [ "x$1" = "x--debug" ]; then 241 run_args="${run_args} --debug" 242 shift 243 elif [ "x$1" = "x--gdb" ]; then 244 run_args="${run_args} --gdb" 245 dev_mode="yes" 246 shift 247 elif [ "x$1" = "x--strace" ]; then 248 strace="yes" 249 run_args="${run_args} --invoke-with strace --invoke-with -o --invoke-with $tmp_dir/$strace_output" 250 shift 251 elif [ "x$1" = "x--zygote" ]; then 252 run_args="${run_args} --zygote" 253 shift 254 elif [ "x$1" = "x--interpreter" ]; then 255 run_args="${run_args} --interpreter" 256 image_suffix="-interpreter" 257 shift 258 elif [ "x$1" = "x--jit" ]; then 259 run_args="${run_args} --jit" 260 image_suffix="-jit" 261 shift 262 elif [ "x$1" = "x--optimizing" ]; then 263 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing" 264 image_suffix="-optimizing" 265 shift 266 elif [ "x$1" = "x--quick" ]; then 267 run_args="${run_args} -Xcompiler-option --compiler-backend=Quick" 268 shift 269 elif [ "x$1" = "x--no-verify" ]; then 270 run_args="${run_args} --no-verify" 271 shift 272 elif [ "x$1" = "x--verify-soft-fail" ]; then 273 run_args="${run_args} --verify-soft-fail" 274 image_suffix="-interp-ac" 275 shift 276 elif [ "x$1" = "x--no-optimize" ]; then 277 run_args="${run_args} --no-optimize" 278 shift 279 elif [ "x$1" = "x--no-precise" ]; then 280 run_args="${run_args} --no-precise" 281 shift 282 elif [ "x$1" = "x--invoke-with" ]; then 283 shift 284 what="$1" 285 if [ "x$what" = "x" ]; then 286 echo "$0 missing argument to --invoke-with" 1>&2 287 usage="yes" 288 break 289 fi 290 run_args="${run_args} --invoke-with ${what}" 291 shift 292 elif [ "x$1" = "x--dev" ]; then 293 run_args="${run_args} --dev" 294 dev_mode="yes" 295 shift 296 elif [ "x$1" = "x--build-only" ]; then 297 build_only="yes" 298 shift 299 elif [ "x$1" = "x--build-with-javac-dx" ]; then 300 USE_JACK="false" 301 shift 302 elif [ "x$1" = "x--build-with-jack" ]; then 303 USE_JACK="true" 304 shift 305 elif [ "x$1" = "x--output-path" ]; then 306 shift 307 tmp_dir=$1 308 if [ "x$tmp_dir" = "x" ]; then 309 echo "$0 missing argument to --output-path" 1>&2 310 usage="yes" 311 break 312 fi 313 shift 314 elif [ "x$1" = "x--android-root" ]; then 315 shift 316 if [ "x$1" = "x" ]; then 317 echo "$0 missing argument to --android-root" 1>&2 318 usage="yes" 319 break 320 fi 321 android_root="$1" 322 run_args="${run_args} --android-root $1" 323 shift 324 elif [ "x$1" = "x--update" ]; then 325 update_mode="yes" 326 shift 327 elif [ "x$1" = "x--help" ]; then 328 usage="yes" 329 shift 330 elif [ "x$1" = "x--64" ]; then 331 run_args="${run_args} --64" 332 suffix64="64" 333 shift 334 elif [ "x$1" = "x--trace" ]; then 335 trace="true" 336 shift 337 elif [ "x$1" = "x--stream" ]; then 338 trace_stream="true" 339 shift 340 elif [ "x$1" = "x--always-clean" ]; then 341 always_clean="yes" 342 shift 343 elif [ "x$1" = "x--never-clean" ]; then 344 never_clean="yes" 345 shift 346 elif [ "x$1" = "x--dex2oat-swap" ]; then 347 run_args="${run_args} --dex2oat-swap" 348 shift 349 elif [ "x$1" = "x--instruction-set-features" ]; then 350 shift 351 run_args="${run_args} --instruction-set-features $1" 352 shift 353 elif expr "x$1" : "x--" >/dev/null 2>&1; then 354 echo "unknown $0 option: $1" 1>&2 355 usage="yes" 356 break 357 else 358 break 359 fi 360done 361 362# Allocate file descriptor real_stderr and redirect it to the shell's error 363# output (fd 2). 364if [ ${BASH_VERSINFO[1]} -ge 4 ] && [ ${BASH_VERSINFO[2]} -ge 1 ]; then 365 exec {real_stderr}>&2 366else 367 # In bash before version 4.1 we need to do a manual search for free file 368 # descriptors. 369 FD=3 370 while [ -e /dev/fd/$FD ]; do FD=$((FD + 1)); done 371 real_stderr=$FD 372 eval "exec ${real_stderr}>&2" 373fi 374if [ "$quiet" = "yes" ]; then 375 # Force the default standard output and error to go to /dev/null so we will 376 # not print them. 377 exec 1>/dev/null 378 exec 2>/dev/null 379fi 380 381function err_echo() { 382 echo "$@" 1>&${real_stderr} 383} 384 385# tmp_dir may be relative, resolve. 386# 387# Cannot use realpath, as it does not exist on Mac. 388# Cannot us a simple "cd", as the path might not be created yet. 389# Cannot use readlink -m, as it does not exist on Mac. 390# Fallback to nuclear option: 391noncanonical_tmp_dir=$tmp_dir 392tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`" 393mkdir -p $tmp_dir 394 395if [ "$basic_verify" = "true" ]; then 396 # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests. 397 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0" 398fi 399if [ "$gc_verify" = "true" ]; then 400 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc" 401fi 402if [ "$gc_stress" = "true" ]; then 403 run_args="${run_args} --runtime-option -Xgc:SS,gcstress --runtime-option -Xms2m --runtime-option -Xmx16m" 404fi 405if [ "$trace" = "true" ]; then 406 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file-size:2000000" 407 if [ "$trace_stream" = "true" ]; then 408 # Streaming mode uses the file size as the buffer size. So output gets really large. Drop 409 # the ability to analyze the file and just write to /dev/null. 410 run_args="${run_args} --runtime-option -Xmethod-trace-file:/dev/null" 411 # Enable streaming mode. 412 run_args="${run_args} --runtime-option -Xmethod-trace-stream" 413 else 414 run_args="${run_args} --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin" 415 fi 416elif [ "$trace_stream" = "true" ]; then 417 err_echo "Cannot use --stream without --trace." 418 exit 1 419fi 420 421# Most interesting target architecture variables are Makefile variables, not environment variables. 422# Try to map the suffix64 flag and what we find in ${ANDROID_PRODUCT_OUT}/data/art-test to an architecture name. 423function guess_target_arch_name() { 424 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'` 425 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64|mips64)$'` 426 if [ "x${suffix64}" = "x64" ]; then 427 target_arch_name=${grep64bit} 428 else 429 target_arch_name=${grep32bit} 430 fi 431} 432 433function guess_host_arch_name() { 434 if [ "x${suffix64}" = "x64" ]; then 435 host_arch_name="x86_64" 436 else 437 host_arch_name="x86" 438 fi 439} 440 441if [ "$target_mode" = "no" ]; then 442 if [ "$runtime" = "jvm" ]; then 443 if [ "$prebuild_mode" = "yes" ]; then 444 err_echo "--prebuild with --jvm is unsupported" 445 exit 1; 446 fi 447 fi 448fi 449 450if [ "$have_patchoat" = "no" ]; then 451 run_args="${run_args} --no-patchoat" 452fi 453 454if [ "$have_dex2oat" = "no" ]; then 455 run_args="${run_args} --no-dex2oat" 456fi 457 458if [ ! "$runtime" = "jvm" ]; then 459 run_args="${run_args} --lib $lib" 460fi 461 462if [ "$runtime" = "dalvik" ]; then 463 if [ "$target_mode" = "no" ]; then 464 framework="${ANDROID_PRODUCT_OUT}/system/framework" 465 bpath="${framework}/core-libart.jar:${framework}/core-oj.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/bouncycastle.jar:${framework}/ext.jar" 466 run_args="${run_args} --boot -Xbootclasspath:${bpath}" 467 else 468 true # defaults to using target BOOTCLASSPATH 469 fi 470elif [ "$runtime" = "art" ]; then 471 if [ "$target_mode" = "no" ]; then 472 # ANDROID_HOST_OUT is not set in a build environment. 473 if [ -z "$ANDROID_HOST_OUT" ]; then 474 export ANDROID_HOST_OUT=${OUT_DIR:-$ANDROID_BUILD_TOP/out/}host/linux-x86 475 fi 476 guess_host_arch_name 477 run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}${multi_image_suffix}.art" 478 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}" 479 else 480 guess_target_arch_name 481 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}" 482 run_args="${run_args} --boot /data/art-test/core${image_suffix}${pic_image_suffix}${multi_image_suffix}.art" 483 fi 484 if [ "$relocate" = "yes" ]; then 485 run_args="${run_args} --relocate" 486 else 487 run_args="${run_args} --no-relocate" 488 fi 489elif [ "$runtime" = "jvm" ]; then 490 # TODO: Detect whether the host is 32-bit or 64-bit. 491 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib64" 492fi 493 494if [ "$have_image" = "no" ]; then 495 if [ "$runtime" != "art" ]; then 496 err_echo "--no-image is only supported on the art runtime" 497 exit 1 498 fi 499 if [ "$target_mode" = "no" ]; then 500 framework="${ANDROID_HOST_OUT}/framework" 501 bpath_suffix="-hostdex" 502 else 503 framework="${android_root}/framework" 504 bpath_suffix="" 505 fi 506 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will 507 # fail since these jar files will be stripped. 508 bpath="${framework}/core-libart${bpath_suffix}.jar" 509 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar" 510 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar" 511 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar" 512 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar" 513 # Pass down the bootclasspath 514 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}" 515 run_args="${run_args} --no-image" 516fi 517 518if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then 519 err_echo "--dev and --update are mutually exclusive" 520 usage="yes" 521fi 522 523if [ "$dev_mode" = "yes" -a "$quiet" = "yes" ]; then 524 err_echo "--dev and --quiet are mutually exclusive" 525 usage="yes" 526fi 527 528if [ "$usage" = "no" ]; then 529 if [ "x$1" = "x" -o "x$1" = "x-" ]; then 530 test_dir=`basename "$oldwd"` 531 else 532 test_dir="$1" 533 fi 534 535 if [ '!' -d "$test_dir" ]; then 536 td2=`echo ${test_dir}-*` 537 if [ '!' -d "$td2" ]; then 538 err_echo "${test_dir}: no such test directory" 539 usage="yes" 540 fi 541 test_dir="$td2" 542 fi 543 # Shift to get rid of the test name argument. The rest of the arguments 544 # will get passed to the test run. 545 shift 546fi 547 548if [ "$usage" = "yes" ]; then 549 prog=`basename $prog` 550 ( 551 echo "usage:" 552 echo " $prog --help Print this message." 553 echo " $prog [options] [test-name] Run test normally." 554 echo " $prog --dev [options] [test-name] Development mode" \ 555 "(dumps to stdout)." 556 echo " $prog --update [options] [test-name] Update mode" \ 557 "(replaces expected.txt)." 558 echo ' Omitting the test name or specifying "-" will use the' \ 559 "current directory." 560 echo " Runtime Options:" 561 echo " -O Run non-debug rather than debug build (off by default)." 562 echo " -Xcompiler-option Pass an option to the compiler." 563 echo " --runtime-option Pass an option to the runtime." 564 echo " --debug Wait for a debugger to attach." 565 echo " --debuggable Whether to compile Java code for a debugger." 566 echo " --gdb Run under gdb; incompatible with some tests." 567 echo " --gdb-arg Pass an option to gdb." 568 echo " --build-only Build test files only (off by default)." 569 echo " --build-with-javac-dx Build test files with javac and dx (on by default)." 570 echo " --build-with-jack Build test files with jack and jill (off by default)." 571 echo " --interpreter Enable interpreter only mode (off by default)." 572 echo " --jit Enable jit (off by default)." 573 echo " --optimizing Enable optimizing compiler (default)." 574 echo " --quick Use Quick compiler (off by default)." 575 echo " --no-verify Turn off verification (on by default)." 576 echo " --verify-soft-fail Force soft fail verification (off by default)." 577 echo " Verification is enabled if neither --no-verify" 578 echo " nor --verify-soft-fail is specified." 579 echo " --no-optimize Turn off optimization (on by default)." 580 echo " --no-precise Turn off precise GC (on by default)." 581 echo " --zygote Spawn the process from the Zygote." \ 582 "If used, then the" 583 echo " other runtime options are ignored." 584 echo " --no-dex2oat Run as though dex2oat was failing." 585 echo " --no-patchoat Run as though patchoat was failing." 586 echo " --prebuild Run dex2oat on the files before starting test. (default)" 587 echo " --no-prebuild Do not run dex2oat on the files before starting" 588 echo " the test." 589 echo " --relocate Force the use of relocating in the test, making" 590 echo " the image and oat files be relocated to a random" 591 echo " address before running. (default)" 592 echo " --no-relocate Force the use of no relocating in the test" 593 echo " --image Run the test using a precompiled boot image. (default)" 594 echo " --no-image Run the test without a precompiled boot image." 595 echo " --host Use the host-mode virtual machine." 596 echo " --invoke-with Pass --invoke-with option to runtime." 597 echo " --dalvik Use Dalvik (off by default)." 598 echo " --jvm Use a host-local RI virtual machine." 599 echo " --use-java-home Use the JAVA_HOME environment variable" 600 echo " to find the java compiler and runtime" 601 echo " (if applicable) to run the test with." 602 echo " --output-path [path] Location where to store the build" \ 603 "files." 604 echo " --64 Run the test in 64-bit mode" 605 echo " --trace Run with method tracing" 606 echo " --strace Run with syscall tracing from strace." 607 echo " --stream Run method tracing in streaming mode (requires --trace)" 608 echo " --gcstress Run with gc stress testing" 609 echo " --gcverify Run with gc verification" 610 echo " --always-clean Delete the test files even if the test fails." 611 echo " --never-clean Keep the test files even if the test succeeds." 612 echo " --android-root [path] The path on target for the android root. (/system by default)." 613 echo " --dex2oat-swap Use a dex2oat swap file." 614 echo " --instruction-set-features [string]" 615 echo " Set instruction-set-features for compilation." 616 echo " --pic-image Use an image compiled with position independent code for the" 617 echo " boot class path." 618 echo " --multi-image Use a set of images compiled with dex2oat multi-image for" 619 echo " the boot class path." 620 echo " --pic-test Compile the test code position independent." 621 echo " --quiet Don't print anything except failure messages" 622 ) 1>&2 # Direct to stderr so usage is not printed if --quiet is set. 623 exit 1 624fi 625 626cd "$test_dir" 627test_dir=`pwd` 628 629td_info="${test_dir}/${info}" 630td_expected="${test_dir}/${expected}" 631 632if [ ! -r $td_info ]; then 633 err_echo "${test_dir}: missing file $td_info" 634 exit 1 635fi 636 637if [ ! -r $td_expected ]; then 638 err_echo "${test_dir}: missing file $td_expected" 639 exit 1 640fi 641 642# copy the test to a temp dir and run it 643 644echo "${test_dir}: building..." 1>&2 645 646rm -rf "$tmp_dir" 647cp -Rp "$test_dir" "$tmp_dir" 648cd "$tmp_dir" 649 650if [ '!' -r "$build" ]; then 651 cp "${progdir}/etc/default-build" build 652else 653 cp "${progdir}/etc/default-build" . 654fi 655 656if [ '!' -r "$run" ]; then 657 cp "${progdir}/etc/default-run" run 658else 659 cp "${progdir}/etc/default-run" . 660fi 661 662if [ '!' -r "$check_cmd" ]; then 663 cp "${progdir}/etc/default-check" check 664else 665 cp "${progdir}/etc/default-check" . 666fi 667 668chmod 755 "$build" 669chmod 755 "$run" 670chmod 755 "$check_cmd" 671 672export TEST_NAME=`basename ${test_dir}` 673 674# arch_supports_read_barrier ARCH 675# ------------------------------- 676# Return whether the Optimizing compiler has read barrier support for ARCH. 677function arch_supports_read_barrier() { 678 # Optimizing has read barrier support for ARM, ARM64, x86 and x86-64 at the 679 # moment. 680 [ "x$1" = xarm ] || [ "x$1" = xarm64 ] || [ "x$1" = xx86 ] || [ "x$1" = xx86_64 ] 681} 682 683# Tests named '<number>-checker-*' will also have their CFGs verified with 684# Checker when compiled with Optimizing on host. 685if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then 686 # Jack does not necessarily generate the same DEX output than dx. Because these tests depend 687 # on a particular DEX output, keep building them with dx for now (b/19467889). 688 USE_JACK="false" 689 690 if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" ]; then 691 # Optimizing has read barrier support for certain architectures 692 # only. On other architectures, compiling is disabled when read 693 # barriers are enabled, meaning that we do not produce a CFG file 694 # as a side-effect of compilation, thus the Checker assertions 695 # cannot be checked. Disable Checker for those cases. 696 # 697 # TODO: Enable Checker when read barrier support is added to more 698 # architectures (b/12687968). 699 if [ "x$ART_USE_READ_BARRIER" = xtrue ] \ 700 && (([ "x$host_mode" = "xyes" ] \ 701 && ! arch_supports_read_barrier "$host_arch_name") \ 702 || ([ "x$target_mode" = "xyes" ] \ 703 && ! arch_supports_read_barrier "$target_arch_name")); then 704 run_checker="no" 705 # In no-prebuild mode, the compiler is only invoked if both dex2oat and 706 # patchoat are available. Disable Checker otherwise (b/22552692). 707 elif [ "$prebuild_mode" = "yes" ] \ 708 || [ "$have_patchoat" = "yes" -a "$have_dex2oat" = "yes" ]; then 709 run_checker="yes" 710 711 if [ "$target_mode" = "no" ]; then 712 cfg_output_dir="$tmp_dir" 713 checker_args="--arch=${host_arch_name^^}" 714 else 715 cfg_output_dir="$DEX_LOCATION" 716 checker_args="--arch=${target_arch_name^^}" 717 fi 718 719 if [ "$debuggable" = "yes" ]; then 720 checker_args="$checker_args --debuggable" 721 fi 722 723 run_args="${run_args} -Xcompiler-option --dump-cfg=$cfg_output_dir/$cfg_output \ 724 -Xcompiler-option -j1" 725 fi 726 fi 727fi 728 729if [ "$runtime" != "jvm" ]; then 730 run_args="${run_args} --testlib ${testlib}" 731fi 732 733# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB. 734build_file_size_limit=2048 735run_file_size_limit=2048 736if echo "$test_dir" | grep -Eq "(083|089|964)" > /dev/null; then 737 build_file_size_limit=5120 738 run_file_size_limit=5120 739fi 740if [ "$run_checker" = "yes" -a "$target_mode" = "yes" ]; then 741 # We will need to `adb pull` the .cfg output from the target onto the host to 742 # run checker on it. This file can be big. 743 build_file_size_limit=24576 744 run_file_size_limit=24576 745fi 746if [ ${USE_JACK} = "false" ]; then 747 # Set ulimit if we build with dx only, Jack can generate big temp files. 748 if ! ulimit -S "$build_file_size_limit"; then 749 err_echo "ulimit file size setting failed" 750 fi 751fi 752 753good="no" 754good_build="yes" 755good_run="yes" 756if [ "$dev_mode" = "yes" ]; then 757 "./${build}" $build_args 2>&1 758 build_exit="$?" 759 echo "build exit status: $build_exit" 1>&2 760 if [ "$build_exit" = '0' ]; then 761 if ! ulimit -S "$run_file_size_limit"; then 762 err_echo "ulimit file size setting failed" 763 fi 764 echo "${test_dir}: running..." 1>&2 765 "./${run}" $run_args "$@" 2>&1 766 run_exit="$?" 767 768 if [ "$run_exit" = "0" ]; then 769 if [ "$run_checker" = "yes" ]; then 770 if [ "$target_mode" = "yes" ]; then 771 adb pull $cfg_output_dir/$cfg_output &> /dev/null 772 fi 773 "$checker" $checker_args "$cfg_output" "$tmp_dir" 2>&1 774 checker_exit="$?" 775 if [ "$checker_exit" = "0" ]; then 776 good="yes" 777 fi 778 err_echo "checker exit status: $checker_exit" 779 else 780 good="yes" 781 fi 782 fi 783 echo "run exit status: $run_exit" 1>&2 784 fi 785elif [ "$update_mode" = "yes" ]; then 786 "./${build}" $build_args >"$build_output" 2>&1 787 build_exit="$?" 788 if [ "$build_exit" = '0' ]; then 789 if ! ulimit -S "$run_file_size_limit"; then 790 err_echo "ulimit file size setting failed" 791 fi 792 echo "${test_dir}: running..." 1>&2 793 "./${run}" $run_args "$@" >"$output" 2>&1 794 if [ "$run_checker" = "yes" ]; then 795 if [ "$target_mode" = "yes" ]; then 796 adb pull $cfg_output_dir/$cfg_output &> /dev/null 797 fi 798 "$checker" -q $checker_args "$cfg_output" "$tmp_dir" >> "$output" 2>&1 799 fi 800 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}" 801 good="yes" 802 else 803 cat "$build_output" 1>&${real_stderr} 1>&2 804 err_echo "build exit status: $build_exit" 805 fi 806elif [ "$build_only" = "yes" ]; then 807 good="yes" 808 "./${build}" $build_args >"$build_output" 2>&1 809 build_exit="$?" 810 if [ "$build_exit" '!=' '0' ]; then 811 cp "$build_output" "$output" 812 echo "build exit status: $build_exit" >>"$output" 813 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null 814 if [ "$?" '!=' "0" ]; then 815 good="no" 816 err_echo "BUILD FAILED For ${TEST_NAME}" 817 fi 818 fi 819 # Clean up extraneous files that are not used by tests. 820 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf 821 exit 0 822else 823 "./${build}" $build_args >"$build_output" 2>&1 824 build_exit="$?" 825 if [ "$build_exit" = '0' ]; then 826 if ! ulimit -S "$run_file_size_limit"; then 827 err_echo "ulimit file size setting failed" 828 fi 829 echo "${test_dir}: running..." 1>&2 830 "./${run}" $run_args "$@" >"$output" 2>&1 831 run_exit="$?" 832 if [ "$run_exit" != "0" ]; then 833 err_echo "run exit status: $run_exit" 834 good_run="no" 835 elif [ "$run_checker" = "yes" ]; then 836 if [ "$target_mode" = "yes" ]; then 837 adb pull $cfg_output_dir/$cfg_output &> /dev/null 838 fi 839 "$checker" -q $checker_args "$cfg_output" "$tmp_dir" >> "$output" 2>&1 840 checker_exit="$?" 841 if [ "$checker_exit" != "0" ]; then 842 err_echo "checker exit status: $checker_exit" 843 good_run="no" 844 else 845 good_run="yes" 846 fi 847 else 848 good_run="yes" 849 fi 850 else 851 good_build="no" 852 cp "$build_output" "$output" 853 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output" 854 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output" 855 echo "Args: ${args}" >> "$output" 856 echo "build exit status: $build_exit" >> "$output" 857 max_name_length=$(getconf NAME_MAX ${tmp_dir}) 858 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output" 859 max_path_length=$(getconf PATH_MAX ${tmp_dir}) 860 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output" 861 fi 862 ./$check_cmd "$expected" "$output" 863 if [ "$?" = "0" ]; then 864 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then 865 # output == expected 866 good="yes" 867 echo "${test_dir}: succeeded!" 1>&2 868 fi 869 fi 870fi 871 872( 873 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then 874 echo "${test_dir}: FAILED!" 875 echo ' ' 876 echo '#################### info' 877 cat "${td_info}" | sed 's/^/# /g' 878 echo '#################### diffs' 879 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 3000 880 echo '####################' 881 if [ "$strace" = "yes" ]; then 882 echo '#################### strace output' 883 tail -n 3000 "$tmp_dir/$strace_output" 884 echo '####################' 885 fi 886 echo ' ' 887 fi 888 889) 2>&${real_stderr} 1>&2 890 891# Clean up test files. 892if [ "$always_clean" = "yes" -o "$good" = "yes" ] && [ "$never_clean" = "no" ]; then 893 cd "$oldwd" 894 rm -rf "$tmp_dir" 895 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then 896 adb shell rm -rf $DEX_LOCATION 897 fi 898 if [ "$good" = "yes" ]; then 899 exit 0 900 fi 901fi 902 903 904( 905 if [ "$always_clean" = "yes" ]; then 906 echo "${TEST_NAME} files deleted from host " 907 if [ "$target_mode" == "yes" ]; then 908 echo "and from target" 909 fi 910 else 911 echo "${TEST_NAME} files left in ${tmp_dir} on host" 912 if [ "$target_mode" == "yes" ]; then 913 echo "and in ${DEX_LOCATION} on target" 914 fi 915 fi 916 917) 2>&${real_stderr} 1>&2 918 919exit 1 920