blob: 11dcfc57defc27fa786c44722c9297d845ed004c [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/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}"`
Brian Carlstrom105215d2012-06-14 12:50:44 -070035test_dir="test-$$"
36tmp_dir="/tmp/${test_dir}"
jeffhao5d1ac922011-09-29 17:41:15 -070037
38export JAVA="java"
Elliott Hughes9829e332013-03-21 12:38:10 -070039export JAVAC="javac -g -source 1.5 -target 1.5"
jeffhao5d1ac922011-09-29 17:41:15 -070040export RUN="${progdir}/etc/push-and-run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070041export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070042export NEED_DEX="true"
jeffhao5d1ac922011-09-29 17:41:15 -070043
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070044# If dx was not set by the environment variable, assume it is in the path.
45if [ -z "$DX" ]; then
46 export DX="dx"
47fi
48
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080049# If jasmin was not set by the environment variable, assume it is in the path.
50if [ -z "$JASMIN" ]; then
51 export JASMIN="jasmin"
52fi
53
54
jeffhao5d1ac922011-09-29 17:41:15 -070055info="info.txt"
56build="build"
57run="run"
58expected="expected.txt"
59output="output.txt"
60build_output="build-output.txt"
61run_args="--quiet"
62
Brian Carlstrom2613de42012-06-15 17:37:16 -070063target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070064dev_mode="no"
65update_mode="no"
66debug_mode="no"
67usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070068build_only="no"
jeffhao5d1ac922011-09-29 17:41:15 -070069
70while true; do
71 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070072 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070073 RUN="${progdir}/etc/host-run-test-jar"
TDYa127b92bcab2012-04-08 00:09:51 -070074 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070075 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080076 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070077 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070078 RUN="${progdir}/etc/reference-run-test-classes"
Elliott Hughesc717eef2012-06-15 16:01:26 -070079 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070080 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080081 elif [ "x$1" = "x-O" ]; then
82 run_args="${run_args} -O"
Elliott Hughes7c046102011-10-19 18:16:03 -070083 shift
jeffhao5d1ac922011-09-29 17:41:15 -070084 elif [ "x$1" = "x--debug" ]; then
85 run_args="${run_args} --debug"
86 shift
87 elif [ "x$1" = "x--gdb" ]; then
88 run_args="${run_args} --gdb"
89 dev_mode="yes"
90 shift
91 elif [ "x$1" = "x--zygote" ]; then
92 run_args="${run_args} --zygote"
93 shift
jeffhao0dff3f42012-11-20 15:13:43 -080094 elif [ "x$1" = "x--interpreter" ]; then
95 run_args="${run_args} --interpreter"
96 shift
jeffhao5d1ac922011-09-29 17:41:15 -070097 elif [ "x$1" = "x--no-verify" ]; then
98 run_args="${run_args} --no-verify"
99 shift
100 elif [ "x$1" = "x--no-optimize" ]; then
101 run_args="${run_args} --no-optimize"
102 shift
103 elif [ "x$1" = "x--no-precise" ]; then
104 run_args="${run_args} --no-precise"
105 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700106 elif [ "x$1" = "x--invoke-with" ]; then
107 shift
108 what="$1"
Ian Rogers0e033672013-04-19 10:22:46 -0700109 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700110 shift
111 elif [ "x$1" = "x--dev" ]; then
112 run_args="${run_args} --dev"
113 dev_mode="yes"
114 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700115 elif [ "x$1" = "x--build-only" ]; then
116 build_only="yes"
117 shift
118 elif [ "x$1" = "x--output-path" ]; then
119 shift
120 tmp_dir=$1
121 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700122 elif [ "x$1" = "x--update" ]; then
123 update_mode="yes"
124 shift
125 elif [ "x$1" = "x--help" ]; then
126 usage="yes"
127 shift
128 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700129 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700130 usage="yes"
131 break
132 else
133 break
134 fi
135done
136
137if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
138 echo "--dev and --update are mutually exclusive" 1>&2
139 usage="yes"
140fi
141
142if [ "$usage" = "no" ]; then
143 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
144 test_dir=`basename "$oldwd"`
145 else
146 test_dir="$1"
147 fi
148
149 if [ '!' -d "$test_dir" ]; then
150 td2=`echo ${test_dir}-*`
151 if [ '!' -d "$td2" ]; then
152 echo "${test_dir}: no such test directory" 1>&2
153 usage="yes"
154 fi
155 test_dir="$td2"
156 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700157 # Shift to get rid of the test name argument. The rest of the arguments
158 # will get passed to the test run.
159 shift
160fi
161
162if [ "$usage" = "yes" ]; then
163 prog=`basename $prog`
164 (
165 echo "usage:"
166 echo " $prog --help Print this message."
167 echo " $prog [options] [test-name] Run test normally."
168 echo " $prog --dev [options] [test-name] Development mode" \
169 "(dumps to stdout)."
170 echo " $prog --update [options] [test-name] Update mode" \
171 "(replaces expected.txt)."
172 echo ' Omitting the test name or specifying "-" will use the' \
173 "current directory."
174 echo " Runtime Options:"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700175 echo " -O Run non-debug rather than debug build (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700176 echo " --debug Wait for a debugger to attach."
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800177 echo " --gdb Run under gdb; incompatible with some tests."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700178 echo " --build-only Build test files only (off by default)."
jeffhao0dff3f42012-11-20 15:13:43 -0800179 echo " --interpreter Enable interpreter only mode (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700180 echo " --no-verify Turn off verification (on by default)."
181 echo " --no-optimize Turn off optimization (on by default)."
182 echo " --no-precise Turn off precise GC (on by default)."
183 echo " --zygote Spawn the process from the Zygote." \
184 "If used, then the"
185 echo " other runtime options are ignored."
186 echo " --host Use the host-mode virtual machine."
Ian Rogers0e033672013-04-19 10:22:46 -0700187 echo " --invoke-with Pass --invoke-with option to runtime."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800188 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700189 echo " --output-path [path] Location where to store the build" \
190 "files."
jeffhao5d1ac922011-09-29 17:41:15 -0700191 ) 1>&2
192 exit 1
193fi
194
195cd "$test_dir"
196test_dir=`pwd`
197
198td_info="${test_dir}/${info}"
199td_expected="${test_dir}/${expected}"
200
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700201if [ ! -r $td_info ]; then
202 echo "${test_dir}: missing file $td_info" 1>&2
203 exit 1
204fi
205
206if [ ! -r $td_expected ]; then
207 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700208 exit 1
209fi
210
211# copy the test to a temp dir and run it
212
Elliott Hughes510c8782011-10-06 10:57:34 -0700213echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700214
215rm -rf "$tmp_dir"
216cp -Rp "$test_dir" "$tmp_dir"
217cd "$tmp_dir"
218
219if [ '!' -r "$build" ]; then
220 cp "${progdir}/etc/default-build" build
221fi
222
223if [ '!' -r "$run" ]; then
224 cp "${progdir}/etc/default-run" run
225fi
226
227chmod 755 "$build"
228chmod 755 "$run"
229
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700230export TEST_NAME=`basename ${test_dir}`
231
jeffhao5d1ac922011-09-29 17:41:15 -0700232good="no"
233if [ "$dev_mode" = "yes" ]; then
234 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700235 build_exit="$?"
236 echo "build exit status: $build_exit" 1>&2
237 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800238 echo "${test_dir}: running..." 1>&2
239 "./${run}" $run_args "$@" 2>&1
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800240 run_exit="$?"
241 echo "run exit status: $run_exit" 1>&2
242 if [ "$run_exit" = "0" ]; then
243 good="yes"
244 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700245 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700246elif [ "$update_mode" = "yes" ]; then
247 "./${build}" >"$build_output" 2>&1
248 build_exit="$?"
249 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800250 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700251 "./${run}" $run_args "$@" >"$output" 2>&1
252 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
253 good="yes"
254 else
255 cat "$build_output" 1>&2
256 echo "build exit status: $build_exit" 1>&2
257 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700258elif [ "$build_only" = "yes" ]; then
259 good="yes"
260 "./${build}" >"$build_output" 2>&1
261 build_exit="$?"
262 if [ "$build_exit" '!=' '0' ]; then
263 cp "$build_output" "$output"
264 echo "build exit status: $build_exit" >>"$output"
265 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
266 if [ "$?" '!=' "0" ]; then
267 good="no"
268 echo "BUILD FAILED For ${TEST_NAME}"
269 fi
270 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700271 # Clean up extraneous files that are not used by tests.
272 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$build_output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700273 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700274else
275 "./${build}" >"$build_output" 2>&1
276 build_exit="$?"
277 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800278 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700279 "./${run}" $run_args "$@" >"$output" 2>&1
280 else
281 cp "$build_output" "$output"
282 echo "build exit status: $build_exit" >>"$output"
283 fi
284 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
285 if [ "$?" = "0" ]; then
286 # output == expected
287 good="yes"
288 echo "${test_dir}: succeeded!" 1>&2
289 fi
290fi
291
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700292# Clean up test files.
293if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700294 cd "$oldwd"
295 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700296 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700297 adb shell rm -r $DEX_LOCATION
298 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700299 exit 0
300fi
301
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700302
jeffhao5d1ac922011-09-29 17:41:15 -0700303(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700304 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700305 echo "${test_dir}: FAILED!"
306 echo ' '
307 echo '#################### info'
308 cat "${td_info}" | sed 's/^/# /g'
309 echo '#################### diffs'
310 diff --strip-trailing-cr -u "$expected" "$output"
311 echo '####################'
312 echo ' '
313 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700314 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700315 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700316 echo "and in ${DEX_LOCATION} on target"
317 fi
318
jeffhao5d1ac922011-09-29 17:41:15 -0700319) 1>&2
320
321exit 1