blob: 2989f2578c349122de43ee9130b810844d7bf6a3 [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-$$"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +070036tmp_dir="/tmp/$USER/${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"
Jeff Hao201803f2013-11-20 18:11:39 -080067runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070068usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070069build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070070suffix64=""
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
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700101 elif [ "x$1" = "x--runtime-option" ]; then
102 shift
103 option="$1"
104 run_args="${run_args} --runtime-option $option"
105 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700106 elif [ "x$1" = "x--debug" ]; then
107 run_args="${run_args} --debug"
108 shift
109 elif [ "x$1" = "x--gdb" ]; then
110 run_args="${run_args} --gdb"
111 dev_mode="yes"
112 shift
113 elif [ "x$1" = "x--zygote" ]; then
114 run_args="${run_args} --zygote"
115 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800116 elif [ "x$1" = "x--interpreter" ]; then
117 run_args="${run_args} --interpreter"
118 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700119 elif [ "x$1" = "x--no-verify" ]; then
120 run_args="${run_args} --no-verify"
121 shift
122 elif [ "x$1" = "x--no-optimize" ]; then
123 run_args="${run_args} --no-optimize"
124 shift
125 elif [ "x$1" = "x--no-precise" ]; then
126 run_args="${run_args} --no-precise"
127 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700128 elif [ "x$1" = "x--invoke-with" ]; then
129 shift
130 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700131 if [ "x$what" = "x" ]; then
132 echo "$0 missing argument to --invoke-with" 1>&2
133 usage="yes"
134 break
135 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700136 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700137 shift
138 elif [ "x$1" = "x--dev" ]; then
139 run_args="${run_args} --dev"
140 dev_mode="yes"
141 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700142 elif [ "x$1" = "x--build-only" ]; then
143 build_only="yes"
144 shift
145 elif [ "x$1" = "x--output-path" ]; then
146 shift
147 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700148 if [ "x$tmp_dir" = "x" ]; then
149 echo "$0 missing argument to --output-path" 1>&2
150 usage="yes"
151 break
152 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700153 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700154 elif [ "x$1" = "x--update" ]; then
155 update_mode="yes"
156 shift
157 elif [ "x$1" = "x--help" ]; then
158 usage="yes"
159 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700160 elif [ "x$1" = "x--64" ]; then
161 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700162 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700163 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200164 elif [ "x$1" = "x--trace" ]; then
165 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin"
166 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700167 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700168 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700169 usage="yes"
170 break
171 else
172 break
173 fi
174done
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700175mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700176
Jeff Hao201803f2013-11-20 18:11:39 -0800177if [ ! "$runtime" = "jvm" ]; then
178 run_args="${run_args} --lib $lib"
179fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700180
Jeff Hao201803f2013-11-20 18:11:39 -0800181if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700182 if [ "$target_mode" = "no" ]; then
183 framework="${OUT}/system/framework"
184 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
185 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
186 else
187 true # defaults to using target BOOTCLASSPATH
188 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800189elif [ "$runtime" = "art" ]; then
190 if [ "$target_mode" = "no" ]; then
Brian Carlstrom43534862014-02-19 01:13:52 -0800191 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
192 if [ -z "$ANDROID_BUILD_TOP" ]; then
193 export ANDROID_BUILD_TOP=$oldwd
194 fi
195 if [ -z "$ANDROID_HOST_OUT" ]; then
196 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
197 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800198 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
199 else
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700200 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800201 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700202fi
203
jeffhao5d1ac922011-09-29 17:41:15 -0700204if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
205 echo "--dev and --update are mutually exclusive" 1>&2
206 usage="yes"
207fi
208
209if [ "$usage" = "no" ]; then
210 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
211 test_dir=`basename "$oldwd"`
212 else
213 test_dir="$1"
214 fi
215
216 if [ '!' -d "$test_dir" ]; then
217 td2=`echo ${test_dir}-*`
218 if [ '!' -d "$td2" ]; then
219 echo "${test_dir}: no such test directory" 1>&2
220 usage="yes"
221 fi
222 test_dir="$td2"
223 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700224 # Shift to get rid of the test name argument. The rest of the arguments
225 # will get passed to the test run.
226 shift
227fi
228
229if [ "$usage" = "yes" ]; then
230 prog=`basename $prog`
231 (
232 echo "usage:"
233 echo " $prog --help Print this message."
234 echo " $prog [options] [test-name] Run test normally."
235 echo " $prog --dev [options] [test-name] Development mode" \
236 "(dumps to stdout)."
237 echo " $prog --update [options] [test-name] Update mode" \
238 "(replaces expected.txt)."
239 echo ' Omitting the test name or specifying "-" will use the' \
240 "current directory."
241 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000242 echo " -O Run non-debug rather than debug build (off by default)."
243 echo " -Xcompiler-option Pass an option to the compiler."
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700244 echo " -runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000245 echo " --debug Wait for a debugger to attach."
246 echo " --gdb Run under gdb; incompatible with some tests."
247 echo " --build-only Build test files only (off by default)."
248 echo " --interpreter Enable interpreter only mode (off by default)."
249 echo " --no-verify Turn off verification (on by default)."
250 echo " --no-optimize Turn off optimization (on by default)."
251 echo " --no-precise Turn off precise GC (on by default)."
252 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700253 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000254 echo " other runtime options are ignored."
255 echo " --host Use the host-mode virtual machine."
256 echo " --invoke-with Pass --invoke-with option to runtime."
257 echo " --dalvik Use Dalvik (off by default)."
258 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700259 echo " --output-path [path] Location where to store the build" \
260 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700261 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200262 echo " --trace Run with method tracing"
jeffhao5d1ac922011-09-29 17:41:15 -0700263 ) 1>&2
264 exit 1
265fi
266
267cd "$test_dir"
268test_dir=`pwd`
269
270td_info="${test_dir}/${info}"
271td_expected="${test_dir}/${expected}"
272
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700273if [ ! -r $td_info ]; then
274 echo "${test_dir}: missing file $td_info" 1>&2
275 exit 1
276fi
277
278if [ ! -r $td_expected ]; then
279 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700280 exit 1
281fi
282
283# copy the test to a temp dir and run it
284
Elliott Hughes510c8782011-10-06 10:57:34 -0700285echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700286
287rm -rf "$tmp_dir"
288cp -Rp "$test_dir" "$tmp_dir"
289cd "$tmp_dir"
290
291if [ '!' -r "$build" ]; then
292 cp "${progdir}/etc/default-build" build
293fi
294
295if [ '!' -r "$run" ]; then
296 cp "${progdir}/etc/default-run" run
297fi
298
299chmod 755 "$build"
300chmod 755 "$run"
301
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700302export TEST_NAME=`basename ${test_dir}`
303
Ian Rogers997f0f92014-06-21 22:58:05 -0700304# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
305file_size_limit=2048
306if echo "$test_dir" | grep 089; then
307 file_size_limit=5120
308elif echo "$test_dir" | grep 083; then
309 file_size_limit=5120
310fi
311if ! ulimit "$file_size_limit"; then
312 echo "ulimit file size setting failed"
313fi
314
jeffhao5d1ac922011-09-29 17:41:15 -0700315good="no"
316if [ "$dev_mode" = "yes" ]; then
317 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700318 build_exit="$?"
319 echo "build exit status: $build_exit" 1>&2
320 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800321 echo "${test_dir}: running..." 1>&2
322 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700323 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800324 echo "run exit status: $run_exit" 1>&2
325 if [ "$run_exit" = "0" ]; then
326 good="yes"
327 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700328 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700329elif [ "$update_mode" = "yes" ]; then
330 "./${build}" >"$build_output" 2>&1
331 build_exit="$?"
332 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800333 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700334 "./${run}" $run_args "$@" >"$output" 2>&1
335 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
336 good="yes"
337 else
338 cat "$build_output" 1>&2
339 echo "build exit status: $build_exit" 1>&2
340 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700341elif [ "$build_only" = "yes" ]; then
342 good="yes"
343 "./${build}" >"$build_output" 2>&1
344 build_exit="$?"
345 if [ "$build_exit" '!=' '0' ]; then
346 cp "$build_output" "$output"
347 echo "build exit status: $build_exit" >>"$output"
348 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
349 if [ "$?" '!=' "0" ]; then
350 good="no"
351 echo "BUILD FAILED For ${TEST_NAME}"
352 fi
353 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700354 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700355 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700356 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700357else
358 "./${build}" >"$build_output" 2>&1
359 build_exit="$?"
360 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800361 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700362 "./${run}" $run_args "$@" >"$output" 2>&1
363 else
364 cp "$build_output" "$output"
365 echo "build exit status: $build_exit" >>"$output"
366 fi
367 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
368 if [ "$?" = "0" ]; then
369 # output == expected
370 good="yes"
371 echo "${test_dir}: succeeded!" 1>&2
372 fi
373fi
374
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700375# Clean up test files.
376if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700377 cd "$oldwd"
378 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700379 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700380 adb shell rm -rf $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -0700381 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700382 exit 0
383fi
384
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700385
jeffhao5d1ac922011-09-29 17:41:15 -0700386(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700387 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700388 echo "${test_dir}: FAILED!"
389 echo ' '
390 echo '#################### info'
391 cat "${td_info}" | sed 's/^/# /g'
392 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700393 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700394 echo '####################'
395 echo ' '
396 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700397 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700398 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700399 echo "and in ${DEX_LOCATION} on target"
400 fi
401
jeffhao5d1ac922011-09-29 17:41:15 -0700402) 1>&2
403
404exit 1