blob: 787670ac8c4fefa23a07797e4f365cf962bf5b3d [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
Alex Light9d722532014-07-22 18:07:12 -070064prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -070065target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070066dev_mode="no"
67update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -070068debug_mode="no"
69relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -080070runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070071usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070072build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070073suffix64=""
jeffhao5d1ac922011-09-29 17:41:15 -070074
75while true; do
76 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070077 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -070078 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070079 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080080 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070081 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -080082 runtime="jvm"
Elliott Hughesc717eef2012-06-15 16:01:26 -070083 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070084 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080085 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -070086 lib="libart.so"
87 shift
88 elif [ "x$1" = "x--dalvik" ]; then
89 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -080090 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070091 shift
Alex Lighta59dd802014-07-02 16:28:08 -070092 elif [ "x$1" = "x--relocate" ]; then
93 relocate="yes"
94 shift
95 elif [ "x$1" = "x--no-relocate" ]; then
96 relocate="no"
97 shift
98 elif [ "x$1" = "x--prebuild" ]; then
99 prebuild_mode="yes"
100 shift;
101 elif [ "x$1" = "x--no-prebuild" ]; then
102 prebuild_mode="no"
103 shift;
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700104 elif [ "x$1" = "x--image" ]; then
105 shift
106 image="$1"
107 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700108 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000109 elif [ "x$1" = "x-Xcompiler-option" ]; then
110 shift
111 option="$1"
112 run_args="${run_args} -Xcompiler-option $option"
113 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700114 elif [ "x$1" = "x--runtime-option" ]; then
115 shift
116 option="$1"
117 run_args="${run_args} --runtime-option $option"
118 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700119 elif [ "x$1" = "x--debug" ]; then
120 run_args="${run_args} --debug"
121 shift
122 elif [ "x$1" = "x--gdb" ]; then
123 run_args="${run_args} --gdb"
124 dev_mode="yes"
125 shift
126 elif [ "x$1" = "x--zygote" ]; then
127 run_args="${run_args} --zygote"
128 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800129 elif [ "x$1" = "x--interpreter" ]; then
130 run_args="${run_args} --interpreter"
131 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700132 elif [ "x$1" = "x--no-verify" ]; then
133 run_args="${run_args} --no-verify"
134 shift
135 elif [ "x$1" = "x--no-optimize" ]; then
136 run_args="${run_args} --no-optimize"
137 shift
138 elif [ "x$1" = "x--no-precise" ]; then
139 run_args="${run_args} --no-precise"
140 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700141 elif [ "x$1" = "x--invoke-with" ]; then
142 shift
143 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700144 if [ "x$what" = "x" ]; then
145 echo "$0 missing argument to --invoke-with" 1>&2
146 usage="yes"
147 break
148 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700149 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700150 shift
151 elif [ "x$1" = "x--dev" ]; then
152 run_args="${run_args} --dev"
153 dev_mode="yes"
154 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700155 elif [ "x$1" = "x--build-only" ]; then
156 build_only="yes"
157 shift
158 elif [ "x$1" = "x--output-path" ]; then
159 shift
160 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700161 if [ "x$tmp_dir" = "x" ]; then
162 echo "$0 missing argument to --output-path" 1>&2
163 usage="yes"
164 break
165 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700166 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700167 elif [ "x$1" = "x--update" ]; then
168 update_mode="yes"
169 shift
170 elif [ "x$1" = "x--help" ]; then
171 usage="yes"
172 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700173 elif [ "x$1" = "x--64" ]; then
174 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700175 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700176 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200177 elif [ "x$1" = "x--trace" ]; then
178 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin"
179 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700180 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700181 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700182 usage="yes"
183 break
184 else
185 break
186 fi
187done
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700188mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700189
Alex Lighta59dd802014-07-02 16:28:08 -0700190if [ "$target_mode" = "no" ]; then
191 if [ "$runtime" = "jvm" ]; then
192 RUN="${progdir}/etc/reference-run-test-classes"
193 if [ "$prebuild_mode" = "yes" ]; then
194 echo "--prebuild with --jvm is unsupported";
195 exit 1;
196 fi
197 else
198 RUN="${progdir}/etc/host-run-test-jar"
199 if [ "$prebuild_mode" = "yes" ]; then
200 run_args="${run_args} --prebuild"
201 fi
202 fi
203else
204 if [ "$prebuild_mode" = "yes" ]; then
205 RUN="${progdir}/etc/push-and-run-prebuilt-test-jar"
206 fi
207fi
208
Jeff Hao201803f2013-11-20 18:11:39 -0800209if [ ! "$runtime" = "jvm" ]; then
210 run_args="${run_args} --lib $lib"
211fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700212
Jeff Hao201803f2013-11-20 18:11:39 -0800213if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700214 if [ "$target_mode" = "no" ]; then
215 framework="${OUT}/system/framework"
216 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
217 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
218 else
219 true # defaults to using target BOOTCLASSPATH
220 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800221elif [ "$runtime" = "art" ]; then
222 if [ "$target_mode" = "no" ]; then
Brian Carlstrom43534862014-02-19 01:13:52 -0800223 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
224 if [ -z "$ANDROID_BUILD_TOP" ]; then
225 export ANDROID_BUILD_TOP=$oldwd
226 fi
227 if [ -z "$ANDROID_HOST_OUT" ]; then
228 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
229 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800230 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
231 else
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700232 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800233 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700234 if [ "$relocate" = "yes" ]; then
235 run_args="${run_args} --relocate"
236 else
237 run_args="${run_args} --no-relocate"
238 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700239fi
240
jeffhao5d1ac922011-09-29 17:41:15 -0700241if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
242 echo "--dev and --update are mutually exclusive" 1>&2
243 usage="yes"
244fi
245
246if [ "$usage" = "no" ]; then
247 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
248 test_dir=`basename "$oldwd"`
249 else
250 test_dir="$1"
251 fi
252
253 if [ '!' -d "$test_dir" ]; then
254 td2=`echo ${test_dir}-*`
255 if [ '!' -d "$td2" ]; then
256 echo "${test_dir}: no such test directory" 1>&2
257 usage="yes"
258 fi
259 test_dir="$td2"
260 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700261 # Shift to get rid of the test name argument. The rest of the arguments
262 # will get passed to the test run.
263 shift
264fi
265
266if [ "$usage" = "yes" ]; then
267 prog=`basename $prog`
268 (
269 echo "usage:"
270 echo " $prog --help Print this message."
271 echo " $prog [options] [test-name] Run test normally."
272 echo " $prog --dev [options] [test-name] Development mode" \
273 "(dumps to stdout)."
274 echo " $prog --update [options] [test-name] Update mode" \
275 "(replaces expected.txt)."
276 echo ' Omitting the test name or specifying "-" will use the' \
277 "current directory."
278 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000279 echo " -O Run non-debug rather than debug build (off by default)."
280 echo " -Xcompiler-option Pass an option to the compiler."
Ian Rogers701aa642014-07-18 11:38:13 -0700281 echo " --runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000282 echo " --debug Wait for a debugger to attach."
283 echo " --gdb Run under gdb; incompatible with some tests."
284 echo " --build-only Build test files only (off by default)."
285 echo " --interpreter Enable interpreter only mode (off by default)."
286 echo " --no-verify Turn off verification (on by default)."
287 echo " --no-optimize Turn off optimization (on by default)."
288 echo " --no-precise Turn off precise GC (on by default)."
289 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700290 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000291 echo " other runtime options are ignored."
Alex Light9d722532014-07-22 18:07:12 -0700292 echo " --prebuild Run dex2oat on the files before starting test. (default)"
Alex Lighta59dd802014-07-02 16:28:08 -0700293 echo " --no-prebuild Do not run dex2oat on the files before starting"
Alex Light9d722532014-07-22 18:07:12 -0700294 echo " the test."
Alex Lighta59dd802014-07-02 16:28:08 -0700295 echo " --relocate Force the use of relocating in the test, making"
296 echo " the image and oat files be relocated to a random"
297 echo " address before running. (default)"
298 echo " --no-relocate Force the use of no relocating in the test"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000299 echo " --host Use the host-mode virtual machine."
300 echo " --invoke-with Pass --invoke-with option to runtime."
301 echo " --dalvik Use Dalvik (off by default)."
302 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700303 echo " --output-path [path] Location where to store the build" \
304 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700305 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200306 echo " --trace Run with method tracing"
jeffhao5d1ac922011-09-29 17:41:15 -0700307 ) 1>&2
308 exit 1
309fi
310
311cd "$test_dir"
312test_dir=`pwd`
313
314td_info="${test_dir}/${info}"
315td_expected="${test_dir}/${expected}"
316
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700317if [ ! -r $td_info ]; then
318 echo "${test_dir}: missing file $td_info" 1>&2
319 exit 1
320fi
321
322if [ ! -r $td_expected ]; then
323 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700324 exit 1
325fi
326
327# copy the test to a temp dir and run it
328
Elliott Hughes510c8782011-10-06 10:57:34 -0700329echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700330
331rm -rf "$tmp_dir"
332cp -Rp "$test_dir" "$tmp_dir"
333cd "$tmp_dir"
334
335if [ '!' -r "$build" ]; then
336 cp "${progdir}/etc/default-build" build
337fi
338
339if [ '!' -r "$run" ]; then
340 cp "${progdir}/etc/default-run" run
341fi
342
343chmod 755 "$build"
344chmod 755 "$run"
345
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700346export TEST_NAME=`basename ${test_dir}`
347
Ian Rogers997f0f92014-06-21 22:58:05 -0700348# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
349file_size_limit=2048
350if echo "$test_dir" | grep 089; then
351 file_size_limit=5120
352elif echo "$test_dir" | grep 083; then
353 file_size_limit=5120
354fi
Alex Lighta59dd802014-07-02 16:28:08 -0700355if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700356 echo "ulimit file size setting failed"
357fi
358
jeffhao5d1ac922011-09-29 17:41:15 -0700359good="no"
360if [ "$dev_mode" = "yes" ]; then
361 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700362 build_exit="$?"
363 echo "build exit status: $build_exit" 1>&2
364 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800365 echo "${test_dir}: running..." 1>&2
366 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700367 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800368 echo "run exit status: $run_exit" 1>&2
369 if [ "$run_exit" = "0" ]; then
370 good="yes"
371 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700372 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700373elif [ "$update_mode" = "yes" ]; then
374 "./${build}" >"$build_output" 2>&1
375 build_exit="$?"
376 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800377 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700378 "./${run}" $run_args "$@" >"$output" 2>&1
379 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
380 good="yes"
381 else
382 cat "$build_output" 1>&2
383 echo "build exit status: $build_exit" 1>&2
384 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700385elif [ "$build_only" = "yes" ]; then
386 good="yes"
387 "./${build}" >"$build_output" 2>&1
388 build_exit="$?"
389 if [ "$build_exit" '!=' '0' ]; then
390 cp "$build_output" "$output"
391 echo "build exit status: $build_exit" >>"$output"
392 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
393 if [ "$?" '!=' "0" ]; then
394 good="no"
395 echo "BUILD FAILED For ${TEST_NAME}"
396 fi
397 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700398 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700399 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700400 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700401else
402 "./${build}" >"$build_output" 2>&1
403 build_exit="$?"
404 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800405 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700406 "./${run}" $run_args "$@" >"$output" 2>&1
407 else
408 cp "$build_output" "$output"
409 echo "build exit status: $build_exit" >>"$output"
410 fi
411 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
412 if [ "$?" = "0" ]; then
413 # output == expected
414 good="yes"
415 echo "${test_dir}: succeeded!" 1>&2
416 fi
417fi
418
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700419# Clean up test files.
420if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700421 cd "$oldwd"
422 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700423 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700424 adb shell rm -rf $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -0700425 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700426 exit 0
427fi
428
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700429
jeffhao5d1ac922011-09-29 17:41:15 -0700430(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700431 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700432 echo "${test_dir}: FAILED!"
433 echo ' '
434 echo '#################### info'
435 cat "${td_info}" | sed 's/^/# /g'
436 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700437 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700438 echo '####################'
439 echo ' '
440 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700441 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700442 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700443 echo "and in ${DEX_LOCATION} on target"
444 fi
445
jeffhao5d1ac922011-09-29 17:41:15 -0700446) 1>&2
447
448exit 1