blob: a34cc72b1e628288d3ffdd8774637c0d8d1b56d5 [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"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070068dalvik_mode="no"
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"
jeffhao5d1ac922011-09-29 17:41:15 -070080 RUN="${progdir}/etc/reference-run-test-classes"
Elliott Hughesc717eef2012-06-15 16:01:26 -070081 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070082 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080083 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -070084 lib="libart.so"
85 shift
86 elif [ "x$1" = "x--dalvik" ]; then
87 lib="libdvm.so"
88 dalvik_mode="yes"
89 shift
90 elif [ "x$1" = "x--image" ]; then
91 shift
92 image="$1"
93 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -070094 shift
jeffhao5d1ac922011-09-29 17:41:15 -070095 elif [ "x$1" = "x--debug" ]; then
96 run_args="${run_args} --debug"
97 shift
98 elif [ "x$1" = "x--gdb" ]; then
99 run_args="${run_args} --gdb"
100 dev_mode="yes"
101 shift
102 elif [ "x$1" = "x--zygote" ]; then
103 run_args="${run_args} --zygote"
104 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800105 elif [ "x$1" = "x--interpreter" ]; then
106 run_args="${run_args} --interpreter"
107 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700108 elif [ "x$1" = "x--no-verify" ]; then
109 run_args="${run_args} --no-verify"
110 shift
111 elif [ "x$1" = "x--no-optimize" ]; then
112 run_args="${run_args} --no-optimize"
113 shift
114 elif [ "x$1" = "x--no-precise" ]; then
115 run_args="${run_args} --no-precise"
116 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700117 elif [ "x$1" = "x--invoke-with" ]; then
118 shift
119 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700120 if [ "x$what" = "x" ]; then
121 echo "$0 missing argument to --invoke-with" 1>&2
122 usage="yes"
123 break
124 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700125 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700126 shift
127 elif [ "x$1" = "x--dev" ]; then
128 run_args="${run_args} --dev"
129 dev_mode="yes"
130 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700131 elif [ "x$1" = "x--build-only" ]; then
132 build_only="yes"
133 shift
134 elif [ "x$1" = "x--output-path" ]; then
135 shift
136 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700137 if [ "x$tmp_dir" = "x" ]; then
138 echo "$0 missing argument to --output-path" 1>&2
139 usage="yes"
140 break
141 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700142 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700143 elif [ "x$1" = "x--update" ]; then
144 update_mode="yes"
145 shift
146 elif [ "x$1" = "x--help" ]; then
147 usage="yes"
148 shift
149 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700150 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700151 usage="yes"
152 break
153 else
154 break
155 fi
156done
157
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700158run_args="${run_args} --lib $lib"
159
160if [ "$dalvik_mode" = "no" ]; then
161 if [ "$target_mode" = "no" ]; then
162 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
163 else
164 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
165 fi
166else
167 if [ "$target_mode" = "no" ]; then
168 framework="${OUT}/system/framework"
169 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
170 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
171 else
172 true # defaults to using target BOOTCLASSPATH
173 fi
174fi
175
jeffhao5d1ac922011-09-29 17:41:15 -0700176if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
177 echo "--dev and --update are mutually exclusive" 1>&2
178 usage="yes"
179fi
180
181if [ "$usage" = "no" ]; then
182 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
183 test_dir=`basename "$oldwd"`
184 else
185 test_dir="$1"
186 fi
187
188 if [ '!' -d "$test_dir" ]; then
189 td2=`echo ${test_dir}-*`
190 if [ '!' -d "$td2" ]; then
191 echo "${test_dir}: no such test directory" 1>&2
192 usage="yes"
193 fi
194 test_dir="$td2"
195 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700196 # Shift to get rid of the test name argument. The rest of the arguments
197 # will get passed to the test run.
198 shift
199fi
200
201if [ "$usage" = "yes" ]; then
202 prog=`basename $prog`
203 (
204 echo "usage:"
205 echo " $prog --help Print this message."
206 echo " $prog [options] [test-name] Run test normally."
207 echo " $prog --dev [options] [test-name] Development mode" \
208 "(dumps to stdout)."
209 echo " $prog --update [options] [test-name] Update mode" \
210 "(replaces expected.txt)."
211 echo ' Omitting the test name or specifying "-" will use the' \
212 "current directory."
213 echo " Runtime Options:"
Brian Carlstromfa42b442013-06-17 12:53:45 -0700214 echo " -O Run non-debug rather than debug build (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700215 echo " --debug Wait for a debugger to attach."
Ian Rogers4c1bf1a2012-12-11 10:44:28 -0800216 echo " --gdb Run under gdb; incompatible with some tests."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700217 echo " --build-only Build test files only (off by default)."
jeffhao0dff3f42012-11-20 15:13:43 -0800218 echo " --interpreter Enable interpreter only mode (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700219 echo " --no-verify Turn off verification (on by default)."
220 echo " --no-optimize Turn off optimization (on by default)."
221 echo " --no-precise Turn off precise GC (on by default)."
222 echo " --zygote Spawn the process from the Zygote." \
223 "If used, then the"
224 echo " other runtime options are ignored."
225 echo " --host Use the host-mode virtual machine."
Ian Rogers0e033672013-04-19 10:22:46 -0700226 echo " --invoke-with Pass --invoke-with option to runtime."
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700227 echo " --dalvik Use Dalvik (off by default)."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800228 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700229 echo " --output-path [path] Location where to store the build" \
230 "files."
jeffhao5d1ac922011-09-29 17:41:15 -0700231 ) 1>&2
232 exit 1
233fi
234
235cd "$test_dir"
236test_dir=`pwd`
237
238td_info="${test_dir}/${info}"
239td_expected="${test_dir}/${expected}"
240
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700241if [ ! -r $td_info ]; then
242 echo "${test_dir}: missing file $td_info" 1>&2
243 exit 1
244fi
245
246if [ ! -r $td_expected ]; then
247 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700248 exit 1
249fi
250
251# copy the test to a temp dir and run it
252
Elliott Hughes510c8782011-10-06 10:57:34 -0700253echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700254
255rm -rf "$tmp_dir"
256cp -Rp "$test_dir" "$tmp_dir"
257cd "$tmp_dir"
258
259if [ '!' -r "$build" ]; then
260 cp "${progdir}/etc/default-build" build
261fi
262
263if [ '!' -r "$run" ]; then
264 cp "${progdir}/etc/default-run" run
265fi
266
267chmod 755 "$build"
268chmod 755 "$run"
269
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700270export TEST_NAME=`basename ${test_dir}`
271
jeffhao5d1ac922011-09-29 17:41:15 -0700272good="no"
273if [ "$dev_mode" = "yes" ]; then
274 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700275 build_exit="$?"
276 echo "build exit status: $build_exit" 1>&2
277 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800278 echo "${test_dir}: running..." 1>&2
279 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700280 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800281 echo "run exit status: $run_exit" 1>&2
282 if [ "$run_exit" = "0" ]; then
283 good="yes"
284 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700285 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700286elif [ "$update_mode" = "yes" ]; then
287 "./${build}" >"$build_output" 2>&1
288 build_exit="$?"
289 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800290 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700291 "./${run}" $run_args "$@" >"$output" 2>&1
292 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
293 good="yes"
294 else
295 cat "$build_output" 1>&2
296 echo "build exit status: $build_exit" 1>&2
297 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700298elif [ "$build_only" = "yes" ]; then
299 good="yes"
300 "./${build}" >"$build_output" 2>&1
301 build_exit="$?"
302 if [ "$build_exit" '!=' '0' ]; then
303 cp "$build_output" "$output"
304 echo "build exit status: $build_exit" >>"$output"
305 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
306 if [ "$?" '!=' "0" ]; then
307 good="no"
308 echo "BUILD FAILED For ${TEST_NAME}"
309 fi
310 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700311 # Clean up extraneous files that are not used by tests.
312 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$build_output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700313 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700314else
315 "./${build}" >"$build_output" 2>&1
316 build_exit="$?"
317 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800318 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700319 "./${run}" $run_args "$@" >"$output" 2>&1
320 else
321 cp "$build_output" "$output"
322 echo "build exit status: $build_exit" >>"$output"
323 fi
324 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
325 if [ "$?" = "0" ]; then
326 # output == expected
327 good="yes"
328 echo "${test_dir}: succeeded!" 1>&2
329 fi
330fi
331
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700332# Clean up test files.
333if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700334 cd "$oldwd"
335 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700336 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700337 adb shell rm -r $DEX_LOCATION
338 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700339 exit 0
340fi
341
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700342
jeffhao5d1ac922011-09-29 17:41:15 -0700343(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700344 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700345 echo "${test_dir}: FAILED!"
346 echo ' '
347 echo '#################### info'
348 cat "${td_info}" | sed 's/^/# /g'
349 echo '#################### diffs'
350 diff --strip-trailing-cr -u "$expected" "$output"
351 echo '####################'
352 echo ' '
353 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700354 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700355 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700356 echo "and in ${DEX_LOCATION} on target"
357 fi
358
jeffhao5d1ac922011-09-29 17:41:15 -0700359) 1>&2
360
361exit 1