blob: 58de9809df65465a0322b052ab2263b355bd3cee [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"
Brian Carlstrom5103ce62014-03-30 16:17:42 -070039export JAVAC="javac -g"
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
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000096 elif [ "x$1" = "x-Xcompiler-option" ]; then
97 shift
98 option="$1"
99 run_args="${run_args} -Xcompiler-option $option"
100 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700101 elif [ "x$1" = "x--debug" ]; then
102 run_args="${run_args} --debug"
103 shift
104 elif [ "x$1" = "x--gdb" ]; then
105 run_args="${run_args} --gdb"
106 dev_mode="yes"
107 shift
108 elif [ "x$1" = "x--zygote" ]; then
109 run_args="${run_args} --zygote"
110 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800111 elif [ "x$1" = "x--interpreter" ]; then
112 run_args="${run_args} --interpreter"
113 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700114 elif [ "x$1" = "x--no-verify" ]; then
115 run_args="${run_args} --no-verify"
116 shift
117 elif [ "x$1" = "x--no-optimize" ]; then
118 run_args="${run_args} --no-optimize"
119 shift
120 elif [ "x$1" = "x--no-precise" ]; then
121 run_args="${run_args} --no-precise"
122 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700123 elif [ "x$1" = "x--invoke-with" ]; then
124 shift
125 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700126 if [ "x$what" = "x" ]; then
127 echo "$0 missing argument to --invoke-with" 1>&2
128 usage="yes"
129 break
130 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700131 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700132 shift
133 elif [ "x$1" = "x--dev" ]; then
134 run_args="${run_args} --dev"
135 dev_mode="yes"
136 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700137 elif [ "x$1" = "x--build-only" ]; then
138 build_only="yes"
139 shift
140 elif [ "x$1" = "x--output-path" ]; then
141 shift
142 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700143 if [ "x$tmp_dir" = "x" ]; then
144 echo "$0 missing argument to --output-path" 1>&2
145 usage="yes"
146 break
147 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700148 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700149 elif [ "x$1" = "x--update" ]; then
150 update_mode="yes"
151 shift
152 elif [ "x$1" = "x--help" ]; then
153 usage="yes"
154 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700155 elif [ "x$1" = "x--64" ]; then
156 run_args="${run_args} --64"
157 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700158 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700159 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700160 usage="yes"
161 break
162 else
163 break
164 fi
165done
166
Jeff Hao201803f2013-11-20 18:11:39 -0800167if [ ! "$runtime" = "jvm" ]; then
168 run_args="${run_args} --lib $lib"
169fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700170
Jeff Hao201803f2013-11-20 18:11:39 -0800171if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700172 if [ "$target_mode" = "no" ]; then
173 framework="${OUT}/system/framework"
174 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
175 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
176 else
177 true # defaults to using target BOOTCLASSPATH
178 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800179elif [ "$runtime" = "art" ]; then
180 if [ "$target_mode" = "no" ]; then
Brian Carlstrom43534862014-02-19 01:13:52 -0800181 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
182 if [ -z "$ANDROID_BUILD_TOP" ]; then
183 export ANDROID_BUILD_TOP=$oldwd
184 fi
185 if [ -z "$ANDROID_HOST_OUT" ]; then
186 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
187 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800188 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
189 else
190 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
191 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700192fi
193
jeffhao5d1ac922011-09-29 17:41:15 -0700194if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
195 echo "--dev and --update are mutually exclusive" 1>&2
196 usage="yes"
197fi
198
199if [ "$usage" = "no" ]; then
200 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
201 test_dir=`basename "$oldwd"`
202 else
203 test_dir="$1"
204 fi
205
206 if [ '!' -d "$test_dir" ]; then
207 td2=`echo ${test_dir}-*`
208 if [ '!' -d "$td2" ]; then
209 echo "${test_dir}: no such test directory" 1>&2
210 usage="yes"
211 fi
212 test_dir="$td2"
213 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700214 # Shift to get rid of the test name argument. The rest of the arguments
215 # will get passed to the test run.
216 shift
217fi
218
219if [ "$usage" = "yes" ]; then
220 prog=`basename $prog`
221 (
222 echo "usage:"
223 echo " $prog --help Print this message."
224 echo " $prog [options] [test-name] Run test normally."
225 echo " $prog --dev [options] [test-name] Development mode" \
226 "(dumps to stdout)."
227 echo " $prog --update [options] [test-name] Update mode" \
228 "(replaces expected.txt)."
229 echo ' Omitting the test name or specifying "-" will use the' \
230 "current directory."
231 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000232 echo " -O Run non-debug rather than debug build (off by default)."
233 echo " -Xcompiler-option Pass an option to the compiler."
234 echo " --debug Wait for a debugger to attach."
235 echo " --gdb Run under gdb; incompatible with some tests."
236 echo " --build-only Build test files only (off by default)."
237 echo " --interpreter Enable interpreter only mode (off by default)."
238 echo " --no-verify Turn off verification (on by default)."
239 echo " --no-optimize Turn off optimization (on by default)."
240 echo " --no-precise Turn off precise GC (on by default)."
241 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700242 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000243 echo " other runtime options are ignored."
244 echo " --host Use the host-mode virtual machine."
245 echo " --invoke-with Pass --invoke-with option to runtime."
246 echo " --dalvik Use Dalvik (off by default)."
247 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700248 echo " --output-path [path] Location where to store the build" \
249 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700250 echo " --64 Run the test in 64-bit mode"
jeffhao5d1ac922011-09-29 17:41:15 -0700251 ) 1>&2
252 exit 1
253fi
254
255cd "$test_dir"
256test_dir=`pwd`
257
258td_info="${test_dir}/${info}"
259td_expected="${test_dir}/${expected}"
260
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700261if [ ! -r $td_info ]; then
262 echo "${test_dir}: missing file $td_info" 1>&2
263 exit 1
264fi
265
266if [ ! -r $td_expected ]; then
267 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700268 exit 1
269fi
270
271# copy the test to a temp dir and run it
272
Elliott Hughes510c8782011-10-06 10:57:34 -0700273echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700274
275rm -rf "$tmp_dir"
276cp -Rp "$test_dir" "$tmp_dir"
277cd "$tmp_dir"
278
279if [ '!' -r "$build" ]; then
280 cp "${progdir}/etc/default-build" build
281fi
282
283if [ '!' -r "$run" ]; then
284 cp "${progdir}/etc/default-run" run
285fi
286
287chmod 755 "$build"
288chmod 755 "$run"
289
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700290export TEST_NAME=`basename ${test_dir}`
291
jeffhao5d1ac922011-09-29 17:41:15 -0700292good="no"
293if [ "$dev_mode" = "yes" ]; then
294 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700295 build_exit="$?"
296 echo "build exit status: $build_exit" 1>&2
297 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800298 echo "${test_dir}: running..." 1>&2
299 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700300 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800301 echo "run exit status: $run_exit" 1>&2
302 if [ "$run_exit" = "0" ]; then
303 good="yes"
304 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700305 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700306elif [ "$update_mode" = "yes" ]; then
307 "./${build}" >"$build_output" 2>&1
308 build_exit="$?"
309 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800310 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700311 "./${run}" $run_args "$@" >"$output" 2>&1
312 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
313 good="yes"
314 else
315 cat "$build_output" 1>&2
316 echo "build exit status: $build_exit" 1>&2
317 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700318elif [ "$build_only" = "yes" ]; then
319 good="yes"
320 "./${build}" >"$build_output" 2>&1
321 build_exit="$?"
322 if [ "$build_exit" '!=' '0' ]; then
323 cp "$build_output" "$output"
324 echo "build exit status: $build_exit" >>"$output"
325 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
326 if [ "$?" '!=' "0" ]; then
327 good="no"
328 echo "BUILD FAILED For ${TEST_NAME}"
329 fi
330 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700331 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700332 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700333 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700334else
335 "./${build}" >"$build_output" 2>&1
336 build_exit="$?"
337 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800338 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700339 "./${run}" $run_args "$@" >"$output" 2>&1
340 else
341 cp "$build_output" "$output"
342 echo "build exit status: $build_exit" >>"$output"
343 fi
344 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
345 if [ "$?" = "0" ]; then
346 # output == expected
347 good="yes"
348 echo "${test_dir}: succeeded!" 1>&2
349 fi
350fi
351
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700352# Clean up test files.
353if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700354 cd "$oldwd"
355 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700356 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700357 adb shell rm -r $DEX_LOCATION
358 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700359 exit 0
360fi
361
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700362
jeffhao5d1ac922011-09-29 17:41:15 -0700363(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700364 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700365 echo "${test_dir}: FAILED!"
366 echo ' '
367 echo '#################### info'
368 cat "${td_info}" | sed 's/^/# /g'
369 echo '#################### diffs'
370 diff --strip-trailing-cr -u "$expected" "$output"
371 echo '####################'
372 echo ' '
373 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700374 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700375 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700376 echo "and in ${DEX_LOCATION} on target"
377 fi
378
jeffhao5d1ac922011-09-29 17:41:15 -0700379) 1>&2
380
381exit 1