blob: d184ea2b5846bfba048914aa8487946200525be4 [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-$$"
Andreas Gampe5a79fde2014-08-06 13:12:26 -070036if [ -z "$TMPDIR" ]; then
37 tmp_dir="/tmp/$USER/${test_dir}"
38else
39 tmp_dir="${TMPDIR}/$USER/${test_dir}"
40fi
jeffhao5d1ac922011-09-29 17:41:15 -070041
42export JAVA="java"
Brian Carlstrom5103ce62014-03-30 16:17:42 -070043export JAVAC="javac -g"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010044export RUN="${progdir}/etc/run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070045export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070046export NEED_DEX="true"
jeffhao5d1ac922011-09-29 17:41:15 -070047
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070048# If dx was not set by the environment variable, assume it is in the path.
49if [ -z "$DX" ]; then
50 export DX="dx"
51fi
52
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080053# If jasmin was not set by the environment variable, assume it is in the path.
54if [ -z "$JASMIN" ]; then
55 export JASMIN="jasmin"
56fi
57
58
jeffhao5d1ac922011-09-29 17:41:15 -070059info="info.txt"
60build="build"
61run="run"
62expected="expected.txt"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -070063check_cmd="check"
jeffhao5d1ac922011-09-29 17:41:15 -070064output="output.txt"
65build_output="build-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070066lib="libartd.so"
jeffhao5d1ac922011-09-29 17:41:15 -070067run_args="--quiet"
68
Alex Light9d722532014-07-22 18:07:12 -070069prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -070070target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070071dev_mode="no"
72update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -070073debug_mode="no"
74relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -080075runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070076usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070077build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070078suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -070079trace="false"
Alex Lighte7873ec2014-08-12 09:53:50 -070080basic_verify="false"
81gc_verify="false"
82gc_stress="false"
Alex Lightbfac14a2014-07-30 09:41:21 -070083always_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -070084have_dex2oat="yes"
85have_patchoat="yes"
86have_image="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070087
88while true; do
89 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070090 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -070091 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010092 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -070093 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080094 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070095 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -080096 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -070097 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -070098 NEED_DEX="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010099 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700100 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800101 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700102 lib="libart.so"
103 shift
104 elif [ "x$1" = "x--dalvik" ]; then
105 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800106 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700107 shift
Alex Light03a112d2014-08-25 13:25:56 -0700108 elif [ "x$1" = "x--no-dex2oat" ]; then
109 have_dex2oat="no"
110 shift
111 elif [ "x$1" = "x--no-patchoat" ]; then
112 have_patchoat="no"
113 shift
114 elif [ "x$1" = "x--no-image" ]; then
115 have_image="no"
116 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700117 elif [ "x$1" = "x--relocate" ]; then
118 relocate="yes"
119 shift
120 elif [ "x$1" = "x--no-relocate" ]; then
121 relocate="no"
122 shift
123 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100124 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700125 prebuild_mode="yes"
126 shift;
127 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100128 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700129 prebuild_mode="no"
130 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700131 elif [ "x$1" = "x--gcverify" ]; then
132 basic_verify="true"
133 gc_verify="true"
134 shift
135 elif [ "x$1" = "x--gcstress" ]; then
136 basic_verify="true"
137 gc_stress="true"
138 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700139 elif [ "x$1" = "x--image" ]; then
140 shift
141 image="$1"
142 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700143 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000144 elif [ "x$1" = "x-Xcompiler-option" ]; then
145 shift
146 option="$1"
147 run_args="${run_args} -Xcompiler-option $option"
148 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700149 elif [ "x$1" = "x--runtime-option" ]; then
150 shift
151 option="$1"
152 run_args="${run_args} --runtime-option $option"
153 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700154 elif [ "x$1" = "x--debug" ]; then
155 run_args="${run_args} --debug"
156 shift
157 elif [ "x$1" = "x--gdb" ]; then
158 run_args="${run_args} --gdb"
159 dev_mode="yes"
160 shift
161 elif [ "x$1" = "x--zygote" ]; then
162 run_args="${run_args} --zygote"
163 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800164 elif [ "x$1" = "x--interpreter" ]; then
165 run_args="${run_args} --interpreter"
166 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700167 elif [ "x$1" = "x--no-verify" ]; then
168 run_args="${run_args} --no-verify"
169 shift
170 elif [ "x$1" = "x--no-optimize" ]; then
171 run_args="${run_args} --no-optimize"
172 shift
173 elif [ "x$1" = "x--no-precise" ]; then
174 run_args="${run_args} --no-precise"
175 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700176 elif [ "x$1" = "x--invoke-with" ]; then
177 shift
178 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700179 if [ "x$what" = "x" ]; then
180 echo "$0 missing argument to --invoke-with" 1>&2
181 usage="yes"
182 break
183 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700184 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700185 shift
186 elif [ "x$1" = "x--dev" ]; then
187 run_args="${run_args} --dev"
188 dev_mode="yes"
189 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700190 elif [ "x$1" = "x--build-only" ]; then
191 build_only="yes"
192 shift
193 elif [ "x$1" = "x--output-path" ]; then
194 shift
195 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700196 if [ "x$tmp_dir" = "x" ]; then
197 echo "$0 missing argument to --output-path" 1>&2
198 usage="yes"
199 break
200 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700201 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700202 elif [ "x$1" = "x--update" ]; then
203 update_mode="yes"
204 shift
205 elif [ "x$1" = "x--help" ]; then
206 usage="yes"
207 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700208 elif [ "x$1" = "x--64" ]; then
209 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700210 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700211 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200212 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700213 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200214 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700215 elif [ "x$1" = "x--always-clean" ]; then
216 always_clean="yes"
217 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700218 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700219 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700220 usage="yes"
221 break
222 else
223 break
224 fi
225done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700226
227# tmp_dir may be relative, resolve.
228#
229# Cannot use realpath, as it does not exist on Mac.
230# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700231# Cannot use readlink -m, as it does not exist on Mac.
232# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700233noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700234tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700235mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700236
Alex Lighte7873ec2014-08-12 09:53:50 -0700237if [ "$basic_verify" = "true" ]; then
238 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify"
239fi
240if [ "$gc_verify" = "true" ]; then
241 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
242fi
243if [ "$gc_stress" = "true" ]; then
244 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
245fi
Jeff Hao85139a32014-07-23 11:52:52 -0700246if [ "$trace" = "true" ]; then
247 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
248fi
249
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700250# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100251# 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 -0700252function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100253 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
254 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700255 if [ "x${suffix64}" = "x64" ]; then
256 target_arch_name=${grep64bit}
257 else
258 target_arch_name=${grep32bit}
259 fi
260}
261
Alex Lighta59dd802014-07-02 16:28:08 -0700262if [ "$target_mode" = "no" ]; then
263 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700264 if [ "$prebuild_mode" = "yes" ]; then
265 echo "--prebuild with --jvm is unsupported";
266 exit 1;
267 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700268 fi
269fi
270
Alex Light03a112d2014-08-25 13:25:56 -0700271if [ "$have_patchoat" = "no" ]; then
272 run_args="${run_args} --no-patchoat"
273fi
274
275if [ "$have_dex2oat" = "no" ]; then
276 run_args="${run_args} --no-dex2oat"
277fi
278
Jeff Hao201803f2013-11-20 18:11:39 -0800279if [ ! "$runtime" = "jvm" ]; then
280 run_args="${run_args} --lib $lib"
281fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700282
Jeff Hao201803f2013-11-20 18:11:39 -0800283if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700284 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100285 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700286 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
287 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
288 else
289 true # defaults to using target BOOTCLASSPATH
290 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800291elif [ "$runtime" = "art" ]; then
292 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100293 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800294 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100295 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800296 fi
297 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100298 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800299 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800300 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700301 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800302 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700303 guess_arch_name
304 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700305 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800306 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700307 if [ "$relocate" = "yes" ]; then
308 run_args="${run_args} --relocate"
309 else
310 run_args="${run_args} --no-relocate"
311 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700312fi
313
Alex Light03a112d2014-08-25 13:25:56 -0700314if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700315 if [ "$runtime" != "art" ]; then
316 echo "--no-image is only supported on the art runtime"
317 exit 1
318 fi
319 if [ "$target_mode" = "no" ]; then
320 framework="${ANDROID_HOST_OUT}/framework"
321 bpath_suffix="-hostdex"
322 else
323 framework="/system/framework"
324 bpath_suffix=""
325 fi
326 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
327 # fail since these jar files will be stripped.
328 bpath="${framework}/core-libart${bpath_suffix}.jar"
329 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
330 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
331 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
332 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
333 # Pass down the bootclasspath
334 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700335 run_args="${run_args} --no-image"
336fi
337
jeffhao5d1ac922011-09-29 17:41:15 -0700338if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
339 echo "--dev and --update are mutually exclusive" 1>&2
340 usage="yes"
341fi
342
343if [ "$usage" = "no" ]; then
344 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
345 test_dir=`basename "$oldwd"`
346 else
347 test_dir="$1"
348 fi
349
350 if [ '!' -d "$test_dir" ]; then
351 td2=`echo ${test_dir}-*`
352 if [ '!' -d "$td2" ]; then
353 echo "${test_dir}: no such test directory" 1>&2
354 usage="yes"
355 fi
356 test_dir="$td2"
357 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700358 # Shift to get rid of the test name argument. The rest of the arguments
359 # will get passed to the test run.
360 shift
361fi
362
363if [ "$usage" = "yes" ]; then
364 prog=`basename $prog`
365 (
366 echo "usage:"
367 echo " $prog --help Print this message."
368 echo " $prog [options] [test-name] Run test normally."
369 echo " $prog --dev [options] [test-name] Development mode" \
370 "(dumps to stdout)."
371 echo " $prog --update [options] [test-name] Update mode" \
372 "(replaces expected.txt)."
373 echo ' Omitting the test name or specifying "-" will use the' \
374 "current directory."
375 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000376 echo " -O Run non-debug rather than debug build (off by default)."
377 echo " -Xcompiler-option Pass an option to the compiler."
Ian Rogers701aa642014-07-18 11:38:13 -0700378 echo " --runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000379 echo " --debug Wait for a debugger to attach."
380 echo " --gdb Run under gdb; incompatible with some tests."
381 echo " --build-only Build test files only (off by default)."
382 echo " --interpreter Enable interpreter only mode (off by default)."
383 echo " --no-verify Turn off verification (on by default)."
384 echo " --no-optimize Turn off optimization (on by default)."
385 echo " --no-precise Turn off precise GC (on by default)."
386 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700387 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000388 echo " other runtime options are ignored."
Alex Light03a112d2014-08-25 13:25:56 -0700389 echo " --no-dex2oat Run as though dex2oat was failing."
390 echo " --no-patchoat Run as though patchoat was failing."
Alex Light9d722532014-07-22 18:07:12 -0700391 echo " --prebuild Run dex2oat on the files before starting test. (default)"
Alex Lighta59dd802014-07-02 16:28:08 -0700392 echo " --no-prebuild Do not run dex2oat on the files before starting"
Alex Light9d722532014-07-22 18:07:12 -0700393 echo " the test."
Alex Lighta59dd802014-07-02 16:28:08 -0700394 echo " --relocate Force the use of relocating in the test, making"
395 echo " the image and oat files be relocated to a random"
396 echo " address before running. (default)"
397 echo " --no-relocate Force the use of no relocating in the test"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000398 echo " --host Use the host-mode virtual machine."
399 echo " --invoke-with Pass --invoke-with option to runtime."
400 echo " --dalvik Use Dalvik (off by default)."
401 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700402 echo " --output-path [path] Location where to store the build" \
403 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700404 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200405 echo " --trace Run with method tracing"
Alex Lighte7873ec2014-08-12 09:53:50 -0700406 echo " --gcstress Run with gc stress testing"
407 echo " --gcverify Run with gc verification"
Alex Lightbfac14a2014-07-30 09:41:21 -0700408 echo " --always-clean Delete the test files even if the test fails."
jeffhao5d1ac922011-09-29 17:41:15 -0700409 ) 1>&2
410 exit 1
411fi
412
413cd "$test_dir"
414test_dir=`pwd`
415
416td_info="${test_dir}/${info}"
417td_expected="${test_dir}/${expected}"
418
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700419if [ ! -r $td_info ]; then
420 echo "${test_dir}: missing file $td_info" 1>&2
421 exit 1
422fi
423
424if [ ! -r $td_expected ]; then
425 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700426 exit 1
427fi
428
429# copy the test to a temp dir and run it
430
Elliott Hughes510c8782011-10-06 10:57:34 -0700431echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700432
433rm -rf "$tmp_dir"
434cp -Rp "$test_dir" "$tmp_dir"
435cd "$tmp_dir"
436
437if [ '!' -r "$build" ]; then
438 cp "${progdir}/etc/default-build" build
439fi
440
441if [ '!' -r "$run" ]; then
442 cp "${progdir}/etc/default-run" run
443fi
444
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700445if [ '!' -r "$check_cmd" ]; then
446 cp "${progdir}/etc/default-check" check
447fi
448
jeffhao5d1ac922011-09-29 17:41:15 -0700449chmod 755 "$build"
450chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700451chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700452
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700453export TEST_NAME=`basename ${test_dir}`
454
Ian Rogers997f0f92014-06-21 22:58:05 -0700455# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
456file_size_limit=2048
457if echo "$test_dir" | grep 089; then
458 file_size_limit=5120
459elif echo "$test_dir" | grep 083; then
460 file_size_limit=5120
Andreas Gampe855564b2014-07-25 02:32:19 -0700461elif echo "$test_dir" | grep 115; then
462# Native bridge test copies libarttest.so into its directory, which needs 2MB already.
463 file_size_limit=5120
Ian Rogers997f0f92014-06-21 22:58:05 -0700464fi
Alex Lighta59dd802014-07-02 16:28:08 -0700465if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700466 echo "ulimit file size setting failed"
467fi
468
jeffhao5d1ac922011-09-29 17:41:15 -0700469good="no"
470if [ "$dev_mode" = "yes" ]; then
471 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700472 build_exit="$?"
473 echo "build exit status: $build_exit" 1>&2
474 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800475 echo "${test_dir}: running..." 1>&2
476 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700477 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800478 echo "run exit status: $run_exit" 1>&2
479 if [ "$run_exit" = "0" ]; then
480 good="yes"
481 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700482 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700483elif [ "$update_mode" = "yes" ]; then
484 "./${build}" >"$build_output" 2>&1
485 build_exit="$?"
486 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800487 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700488 "./${run}" $run_args "$@" >"$output" 2>&1
489 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
490 good="yes"
491 else
492 cat "$build_output" 1>&2
493 echo "build exit status: $build_exit" 1>&2
494 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700495elif [ "$build_only" = "yes" ]; then
496 good="yes"
497 "./${build}" >"$build_output" 2>&1
498 build_exit="$?"
499 if [ "$build_exit" '!=' '0' ]; then
500 cp "$build_output" "$output"
501 echo "build exit status: $build_exit" >>"$output"
502 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
503 if [ "$?" '!=' "0" ]; then
504 good="no"
505 echo "BUILD FAILED For ${TEST_NAME}"
506 fi
507 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700508 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700509 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700510 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700511else
512 "./${build}" >"$build_output" 2>&1
513 build_exit="$?"
514 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800515 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700516 "./${run}" $run_args "$@" >"$output" 2>&1
517 else
518 cp "$build_output" "$output"
Andreas Gampe907b6992014-08-18 22:26:49 -0700519 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`"
520 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}"
jeffhao5d1ac922011-09-29 17:41:15 -0700521 echo "build exit status: $build_exit" >>"$output"
522 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700523 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700524 if [ "$?" = "0" ]; then
525 # output == expected
526 good="yes"
527 echo "${test_dir}: succeeded!" 1>&2
528 fi
529fi
530
jeffhao5d1ac922011-09-29 17:41:15 -0700531(
Alex Lightbfac14a2014-07-30 09:41:21 -0700532 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700533 echo "${test_dir}: FAILED!"
534 echo ' '
535 echo '#################### info'
536 cat "${td_info}" | sed 's/^/# /g'
537 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700538 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700539 echo '####################'
540 echo ' '
541 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700542
543) 1>&2
544
545# Clean up test files.
546if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
547 cd "$oldwd"
548 rm -rf "$tmp_dir"
549 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
550 adb shell rm -rf $DEX_LOCATION
551 fi
552 if [ "$good" = "yes" ]; then
553 exit 0
554 fi
555fi
556
557
558(
559 if [ "$always_clean" = "yes" ]; then
560 echo "${TEST_NAME} files deleted from host "
561 if [ "$target_mode" == "yes" ]; then
562 echo "and from target"
563 fi
564 else
565 echo "${TEST_NAME} files left in ${tmp_dir} on host"
566 if [ "$target_mode" == "yes" ]; then
567 echo "and in ${DEX_LOCATION} on target"
568 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700569 fi
570
jeffhao5d1ac922011-09-29 17:41:15 -0700571) 1>&2
572
573exit 1