blob: c3943e70bef91ceb75a8072cd86b53c1235e1277 [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"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070061lib="libartd.so"
jeffhao5d1ac922011-09-29 17:41:15 -070062run_args="--quiet"
63
Brian Carlstrom2613de42012-06-15 17:37:16 -070064target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070065dev_mode="no"
66update_mode="no"
67debug_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -080068runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070069usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070070build_only="no"
jeffhao5d1ac922011-09-29 17:41:15 -070071
72while true; do
73 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070074 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070075 RUN="${progdir}/etc/host-run-test-jar"
TDYa127b92bcab2012-04-08 00:09:51 -070076 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070077 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080078 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070079 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -080080 runtime="jvm"
jeffhao5d1ac922011-09-29 17:41:15 -070081 RUN="${progdir}/etc/reference-run-test-classes"
Elliott Hughesc717eef2012-06-15 16:01:26 -070082 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070083 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080084 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -070085 lib="libart.so"
86 shift
87 elif [ "x$1" = "x--dalvik" ]; then
88 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -080089 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070090 shift
91 elif [ "x$1" = "x--image" ]; then
92 shift
93 image="$1"
94 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -070095 shift
jeffhao5d1ac922011-09-29 17:41:15 -070096 elif [ "x$1" = "x--debug" ]; then
97 run_args="${run_args} --debug"
98 shift
99 elif [ "x$1" = "x--gdb" ]; then
100 run_args="${run_args} --gdb"
101 dev_mode="yes"
102 shift
103 elif [ "x$1" = "x--zygote" ]; then
104 run_args="${run_args} --zygote"
105 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800106 elif [ "x$1" = "x--interpreter" ]; then
107 run_args="${run_args} --interpreter"
108 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700109 elif [ "x$1" = "x--no-verify" ]; then
110 run_args="${run_args} --no-verify"
111 shift
112 elif [ "x$1" = "x--no-optimize" ]; then
113 run_args="${run_args} --no-optimize"
114 shift
115 elif [ "x$1" = "x--no-precise" ]; then
116 run_args="${run_args} --no-precise"
117 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700118 elif [ "x$1" = "x--invoke-with" ]; then
119 shift
120 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700121 if [ "x$what" = "x" ]; then
122 echo "$0 missing argument to --invoke-with" 1>&2
123 usage="yes"
124 break
125 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700126 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700127 shift
128 elif [ "x$1" = "x--dev" ]; then
129 run_args="${run_args} --dev"
130 dev_mode="yes"
131 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700132 elif [ "x$1" = "x--build-only" ]; then
133 build_only="yes"
134 shift
135 elif [ "x$1" = "x--output-path" ]; then
136 shift
137 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700138 if [ "x$tmp_dir" = "x" ]; then
139 echo "$0 missing argument to --output-path" 1>&2
140 usage="yes"
141 break
142 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700143 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700144 elif [ "x$1" = "x--update" ]; then
145 update_mode="yes"
146 shift
147 elif [ "x$1" = "x--help" ]; then
148 usage="yes"
149 shift
150 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700151 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700152 usage="yes"
153 break
154 else
155 break
156 fi
157done
158
Jeff Hao201803f2013-11-20 18:11:39 -0800159if [ ! "$runtime" = "jvm" ]; then
160 run_args="${run_args} --lib $lib"
161fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700162
Jeff Hao201803f2013-11-20 18:11:39 -0800163if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700164 if [ "$target_mode" = "no" ]; then
165 framework="${OUT}/system/framework"
166 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
167 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
168 else
169 true # defaults to using target BOOTCLASSPATH
170 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800171elif [ "$runtime" = "art" ]; then
172 if [ "$target_mode" = "no" ]; then
173 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
174 else
175 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
176 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700177fi
178
jeffhao5d1ac922011-09-29 17:41:15 -0700179if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
180 echo "--dev and --update are mutually exclusive" 1>&2
181 usage="yes"
182fi
183
184if [ "$usage" = "no" ]; then
185 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
186 test_dir=`basename "$oldwd"`
187 else
188 test_dir="$1"
189 fi
190
191 if [ '!' -d "$test_dir" ]; then
192 td2=`echo ${test_dir}-*`
193 if [ '!' -d "$td2" ]; then
194 echo "${test_dir}: no such test directory" 1>&2
195 usage="yes"
196 fi
197 test_dir="$td2"
198 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700199 # Shift to get rid of the test name argument. The rest of the arguments
200 # will get passed to the test run.
201 shift
202fi
203
204if [ "$usage" = "yes" ]; then
205 prog=`basename $prog`
206 (
207 echo "usage:"
208 echo " $prog --help Print this message."
209 echo " $prog [options] [test-name] Run test normally."
210 echo " $prog --dev [options] [test-name] Development mode" \
211 "(dumps to stdout)."
212 echo " $prog --update [options] [test-name] Update mode" \
213 "(replaces expected.txt)."
214 echo ' Omitting the test name or specifying "-" will use the' \
215 "current directory."
216 echo " Runtime Options:"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700217 echo " -O Run non-debug rather than debug build (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700218 echo " --debug Wait for a debugger to attach."
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800219 echo " --gdb Run under gdb; incompatible with some tests."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700220 echo " --build-only Build test files only (off by default)."
jeffhao0dff3f42012-11-20 15:13:43 -0800221 echo " --interpreter Enable interpreter only mode (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700222 echo " --no-verify Turn off verification (on by default)."
223 echo " --no-optimize Turn off optimization (on by default)."
224 echo " --no-precise Turn off precise GC (on by default)."
225 echo " --zygote Spawn the process from the Zygote." \
226 "If used, then the"
227 echo " other runtime options are ignored."
228 echo " --host Use the host-mode virtual machine."
Ian Rogers0e033672013-04-19 10:22:46 -0700229 echo " --invoke-with Pass --invoke-with option to runtime."
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700230 echo " --dalvik Use Dalvik (off by default)."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800231 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700232 echo " --output-path [path] Location where to store the build" \
233 "files."
jeffhao5d1ac922011-09-29 17:41:15 -0700234 ) 1>&2
235 exit 1
236fi
237
238cd "$test_dir"
239test_dir=`pwd`
240
241td_info="${test_dir}/${info}"
242td_expected="${test_dir}/${expected}"
243
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700244if [ ! -r $td_info ]; then
245 echo "${test_dir}: missing file $td_info" 1>&2
246 exit 1
247fi
248
249if [ ! -r $td_expected ]; then
250 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700251 exit 1
252fi
253
254# copy the test to a temp dir and run it
255
Elliott Hughes510c8782011-10-06 10:57:34 -0700256echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700257
258rm -rf "$tmp_dir"
259cp -Rp "$test_dir" "$tmp_dir"
260cd "$tmp_dir"
261
262if [ '!' -r "$build" ]; then
263 cp "${progdir}/etc/default-build" build
264fi
265
266if [ '!' -r "$run" ]; then
267 cp "${progdir}/etc/default-run" run
268fi
269
270chmod 755 "$build"
271chmod 755 "$run"
272
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700273export TEST_NAME=`basename ${test_dir}`
274
jeffhao5d1ac922011-09-29 17:41:15 -0700275good="no"
276if [ "$dev_mode" = "yes" ]; then
277 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700278 build_exit="$?"
279 echo "build exit status: $build_exit" 1>&2
280 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800281 echo "${test_dir}: running..." 1>&2
282 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700283 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800284 echo "run exit status: $run_exit" 1>&2
285 if [ "$run_exit" = "0" ]; then
286 good="yes"
287 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700288 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700289elif [ "$update_mode" = "yes" ]; then
290 "./${build}" >"$build_output" 2>&1
291 build_exit="$?"
292 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800293 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700294 "./${run}" $run_args "$@" >"$output" 2>&1
295 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
296 good="yes"
297 else
298 cat "$build_output" 1>&2
299 echo "build exit status: $build_exit" 1>&2
300 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700301elif [ "$build_only" = "yes" ]; then
302 good="yes"
303 "./${build}" >"$build_output" 2>&1
304 build_exit="$?"
305 if [ "$build_exit" '!=' '0' ]; then
306 cp "$build_output" "$output"
307 echo "build exit status: $build_exit" >>"$output"
308 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
309 if [ "$?" '!=' "0" ]; then
310 good="no"
311 echo "BUILD FAILED For ${TEST_NAME}"
312 fi
313 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700314 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700315 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700316 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700317else
318 "./${build}" >"$build_output" 2>&1
319 build_exit="$?"
320 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800321 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700322 "./${run}" $run_args "$@" >"$output" 2>&1
323 else
324 cp "$build_output" "$output"
325 echo "build exit status: $build_exit" >>"$output"
326 fi
327 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
328 if [ "$?" = "0" ]; then
329 # output == expected
330 good="yes"
331 echo "${test_dir}: succeeded!" 1>&2
332 fi
333fi
334
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700335# Clean up test files.
336if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700337 cd "$oldwd"
338 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700339 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700340 adb shell rm -r $DEX_LOCATION
341 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700342 exit 0
343fi
344
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700345
jeffhao5d1ac922011-09-29 17:41:15 -0700346(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700347 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700348 echo "${test_dir}: FAILED!"
349 echo ' '
350 echo '#################### info'
351 cat "${td_info}" | sed 's/^/# /g'
352 echo '#################### diffs'
353 diff --strip-trailing-cr -u "$expected" "$output"
354 echo '####################'
355 echo ' '
356 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700357 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700358 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700359 echo "and in ${DEX_LOCATION} on target"
360 fi
361
jeffhao5d1ac922011-09-29 17:41:15 -0700362) 1>&2
363
364exit 1