blob: aba4e05d034b9f6a9218fd9daf01dfd03370488b [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"
Andreas Gampedeb48a02014-10-22 00:44:35 -070020args="$@"
jeffhao5d1ac922011-09-29 17:41:15 -070021while [ -h "${prog}" ]; do
22 newProg=`/bin/ls -ld "${prog}"`
23 newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
24 if expr "x${newProg}" : 'x/' >/dev/null; then
25 prog="${newProg}"
26 else
27 progdir=`dirname "${prog}"`
28 prog="${progdir}/${newProg}"
29 fi
30done
31oldwd=`pwd`
32progdir=`dirname "${prog}"`
33cd "${progdir}"
34progdir=`pwd`
35prog="${progdir}"/`basename "${prog}"`
Brian Carlstrom105215d2012-06-14 12:50:44 -070036test_dir="test-$$"
Andreas Gampe5a79fde2014-08-06 13:12:26 -070037if [ -z "$TMPDIR" ]; then
38 tmp_dir="/tmp/$USER/${test_dir}"
39else
40 tmp_dir="${TMPDIR}/$USER/${test_dir}"
41fi
jeffhao5d1ac922011-09-29 17:41:15 -070042
43export JAVA="java"
Brian Carlstrom5103ce62014-03-30 16:17:42 -070044export JAVAC="javac -g"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010045export RUN="${progdir}/etc/run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070046export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070047export NEED_DEX="true"
jeffhao5d1ac922011-09-29 17:41:15 -070048
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070049# If dx was not set by the environment variable, assume it is in the path.
50if [ -z "$DX" ]; then
51 export DX="dx"
52fi
53
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080054# If jasmin was not set by the environment variable, assume it is in the path.
55if [ -z "$JASMIN" ]; then
56 export JASMIN="jasmin"
57fi
58
Andreas Gampe8fda9f22014-10-03 16:15:37 -070059# If smali was not set by the environment variable, assume it is in the path.
60if [ -z "$SMALI" ]; then
61 export SMALI="smali"
62fi
63
64# If dexmerger was not set by the environment variable, assume it is in the path.
65if [ -z "$DXMERGER" ]; then
66 export DXMERGER="dexmerger"
67fi
68
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080069
jeffhao5d1ac922011-09-29 17:41:15 -070070info="info.txt"
71build="build"
72run="run"
73expected="expected.txt"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -070074check_cmd="check"
jeffhao5d1ac922011-09-29 17:41:15 -070075output="output.txt"
76build_output="build-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070077lib="libartd.so"
jeffhao5d1ac922011-09-29 17:41:15 -070078run_args="--quiet"
79
Alex Light9d722532014-07-22 18:07:12 -070080prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -070081target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070082dev_mode="no"
83update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -070084debug_mode="no"
85relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -080086runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070087usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070088build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070089suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -070090trace="false"
Alex Lighte7873ec2014-08-12 09:53:50 -070091basic_verify="false"
92gc_verify="false"
93gc_stress="false"
Alex Lightbfac14a2014-07-30 09:41:21 -070094always_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -070095have_dex2oat="yes"
96have_patchoat="yes"
97have_image="yes"
Andreas Gampe63fc30e2014-10-24 21:58:16 -070098image_suffix=""
Andreas Gampec23c9c92014-10-28 14:47:25 -070099pic_image_suffix=""
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000100android_root="/system"
jeffhao5d1ac922011-09-29 17:41:15 -0700101
102while true; do
103 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700104 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700105 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100106 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700107 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800108 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700109 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800110 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700111 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700112 NEED_DEX="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100113 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700114 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800115 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700116 lib="libart.so"
117 shift
118 elif [ "x$1" = "x--dalvik" ]; then
119 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800120 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700121 shift
Alex Light03a112d2014-08-25 13:25:56 -0700122 elif [ "x$1" = "x--no-dex2oat" ]; then
123 have_dex2oat="no"
124 shift
125 elif [ "x$1" = "x--no-patchoat" ]; then
126 have_patchoat="no"
127 shift
128 elif [ "x$1" = "x--no-image" ]; then
129 have_image="no"
130 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700131 elif [ "x$1" = "x--pic-image" ]; then
132 pic_image_suffix="-pic"
133 shift
134 elif [ "x$1" = "x--pic-test" ]; then
135 run_args="${run_args} --pic-test"
136 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700137 elif [ "x$1" = "x--relocate" ]; then
138 relocate="yes"
139 shift
140 elif [ "x$1" = "x--no-relocate" ]; then
141 relocate="no"
142 shift
143 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100144 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700145 prebuild_mode="yes"
146 shift;
147 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100148 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700149 prebuild_mode="no"
150 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700151 elif [ "x$1" = "x--gcverify" ]; then
152 basic_verify="true"
153 gc_verify="true"
154 shift
155 elif [ "x$1" = "x--gcstress" ]; then
156 basic_verify="true"
157 gc_stress="true"
158 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700159 elif [ "x$1" = "x--image" ]; then
160 shift
161 image="$1"
162 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700163 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000164 elif [ "x$1" = "x-Xcompiler-option" ]; then
165 shift
166 option="$1"
167 run_args="${run_args} -Xcompiler-option $option"
168 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700169 elif [ "x$1" = "x--runtime-option" ]; then
170 shift
171 option="$1"
172 run_args="${run_args} --runtime-option $option"
173 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700174 elif [ "x$1" = "x--gdb-arg" ]; then
175 shift
176 gdb_arg="$1"
177 run_args="${run_args} --gdb-arg $gdb_arg"
178 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700179 elif [ "x$1" = "x--debug" ]; then
180 run_args="${run_args} --debug"
181 shift
182 elif [ "x$1" = "x--gdb" ]; then
183 run_args="${run_args} --gdb"
184 dev_mode="yes"
185 shift
186 elif [ "x$1" = "x--zygote" ]; then
187 run_args="${run_args} --zygote"
188 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800189 elif [ "x$1" = "x--interpreter" ]; then
190 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700191 image_suffix="-interpreter"
192 shift
193 elif [ "x$1" = "x--optimizing" ]; then
194 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
195 image_suffix="-optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800196 shift
Nicolas Geoffrayc9338b92014-12-03 13:36:10 +0000197 elif [ "x$1" = "x--quick" ]; then
198 run_args="${run_args} -Xcompiler-option --compiler-backend=Quick"
199 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700200 elif [ "x$1" = "x--no-verify" ]; then
201 run_args="${run_args} --no-verify"
202 shift
203 elif [ "x$1" = "x--no-optimize" ]; then
204 run_args="${run_args} --no-optimize"
205 shift
206 elif [ "x$1" = "x--no-precise" ]; then
207 run_args="${run_args} --no-precise"
208 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700209 elif [ "x$1" = "x--invoke-with" ]; then
210 shift
211 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700212 if [ "x$what" = "x" ]; then
213 echo "$0 missing argument to --invoke-with" 1>&2
214 usage="yes"
215 break
216 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700217 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700218 shift
219 elif [ "x$1" = "x--dev" ]; then
220 run_args="${run_args} --dev"
221 dev_mode="yes"
222 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700223 elif [ "x$1" = "x--build-only" ]; then
224 build_only="yes"
225 shift
226 elif [ "x$1" = "x--output-path" ]; then
227 shift
228 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700229 if [ "x$tmp_dir" = "x" ]; then
230 echo "$0 missing argument to --output-path" 1>&2
231 usage="yes"
232 break
233 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700234 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000235 elif [ "x$1" = "x--android-root" ]; then
236 shift
237 if [ "x$1" = "x" ]; then
238 echo "$0 missing argument to --android-root" 1>&2
239 usage="yes"
240 break
241 fi
242 android_root="$1"
243 run_args="${run_args} --android-root $1"
244 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700245 elif [ "x$1" = "x--update" ]; then
246 update_mode="yes"
247 shift
248 elif [ "x$1" = "x--help" ]; then
249 usage="yes"
250 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700251 elif [ "x$1" = "x--64" ]; then
252 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700253 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700254 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200255 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700256 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200257 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700258 elif [ "x$1" = "x--always-clean" ]; then
259 always_clean="yes"
260 shift
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800261 elif [ "x$1" = "x--dex2oat-swap" ]; then
262 run_args="${run_args} --dex2oat-swap"
263 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700264 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700265 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700266 usage="yes"
267 break
268 else
269 break
270 fi
271done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700272
273# tmp_dir may be relative, resolve.
274#
275# Cannot use realpath, as it does not exist on Mac.
276# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700277# Cannot use readlink -m, as it does not exist on Mac.
278# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700279noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700280tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700281mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700282
Alex Lighte7873ec2014-08-12 09:53:50 -0700283if [ "$basic_verify" = "true" ]; then
284 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify"
285fi
286if [ "$gc_verify" = "true" ]; then
287 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
288fi
289if [ "$gc_stress" = "true" ]; then
290 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
291fi
Jeff Hao85139a32014-07-23 11:52:52 -0700292if [ "$trace" = "true" ]; then
293 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
294fi
295
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700296# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100297# Try to map the suffix64 flag and what we find in ${ANDROID_PRODUCT_OUT}/data/art-test to an architecture name.
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700298function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100299 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
300 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700301 if [ "x${suffix64}" = "x64" ]; then
302 target_arch_name=${grep64bit}
303 else
304 target_arch_name=${grep32bit}
305 fi
306}
307
Alex Lighta59dd802014-07-02 16:28:08 -0700308if [ "$target_mode" = "no" ]; then
309 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700310 if [ "$prebuild_mode" = "yes" ]; then
311 echo "--prebuild with --jvm is unsupported";
312 exit 1;
313 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700314 fi
315fi
316
Alex Light03a112d2014-08-25 13:25:56 -0700317if [ "$have_patchoat" = "no" ]; then
318 run_args="${run_args} --no-patchoat"
319fi
320
321if [ "$have_dex2oat" = "no" ]; then
322 run_args="${run_args} --no-dex2oat"
323fi
324
Jeff Hao201803f2013-11-20 18:11:39 -0800325if [ ! "$runtime" = "jvm" ]; then
326 run_args="${run_args} --lib $lib"
327fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700328
Jeff Hao201803f2013-11-20 18:11:39 -0800329if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700330 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100331 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700332 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
333 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
334 else
335 true # defaults to using target BOOTCLASSPATH
336 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800337elif [ "$runtime" = "art" ]; then
338 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100339 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800340 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100341 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800342 fi
343 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100344 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800345 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000346 run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700347 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800348 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700349 guess_arch_name
350 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000351 run_args="${run_args} --boot /data/art-test/core${image_suffix}${pic_image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800352 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700353 if [ "$relocate" = "yes" ]; then
354 run_args="${run_args} --relocate"
355 else
356 run_args="${run_args} --no-relocate"
357 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700358fi
359
Alex Light03a112d2014-08-25 13:25:56 -0700360if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700361 if [ "$runtime" != "art" ]; then
362 echo "--no-image is only supported on the art runtime"
363 exit 1
364 fi
365 if [ "$target_mode" = "no" ]; then
366 framework="${ANDROID_HOST_OUT}/framework"
367 bpath_suffix="-hostdex"
368 else
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000369 framework="${android_root}/framework"
Alex Light1ef4ce82014-08-27 11:13:47 -0700370 bpath_suffix=""
371 fi
372 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
373 # fail since these jar files will be stripped.
374 bpath="${framework}/core-libart${bpath_suffix}.jar"
375 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
376 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
377 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
378 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
379 # Pass down the bootclasspath
380 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700381 run_args="${run_args} --no-image"
382fi
383
jeffhao5d1ac922011-09-29 17:41:15 -0700384if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
385 echo "--dev and --update are mutually exclusive" 1>&2
386 usage="yes"
387fi
388
389if [ "$usage" = "no" ]; then
390 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
391 test_dir=`basename "$oldwd"`
392 else
393 test_dir="$1"
394 fi
395
396 if [ '!' -d "$test_dir" ]; then
397 td2=`echo ${test_dir}-*`
398 if [ '!' -d "$td2" ]; then
399 echo "${test_dir}: no such test directory" 1>&2
400 usage="yes"
401 fi
402 test_dir="$td2"
403 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700404 # Shift to get rid of the test name argument. The rest of the arguments
405 # will get passed to the test run.
406 shift
407fi
408
409if [ "$usage" = "yes" ]; then
410 prog=`basename $prog`
411 (
412 echo "usage:"
413 echo " $prog --help Print this message."
414 echo " $prog [options] [test-name] Run test normally."
415 echo " $prog --dev [options] [test-name] Development mode" \
416 "(dumps to stdout)."
417 echo " $prog --update [options] [test-name] Update mode" \
418 "(replaces expected.txt)."
419 echo ' Omitting the test name or specifying "-" will use the' \
420 "current directory."
421 echo " Runtime Options:"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000422 echo " -O Run non-debug rather than debug build (off by default)."
423 echo " -Xcompiler-option Pass an option to the compiler."
424 echo " --runtime-option Pass an option to the runtime."
425 echo " --debug Wait for a debugger to attach."
426 echo " --gdb Run under gdb; incompatible with some tests."
427 echo " --build-only Build test files only (off by default)."
428 echo " --interpreter Enable interpreter only mode (off by default)."
429 echo " --optimizing Enable optimizing compiler (off by default)."
Nicolas Geoffrayc9338b92014-12-03 13:36:10 +0000430 echo " --quick Use Quick compiler (default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000431 echo " --no-verify Turn off verification (on by default)."
432 echo " --no-optimize Turn off optimization (on by default)."
433 echo " --no-precise Turn off precise GC (on by default)."
434 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700435 "If used, then the"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000436 echo " other runtime options are ignored."
437 echo " --no-dex2oat Run as though dex2oat was failing."
438 echo " --no-patchoat Run as though patchoat was failing."
439 echo " --prebuild Run dex2oat on the files before starting test. (default)"
440 echo " --no-prebuild Do not run dex2oat on the files before starting"
441 echo " the test."
442 echo " --relocate Force the use of relocating in the test, making"
443 echo " the image and oat files be relocated to a random"
444 echo " address before running. (default)"
445 echo " --no-relocate Force the use of no relocating in the test"
446 echo " --host Use the host-mode virtual machine."
447 echo " --invoke-with Pass --invoke-with option to runtime."
448 echo " --dalvik Use Dalvik (off by default)."
449 echo " --jvm Use a host-local RI virtual machine."
450 echo " --output-path [path] Location where to store the build" \
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700451 "files."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000452 echo " --64 Run the test in 64-bit mode"
453 echo " --trace Run with method tracing"
454 echo " --gcstress Run with gc stress testing"
455 echo " --gcverify Run with gc verification"
456 echo " --always-clean Delete the test files even if the test fails."
457 echo " --android-root [path] The path on target for the android root. (/system by default)."
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800458 echo " --dex2oat-swap Use a dex2oat swap file."
jeffhao5d1ac922011-09-29 17:41:15 -0700459 ) 1>&2
460 exit 1
461fi
462
463cd "$test_dir"
464test_dir=`pwd`
465
466td_info="${test_dir}/${info}"
467td_expected="${test_dir}/${expected}"
468
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700469if [ ! -r $td_info ]; then
470 echo "${test_dir}: missing file $td_info" 1>&2
471 exit 1
472fi
473
474if [ ! -r $td_expected ]; then
475 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700476 exit 1
477fi
478
479# copy the test to a temp dir and run it
480
Elliott Hughes510c8782011-10-06 10:57:34 -0700481echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700482
483rm -rf "$tmp_dir"
484cp -Rp "$test_dir" "$tmp_dir"
485cd "$tmp_dir"
486
487if [ '!' -r "$build" ]; then
488 cp "${progdir}/etc/default-build" build
489fi
490
491if [ '!' -r "$run" ]; then
492 cp "${progdir}/etc/default-run" run
493fi
494
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700495if [ '!' -r "$check_cmd" ]; then
496 cp "${progdir}/etc/default-check" check
497fi
498
jeffhao5d1ac922011-09-29 17:41:15 -0700499chmod 755 "$build"
500chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700501chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700502
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700503export TEST_NAME=`basename ${test_dir}`
504
Ian Rogers997f0f92014-06-21 22:58:05 -0700505# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
506file_size_limit=2048
507if echo "$test_dir" | grep 089; then
508 file_size_limit=5120
509elif echo "$test_dir" | grep 083; then
510 file_size_limit=5120
511fi
Alex Lighta59dd802014-07-02 16:28:08 -0700512if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700513 echo "ulimit file size setting failed"
514fi
515
jeffhao5d1ac922011-09-29 17:41:15 -0700516good="no"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000517good_build="yes"
518good_run="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700519if [ "$dev_mode" = "yes" ]; then
520 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700521 build_exit="$?"
522 echo "build exit status: $build_exit" 1>&2
523 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800524 echo "${test_dir}: running..." 1>&2
525 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700526 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800527 echo "run exit status: $run_exit" 1>&2
528 if [ "$run_exit" = "0" ]; then
529 good="yes"
530 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700531 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700532elif [ "$update_mode" = "yes" ]; then
533 "./${build}" >"$build_output" 2>&1
534 build_exit="$?"
535 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800536 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700537 "./${run}" $run_args "$@" >"$output" 2>&1
538 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
539 good="yes"
540 else
541 cat "$build_output" 1>&2
542 echo "build exit status: $build_exit" 1>&2
543 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700544elif [ "$build_only" = "yes" ]; then
545 good="yes"
546 "./${build}" >"$build_output" 2>&1
547 build_exit="$?"
548 if [ "$build_exit" '!=' '0' ]; then
549 cp "$build_output" "$output"
550 echo "build exit status: $build_exit" >>"$output"
551 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
552 if [ "$?" '!=' "0" ]; then
553 good="no"
554 echo "BUILD FAILED For ${TEST_NAME}"
555 fi
556 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700557 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700558 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700559 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700560else
561 "./${build}" >"$build_output" 2>&1
562 build_exit="$?"
563 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800564 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700565 "./${run}" $run_args "$@" >"$output" 2>&1
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000566 run_exit="$?"
567 if [ "$run_exit" != "0" ]; then
568 echo "run exit status: $run_exit" 1>&2
569 good_run="no"
570 else
571 good_run="yes"
572 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700573 else
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000574 good_build="no"
jeffhao5d1ac922011-09-29 17:41:15 -0700575 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700576 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
577 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700578 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700579 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700580 max_name_length=$(getconf NAME_MAX ${tmp_dir})
581 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
582 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700583 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700584 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700585 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700586 if [ "$?" = "0" ]; then
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000587 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
588 # output == expected
589 good="yes"
590 echo "${test_dir}: succeeded!" 1>&2
591 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700592 fi
593fi
594
jeffhao5d1ac922011-09-29 17:41:15 -0700595(
Alex Lightbfac14a2014-07-30 09:41:21 -0700596 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700597 echo "${test_dir}: FAILED!"
598 echo ' '
599 echo '#################### info'
600 cat "${td_info}" | sed 's/^/# /g'
601 echo '#################### diffs'
Ian Rogers75deec02014-11-23 20:07:39 -0800602 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 2000
jeffhao5d1ac922011-09-29 17:41:15 -0700603 echo '####################'
604 echo ' '
605 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700606
607) 1>&2
608
609# Clean up test files.
610if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
611 cd "$oldwd"
612 rm -rf "$tmp_dir"
613 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
614 adb shell rm -rf $DEX_LOCATION
615 fi
616 if [ "$good" = "yes" ]; then
617 exit 0
618 fi
619fi
620
621
622(
623 if [ "$always_clean" = "yes" ]; then
624 echo "${TEST_NAME} files deleted from host "
625 if [ "$target_mode" == "yes" ]; then
626 echo "and from target"
627 fi
628 else
629 echo "${TEST_NAME} files left in ${tmp_dir} on host"
630 if [ "$target_mode" == "yes" ]; then
631 echo "and in ${DEX_LOCATION} on target"
632 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700633 fi
634
jeffhao5d1ac922011-09-29 17:41:15 -0700635) 1>&2
636
637exit 1