blob: 3e98d6d09a2eabfac1a62c8184dd31d432a2f5b9 [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
Andreas Gampe8fda9f22014-10-03 16:15:37 -070058# If smali was not set by the environment variable, assume it is in the path.
59if [ -z "$SMALI" ]; then
60 export SMALI="smali"
61fi
62
63# If dexmerger was not set by the environment variable, assume it is in the path.
64if [ -z "$DXMERGER" ]; then
65 export DXMERGER="dexmerger"
66fi
67
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080068
jeffhao5d1ac922011-09-29 17:41:15 -070069info="info.txt"
70build="build"
71run="run"
72expected="expected.txt"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -070073check_cmd="check"
jeffhao5d1ac922011-09-29 17:41:15 -070074output="output.txt"
75build_output="build-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070076lib="libartd.so"
jeffhao5d1ac922011-09-29 17:41:15 -070077run_args="--quiet"
78
Alex Light9d722532014-07-22 18:07:12 -070079prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -070080target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070081dev_mode="no"
82update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -070083debug_mode="no"
84relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -080085runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070086usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070087build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070088suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -070089trace="false"
Alex Lighte7873ec2014-08-12 09:53:50 -070090basic_verify="false"
91gc_verify="false"
92gc_stress="false"
Alex Lightbfac14a2014-07-30 09:41:21 -070093always_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -070094have_dex2oat="yes"
95have_patchoat="yes"
96have_image="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070097
98while true; do
99 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700100 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700101 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100102 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700103 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800104 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700105 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800106 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700107 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700108 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -0700109 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800110 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700111 lib="libart.so"
112 shift
113 elif [ "x$1" = "x--dalvik" ]; then
114 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800115 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700116 shift
Alex Light03a112d2014-08-25 13:25:56 -0700117 elif [ "x$1" = "x--no-dex2oat" ]; then
118 have_dex2oat="no"
119 shift
120 elif [ "x$1" = "x--no-patchoat" ]; then
121 have_patchoat="no"
122 shift
123 elif [ "x$1" = "x--no-image" ]; then
124 have_image="no"
125 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700126 elif [ "x$1" = "x--relocate" ]; then
127 relocate="yes"
128 shift
129 elif [ "x$1" = "x--no-relocate" ]; then
130 relocate="no"
131 shift
132 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100133 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700134 prebuild_mode="yes"
135 shift;
136 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100137 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700138 prebuild_mode="no"
139 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700140 elif [ "x$1" = "x--gcverify" ]; then
141 basic_verify="true"
142 gc_verify="true"
143 shift
144 elif [ "x$1" = "x--gcstress" ]; then
145 basic_verify="true"
146 gc_stress="true"
147 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700148 elif [ "x$1" = "x--image" ]; then
149 shift
150 image="$1"
151 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700152 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000153 elif [ "x$1" = "x-Xcompiler-option" ]; then
154 shift
155 option="$1"
156 run_args="${run_args} -Xcompiler-option $option"
157 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700158 elif [ "x$1" = "x--runtime-option" ]; then
159 shift
160 option="$1"
161 run_args="${run_args} --runtime-option $option"
162 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700163 elif [ "x$1" = "x--debug" ]; then
164 run_args="${run_args} --debug"
165 shift
166 elif [ "x$1" = "x--gdb" ]; then
167 run_args="${run_args} --gdb"
168 dev_mode="yes"
169 shift
170 elif [ "x$1" = "x--zygote" ]; then
171 run_args="${run_args} --zygote"
172 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800173 elif [ "x$1" = "x--interpreter" ]; then
174 run_args="${run_args} --interpreter"
175 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700176 elif [ "x$1" = "x--no-verify" ]; then
177 run_args="${run_args} --no-verify"
178 shift
179 elif [ "x$1" = "x--no-optimize" ]; then
180 run_args="${run_args} --no-optimize"
181 shift
182 elif [ "x$1" = "x--no-precise" ]; then
183 run_args="${run_args} --no-precise"
184 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700185 elif [ "x$1" = "x--invoke-with" ]; then
186 shift
187 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700188 if [ "x$what" = "x" ]; then
189 echo "$0 missing argument to --invoke-with" 1>&2
190 usage="yes"
191 break
192 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700193 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700194 shift
195 elif [ "x$1" = "x--dev" ]; then
196 run_args="${run_args} --dev"
197 dev_mode="yes"
198 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700199 elif [ "x$1" = "x--build-only" ]; then
200 build_only="yes"
201 shift
202 elif [ "x$1" = "x--output-path" ]; then
203 shift
204 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700205 if [ "x$tmp_dir" = "x" ]; then
206 echo "$0 missing argument to --output-path" 1>&2
207 usage="yes"
208 break
209 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700210 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700211 elif [ "x$1" = "x--update" ]; then
212 update_mode="yes"
213 shift
214 elif [ "x$1" = "x--help" ]; then
215 usage="yes"
216 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700217 elif [ "x$1" = "x--64" ]; then
218 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700219 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700220 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200221 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700222 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200223 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700224 elif [ "x$1" = "x--always-clean" ]; then
225 always_clean="yes"
226 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700227 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700228 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700229 usage="yes"
230 break
231 else
232 break
233 fi
234done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700235
236# tmp_dir may be relative, resolve.
237#
238# Cannot use realpath, as it does not exist on Mac.
239# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700240# Cannot use readlink -m, as it does not exist on Mac.
241# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700242noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700243tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700244mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700245
Alex Lighte7873ec2014-08-12 09:53:50 -0700246if [ "$basic_verify" = "true" ]; then
247 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify"
248fi
249if [ "$gc_verify" = "true" ]; then
250 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
251fi
252if [ "$gc_stress" = "true" ]; then
253 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
254fi
Jeff Hao85139a32014-07-23 11:52:52 -0700255if [ "$trace" = "true" ]; then
256 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
257fi
258
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700259# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100260# 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 -0700261function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100262 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
263 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700264 if [ "x${suffix64}" = "x64" ]; then
265 target_arch_name=${grep64bit}
266 else
267 target_arch_name=${grep32bit}
268 fi
269}
270
Alex Lighta59dd802014-07-02 16:28:08 -0700271if [ "$target_mode" = "no" ]; then
272 if [ "$runtime" = "jvm" ]; then
273 RUN="${progdir}/etc/reference-run-test-classes"
274 if [ "$prebuild_mode" = "yes" ]; then
275 echo "--prebuild with --jvm is unsupported";
276 exit 1;
277 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700278 fi
279fi
280
Alex Light03a112d2014-08-25 13:25:56 -0700281if [ "$have_patchoat" = "no" ]; then
282 run_args="${run_args} --no-patchoat"
283fi
284
285if [ "$have_dex2oat" = "no" ]; then
286 run_args="${run_args} --no-dex2oat"
287fi
288
Jeff Hao201803f2013-11-20 18:11:39 -0800289if [ ! "$runtime" = "jvm" ]; then
290 run_args="${run_args} --lib $lib"
291fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700292
Jeff Hao201803f2013-11-20 18:11:39 -0800293if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700294 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100295 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700296 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
297 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
298 else
299 true # defaults to using target BOOTCLASSPATH
300 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800301elif [ "$runtime" = "art" ]; then
302 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100303 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800304 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100305 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800306 fi
307 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100308 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800309 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800310 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700311 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800312 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700313 guess_arch_name
314 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700315 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800316 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700317 if [ "$relocate" = "yes" ]; then
318 run_args="${run_args} --relocate"
319 else
320 run_args="${run_args} --no-relocate"
321 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700322fi
323
Alex Light03a112d2014-08-25 13:25:56 -0700324if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700325 if [ "$runtime" != "art" ]; then
326 echo "--no-image is only supported on the art runtime"
327 exit 1
328 fi
329 if [ "$target_mode" = "no" ]; then
330 framework="${ANDROID_HOST_OUT}/framework"
331 bpath_suffix="-hostdex"
332 else
333 framework="/system/framework"
334 bpath_suffix=""
335 fi
336 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
337 # fail since these jar files will be stripped.
338 bpath="${framework}/core-libart${bpath_suffix}.jar"
339 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
340 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
341 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
342 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
343 # Pass down the bootclasspath
344 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700345 run_args="${run_args} --no-image"
346fi
347
jeffhao5d1ac922011-09-29 17:41:15 -0700348if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
349 echo "--dev and --update are mutually exclusive" 1>&2
350 usage="yes"
351fi
352
353if [ "$usage" = "no" ]; then
354 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
355 test_dir=`basename "$oldwd"`
356 else
357 test_dir="$1"
358 fi
359
360 if [ '!' -d "$test_dir" ]; then
361 td2=`echo ${test_dir}-*`
362 if [ '!' -d "$td2" ]; then
363 echo "${test_dir}: no such test directory" 1>&2
364 usage="yes"
365 fi
366 test_dir="$td2"
367 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700368 # Shift to get rid of the test name argument. The rest of the arguments
369 # will get passed to the test run.
370 shift
371fi
372
373if [ "$usage" = "yes" ]; then
374 prog=`basename $prog`
375 (
376 echo "usage:"
377 echo " $prog --help Print this message."
378 echo " $prog [options] [test-name] Run test normally."
379 echo " $prog --dev [options] [test-name] Development mode" \
380 "(dumps to stdout)."
381 echo " $prog --update [options] [test-name] Update mode" \
382 "(replaces expected.txt)."
383 echo ' Omitting the test name or specifying "-" will use the' \
384 "current directory."
385 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000386 echo " -O Run non-debug rather than debug build (off by default)."
387 echo " -Xcompiler-option Pass an option to the compiler."
Ian Rogers701aa642014-07-18 11:38:13 -0700388 echo " --runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000389 echo " --debug Wait for a debugger to attach."
390 echo " --gdb Run under gdb; incompatible with some tests."
391 echo " --build-only Build test files only (off by default)."
392 echo " --interpreter Enable interpreter only mode (off by default)."
393 echo " --no-verify Turn off verification (on by default)."
394 echo " --no-optimize Turn off optimization (on by default)."
395 echo " --no-precise Turn off precise GC (on by default)."
396 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700397 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000398 echo " other runtime options are ignored."
Alex Light03a112d2014-08-25 13:25:56 -0700399 echo " --no-dex2oat Run as though dex2oat was failing."
400 echo " --no-patchoat Run as though patchoat was failing."
Alex Light9d722532014-07-22 18:07:12 -0700401 echo " --prebuild Run dex2oat on the files before starting test. (default)"
Alex Lighta59dd802014-07-02 16:28:08 -0700402 echo " --no-prebuild Do not run dex2oat on the files before starting"
Alex Light9d722532014-07-22 18:07:12 -0700403 echo " the test."
Alex Lighta59dd802014-07-02 16:28:08 -0700404 echo " --relocate Force the use of relocating in the test, making"
405 echo " the image and oat files be relocated to a random"
406 echo " address before running. (default)"
407 echo " --no-relocate Force the use of no relocating in the test"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000408 echo " --host Use the host-mode virtual machine."
409 echo " --invoke-with Pass --invoke-with option to runtime."
410 echo " --dalvik Use Dalvik (off by default)."
411 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700412 echo " --output-path [path] Location where to store the build" \
413 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700414 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200415 echo " --trace Run with method tracing"
Alex Lighte7873ec2014-08-12 09:53:50 -0700416 echo " --gcstress Run with gc stress testing"
417 echo " --gcverify Run with gc verification"
Alex Lightbfac14a2014-07-30 09:41:21 -0700418 echo " --always-clean Delete the test files even if the test fails."
jeffhao5d1ac922011-09-29 17:41:15 -0700419 ) 1>&2
420 exit 1
421fi
422
423cd "$test_dir"
424test_dir=`pwd`
425
426td_info="${test_dir}/${info}"
427td_expected="${test_dir}/${expected}"
428
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700429if [ ! -r $td_info ]; then
430 echo "${test_dir}: missing file $td_info" 1>&2
431 exit 1
432fi
433
434if [ ! -r $td_expected ]; then
435 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700436 exit 1
437fi
438
439# copy the test to a temp dir and run it
440
Elliott Hughes510c8782011-10-06 10:57:34 -0700441echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700442
443rm -rf "$tmp_dir"
444cp -Rp "$test_dir" "$tmp_dir"
445cd "$tmp_dir"
446
447if [ '!' -r "$build" ]; then
448 cp "${progdir}/etc/default-build" build
449fi
450
451if [ '!' -r "$run" ]; then
452 cp "${progdir}/etc/default-run" run
453fi
454
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700455if [ '!' -r "$check_cmd" ]; then
456 cp "${progdir}/etc/default-check" check
457fi
458
jeffhao5d1ac922011-09-29 17:41:15 -0700459chmod 755 "$build"
460chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700461chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700462
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700463export TEST_NAME=`basename ${test_dir}`
464
Ian Rogers997f0f92014-06-21 22:58:05 -0700465# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
466file_size_limit=2048
467if echo "$test_dir" | grep 089; then
468 file_size_limit=5120
469elif echo "$test_dir" | grep 083; then
470 file_size_limit=5120
Andreas Gampe855564b2014-07-25 02:32:19 -0700471elif echo "$test_dir" | grep 115; then
472# Native bridge test copies libarttest.so into its directory, which needs 2MB already.
473 file_size_limit=5120
Ian Rogers997f0f92014-06-21 22:58:05 -0700474fi
Alex Lighta59dd802014-07-02 16:28:08 -0700475if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700476 echo "ulimit file size setting failed"
477fi
478
jeffhao5d1ac922011-09-29 17:41:15 -0700479good="no"
480if [ "$dev_mode" = "yes" ]; then
481 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700482 build_exit="$?"
483 echo "build exit status: $build_exit" 1>&2
484 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800485 echo "${test_dir}: running..." 1>&2
486 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700487 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800488 echo "run exit status: $run_exit" 1>&2
489 if [ "$run_exit" = "0" ]; then
490 good="yes"
491 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700492 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700493elif [ "$update_mode" = "yes" ]; then
494 "./${build}" >"$build_output" 2>&1
495 build_exit="$?"
496 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800497 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700498 "./${run}" $run_args "$@" >"$output" 2>&1
499 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
500 good="yes"
501 else
502 cat "$build_output" 1>&2
503 echo "build exit status: $build_exit" 1>&2
504 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700505elif [ "$build_only" = "yes" ]; then
506 good="yes"
507 "./${build}" >"$build_output" 2>&1
508 build_exit="$?"
509 if [ "$build_exit" '!=' '0' ]; then
510 cp "$build_output" "$output"
511 echo "build exit status: $build_exit" >>"$output"
512 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
513 if [ "$?" '!=' "0" ]; then
514 good="no"
515 echo "BUILD FAILED For ${TEST_NAME}"
516 fi
517 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700518 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700519 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700520 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700521else
522 "./${build}" >"$build_output" 2>&1
523 build_exit="$?"
524 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800525 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700526 "./${run}" $run_args "$@" >"$output" 2>&1
527 else
528 cp "$build_output" "$output"
Andreas Gampe907b6992014-08-18 22:26:49 -0700529 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`"
530 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}"
jeffhao5d1ac922011-09-29 17:41:15 -0700531 echo "build exit status: $build_exit" >>"$output"
532 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700533 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700534 if [ "$?" = "0" ]; then
535 # output == expected
536 good="yes"
537 echo "${test_dir}: succeeded!" 1>&2
538 fi
539fi
540
jeffhao5d1ac922011-09-29 17:41:15 -0700541(
Alex Lightbfac14a2014-07-30 09:41:21 -0700542 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700543 echo "${test_dir}: FAILED!"
544 echo ' '
545 echo '#################### info'
546 cat "${td_info}" | sed 's/^/# /g'
547 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700548 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700549 echo '####################'
550 echo ' '
551 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700552
553) 1>&2
554
555# Clean up test files.
556if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
557 cd "$oldwd"
558 rm -rf "$tmp_dir"
559 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
560 adb shell rm -rf $DEX_LOCATION
561 fi
562 if [ "$good" = "yes" ]; then
563 exit 0
564 fi
565fi
566
567
568(
569 if [ "$always_clean" = "yes" ]; then
570 echo "${TEST_NAME} files deleted from host "
571 if [ "$target_mode" == "yes" ]; then
572 echo "and from target"
573 fi
574 else
575 echo "${TEST_NAME} files left in ${tmp_dir} on host"
576 if [ "$target_mode" == "yes" ]; then
577 echo "and in ${DEX_LOCATION} on target"
578 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700579 fi
580
jeffhao5d1ac922011-09-29 17:41:15 -0700581) 1>&2
582
583exit 1