blob: 9095dd3d536d5067b57925a195f20f3fbc98fd67 [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 Hughes4b0d1ee2011-11-30 14:11:39 -080039export JAVAC="javac -g -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
jeffhao5d1ac922011-09-29 17:41:15 -070049info="info.txt"
50build="build"
51run="run"
52expected="expected.txt"
53output="output.txt"
54build_output="build-output.txt"
55run_args="--quiet"
56
Brian Carlstrom2613de42012-06-15 17:37:16 -070057target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070058dev_mode="no"
59update_mode="no"
60debug_mode="no"
61usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070062build_only="no"
jeffhao5d1ac922011-09-29 17:41:15 -070063
64while true; do
65 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070066 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070067 RUN="${progdir}/etc/host-run-test-jar"
TDYa127b92bcab2012-04-08 00:09:51 -070068 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070069 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080070 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070071 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070072 RUN="${progdir}/etc/reference-run-test-classes"
Elliott Hughesc717eef2012-06-15 16:01:26 -070073 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070074 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080075 elif [ "x$1" = "x-O" ]; then
76 run_args="${run_args} -O"
Elliott Hughes7c046102011-10-19 18:16:03 -070077 shift
jeffhao5d1ac922011-09-29 17:41:15 -070078 elif [ "x$1" = "x--debug" ]; then
79 run_args="${run_args} --debug"
80 shift
81 elif [ "x$1" = "x--gdb" ]; then
82 run_args="${run_args} --gdb"
83 dev_mode="yes"
84 shift
85 elif [ "x$1" = "x--zygote" ]; then
86 run_args="${run_args} --zygote"
87 shift
jeffhao0dff3f42012-11-20 15:13:43 -080088 elif [ "x$1" = "x--interpreter" ]; then
89 run_args="${run_args} --interpreter"
90 shift
jeffhao5d1ac922011-09-29 17:41:15 -070091 elif [ "x$1" = "x--no-verify" ]; then
92 run_args="${run_args} --no-verify"
93 shift
94 elif [ "x$1" = "x--no-optimize" ]; then
95 run_args="${run_args} --no-optimize"
96 shift
97 elif [ "x$1" = "x--no-precise" ]; then
98 run_args="${run_args} --no-precise"
99 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700100 elif [ "x$1" = "x--invoke-with" ]; then
101 shift
102 what="$1"
103 run_args="${run_args} --invoke-with \"${what}\""
jeffhao5d1ac922011-09-29 17:41:15 -0700104 shift
105 elif [ "x$1" = "x--dev" ]; then
106 run_args="${run_args} --dev"
107 dev_mode="yes"
108 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700109 elif [ "x$1" = "x--build-only" ]; then
110 build_only="yes"
111 shift
112 elif [ "x$1" = "x--output-path" ]; then
113 shift
114 tmp_dir=$1
115 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700116 elif [ "x$1" = "x--update" ]; then
117 update_mode="yes"
118 shift
119 elif [ "x$1" = "x--help" ]; then
120 usage="yes"
121 shift
122 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700123 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700124 usage="yes"
125 break
126 else
127 break
128 fi
129done
130
131if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
132 echo "--dev and --update are mutually exclusive" 1>&2
133 usage="yes"
134fi
135
136if [ "$usage" = "no" ]; then
137 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
138 test_dir=`basename "$oldwd"`
139 else
140 test_dir="$1"
141 fi
142
143 if [ '!' -d "$test_dir" ]; then
144 td2=`echo ${test_dir}-*`
145 if [ '!' -d "$td2" ]; then
146 echo "${test_dir}: no such test directory" 1>&2
147 usage="yes"
148 fi
149 test_dir="$td2"
150 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700151 # Shift to get rid of the test name argument. The rest of the arguments
152 # will get passed to the test run.
153 shift
154fi
155
156if [ "$usage" = "yes" ]; then
157 prog=`basename $prog`
158 (
159 echo "usage:"
160 echo " $prog --help Print this message."
161 echo " $prog [options] [test-name] Run test normally."
162 echo " $prog --dev [options] [test-name] Development mode" \
163 "(dumps to stdout)."
164 echo " $prog --update [options] [test-name] Update mode" \
165 "(replaces expected.txt)."
166 echo ' Omitting the test name or specifying "-" will use the' \
167 "current directory."
168 echo " Runtime Options:"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800169 echo " -O Run oatexec rather than oatexecd (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700170 echo " --debug Wait for a debugger to attach."
171 #echo " --gdb Run under gdb; incompatible with some tests."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700172 echo " --build-only Build test files only (off by default)."
jeffhao0dff3f42012-11-20 15:13:43 -0800173 echo " --interpreter Enable interpreter only mode (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700174 echo " --no-verify Turn off verification (on by default)."
175 echo " --no-optimize Turn off optimization (on by default)."
176 echo " --no-precise Turn off precise GC (on by default)."
177 echo " --zygote Spawn the process from the Zygote." \
178 "If used, then the"
179 echo " other runtime options are ignored."
180 echo " --host Use the host-mode virtual machine."
181 echo " --valgrind Use valgrind when running locally."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800182 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700183 echo " --output-path [path] Location where to store the build" \
184 "files."
jeffhao5d1ac922011-09-29 17:41:15 -0700185 ) 1>&2
186 exit 1
187fi
188
189cd "$test_dir"
190test_dir=`pwd`
191
192td_info="${test_dir}/${info}"
193td_expected="${test_dir}/${expected}"
194
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700195if [ ! -r $td_info ]; then
196 echo "${test_dir}: missing file $td_info" 1>&2
197 exit 1
198fi
199
200if [ ! -r $td_expected ]; then
201 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700202 exit 1
203fi
204
205# copy the test to a temp dir and run it
206
Elliott Hughes510c8782011-10-06 10:57:34 -0700207echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700208
209rm -rf "$tmp_dir"
210cp -Rp "$test_dir" "$tmp_dir"
211cd "$tmp_dir"
212
213if [ '!' -r "$build" ]; then
214 cp "${progdir}/etc/default-build" build
215fi
216
Elliott Hughes510c8782011-10-06 10:57:34 -0700217echo "${test_dir}: running..." 1>&2
218
jeffhao5d1ac922011-09-29 17:41:15 -0700219if [ '!' -r "$run" ]; then
220 cp "${progdir}/etc/default-run" run
221fi
222
223chmod 755 "$build"
224chmod 755 "$run"
225
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700226export TEST_NAME=`basename ${test_dir}`
227
jeffhao5d1ac922011-09-29 17:41:15 -0700228good="no"
229if [ "$dev_mode" = "yes" ]; then
230 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700231 build_exit="$?"
232 echo "build exit status: $build_exit" 1>&2
233 if [ "$build_exit" = '0' ]; then
234 "./${run}" $run_args "$@" 2>&1
235 echo "run exit status: $?" 1>&2
236 good="yes"
237 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700238elif [ "$update_mode" = "yes" ]; then
239 "./${build}" >"$build_output" 2>&1
240 build_exit="$?"
241 if [ "$build_exit" = '0' ]; then
242 "./${run}" $run_args "$@" >"$output" 2>&1
243 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
244 good="yes"
245 else
246 cat "$build_output" 1>&2
247 echo "build exit status: $build_exit" 1>&2
248 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700249elif [ "$build_only" = "yes" ]; then
250 good="yes"
251 "./${build}" >"$build_output" 2>&1
252 build_exit="$?"
253 if [ "$build_exit" '!=' '0' ]; then
254 cp "$build_output" "$output"
255 echo "build exit status: $build_exit" >>"$output"
256 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
257 if [ "$?" '!=' "0" ]; then
258 good="no"
259 echo "BUILD FAILED For ${TEST_NAME}"
260 fi
261 fi
262 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700263else
264 "./${build}" >"$build_output" 2>&1
265 build_exit="$?"
266 if [ "$build_exit" = '0' ]; then
267 "./${run}" $run_args "$@" >"$output" 2>&1
268 else
269 cp "$build_output" "$output"
270 echo "build exit status: $build_exit" >>"$output"
271 fi
272 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
273 if [ "$?" = "0" ]; then
274 # output == expected
275 good="yes"
276 echo "${test_dir}: succeeded!" 1>&2
277 fi
278fi
279
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700280# Clean up test files.
281if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700282 cd "$oldwd"
283 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700284 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700285 adb shell rm -r $DEX_LOCATION
286 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700287 exit 0
288fi
289
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700290
jeffhao5d1ac922011-09-29 17:41:15 -0700291(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700292 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700293 echo "${test_dir}: FAILED!"
294 echo ' '
295 echo '#################### info'
296 cat "${td_info}" | sed 's/^/# /g'
297 echo '#################### diffs'
298 diff --strip-trailing-cr -u "$expected" "$output"
299 echo '####################'
300 echo ' '
301 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700302 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700303 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700304 echo "and in ${DEX_LOCATION} on target"
305 fi
306
jeffhao5d1ac922011-09-29 17:41:15 -0700307) 1>&2
308
309exit 1