blob: 945abb15359348ec1f2190b271025e8570c4f57b [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"
jeffhao5d1ac922011-09-29 17:41:15 -070098
99while true; do
100 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700101 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700102 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100103 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700104 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800105 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700106 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800107 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700108 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700109 NEED_DEX="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100110 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700111 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800112 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700113 lib="libart.so"
114 shift
115 elif [ "x$1" = "x--dalvik" ]; then
116 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800117 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700118 shift
Alex Light03a112d2014-08-25 13:25:56 -0700119 elif [ "x$1" = "x--no-dex2oat" ]; then
120 have_dex2oat="no"
121 shift
122 elif [ "x$1" = "x--no-patchoat" ]; then
123 have_patchoat="no"
124 shift
125 elif [ "x$1" = "x--no-image" ]; then
126 have_image="no"
127 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700128 elif [ "x$1" = "x--relocate" ]; then
129 relocate="yes"
130 shift
131 elif [ "x$1" = "x--no-relocate" ]; then
132 relocate="no"
133 shift
134 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100135 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700136 prebuild_mode="yes"
137 shift;
138 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100139 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700140 prebuild_mode="no"
141 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700142 elif [ "x$1" = "x--gcverify" ]; then
143 basic_verify="true"
144 gc_verify="true"
145 shift
146 elif [ "x$1" = "x--gcstress" ]; then
147 basic_verify="true"
148 gc_stress="true"
149 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700150 elif [ "x$1" = "x--image" ]; then
151 shift
152 image="$1"
153 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700154 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000155 elif [ "x$1" = "x-Xcompiler-option" ]; then
156 shift
157 option="$1"
158 run_args="${run_args} -Xcompiler-option $option"
159 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700160 elif [ "x$1" = "x--runtime-option" ]; then
161 shift
162 option="$1"
163 run_args="${run_args} --runtime-option $option"
164 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700165 elif [ "x$1" = "x--debug" ]; then
166 run_args="${run_args} --debug"
167 shift
168 elif [ "x$1" = "x--gdb" ]; then
169 run_args="${run_args} --gdb"
170 dev_mode="yes"
171 shift
172 elif [ "x$1" = "x--zygote" ]; then
173 run_args="${run_args} --zygote"
174 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800175 elif [ "x$1" = "x--interpreter" ]; then
176 run_args="${run_args} --interpreter"
177 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700178 elif [ "x$1" = "x--no-verify" ]; then
179 run_args="${run_args} --no-verify"
180 shift
181 elif [ "x$1" = "x--no-optimize" ]; then
182 run_args="${run_args} --no-optimize"
183 shift
184 elif [ "x$1" = "x--no-precise" ]; then
185 run_args="${run_args} --no-precise"
186 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700187 elif [ "x$1" = "x--invoke-with" ]; then
188 shift
189 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700190 if [ "x$what" = "x" ]; then
191 echo "$0 missing argument to --invoke-with" 1>&2
192 usage="yes"
193 break
194 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700195 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700196 shift
197 elif [ "x$1" = "x--dev" ]; then
198 run_args="${run_args} --dev"
199 dev_mode="yes"
200 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700201 elif [ "x$1" = "x--build-only" ]; then
202 build_only="yes"
203 shift
204 elif [ "x$1" = "x--output-path" ]; then
205 shift
206 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700207 if [ "x$tmp_dir" = "x" ]; then
208 echo "$0 missing argument to --output-path" 1>&2
209 usage="yes"
210 break
211 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700212 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700213 elif [ "x$1" = "x--update" ]; then
214 update_mode="yes"
215 shift
216 elif [ "x$1" = "x--help" ]; then
217 usage="yes"
218 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700219 elif [ "x$1" = "x--64" ]; then
220 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700221 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700222 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200223 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700224 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200225 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700226 elif [ "x$1" = "x--always-clean" ]; then
227 always_clean="yes"
228 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700229 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700230 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700231 usage="yes"
232 break
233 else
234 break
235 fi
236done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700237
238# tmp_dir may be relative, resolve.
239#
240# Cannot use realpath, as it does not exist on Mac.
241# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700242# Cannot use readlink -m, as it does not exist on Mac.
243# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700244noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700245tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700246mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700247
Alex Lighte7873ec2014-08-12 09:53:50 -0700248if [ "$basic_verify" = "true" ]; then
249 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify"
250fi
251if [ "$gc_verify" = "true" ]; then
252 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
253fi
254if [ "$gc_stress" = "true" ]; then
255 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
256fi
Jeff Hao85139a32014-07-23 11:52:52 -0700257if [ "$trace" = "true" ]; then
258 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
259fi
260
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700261# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100262# 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 -0700263function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100264 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
265 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700266 if [ "x${suffix64}" = "x64" ]; then
267 target_arch_name=${grep64bit}
268 else
269 target_arch_name=${grep32bit}
270 fi
271}
272
Alex Lighta59dd802014-07-02 16:28:08 -0700273if [ "$target_mode" = "no" ]; then
274 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700275 if [ "$prebuild_mode" = "yes" ]; then
276 echo "--prebuild with --jvm is unsupported";
277 exit 1;
278 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700279 fi
280fi
281
Alex Light03a112d2014-08-25 13:25:56 -0700282if [ "$have_patchoat" = "no" ]; then
283 run_args="${run_args} --no-patchoat"
284fi
285
286if [ "$have_dex2oat" = "no" ]; then
287 run_args="${run_args} --no-dex2oat"
288fi
289
Jeff Hao201803f2013-11-20 18:11:39 -0800290if [ ! "$runtime" = "jvm" ]; then
291 run_args="${run_args} --lib $lib"
292fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700293
Jeff Hao201803f2013-11-20 18:11:39 -0800294if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700295 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100296 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700297 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
298 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
299 else
300 true # defaults to using target BOOTCLASSPATH
301 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800302elif [ "$runtime" = "art" ]; then
303 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100304 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800305 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100306 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800307 fi
308 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100309 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800310 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800311 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700312 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800313 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700314 guess_arch_name
315 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700316 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800317 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700318 if [ "$relocate" = "yes" ]; then
319 run_args="${run_args} --relocate"
320 else
321 run_args="${run_args} --no-relocate"
322 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700323fi
324
Alex Light03a112d2014-08-25 13:25:56 -0700325if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700326 if [ "$runtime" != "art" ]; then
327 echo "--no-image is only supported on the art runtime"
328 exit 1
329 fi
330 if [ "$target_mode" = "no" ]; then
331 framework="${ANDROID_HOST_OUT}/framework"
332 bpath_suffix="-hostdex"
333 else
334 framework="/system/framework"
335 bpath_suffix=""
336 fi
337 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
338 # fail since these jar files will be stripped.
339 bpath="${framework}/core-libart${bpath_suffix}.jar"
340 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
341 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
342 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
343 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
344 # Pass down the bootclasspath
345 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700346 run_args="${run_args} --no-image"
347fi
348
jeffhao5d1ac922011-09-29 17:41:15 -0700349if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
350 echo "--dev and --update are mutually exclusive" 1>&2
351 usage="yes"
352fi
353
354if [ "$usage" = "no" ]; then
355 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
356 test_dir=`basename "$oldwd"`
357 else
358 test_dir="$1"
359 fi
360
361 if [ '!' -d "$test_dir" ]; then
362 td2=`echo ${test_dir}-*`
363 if [ '!' -d "$td2" ]; then
364 echo "${test_dir}: no such test directory" 1>&2
365 usage="yes"
366 fi
367 test_dir="$td2"
368 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700369 # Shift to get rid of the test name argument. The rest of the arguments
370 # will get passed to the test run.
371 shift
372fi
373
374if [ "$usage" = "yes" ]; then
375 prog=`basename $prog`
376 (
377 echo "usage:"
378 echo " $prog --help Print this message."
379 echo " $prog [options] [test-name] Run test normally."
380 echo " $prog --dev [options] [test-name] Development mode" \
381 "(dumps to stdout)."
382 echo " $prog --update [options] [test-name] Update mode" \
383 "(replaces expected.txt)."
384 echo ' Omitting the test name or specifying "-" will use the' \
385 "current directory."
386 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000387 echo " -O Run non-debug rather than debug build (off by default)."
388 echo " -Xcompiler-option Pass an option to the compiler."
Ian Rogers701aa642014-07-18 11:38:13 -0700389 echo " --runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000390 echo " --debug Wait for a debugger to attach."
391 echo " --gdb Run under gdb; incompatible with some tests."
392 echo " --build-only Build test files only (off by default)."
393 echo " --interpreter Enable interpreter only mode (off by default)."
394 echo " --no-verify Turn off verification (on by default)."
395 echo " --no-optimize Turn off optimization (on by default)."
396 echo " --no-precise Turn off precise GC (on by default)."
397 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700398 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000399 echo " other runtime options are ignored."
Alex Light03a112d2014-08-25 13:25:56 -0700400 echo " --no-dex2oat Run as though dex2oat was failing."
401 echo " --no-patchoat Run as though patchoat was failing."
Alex Light9d722532014-07-22 18:07:12 -0700402 echo " --prebuild Run dex2oat on the files before starting test. (default)"
Alex Lighta59dd802014-07-02 16:28:08 -0700403 echo " --no-prebuild Do not run dex2oat on the files before starting"
Alex Light9d722532014-07-22 18:07:12 -0700404 echo " the test."
Alex Lighta59dd802014-07-02 16:28:08 -0700405 echo " --relocate Force the use of relocating in the test, making"
406 echo " the image and oat files be relocated to a random"
407 echo " address before running. (default)"
408 echo " --no-relocate Force the use of no relocating in the test"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000409 echo " --host Use the host-mode virtual machine."
410 echo " --invoke-with Pass --invoke-with option to runtime."
411 echo " --dalvik Use Dalvik (off by default)."
412 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700413 echo " --output-path [path] Location where to store the build" \
414 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700415 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200416 echo " --trace Run with method tracing"
Alex Lighte7873ec2014-08-12 09:53:50 -0700417 echo " --gcstress Run with gc stress testing"
418 echo " --gcverify Run with gc verification"
Alex Lightbfac14a2014-07-30 09:41:21 -0700419 echo " --always-clean Delete the test files even if the test fails."
jeffhao5d1ac922011-09-29 17:41:15 -0700420 ) 1>&2
421 exit 1
422fi
423
424cd "$test_dir"
425test_dir=`pwd`
426
427td_info="${test_dir}/${info}"
428td_expected="${test_dir}/${expected}"
429
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700430if [ ! -r $td_info ]; then
431 echo "${test_dir}: missing file $td_info" 1>&2
432 exit 1
433fi
434
435if [ ! -r $td_expected ]; then
436 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700437 exit 1
438fi
439
440# copy the test to a temp dir and run it
441
Elliott Hughes510c8782011-10-06 10:57:34 -0700442echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700443
444rm -rf "$tmp_dir"
445cp -Rp "$test_dir" "$tmp_dir"
446cd "$tmp_dir"
447
448if [ '!' -r "$build" ]; then
449 cp "${progdir}/etc/default-build" build
450fi
451
452if [ '!' -r "$run" ]; then
453 cp "${progdir}/etc/default-run" run
454fi
455
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700456if [ '!' -r "$check_cmd" ]; then
457 cp "${progdir}/etc/default-check" check
458fi
459
jeffhao5d1ac922011-09-29 17:41:15 -0700460chmod 755 "$build"
461chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700462chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700463
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700464export TEST_NAME=`basename ${test_dir}`
465
Ian Rogers997f0f92014-06-21 22:58:05 -0700466# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
467file_size_limit=2048
468if echo "$test_dir" | grep 089; then
469 file_size_limit=5120
470elif echo "$test_dir" | grep 083; then
471 file_size_limit=5120
472fi
Alex Lighta59dd802014-07-02 16:28:08 -0700473if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700474 echo "ulimit file size setting failed"
475fi
476
jeffhao5d1ac922011-09-29 17:41:15 -0700477good="no"
478if [ "$dev_mode" = "yes" ]; then
479 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700480 build_exit="$?"
481 echo "build exit status: $build_exit" 1>&2
482 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800483 echo "${test_dir}: running..." 1>&2
484 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700485 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800486 echo "run exit status: $run_exit" 1>&2
487 if [ "$run_exit" = "0" ]; then
488 good="yes"
489 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700490 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700491elif [ "$update_mode" = "yes" ]; then
492 "./${build}" >"$build_output" 2>&1
493 build_exit="$?"
494 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800495 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700496 "./${run}" $run_args "$@" >"$output" 2>&1
497 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
498 good="yes"
499 else
500 cat "$build_output" 1>&2
501 echo "build exit status: $build_exit" 1>&2
502 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700503elif [ "$build_only" = "yes" ]; then
504 good="yes"
505 "./${build}" >"$build_output" 2>&1
506 build_exit="$?"
507 if [ "$build_exit" '!=' '0' ]; then
508 cp "$build_output" "$output"
509 echo "build exit status: $build_exit" >>"$output"
510 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
511 if [ "$?" '!=' "0" ]; then
512 good="no"
513 echo "BUILD FAILED For ${TEST_NAME}"
514 fi
515 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700516 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700517 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700518 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700519else
520 "./${build}" >"$build_output" 2>&1
521 build_exit="$?"
522 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800523 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700524 "./${run}" $run_args "$@" >"$output" 2>&1
525 else
526 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700527 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
528 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700529 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700530 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700531 max_name_length=$(getconf NAME_MAX ${tmp_dir})
532 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
533 max_path_length=$(getconf PATH_MAX ${tmp_dir})
534 echo "Max pathlength (PATH_MAX): ${max_path_lenght}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700535 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700536 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700537 if [ "$?" = "0" ]; then
538 # output == expected
539 good="yes"
540 echo "${test_dir}: succeeded!" 1>&2
541 fi
542fi
543
jeffhao5d1ac922011-09-29 17:41:15 -0700544(
Alex Lightbfac14a2014-07-30 09:41:21 -0700545 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700546 echo "${test_dir}: FAILED!"
547 echo ' '
548 echo '#################### info'
549 cat "${td_info}" | sed 's/^/# /g'
550 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700551 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700552 echo '####################'
553 echo ' '
554 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700555
556) 1>&2
557
558# Clean up test files.
559if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
560 cd "$oldwd"
561 rm -rf "$tmp_dir"
562 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
563 adb shell rm -rf $DEX_LOCATION
564 fi
565 if [ "$good" = "yes" ]; then
566 exit 0
567 fi
568fi
569
570
571(
572 if [ "$always_clean" = "yes" ]; then
573 echo "${TEST_NAME} files deleted from host "
574 if [ "$target_mode" == "yes" ]; then
575 echo "and from target"
576 fi
577 else
578 echo "${TEST_NAME} files left in ${tmp_dir} on host"
579 if [ "$target_mode" == "yes" ]; then
580 echo "and in ${DEX_LOCATION} on target"
581 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700582 fi
583
jeffhao5d1ac922011-09-29 17:41:15 -0700584) 1>&2
585
586exit 1