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