blob: b7c0ecf7fb9f2031d5b3c7d8b672b11ec98b0f7a [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=""
jeffhao5d1ac922011-09-29 17:41:15 -070099
100while true; do
101 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700102 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700103 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100104 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700105 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800106 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700107 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800108 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700109 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700110 NEED_DEX="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100111 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700112 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800113 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700114 lib="libart.so"
115 shift
116 elif [ "x$1" = "x--dalvik" ]; then
117 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800118 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700119 shift
Alex Light03a112d2014-08-25 13:25:56 -0700120 elif [ "x$1" = "x--no-dex2oat" ]; then
121 have_dex2oat="no"
122 shift
123 elif [ "x$1" = "x--no-patchoat" ]; then
124 have_patchoat="no"
125 shift
126 elif [ "x$1" = "x--no-image" ]; then
127 have_image="no"
128 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700129 elif [ "x$1" = "x--relocate" ]; then
130 relocate="yes"
131 shift
132 elif [ "x$1" = "x--no-relocate" ]; then
133 relocate="no"
134 shift
135 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100136 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700137 prebuild_mode="yes"
138 shift;
139 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100140 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700141 prebuild_mode="no"
142 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700143 elif [ "x$1" = "x--gcverify" ]; then
144 basic_verify="true"
145 gc_verify="true"
146 shift
147 elif [ "x$1" = "x--gcstress" ]; then
148 basic_verify="true"
149 gc_stress="true"
150 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700151 elif [ "x$1" = "x--image" ]; then
152 shift
153 image="$1"
154 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700155 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000156 elif [ "x$1" = "x-Xcompiler-option" ]; then
157 shift
158 option="$1"
159 run_args="${run_args} -Xcompiler-option $option"
160 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700161 elif [ "x$1" = "x--runtime-option" ]; then
162 shift
163 option="$1"
164 run_args="${run_args} --runtime-option $option"
165 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700166 elif [ "x$1" = "x--debug" ]; then
167 run_args="${run_args} --debug"
168 shift
169 elif [ "x$1" = "x--gdb" ]; then
170 run_args="${run_args} --gdb"
171 dev_mode="yes"
172 shift
173 elif [ "x$1" = "x--zygote" ]; then
174 run_args="${run_args} --zygote"
175 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800176 elif [ "x$1" = "x--interpreter" ]; then
177 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700178 image_suffix="-interpreter"
179 shift
180 elif [ "x$1" = "x--optimizing" ]; then
181 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
182 image_suffix="-optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800183 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700184 elif [ "x$1" = "x--no-verify" ]; then
185 run_args="${run_args} --no-verify"
186 shift
187 elif [ "x$1" = "x--no-optimize" ]; then
188 run_args="${run_args} --no-optimize"
189 shift
190 elif [ "x$1" = "x--no-precise" ]; then
191 run_args="${run_args} --no-precise"
192 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700193 elif [ "x$1" = "x--invoke-with" ]; then
194 shift
195 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700196 if [ "x$what" = "x" ]; then
197 echo "$0 missing argument to --invoke-with" 1>&2
198 usage="yes"
199 break
200 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700201 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700202 shift
203 elif [ "x$1" = "x--dev" ]; then
204 run_args="${run_args} --dev"
205 dev_mode="yes"
206 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700207 elif [ "x$1" = "x--build-only" ]; then
208 build_only="yes"
209 shift
210 elif [ "x$1" = "x--output-path" ]; then
211 shift
212 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700213 if [ "x$tmp_dir" = "x" ]; then
214 echo "$0 missing argument to --output-path" 1>&2
215 usage="yes"
216 break
217 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700218 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700219 elif [ "x$1" = "x--update" ]; then
220 update_mode="yes"
221 shift
222 elif [ "x$1" = "x--help" ]; then
223 usage="yes"
224 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700225 elif [ "x$1" = "x--64" ]; then
226 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700227 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700228 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200229 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700230 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200231 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700232 elif [ "x$1" = "x--always-clean" ]; then
233 always_clean="yes"
234 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700235 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700236 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700237 usage="yes"
238 break
239 else
240 break
241 fi
242done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700243
244# tmp_dir may be relative, resolve.
245#
246# Cannot use realpath, as it does not exist on Mac.
247# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700248# Cannot use readlink -m, as it does not exist on Mac.
249# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700250noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700251tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700252mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700253
Alex Lighte7873ec2014-08-12 09:53:50 -0700254if [ "$basic_verify" = "true" ]; then
255 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify"
256fi
257if [ "$gc_verify" = "true" ]; then
258 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
259fi
260if [ "$gc_stress" = "true" ]; then
261 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
262fi
Jeff Hao85139a32014-07-23 11:52:52 -0700263if [ "$trace" = "true" ]; then
264 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
265fi
266
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700267# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100268# 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 -0700269function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100270 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
271 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700272 if [ "x${suffix64}" = "x64" ]; then
273 target_arch_name=${grep64bit}
274 else
275 target_arch_name=${grep32bit}
276 fi
277}
278
Alex Lighta59dd802014-07-02 16:28:08 -0700279if [ "$target_mode" = "no" ]; then
280 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700281 if [ "$prebuild_mode" = "yes" ]; then
282 echo "--prebuild with --jvm is unsupported";
283 exit 1;
284 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700285 fi
286fi
287
Alex Light03a112d2014-08-25 13:25:56 -0700288if [ "$have_patchoat" = "no" ]; then
289 run_args="${run_args} --no-patchoat"
290fi
291
292if [ "$have_dex2oat" = "no" ]; then
293 run_args="${run_args} --no-dex2oat"
294fi
295
Jeff Hao201803f2013-11-20 18:11:39 -0800296if [ ! "$runtime" = "jvm" ]; then
297 run_args="${run_args} --lib $lib"
298fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700299
Jeff Hao201803f2013-11-20 18:11:39 -0800300if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700301 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100302 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700303 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
304 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
305 else
306 true # defaults to using target BOOTCLASSPATH
307 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800308elif [ "$runtime" = "art" ]; then
309 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100310 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800311 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100312 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800313 fi
314 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100315 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800316 fi
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700317 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core${image_suffix}.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700318 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800319 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700320 guess_arch_name
321 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700322 run_args="${run_args} --boot -Ximage:/data/art-test/core${image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800323 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700324 if [ "$relocate" = "yes" ]; then
325 run_args="${run_args} --relocate"
326 else
327 run_args="${run_args} --no-relocate"
328 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700329fi
330
Alex Light03a112d2014-08-25 13:25:56 -0700331if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700332 if [ "$runtime" != "art" ]; then
333 echo "--no-image is only supported on the art runtime"
334 exit 1
335 fi
336 if [ "$target_mode" = "no" ]; then
337 framework="${ANDROID_HOST_OUT}/framework"
338 bpath_suffix="-hostdex"
339 else
340 framework="/system/framework"
341 bpath_suffix=""
342 fi
343 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
344 # fail since these jar files will be stripped.
345 bpath="${framework}/core-libart${bpath_suffix}.jar"
346 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
347 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
348 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
349 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
350 # Pass down the bootclasspath
351 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700352 run_args="${run_args} --no-image"
353fi
354
jeffhao5d1ac922011-09-29 17:41:15 -0700355if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
356 echo "--dev and --update are mutually exclusive" 1>&2
357 usage="yes"
358fi
359
360if [ "$usage" = "no" ]; then
361 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
362 test_dir=`basename "$oldwd"`
363 else
364 test_dir="$1"
365 fi
366
367 if [ '!' -d "$test_dir" ]; then
368 td2=`echo ${test_dir}-*`
369 if [ '!' -d "$td2" ]; then
370 echo "${test_dir}: no such test directory" 1>&2
371 usage="yes"
372 fi
373 test_dir="$td2"
374 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700375 # Shift to get rid of the test name argument. The rest of the arguments
376 # will get passed to the test run.
377 shift
378fi
379
380if [ "$usage" = "yes" ]; then
381 prog=`basename $prog`
382 (
383 echo "usage:"
384 echo " $prog --help Print this message."
385 echo " $prog [options] [test-name] Run test normally."
386 echo " $prog --dev [options] [test-name] Development mode" \
387 "(dumps to stdout)."
388 echo " $prog --update [options] [test-name] Update mode" \
389 "(replaces expected.txt)."
390 echo ' Omitting the test name or specifying "-" will use the' \
391 "current directory."
392 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000393 echo " -O Run non-debug rather than debug build (off by default)."
394 echo " -Xcompiler-option Pass an option to the compiler."
Ian Rogers701aa642014-07-18 11:38:13 -0700395 echo " --runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000396 echo " --debug Wait for a debugger to attach."
397 echo " --gdb Run under gdb; incompatible with some tests."
398 echo " --build-only Build test files only (off by default)."
399 echo " --interpreter Enable interpreter only mode (off by default)."
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700400 echo " --optimizing Enable optimizing compiler (off by default)."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000401 echo " --no-verify Turn off verification (on by default)."
402 echo " --no-optimize Turn off optimization (on by default)."
403 echo " --no-precise Turn off precise GC (on by default)."
404 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700405 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000406 echo " other runtime options are ignored."
Alex Light03a112d2014-08-25 13:25:56 -0700407 echo " --no-dex2oat Run as though dex2oat was failing."
408 echo " --no-patchoat Run as though patchoat was failing."
Alex Light9d722532014-07-22 18:07:12 -0700409 echo " --prebuild Run dex2oat on the files before starting test. (default)"
Alex Lighta59dd802014-07-02 16:28:08 -0700410 echo " --no-prebuild Do not run dex2oat on the files before starting"
Alex Light9d722532014-07-22 18:07:12 -0700411 echo " the test."
Alex Lighta59dd802014-07-02 16:28:08 -0700412 echo " --relocate Force the use of relocating in the test, making"
413 echo " the image and oat files be relocated to a random"
414 echo " address before running. (default)"
415 echo " --no-relocate Force the use of no relocating in the test"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000416 echo " --host Use the host-mode virtual machine."
417 echo " --invoke-with Pass --invoke-with option to runtime."
418 echo " --dalvik Use Dalvik (off by default)."
419 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700420 echo " --output-path [path] Location where to store the build" \
421 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700422 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200423 echo " --trace Run with method tracing"
Alex Lighte7873ec2014-08-12 09:53:50 -0700424 echo " --gcstress Run with gc stress testing"
425 echo " --gcverify Run with gc verification"
Alex Lightbfac14a2014-07-30 09:41:21 -0700426 echo " --always-clean Delete the test files even if the test fails."
jeffhao5d1ac922011-09-29 17:41:15 -0700427 ) 1>&2
428 exit 1
429fi
430
431cd "$test_dir"
432test_dir=`pwd`
433
434td_info="${test_dir}/${info}"
435td_expected="${test_dir}/${expected}"
436
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700437if [ ! -r $td_info ]; then
438 echo "${test_dir}: missing file $td_info" 1>&2
439 exit 1
440fi
441
442if [ ! -r $td_expected ]; then
443 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700444 exit 1
445fi
446
447# copy the test to a temp dir and run it
448
Elliott Hughes510c8782011-10-06 10:57:34 -0700449echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700450
451rm -rf "$tmp_dir"
452cp -Rp "$test_dir" "$tmp_dir"
453cd "$tmp_dir"
454
455if [ '!' -r "$build" ]; then
456 cp "${progdir}/etc/default-build" build
457fi
458
459if [ '!' -r "$run" ]; then
460 cp "${progdir}/etc/default-run" run
461fi
462
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700463if [ '!' -r "$check_cmd" ]; then
464 cp "${progdir}/etc/default-check" check
465fi
466
jeffhao5d1ac922011-09-29 17:41:15 -0700467chmod 755 "$build"
468chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700469chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700470
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700471export TEST_NAME=`basename ${test_dir}`
472
Ian Rogers997f0f92014-06-21 22:58:05 -0700473# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
474file_size_limit=2048
475if echo "$test_dir" | grep 089; then
476 file_size_limit=5120
477elif echo "$test_dir" | grep 083; then
478 file_size_limit=5120
479fi
Alex Lighta59dd802014-07-02 16:28:08 -0700480if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700481 echo "ulimit file size setting failed"
482fi
483
jeffhao5d1ac922011-09-29 17:41:15 -0700484good="no"
485if [ "$dev_mode" = "yes" ]; then
486 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700487 build_exit="$?"
488 echo "build exit status: $build_exit" 1>&2
489 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800490 echo "${test_dir}: running..." 1>&2
491 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700492 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800493 echo "run exit status: $run_exit" 1>&2
494 if [ "$run_exit" = "0" ]; then
495 good="yes"
496 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700497 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700498elif [ "$update_mode" = "yes" ]; then
499 "./${build}" >"$build_output" 2>&1
500 build_exit="$?"
501 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800502 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700503 "./${run}" $run_args "$@" >"$output" 2>&1
504 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
505 good="yes"
506 else
507 cat "$build_output" 1>&2
508 echo "build exit status: $build_exit" 1>&2
509 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700510elif [ "$build_only" = "yes" ]; then
511 good="yes"
512 "./${build}" >"$build_output" 2>&1
513 build_exit="$?"
514 if [ "$build_exit" '!=' '0' ]; then
515 cp "$build_output" "$output"
516 echo "build exit status: $build_exit" >>"$output"
517 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
518 if [ "$?" '!=' "0" ]; then
519 good="no"
520 echo "BUILD FAILED For ${TEST_NAME}"
521 fi
522 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700523 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700524 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700525 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700526else
527 "./${build}" >"$build_output" 2>&1
528 build_exit="$?"
529 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800530 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700531 "./${run}" $run_args "$@" >"$output" 2>&1
532 else
533 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700534 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
535 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700536 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700537 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700538 max_name_length=$(getconf NAME_MAX ${tmp_dir})
539 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
540 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700541 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700542 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700543 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700544 if [ "$?" = "0" ]; then
545 # output == expected
546 good="yes"
547 echo "${test_dir}: succeeded!" 1>&2
548 fi
549fi
550
jeffhao5d1ac922011-09-29 17:41:15 -0700551(
Alex Lightbfac14a2014-07-30 09:41:21 -0700552 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700553 echo "${test_dir}: FAILED!"
554 echo ' '
555 echo '#################### info'
556 cat "${td_info}" | sed 's/^/# /g'
557 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700558 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700559 echo '####################'
560 echo ' '
561 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700562
563) 1>&2
564
565# Clean up test files.
566if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
567 cd "$oldwd"
568 rm -rf "$tmp_dir"
569 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
570 adb shell rm -rf $DEX_LOCATION
571 fi
572 if [ "$good" = "yes" ]; then
573 exit 0
574 fi
575fi
576
577
578(
579 if [ "$always_clean" = "yes" ]; then
580 echo "${TEST_NAME} files deleted from host "
581 if [ "$target_mode" == "yes" ]; then
582 echo "and from target"
583 fi
584 else
585 echo "${TEST_NAME} files left in ${tmp_dir} on host"
586 if [ "$target_mode" == "yes" ]; then
587 echo "and in ${DEX_LOCATION} on target"
588 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700589 fi
590
jeffhao5d1ac922011-09-29 17:41:15 -0700591) 1>&2
592
593exit 1