Home | History | Annotate | Download | only in test
      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.
     19 prog="$0"
     20 args="$@"
     21 while [ -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
     30 done
     31 oldwd=`pwd`
     32 progdir=`dirname "${prog}"`
     33 cd "${progdir}"
     34 progdir=`pwd`
     35 prog="${progdir}"/`basename "${prog}"`
     36 test_dir="test-$$"
     37 if [ -z "$TMPDIR" ]; then
     38   tmp_dir="/tmp/$USER/${test_dir}"
     39 else
     40   tmp_dir="${TMPDIR}/$USER/${test_dir}"
     41 fi
     42 checker="${progdir}/../tools/checker.py"
     43 
     44 export JAVA="java"
     45 export JAVAC="javac -g"
     46 export RUN="${progdir}/etc/run-test-jar"
     47 export DEX_LOCATION=/data/run-test/${test_dir}
     48 export NEED_DEX="true"
     49 export USE_JACK="false"
     50 
     51 # If dx was not set by the environment variable, assume it is in the path.
     52 if [ -z "$DX" ]; then
     53   export DX="dx"
     54 fi
     55 
     56 # If jasmin was not set by the environment variable, assume it is in the path.
     57 if [ -z "$JASMIN" ]; then
     58   export JASMIN="jasmin"
     59 fi
     60 
     61 # If smali was not set by the environment variable, assume it is in the path.
     62 if [ -z "$SMALI" ]; then
     63   export SMALI="smali"
     64 fi
     65 
     66 # If dexmerger was not set by the environment variable, assume it is in the path.
     67 if [ -z "$DXMERGER" ]; then
     68   export DXMERGER="dexmerger"
     69 fi
     70 
     71 # If jack was not set by the environment variable, assume it is in the path.
     72 if [ -z "$JACK" ]; then
     73   export JACK="jack"
     74 fi
     75 
     76 # If the tree is compiled with Jack, build test with Jack by default.
     77 if [ "$ANDROID_COMPILE_WITH_JACK" = "true" ]; then
     78   USE_JACK="true"
     79 fi
     80 
     81 # ANDROID_BUILD_TOP is not set in a build environment.
     82 if [ -z "$ANDROID_BUILD_TOP" ]; then
     83     export ANDROID_BUILD_TOP=$oldwd
     84 fi
     85 
     86 # If JACK_VM_COMMAND is not set, assume it launches the prebuilt jack-launcher.
     87 if [ -z "$JACK_VM_COMMAND" ]; then
     88   if [ ! -z "$TMPDIR" ]; then
     89     jack_temp_dir="-Djava.io.tmpdir=$TMPDIR"
     90   fi
     91   export JACK_VM_COMMAND="java -Dfile.encoding=UTF-8 -Xms2560m -XX:+TieredCompilation $jack_temp_dir -jar $ANDROID_BUILD_TOP/prebuilts/sdk/tools/jack-launcher.jar"
     92 fi
     93 
     94 # If JACK_CLASSPATH is not set, assume it only contains core-libart.
     95 if [ -z "$JACK_CLASSPATH" ]; then
     96   export JACK_CLASSPATH="$ANDROID_BUILD_TOP/out/host/common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack"
     97 fi
     98 
     99 # If JACK_JAR is not set, assume it is located in the prebuilts directory.
    100 if [ -z "$JACK_JAR" ]; then
    101   export JACK_JAR="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/jack.jar"
    102 fi
    103 
    104 # If JILL_JAR is not set, assume it is located in the prebuilts directory.
    105 if [ -z "$JILL_JAR" ]; then
    106   export JILL_JAR="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/jill.jar"
    107 fi
    108 
    109 export JACK="$JACK -g -cp $JACK_CLASSPATH"
    110 export JILL="java -jar $JILL_JAR"
    111 
    112 info="info.txt"
    113 build="build"
    114 run="run"
    115 expected="expected.txt"
    116 check_cmd="check"
    117 output="output.txt"
    118 build_output="build-output.txt"
    119 cfg_output="cfg-output.txt"
    120 lib="libartd.so"
    121 run_args="--quiet"
    122 build_args=""
    123 
    124 debuggable="no"
    125 prebuild_mode="yes"
    126 target_mode="yes"
    127 dev_mode="no"
    128 update_mode="no"
    129 debug_mode="no"
    130 relocate="yes"
    131 runtime="art"
    132 usage="no"
    133 build_only="no"
    134 suffix64=""
    135 trace="false"
    136 trace_stream="false"
    137 basic_verify="false"
    138 gc_verify="false"
    139 gc_stress="false"
    140 always_clean="no"
    141 have_dex2oat="yes"
    142 have_patchoat="yes"
    143 have_image="yes"
    144 image_suffix=""
    145 pic_image_suffix=""
    146 android_root="/system"
    147 
    148 while true; do
    149     if [ "x$1" = "x--host" ]; then
    150         target_mode="no"
    151         DEX_LOCATION=$tmp_dir
    152         run_args="${run_args} --host"
    153         shift
    154     elif [ "x$1" = "x--jvm" ]; then
    155         target_mode="no"
    156         runtime="jvm"
    157         prebuild_mode="no"
    158         NEED_DEX="false"
    159         USE_JACK="false"
    160         run_args="${run_args} --jvm"
    161         shift
    162     elif [ "x$1" = "x-O" ]; then
    163         lib="libart.so"
    164         shift
    165     elif [ "x$1" = "x--dalvik" ]; then
    166         lib="libdvm.so"
    167         runtime="dalvik"
    168         shift
    169     elif [ "x$1" = "x--no-dex2oat" ]; then
    170         have_dex2oat="no"
    171         shift
    172     elif [ "x$1" = "x--no-patchoat" ]; then
    173         have_patchoat="no"
    174         shift
    175     elif [ "x$1" = "x--no-image" ]; then
    176         have_image="no"
    177         shift
    178     elif [ "x$1" = "x--pic-image" ]; then
    179         pic_image_suffix="-pic"
    180         shift
    181     elif [ "x$1" = "x--pic-test" ]; then
    182         run_args="${run_args} --pic-test"
    183         shift
    184     elif [ "x$1" = "x--relocate" ]; then
    185         relocate="yes"
    186         shift
    187     elif [ "x$1" = "x--no-relocate" ]; then
    188         relocate="no"
    189         shift
    190     elif [ "x$1" = "x--prebuild" ]; then
    191         run_args="${run_args} --prebuild"
    192         prebuild_mode="yes"
    193         shift;
    194     elif [ "x$1" = "x--debuggable" ]; then
    195         run_args="${run_args} -Xcompiler-option --debuggable"
    196         debuggable="yes"
    197         shift;
    198     elif [ "x$1" = "x--no-prebuild" ]; then
    199         run_args="${run_args} --no-prebuild"
    200         prebuild_mode="no"
    201         shift;
    202     elif [ "x$1" = "x--gcverify" ]; then
    203         basic_verify="true"
    204         gc_verify="true"
    205         shift
    206     elif [ "x$1" = "x--gcstress" ]; then
    207         basic_verify="true"
    208         gc_stress="true"
    209         shift
    210     elif [ "x$1" = "x--image" ]; then
    211         shift
    212         image="$1"
    213         run_args="${run_args} --image $image"
    214         shift
    215     elif [ "x$1" = "x-Xcompiler-option" ]; then
    216         shift
    217         option="$1"
    218         run_args="${run_args} -Xcompiler-option $option"
    219         shift
    220     elif [ "x$1" = "x--runtime-option" ]; then
    221         shift
    222         option="$1"
    223         run_args="${run_args} --runtime-option $option"
    224         shift
    225     elif [ "x$1" = "x--gdb-arg" ]; then
    226         shift
    227         gdb_arg="$1"
    228         run_args="${run_args} --gdb-arg $gdb_arg"
    229         shift
    230     elif [ "x$1" = "x--debug" ]; then
    231         run_args="${run_args} --debug"
    232         shift
    233     elif [ "x$1" = "x--gdb" ]; then
    234         run_args="${run_args} --gdb"
    235         dev_mode="yes"
    236         shift
    237     elif [ "x$1" = "x--zygote" ]; then
    238         run_args="${run_args} --zygote"
    239         shift
    240     elif [ "x$1" = "x--interpreter" ]; then
    241         run_args="${run_args} --interpreter"
    242         image_suffix="-interpreter"
    243         shift
    244     elif [ "x$1" = "x--jit" ]; then
    245         run_args="${run_args} --jit"
    246         image_suffix="-interpreter"
    247         shift
    248     elif [ "x$1" = "x--optimizing" ]; then
    249         run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
    250         image_suffix="-optimizing"
    251         shift
    252     elif [ "x$1" = "x--quick" ]; then
    253         run_args="${run_args} -Xcompiler-option --compiler-backend=Quick"
    254         shift
    255     elif [ "x$1" = "x--no-verify" ]; then
    256         run_args="${run_args} --no-verify"
    257         shift
    258     elif [ "x$1" = "x--no-optimize" ]; then
    259         run_args="${run_args} --no-optimize"
    260         shift
    261     elif [ "x$1" = "x--no-precise" ]; then
    262         run_args="${run_args} --no-precise"
    263         shift
    264     elif [ "x$1" = "x--invoke-with" ]; then
    265         shift
    266         what="$1"
    267         if [ "x$what" = "x" ]; then
    268             echo "$0 missing argument to --invoke-with" 1>&2
    269             usage="yes"
    270             break
    271         fi
    272         run_args="${run_args} --invoke-with ${what}"
    273         shift
    274     elif [ "x$1" = "x--dev" ]; then
    275         run_args="${run_args} --dev"
    276         dev_mode="yes"
    277         shift
    278     elif [ "x$1" = "x--build-only" ]; then
    279         build_only="yes"
    280         shift
    281     elif [ "x$1" = "x--build-with-javac-dx" ]; then
    282         USE_JACK="false"
    283         shift
    284     elif [ "x$1" = "x--build-with-jack" ]; then
    285         USE_JACK="true"
    286         shift
    287     elif [ "x$1" = "x--output-path" ]; then
    288         shift
    289         tmp_dir=$1
    290         if [ "x$tmp_dir" = "x" ]; then
    291             echo "$0 missing argument to --output-path" 1>&2
    292             usage="yes"
    293             break
    294         fi
    295         shift
    296     elif [ "x$1" = "x--android-root" ]; then
    297         shift
    298         if [ "x$1" = "x" ]; then
    299             echo "$0 missing argument to --android-root" 1>&2
    300             usage="yes"
    301             break
    302         fi
    303         android_root="$1"
    304         run_args="${run_args} --android-root $1"
    305         shift
    306     elif [ "x$1" = "x--update" ]; then
    307         update_mode="yes"
    308         shift
    309     elif [ "x$1" = "x--help" ]; then
    310         usage="yes"
    311         shift
    312     elif [ "x$1" = "x--64" ]; then
    313         run_args="${run_args} --64"
    314         suffix64="64"
    315         shift
    316     elif [ "x$1" = "x--trace" ]; then
    317         trace="true"
    318         shift
    319     elif [ "x$1" = "x--stream" ]; then
    320         trace_stream="true"
    321         shift
    322     elif [ "x$1" = "x--always-clean" ]; then
    323         always_clean="yes"
    324         shift
    325     elif [ "x$1" = "x--dex2oat-swap" ]; then
    326         run_args="${run_args} --dex2oat-swap"
    327         shift
    328     elif expr "x$1" : "x--" >/dev/null 2>&1; then
    329         echo "unknown $0 option: $1" 1>&2
    330         usage="yes"
    331         break
    332     else
    333         break
    334     fi
    335 done
    336 
    337 # tmp_dir may be relative, resolve.
    338 #
    339 # Cannot use realpath, as it does not exist on Mac.
    340 # Cannot us a simple "cd", as the path might not be created yet.
    341 # Cannot use readlink -m, as it does not exist on Mac.
    342 # Fallback to nuclear option:
    343 noncanonical_tmp_dir=$tmp_dir
    344 tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
    345 mkdir -p $tmp_dir
    346 
    347 if [ "$basic_verify" = "true" ]; then
    348   # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests.
    349   run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0"
    350 fi
    351 if [ "$gc_verify" = "true" ]; then
    352   run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
    353 fi
    354 if [ "$gc_stress" = "true" ]; then
    355   run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
    356 fi
    357 if [ "$trace" = "true" ]; then
    358     run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file-size:2000000"
    359     if [ "$trace_stream" = "true" ]; then
    360         # Streaming mode uses the file size as the buffer size. So output gets really large. Drop
    361         # the ability to analyze the file and just write to /dev/null.
    362         run_args="${run_args} --runtime-option -Xmethod-trace-file:/dev/null"
    363         # Enable streaming mode.
    364         run_args="${run_args} --runtime-option -Xmethod-trace-stream"
    365     else
    366         run_args="${run_args} --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin"
    367     fi
    368 elif [ "$trace_stream" = "true" ]; then
    369     echo "Cannot use --stream without --trace."
    370     exit 1
    371 fi
    372 
    373 # Most interesting target architecture variables are Makefile variables, not environment variables.
    374 # Try to map the suffix64 flag and what we find in ${ANDROID_PRODUCT_OUT}/data/art-test to an architecture name.
    375 function guess_arch_name() {
    376     grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
    377     grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64|mips64)$'`
    378     if [ "x${suffix64}" = "x64" ]; then
    379         target_arch_name=${grep64bit}
    380     else
    381         target_arch_name=${grep32bit}
    382     fi
    383 }
    384 
    385 if [ "$target_mode" = "no" ]; then
    386     if [ "$runtime" = "jvm" ]; then
    387         if [ "$prebuild_mode" = "yes" ]; then
    388             echo "--prebuild with --jvm is unsupported";
    389             exit 1;
    390         fi
    391     fi
    392 fi
    393 
    394 if [ "$have_patchoat" = "no" ]; then
    395   run_args="${run_args} --no-patchoat"
    396 fi
    397 
    398 if [ "$have_dex2oat" = "no" ]; then
    399   run_args="${run_args} --no-dex2oat"
    400 fi
    401 
    402 if [ ! "$runtime" = "jvm" ]; then
    403   run_args="${run_args} --lib $lib"
    404 fi
    405 
    406 if [ "$runtime" = "dalvik" ]; then
    407     if [ "$target_mode" = "no" ]; then
    408         framework="${ANDROID_PRODUCT_OUT}/system/framework"
    409         bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
    410         run_args="${run_args} --boot -Xbootclasspath:${bpath}"
    411     else
    412         true # defaults to using target BOOTCLASSPATH
    413     fi
    414 elif [ "$runtime" = "art" ]; then
    415     if [ "$target_mode" = "no" ]; then
    416         # ANDROID_HOST_OUT is not set in a build environment.
    417         if [ -z "$ANDROID_HOST_OUT" ]; then
    418             export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
    419         fi
    420         run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}.art"
    421         run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
    422     else
    423         guess_arch_name
    424         run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
    425         run_args="${run_args} --boot /data/art-test/core${image_suffix}${pic_image_suffix}.art"
    426     fi
    427     if [ "$relocate" = "yes" ]; then
    428       run_args="${run_args} --relocate"
    429     else
    430       run_args="${run_args} --no-relocate"
    431     fi
    432 elif [ "$runtime" = "jvm" ]; then
    433     # TODO: Detect whether the host is 32-bit or 64-bit.
    434     run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib64"
    435 fi
    436 
    437 if [ "$have_image" = "no" ]; then
    438     if [ "$runtime" != "art" ]; then
    439         echo "--no-image is only supported on the art runtime"
    440         exit 1
    441     fi
    442     if [ "$target_mode" = "no" ]; then
    443         framework="${ANDROID_HOST_OUT}/framework"
    444         bpath_suffix="-hostdex"
    445     else
    446         framework="${android_root}/framework"
    447         bpath_suffix=""
    448     fi
    449     # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
    450     # fail since these jar files will be stripped.
    451     bpath="${framework}/core-libart${bpath_suffix}.jar"
    452     bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
    453     bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
    454     bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
    455     bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
    456     # Pass down the bootclasspath
    457     run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
    458     run_args="${run_args} --no-image"
    459 fi
    460 
    461 if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
    462     echo "--dev and --update are mutually exclusive" 1>&2
    463     usage="yes"
    464 fi
    465 
    466 if [ "$usage" = "no" ]; then
    467     if [ "x$1" = "x" -o "x$1" = "x-" ]; then
    468         test_dir=`basename "$oldwd"`
    469     else
    470         test_dir="$1"
    471     fi
    472 
    473     if [ '!' -d "$test_dir" ]; then
    474         td2=`echo ${test_dir}-*`
    475         if [ '!' -d "$td2" ]; then
    476             echo "${test_dir}: no such test directory" 1>&2
    477             usage="yes"
    478         fi
    479         test_dir="$td2"
    480     fi
    481     # Shift to get rid of the test name argument. The rest of the arguments
    482     # will get passed to the test run.
    483     shift
    484 fi
    485 
    486 if [ "$usage" = "yes" ]; then
    487     prog=`basename $prog`
    488     (
    489         echo "usage:"
    490         echo "  $prog --help                          Print this message."
    491         echo "  $prog [options] [test-name]           Run test normally."
    492         echo "  $prog --dev [options] [test-name]     Development mode" \
    493              "(dumps to stdout)."
    494         echo "  $prog --update [options] [test-name]  Update mode" \
    495              "(replaces expected.txt)."
    496         echo '  Omitting the test name or specifying "-" will use the' \
    497              "current directory."
    498         echo "  Runtime Options:"
    499         echo "    -O                    Run non-debug rather than debug build (off by default)."
    500         echo "    -Xcompiler-option     Pass an option to the compiler."
    501         echo "    --runtime-option      Pass an option to the runtime."
    502         echo "    --debug               Wait for a debugger to attach."
    503         echo "    --debuggable          Whether to compile Java code for a debugger."
    504         echo "    --gdb                 Run under gdb; incompatible with some tests."
    505         echo "    --build-only          Build test files only (off by default)."
    506         echo "    --build-with-javac-dx Build test files with javac and dx (on by default)."
    507         echo "    --build-with-jack     Build test files with jack and jill (off by default)."
    508         echo "    --interpreter         Enable interpreter only mode (off by default)."
    509         echo "    --jit                 Enable jit (off by default)."
    510         echo "    --optimizing          Enable optimizing compiler (default)."
    511         echo "    --quick               Use Quick compiler (off by default)."
    512         echo "    --no-verify           Turn off verification (on by default)."
    513         echo "    --no-optimize         Turn off optimization (on by default)."
    514         echo "    --no-precise          Turn off precise GC (on by default)."
    515         echo "    --zygote              Spawn the process from the Zygote." \
    516              "If used, then the"
    517         echo "                          other runtime options are ignored."
    518         echo "    --no-dex2oat          Run as though dex2oat was failing."
    519         echo "    --no-patchoat         Run as though patchoat was failing."
    520         echo "    --prebuild            Run dex2oat on the files before starting test. (default)"
    521         echo "    --no-prebuild         Do not run dex2oat on the files before starting"
    522         echo "                          the test."
    523         echo "    --relocate            Force the use of relocating in the test, making"
    524         echo "                          the image and oat files be relocated to a random"
    525         echo "                          address before running. (default)"
    526         echo "    --no-relocate         Force the use of no relocating in the test"
    527         echo "    --host                Use the host-mode virtual machine."
    528         echo "    --invoke-with         Pass --invoke-with option to runtime."
    529         echo "    --dalvik              Use Dalvik (off by default)."
    530         echo "    --jvm                 Use a host-local RI virtual machine."
    531         echo "    --output-path [path]  Location where to store the build" \
    532              "files."
    533         echo "    --64                  Run the test in 64-bit mode"
    534         echo "    --trace               Run with method tracing"
    535         echo "    --stream              Run method tracing in streaming mode (requires --trace)"
    536         echo "    --gcstress            Run with gc stress testing"
    537         echo "    --gcverify            Run with gc verification"
    538         echo "    --always-clean        Delete the test files even if the test fails."
    539         echo "    --android-root [path] The path on target for the android root. (/system by default)."
    540         echo "    --dex2oat-swap        Use a dex2oat swap file."
    541     ) 1>&2
    542     exit 1
    543 fi
    544 
    545 cd "$test_dir"
    546 test_dir=`pwd`
    547 
    548 td_info="${test_dir}/${info}"
    549 td_expected="${test_dir}/${expected}"
    550 
    551 if [ ! -r $td_info ]; then
    552     echo "${test_dir}: missing file $td_info" 1>&2
    553     exit 1
    554 fi
    555 
    556 if [ ! -r $td_expected ]; then
    557     echo "${test_dir}: missing file $td_expected" 1>&2
    558     exit 1
    559 fi
    560 
    561 # copy the test to a temp dir and run it
    562 
    563 echo "${test_dir}: building..." 1>&2
    564 
    565 rm -rf "$tmp_dir"
    566 cp -Rp "$test_dir" "$tmp_dir"
    567 cd "$tmp_dir"
    568 
    569 if [ '!' -r "$build" ]; then
    570     cp "${progdir}/etc/default-build" build
    571 fi
    572 
    573 if [ '!' -r "$run" ]; then
    574     cp "${progdir}/etc/default-run" run
    575 fi
    576 
    577 if [ '!' -r "$check_cmd" ]; then
    578     cp "${progdir}/etc/default-check" check
    579 fi
    580 
    581 chmod 755 "$build"
    582 chmod 755 "$run"
    583 chmod 755 "$check_cmd"
    584 
    585 export TEST_NAME=`basename ${test_dir}`
    586 
    587 # Tests named '<number>-checker-*' will also have their CFGs verified with
    588 # Checker when compiled with Optimizing on host.
    589 if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
    590   # Build Checker DEX files without dx's optimizations so the input to dex2oat
    591   # better resembles the Java source. We always build the DEX the same way, even
    592   # if Checker is not invoked and the test only runs the program.
    593   build_args="${build_args} --dx-option --no-optimize"
    594 
    595   # Jack does not necessarily generate the same DEX output than dx. Because these tests depend
    596   # on a particular DEX output, keep building them with dx for now (b/19467889).
    597   USE_JACK="false"
    598 
    599   if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$target_mode" = "no" -a "$debuggable" = "no" ]; then
    600     run_checker="yes"
    601     run_args="${run_args} -Xcompiler-option --dump-cfg=$tmp_dir/$cfg_output \
    602                           -Xcompiler-option -j1"
    603   fi
    604 fi
    605 
    606 # To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
    607 build_file_size_limit=2048
    608 run_file_size_limit=2048
    609 if echo "$test_dir" | grep 089; then
    610   build_file_size_limit=5120
    611   run_file_size_limit=5120
    612 elif echo "$test_dir" | grep 083; then
    613   build_file_size_limit=5120
    614   run_file_size_limit=5120
    615 fi
    616 if [ ${USE_JACK} = "false" ]; then
    617   # Set ulimit if we build with dx only, Jack can generate big temp files.
    618   if ! ulimit -S "$build_file_size_limit"; then
    619     echo "ulimit file size setting failed"
    620   fi
    621 fi
    622 
    623 good="no"
    624 good_build="yes"
    625 good_run="yes"
    626 if [ "$dev_mode" = "yes" ]; then
    627     "./${build}" $build_args 2>&1
    628     build_exit="$?"
    629     echo "build exit status: $build_exit" 1>&2
    630     if [ "$build_exit" = '0' ]; then
    631         if ! ulimit -S "$run_file_size_limit"; then
    632           echo "ulimit file size setting failed"
    633         fi
    634         echo "${test_dir}: running..." 1>&2
    635         "./${run}" $run_args "$@" 2>&1
    636         run_exit="$?"
    637 
    638         if [ "$run_exit" = "0" ]; then
    639             if [ "$run_checker" = "yes" ]; then
    640                 "$checker" "$cfg_output" "$tmp_dir" 2>&1
    641                 checker_exit="$?"
    642                 if [ "$checker_exit" = "0" ]; then
    643                     good="yes"
    644                 fi
    645                 echo "checker exit status: $checker_exit" 1>&2
    646             else
    647                 good="yes"
    648             fi
    649         fi
    650         echo "run exit status: $run_exit" 1>&2
    651     fi
    652 elif [ "$update_mode" = "yes" ]; then
    653     "./${build}" $build_args >"$build_output" 2>&1
    654     build_exit="$?"
    655     if [ "$build_exit" = '0' ]; then
    656         if ! ulimit -S "$run_file_size_limit"; then
    657           echo "ulimit file size setting failed"
    658         fi
    659         echo "${test_dir}: running..." 1>&2
    660         "./${run}" $run_args "$@" >"$output" 2>&1
    661         if [ "$run_checker" = "yes" ]; then
    662           "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
    663         fi
    664         sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
    665         good="yes"
    666     else
    667         cat "$build_output" 1>&2
    668         echo "build exit status: $build_exit" 1>&2
    669     fi
    670 elif [ "$build_only" = "yes" ]; then
    671     good="yes"
    672     "./${build}" $build_args >"$build_output" 2>&1
    673     build_exit="$?"
    674     if [ "$build_exit" '!=' '0' ]; then
    675         cp "$build_output" "$output"
    676         echo "build exit status: $build_exit" >>"$output"
    677         diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
    678         if [ "$?" '!=' "0" ]; then
    679             good="no"
    680             echo "BUILD FAILED For ${TEST_NAME}"
    681         fi
    682     fi
    683     # Clean up extraneous files that are not used by tests.
    684     find $tmp_dir -mindepth 1  ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
    685     exit 0
    686 else
    687     "./${build}" $build_args >"$build_output" 2>&1
    688     build_exit="$?"
    689     if [ "$build_exit" = '0' ]; then
    690         if ! ulimit -S "$run_file_size_limit"; then
    691           echo "ulimit file size setting failed"
    692         fi
    693         echo "${test_dir}: running..." 1>&2
    694         "./${run}" $run_args "$@" >"$output" 2>&1
    695         run_exit="$?"
    696         if [ "$run_exit" != "0" ]; then
    697             echo "run exit status: $run_exit" 1>&2
    698             good_run="no"
    699         elif [ "$run_checker" = "yes" ]; then
    700             "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
    701             checker_exit="$?"
    702             if [ "$checker_exit" != "0" ]; then
    703                 echo "checker exit status: $checker_exit" 1>&2
    704                 good_run="no"
    705             else
    706                 good_run="yes"
    707             fi
    708         else
    709             good_run="yes"
    710         fi
    711     else
    712         good_build="no"
    713         cp "$build_output" "$output"
    714         echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
    715         echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
    716         echo "Args: ${args}" >> "$output"
    717         echo "build exit status: $build_exit" >> "$output"
    718         max_name_length=$(getconf NAME_MAX ${tmp_dir})
    719         echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
    720         max_path_length=$(getconf PATH_MAX ${tmp_dir})
    721         echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
    722     fi
    723     ./$check_cmd "$expected" "$output"
    724     if [ "$?" = "0" ]; then
    725         if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
    726           # output == expected
    727           good="yes"
    728           echo "${test_dir}: succeeded!" 1>&2
    729         fi
    730     fi
    731 fi
    732 
    733 (
    734     if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
    735         echo "${test_dir}: FAILED!"
    736         echo ' '
    737         echo '#################### info'
    738         cat "${td_info}" | sed 's/^/# /g'
    739         echo '#################### diffs'
    740         diff --strip-trailing-cr -u "$expected" "$output" | tail -n 2000
    741         echo '####################'
    742         echo ' '
    743     fi
    744 
    745 ) 1>&2
    746 
    747 # Clean up test files.
    748 if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
    749     cd "$oldwd"
    750     rm -rf "$tmp_dir"
    751     if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
    752         adb shell rm -rf $DEX_LOCATION
    753     fi
    754     if [ "$good" = "yes" ]; then
    755         exit 0
    756     fi
    757 fi
    758 
    759 
    760 (
    761     if [ "$always_clean" = "yes" ]; then
    762         echo "${TEST_NAME} files deleted from host "
    763         if [ "$target_mode" == "yes" ]; then
    764             echo "and from target"
    765         fi
    766     else
    767         echo "${TEST_NAME} files left in ${tmp_dir} on host"
    768         if [ "$target_mode" == "yes" ]; then
    769             echo "and in ${DEX_LOCATION} on target"
    770         fi
    771     fi
    772 
    773 ) 1>&2
    774 
    775 exit 1
    776