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