run-test revision b92bcabcbb28f69fe99e1c2f2e5559ab2c47aa60
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"
20while [ -h "${prog}" ]; do
21    newProg=`/bin/ls -ld "${prog}"`
22    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
23    if expr "x${newProg}" : 'x/' >/dev/null; then
24        prog="${newProg}"
25    else
26        progdir=`dirname "${prog}"`
27        prog="${progdir}/${newProg}"
28    fi
29done
30oldwd=`pwd`
31progdir=`dirname "${prog}"`
32cd "${progdir}"
33progdir=`pwd`
34prog="${progdir}"/`basename "${prog}"`
35tmp_dir="/tmp/test-$$"
36
37export JAVA="java"
38export JAVAC="javac -g -target 1.5"
39export RUN="${progdir}/etc/push-and-run-test-jar"
40export IMAGE=${ANDROID_PRODUCT_OUT}/data/art-test/core.art
41export DEX_LOCATION=/data/run-test
42export DEX2OAT_ARGS=""
43
44info="info.txt"
45build="build"
46run="run"
47expected="expected.txt"
48output="output.txt"
49build_output="build-output.txt"
50run_args="--quiet"
51
52dev_mode="no"
53update_mode="no"
54debug_mode="no"
55usage="no"
56
57while true; do
58    if [ "x$1" = "x--host" ]; then
59        RUN="${progdir}/etc/host-run-test-jar"
60        IMAGE=${ANDROID_BUILD_TOP}/out/host/linux-x86/framework/core.art
61        DEX_LOCATION=$tmp_dir
62        DEX2OAT_ARGS="--instruction-set=X86 --host-prefix=$ANDROID_BUILD_TOP/"
63        shift
64    elif [ "x$1" = "x--jvm" ]; then
65        RUN="${progdir}/etc/reference-run-test-classes"
66        shift
67    elif [ "x$1" = "x-O" ]; then
68        run_args="${run_args} -O"
69        shift
70    elif [ "x$1" = "x--debug" ]; then
71        run_args="${run_args} --debug"
72        shift
73    elif [ "x$1" = "x--gdb" ]; then
74        run_args="${run_args} --gdb"
75        dev_mode="yes"
76        shift
77    elif [ "x$1" = "x--zygote" ]; then
78        run_args="${run_args} --zygote"
79        shift
80    elif [ "x$1" = "x--no-verify" ]; then
81        run_args="${run_args} --no-verify"
82        shift
83    elif [ "x$1" = "x--no-optimize" ]; then
84        run_args="${run_args} --no-optimize"
85        shift
86    elif [ "x$1" = "x--no-precise" ]; then
87        run_args="${run_args} --no-precise"
88        shift
89    elif [ "x$1" = "x--invoke-with" ]; then
90        shift
91        what="$1"
92        run_args="${run_args} --invoke-with \"${what}\""
93        shift
94    elif [ "x$1" = "x--dev" ]; then
95        run_args="${run_args} --dev"
96        dev_mode="yes"
97        shift
98    elif [ "x$1" = "x--update" ]; then
99        update_mode="yes"
100        shift
101    elif [ "x$1" = "x--help" ]; then
102        usage="yes"
103        shift
104    elif expr "x$1" : "x--" >/dev/null 2>&1; then
105        echo "unknown $0 option: $1" 1>&2
106        usage="yes"
107        break
108    else
109        break
110    fi
111done
112
113if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
114    echo "--dev and --update are mutually exclusive" 1>&2
115    usage="yes"
116fi
117
118if [ "$usage" = "no" ]; then
119    if [ "x$1" = "x" -o "x$1" = "x-" ]; then
120        test_dir=`basename "$oldwd"`
121    else
122        test_dir="$1"
123    fi
124
125    if [ '!' -d "$test_dir" ]; then
126        td2=`echo ${test_dir}-*`
127        if [ '!' -d "$td2" ]; then
128            echo "${test_dir}: no such test directory" 1>&2
129            usage="yes"
130        fi
131        test_dir="$td2"
132    fi
133
134    # Shift to get rid of the test name argument. The rest of the arguments
135    # will get passed to the test run.
136    shift
137fi
138
139if [ "$usage" = "yes" ]; then
140    prog=`basename $prog`
141    (
142        echo "usage:"
143        echo "  $prog --help                          Print this message."
144        echo "  $prog [options] [test-name]           Run test normally."
145        echo "  $prog --dev [options] [test-name]     Development mode" \
146             "(dumps to stdout)."
147        echo "  $prog --update [options] [test-name]  Update mode" \
148             "(replaces expected.txt)."
149        echo '  Omitting the test name or specifying "-" will use the' \
150             "current directory."
151        echo "  Runtime Options:"
152        echo "    -O             Run oatexec rather than oatexecd (off by default)."
153        echo "    --debug        Wait for a debugger to attach."
154        #echo "    --gdb          Run under gdb; incompatible with some tests."
155        echo "    --no-verify    Turn off verification (on by default)."
156        echo "    --no-optimize  Turn off optimization (on by default)."
157        echo "    --no-precise   Turn off precise GC (on by default)."
158        echo "    --zygote       Spawn the process from the Zygote." \
159             "If used, then the"
160        echo "                   other runtime options are ignored."
161        echo "    --host         Use the host-mode virtual machine."
162        echo "    --valgrind     Use valgrind when running locally."
163        echo "    --jvm          Use a host-local RI virtual machine."
164    ) 1>&2
165    exit 1
166fi
167
168cd "$test_dir"
169test_dir=`pwd`
170
171td_info="${test_dir}/${info}"
172td_expected="${test_dir}/${expected}"
173
174if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then
175    echo "${test_dir}: missing files" 1>&2
176    exit 1
177fi
178
179# copy the test to a temp dir and run it
180
181echo "${test_dir}: building..." 1>&2
182
183rm -rf "$tmp_dir"
184cp -Rp "$test_dir" "$tmp_dir"
185cd "$tmp_dir"
186
187if [ '!' -r "$build" ]; then
188    cp "${progdir}/etc/default-build" build
189fi
190
191echo "${test_dir}: running..." 1>&2
192
193if [ '!' -r "$run" ]; then
194    cp "${progdir}/etc/default-run" run
195fi
196
197chmod 755 "$build"
198chmod 755 "$run"
199
200export TEST_NAME=`basename ${test_dir}`
201
202good="no"
203if [ "$dev_mode" = "yes" ]; then
204    "./${build}" 2>&1
205    echo "build exit status: $?" 1>&2
206    "./${run}" $run_args "$@" 2>&1
207    echo "run exit status: $?" 1>&2
208    good="yes"
209elif [ "$update_mode" = "yes" ]; then
210    "./${build}" >"$build_output" 2>&1
211    build_exit="$?"
212    if [ "$build_exit" = '0' ]; then
213        "./${run}" $run_args "$@" >"$output" 2>&1
214        sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
215        good="yes"
216    else
217        cat "$build_output" 1>&2
218        echo "build exit status: $build_exit" 1>&2
219    fi
220else
221    "./${build}" >"$build_output" 2>&1
222    build_exit="$?"
223    if [ "$build_exit" = '0' ]; then
224        "./${run}" $run_args "$@" >"$output" 2>&1
225    else
226        cp "$build_output" "$output"
227        echo "build exit status: $build_exit" >>"$output"
228    fi
229    diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
230    if [ "$?" = "0" ]; then
231        # output == expected
232        good="yes"
233        echo "${test_dir}: succeeded!" 1>&2
234    fi
235fi
236
237if [ "$good" = "yes" ]; then
238    cd "$oldwd"
239    rm -rf "$tmp_dir"
240    exit 0
241fi
242
243(
244    if [ "$update_mode" '!=' "yes" ]; then
245        echo "${test_dir}: FAILED!"
246        echo ' '
247        echo '#################### info'
248        cat "${td_info}" | sed 's/^/# /g'
249        echo '#################### diffs'
250        diff --strip-trailing-cr -u "$expected" "$output"
251        echo '####################'
252        echo ' '
253    fi
254    echo "${TEST_NAME} files left in ${tmp_dir}"
255) 1>&2
256
257exit 1
258