OSDN Git Service

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