blob: b0a4bb169e4e58d2154cd90ead10d024744a6be4 [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=""
jeffhao5d1ac922011-09-29 17:41:15 -0700100
101while true; do
102 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700103 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700104 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100105 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700106 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800107 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700108 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800109 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700110 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700111 NEED_DEX="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100112 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700113 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800114 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700115 lib="libart.so"
116 shift
117 elif [ "x$1" = "x--dalvik" ]; then
118 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800119 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700120 shift
Alex Light03a112d2014-08-25 13:25:56 -0700121 elif [ "x$1" = "x--no-dex2oat" ]; then
122 have_dex2oat="no"
123 shift
124 elif [ "x$1" = "x--no-patchoat" ]; then
125 have_patchoat="no"
126 shift
127 elif [ "x$1" = "x--no-image" ]; then
128 have_image="no"
129 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700130 elif [ "x$1" = "x--pic-image" ]; then
131 pic_image_suffix="-pic"
132 shift
133 elif [ "x$1" = "x--pic-test" ]; then
134 run_args="${run_args} --pic-test"
135 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700136 elif [ "x$1" = "x--relocate" ]; then
137 relocate="yes"
138 shift
139 elif [ "x$1" = "x--no-relocate" ]; then
140 relocate="no"
141 shift
142 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100143 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700144 prebuild_mode="yes"
145 shift;
146 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100147 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700148 prebuild_mode="no"
149 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700150 elif [ "x$1" = "x--gcverify" ]; then
151 basic_verify="true"
152 gc_verify="true"
153 shift
154 elif [ "x$1" = "x--gcstress" ]; then
155 basic_verify="true"
156 gc_stress="true"
157 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700158 elif [ "x$1" = "x--image" ]; then
159 shift
160 image="$1"
161 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700162 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000163 elif [ "x$1" = "x-Xcompiler-option" ]; then
164 shift
165 option="$1"
166 run_args="${run_args} -Xcompiler-option $option"
167 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700168 elif [ "x$1" = "x--runtime-option" ]; then
169 shift
170 option="$1"
171 run_args="${run_args} --runtime-option $option"
172 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700173 elif [ "x$1" = "x--debug" ]; then
174 run_args="${run_args} --debug"
175 shift
176 elif [ "x$1" = "x--gdb" ]; then
177 run_args="${run_args} --gdb"
178 dev_mode="yes"
179 shift
180 elif [ "x$1" = "x--zygote" ]; then
181 run_args="${run_args} --zygote"
182 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800183 elif [ "x$1" = "x--interpreter" ]; then
184 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700185 image_suffix="-interpreter"
186 shift
187 elif [ "x$1" = "x--optimizing" ]; then
188 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
189 image_suffix="-optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800190 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700191 elif [ "x$1" = "x--no-verify" ]; then
192 run_args="${run_args} --no-verify"
193 shift
194 elif [ "x$1" = "x--no-optimize" ]; then
195 run_args="${run_args} --no-optimize"
196 shift
197 elif [ "x$1" = "x--no-precise" ]; then
198 run_args="${run_args} --no-precise"
199 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700200 elif [ "x$1" = "x--invoke-with" ]; then
201 shift
202 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700203 if [ "x$what" = "x" ]; then
204 echo "$0 missing argument to --invoke-with" 1>&2
205 usage="yes"
206 break
207 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700208 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700209 shift
210 elif [ "x$1" = "x--dev" ]; then
211 run_args="${run_args} --dev"
212 dev_mode="yes"
213 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700214 elif [ "x$1" = "x--build-only" ]; then
215 build_only="yes"
216 shift
217 elif [ "x$1" = "x--output-path" ]; then
218 shift
219 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700220 if [ "x$tmp_dir" = "x" ]; then
221 echo "$0 missing argument to --output-path" 1>&2
222 usage="yes"
223 break
224 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700225 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700226 elif [ "x$1" = "x--update" ]; then
227 update_mode="yes"
228 shift
229 elif [ "x$1" = "x--help" ]; then
230 usage="yes"
231 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700232 elif [ "x$1" = "x--64" ]; then
233 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700234 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700235 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200236 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700237 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200238 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700239 elif [ "x$1" = "x--always-clean" ]; then
240 always_clean="yes"
241 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700242 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700243 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700244 usage="yes"
245 break
246 else
247 break
248 fi
249done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700250
251# tmp_dir may be relative, resolve.
252#
253# Cannot use realpath, as it does not exist on Mac.
254# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700255# Cannot use readlink -m, as it does not exist on Mac.
256# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700257noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700258tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700259mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700260
Alex Lighte7873ec2014-08-12 09:53:50 -0700261if [ "$basic_verify" = "true" ]; then
262 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify"
263fi
264if [ "$gc_verify" = "true" ]; then
265 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
266fi
267if [ "$gc_stress" = "true" ]; then
268 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
269fi
Jeff Hao85139a32014-07-23 11:52:52 -0700270if [ "$trace" = "true" ]; then
271 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
272fi
273
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700274# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100275# 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 -0700276function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100277 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
278 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700279 if [ "x${suffix64}" = "x64" ]; then
280 target_arch_name=${grep64bit}
281 else
282 target_arch_name=${grep32bit}
283 fi
284}
285
Alex Lighta59dd802014-07-02 16:28:08 -0700286if [ "$target_mode" = "no" ]; then
287 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700288 if [ "$prebuild_mode" = "yes" ]; then
289 echo "--prebuild with --jvm is unsupported";
290 exit 1;
291 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700292 fi
293fi
294
Alex Light03a112d2014-08-25 13:25:56 -0700295if [ "$have_patchoat" = "no" ]; then
296 run_args="${run_args} --no-patchoat"
297fi
298
299if [ "$have_dex2oat" = "no" ]; then
300 run_args="${run_args} --no-dex2oat"
301fi
302
Jeff Hao201803f2013-11-20 18:11:39 -0800303if [ ! "$runtime" = "jvm" ]; then
304 run_args="${run_args} --lib $lib"
305fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700306
Jeff Hao201803f2013-11-20 18:11:39 -0800307if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700308 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100309 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700310 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
311 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
312 else
313 true # defaults to using target BOOTCLASSPATH
314 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800315elif [ "$runtime" = "art" ]; then
316 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100317 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800318 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100319 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800320 fi
321 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100322 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800323 fi
Andreas Gampec23c9c92014-10-28 14:47:25 -0700324 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700325 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800326 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700327 guess_arch_name
328 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Andreas Gampec23c9c92014-10-28 14:47:25 -0700329 run_args="${run_args} --boot -Ximage:/data/art-test/core${image_suffix}${pic_image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800330 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700331 if [ "$relocate" = "yes" ]; then
332 run_args="${run_args} --relocate"
333 else
334 run_args="${run_args} --no-relocate"
335 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700336fi
337
Alex Light03a112d2014-08-25 13:25:56 -0700338if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700339 if [ "$runtime" != "art" ]; then
340 echo "--no-image is only supported on the art runtime"
341 exit 1
342 fi
343 if [ "$target_mode" = "no" ]; then
344 framework="${ANDROID_HOST_OUT}/framework"
345 bpath_suffix="-hostdex"
346 else
347 framework="/system/framework"
348 bpath_suffix=""
349 fi
350 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
351 # fail since these jar files will be stripped.
352 bpath="${framework}/core-libart${bpath_suffix}.jar"
353 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
354 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
355 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
356 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
357 # Pass down the bootclasspath
358 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700359 run_args="${run_args} --no-image"
360fi
361
jeffhao5d1ac922011-09-29 17:41:15 -0700362if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
363 echo "--dev and --update are mutually exclusive" 1>&2
364 usage="yes"
365fi
366
367if [ "$usage" = "no" ]; then
368 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
369 test_dir=`basename "$oldwd"`
370 else
371 test_dir="$1"
372 fi
373
374 if [ '!' -d "$test_dir" ]; then
375 td2=`echo ${test_dir}-*`
376 if [ '!' -d "$td2" ]; then
377 echo "${test_dir}: no such test directory" 1>&2
378 usage="yes"
379 fi
380 test_dir="$td2"
381 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700382 # Shift to get rid of the test name argument. The rest of the arguments
383 # will get passed to the test run.
384 shift
385fi
386
387if [ "$usage" = "yes" ]; then
388 prog=`basename $prog`
389 (
390 echo "usage:"
391 echo " $prog --help Print this message."
392 echo " $prog [options] [test-name] Run test normally."
393 echo " $prog --dev [options] [test-name] Development mode" \
394 "(dumps to stdout)."
395 echo " $prog --update [options] [test-name] Update mode" \
396 "(replaces expected.txt)."
397 echo ' Omitting the test name or specifying "-" will use the' \
398 "current directory."
399 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000400 echo " -O Run non-debug rather than debug build (off by default)."
401 echo " -Xcompiler-option Pass an option to the compiler."
Ian Rogers701aa642014-07-18 11:38:13 -0700402 echo " --runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000403 echo " --debug Wait for a debugger to attach."
404 echo " --gdb Run under gdb; incompatible with some tests."
405 echo " --build-only Build test files only (off by default)."
406 echo " --interpreter Enable interpreter only mode (off by default)."
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700407 echo " --optimizing Enable optimizing compiler (off by default)."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000408 echo " --no-verify Turn off verification (on by default)."
409 echo " --no-optimize Turn off optimization (on by default)."
410 echo " --no-precise Turn off precise GC (on by default)."
411 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700412 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000413 echo " other runtime options are ignored."
Alex Light03a112d2014-08-25 13:25:56 -0700414 echo " --no-dex2oat Run as though dex2oat was failing."
415 echo " --no-patchoat Run as though patchoat was failing."
Alex Light9d722532014-07-22 18:07:12 -0700416 echo " --prebuild Run dex2oat on the files before starting test. (default)"
Alex Lighta59dd802014-07-02 16:28:08 -0700417 echo " --no-prebuild Do not run dex2oat on the files before starting"
Alex Light9d722532014-07-22 18:07:12 -0700418 echo " the test."
Alex Lighta59dd802014-07-02 16:28:08 -0700419 echo " --relocate Force the use of relocating in the test, making"
420 echo " the image and oat files be relocated to a random"
421 echo " address before running. (default)"
422 echo " --no-relocate Force the use of no relocating in the test"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000423 echo " --host Use the host-mode virtual machine."
424 echo " --invoke-with Pass --invoke-with option to runtime."
425 echo " --dalvik Use Dalvik (off by default)."
426 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700427 echo " --output-path [path] Location where to store the build" \
428 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700429 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200430 echo " --trace Run with method tracing"
Alex Lighte7873ec2014-08-12 09:53:50 -0700431 echo " --gcstress Run with gc stress testing"
432 echo " --gcverify Run with gc verification"
Alex Lightbfac14a2014-07-30 09:41:21 -0700433 echo " --always-clean Delete the test files even if the test fails."
jeffhao5d1ac922011-09-29 17:41:15 -0700434 ) 1>&2
435 exit 1
436fi
437
438cd "$test_dir"
439test_dir=`pwd`
440
441td_info="${test_dir}/${info}"
442td_expected="${test_dir}/${expected}"
443
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700444if [ ! -r $td_info ]; then
445 echo "${test_dir}: missing file $td_info" 1>&2
446 exit 1
447fi
448
449if [ ! -r $td_expected ]; then
450 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700451 exit 1
452fi
453
454# copy the test to a temp dir and run it
455
Elliott Hughes510c8782011-10-06 10:57:34 -0700456echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700457
458rm -rf "$tmp_dir"
459cp -Rp "$test_dir" "$tmp_dir"
460cd "$tmp_dir"
461
462if [ '!' -r "$build" ]; then
463 cp "${progdir}/etc/default-build" build
464fi
465
466if [ '!' -r "$run" ]; then
467 cp "${progdir}/etc/default-run" run
468fi
469
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700470if [ '!' -r "$check_cmd" ]; then
471 cp "${progdir}/etc/default-check" check
472fi
473
jeffhao5d1ac922011-09-29 17:41:15 -0700474chmod 755 "$build"
475chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700476chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700477
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700478export TEST_NAME=`basename ${test_dir}`
479
Ian Rogers997f0f92014-06-21 22:58:05 -0700480# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
481file_size_limit=2048
482if echo "$test_dir" | grep 089; then
483 file_size_limit=5120
484elif echo "$test_dir" | grep 083; then
485 file_size_limit=5120
486fi
Alex Lighta59dd802014-07-02 16:28:08 -0700487if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700488 echo "ulimit file size setting failed"
489fi
490
jeffhao5d1ac922011-09-29 17:41:15 -0700491good="no"
492if [ "$dev_mode" = "yes" ]; then
493 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700494 build_exit="$?"
495 echo "build exit status: $build_exit" 1>&2
496 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800497 echo "${test_dir}: running..." 1>&2
498 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700499 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800500 echo "run exit status: $run_exit" 1>&2
501 if [ "$run_exit" = "0" ]; then
502 good="yes"
503 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700504 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700505elif [ "$update_mode" = "yes" ]; then
506 "./${build}" >"$build_output" 2>&1
507 build_exit="$?"
508 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800509 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700510 "./${run}" $run_args "$@" >"$output" 2>&1
511 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
512 good="yes"
513 else
514 cat "$build_output" 1>&2
515 echo "build exit status: $build_exit" 1>&2
516 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700517elif [ "$build_only" = "yes" ]; then
518 good="yes"
519 "./${build}" >"$build_output" 2>&1
520 build_exit="$?"
521 if [ "$build_exit" '!=' '0' ]; then
522 cp "$build_output" "$output"
523 echo "build exit status: $build_exit" >>"$output"
524 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
525 if [ "$?" '!=' "0" ]; then
526 good="no"
527 echo "BUILD FAILED For ${TEST_NAME}"
528 fi
529 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700530 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700531 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700532 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700533else
534 "./${build}" >"$build_output" 2>&1
535 build_exit="$?"
536 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800537 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700538 "./${run}" $run_args "$@" >"$output" 2>&1
539 else
540 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700541 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
542 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700543 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700544 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700545 max_name_length=$(getconf NAME_MAX ${tmp_dir})
546 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
547 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700548 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700549 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700550 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700551 if [ "$?" = "0" ]; then
552 # output == expected
553 good="yes"
554 echo "${test_dir}: succeeded!" 1>&2
555 fi
556fi
557
jeffhao5d1ac922011-09-29 17:41:15 -0700558(
Alex Lightbfac14a2014-07-30 09:41:21 -0700559 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700560 echo "${test_dir}: FAILED!"
561 echo ' '
562 echo '#################### info'
563 cat "${td_info}" | sed 's/^/# /g'
564 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700565 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700566 echo '####################'
567 echo ' '
568 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700569
570) 1>&2
571
572# Clean up test files.
573if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
574 cd "$oldwd"
575 rm -rf "$tmp_dir"
576 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
577 adb shell rm -rf $DEX_LOCATION
578 fi
579 if [ "$good" = "yes" ]; then
580 exit 0
581 fi
582fi
583
584
585(
586 if [ "$always_clean" = "yes" ]; then
587 echo "${TEST_NAME} files deleted from host "
588 if [ "$target_mode" == "yes" ]; then
589 echo "and from target"
590 fi
591 else
592 echo "${TEST_NAME} files left in ${tmp_dir} on host"
593 if [ "$target_mode" == "yes" ]; then
594 echo "and in ${DEX_LOCATION} on target"
595 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700596 fi
597
jeffhao5d1ac922011-09-29 17:41:15 -0700598) 1>&2
599
600exit 1