blob: 2950af14563851dfd8a392d303de8d3167f61d57 [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
David Brazdil4846d132015-01-15 19:07:08 +000042checker="${progdir}/../tools/checker.py"
jeffhao5d1ac922011-09-29 17:41:15 -070043
44export JAVA="java"
Brian Carlstrom5103ce62014-03-30 16:17:42 -070045export JAVAC="javac -g"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010046export RUN="${progdir}/etc/run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070047export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070048export NEED_DEX="true"
jeffhao5d1ac922011-09-29 17:41:15 -070049
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070050# If dx was not set by the environment variable, assume it is in the path.
51if [ -z "$DX" ]; then
52 export DX="dx"
53fi
54
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080055# If jasmin was not set by the environment variable, assume it is in the path.
56if [ -z "$JASMIN" ]; then
57 export JASMIN="jasmin"
58fi
59
Andreas Gampe8fda9f22014-10-03 16:15:37 -070060# If smali was not set by the environment variable, assume it is in the path.
61if [ -z "$SMALI" ]; then
62 export SMALI="smali"
63fi
64
65# If dexmerger was not set by the environment variable, assume it is in the path.
66if [ -z "$DXMERGER" ]; then
67 export DXMERGER="dexmerger"
68fi
69
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080070
jeffhao5d1ac922011-09-29 17:41:15 -070071info="info.txt"
72build="build"
73run="run"
74expected="expected.txt"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -070075check_cmd="check"
jeffhao5d1ac922011-09-29 17:41:15 -070076output="output.txt"
77build_output="build-output.txt"
David Brazdil4846d132015-01-15 19:07:08 +000078cfg_output="cfg-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070079lib="libartd.so"
jeffhao5d1ac922011-09-29 17:41:15 -070080run_args="--quiet"
David Brazdil4846d132015-01-15 19:07:08 +000081build_args=""
jeffhao5d1ac922011-09-29 17:41:15 -070082
Alex Light9d722532014-07-22 18:07:12 -070083prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -070084target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070085dev_mode="no"
86update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -070087debug_mode="no"
88relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -080089runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070090usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070091build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070092suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -070093trace="false"
Alex Lighte7873ec2014-08-12 09:53:50 -070094basic_verify="false"
95gc_verify="false"
96gc_stress="false"
Alex Lightbfac14a2014-07-30 09:41:21 -070097always_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -070098have_dex2oat="yes"
99have_patchoat="yes"
100have_image="yes"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700101image_suffix=""
Andreas Gampec23c9c92014-10-28 14:47:25 -0700102pic_image_suffix=""
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000103android_root="/system"
jeffhao5d1ac922011-09-29 17:41:15 -0700104
105while true; do
106 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700107 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700108 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100109 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700110 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800111 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700112 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800113 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700114 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700115 NEED_DEX="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100116 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700117 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800118 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700119 lib="libart.so"
120 shift
121 elif [ "x$1" = "x--dalvik" ]; then
122 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800123 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700124 shift
Alex Light03a112d2014-08-25 13:25:56 -0700125 elif [ "x$1" = "x--no-dex2oat" ]; then
126 have_dex2oat="no"
127 shift
128 elif [ "x$1" = "x--no-patchoat" ]; then
129 have_patchoat="no"
130 shift
131 elif [ "x$1" = "x--no-image" ]; then
132 have_image="no"
133 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700134 elif [ "x$1" = "x--pic-image" ]; then
135 pic_image_suffix="-pic"
136 shift
137 elif [ "x$1" = "x--pic-test" ]; then
138 run_args="${run_args} --pic-test"
139 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700140 elif [ "x$1" = "x--relocate" ]; then
141 relocate="yes"
142 shift
143 elif [ "x$1" = "x--no-relocate" ]; then
144 relocate="no"
145 shift
146 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100147 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700148 prebuild_mode="yes"
149 shift;
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000150 elif [ "x$1" = "x--debuggable" ]; then
151 run_args="${run_args} -Xcompiler-option --debuggable"
152 shift;
Alex Lighta59dd802014-07-02 16:28:08 -0700153 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100154 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700155 prebuild_mode="no"
156 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700157 elif [ "x$1" = "x--gcverify" ]; then
158 basic_verify="true"
159 gc_verify="true"
160 shift
161 elif [ "x$1" = "x--gcstress" ]; then
162 basic_verify="true"
163 gc_stress="true"
164 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700165 elif [ "x$1" = "x--image" ]; then
166 shift
167 image="$1"
168 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700169 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000170 elif [ "x$1" = "x-Xcompiler-option" ]; then
171 shift
172 option="$1"
173 run_args="${run_args} -Xcompiler-option $option"
174 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700175 elif [ "x$1" = "x--runtime-option" ]; then
176 shift
177 option="$1"
178 run_args="${run_args} --runtime-option $option"
179 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700180 elif [ "x$1" = "x--gdb-arg" ]; then
181 shift
182 gdb_arg="$1"
183 run_args="${run_args} --gdb-arg $gdb_arg"
184 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700185 elif [ "x$1" = "x--debug" ]; then
186 run_args="${run_args} --debug"
187 shift
188 elif [ "x$1" = "x--gdb" ]; then
189 run_args="${run_args} --gdb"
190 dev_mode="yes"
191 shift
192 elif [ "x$1" = "x--zygote" ]; then
193 run_args="${run_args} --zygote"
194 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800195 elif [ "x$1" = "x--interpreter" ]; then
196 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700197 image_suffix="-interpreter"
198 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800199 elif [ "x$1" = "x--jit" ]; then
200 run_args="${run_args} --jit"
Mathieu Chartiere2a12c02015-02-27 13:21:15 -0800201 image_suffix="-interpreter"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800202 shift
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700203 elif [ "x$1" = "x--optimizing" ]; then
204 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
205 image_suffix="-optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800206 shift
Nicolas Geoffrayc9338b92014-12-03 13:36:10 +0000207 elif [ "x$1" = "x--quick" ]; then
208 run_args="${run_args} -Xcompiler-option --compiler-backend=Quick"
209 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700210 elif [ "x$1" = "x--no-verify" ]; then
211 run_args="${run_args} --no-verify"
212 shift
213 elif [ "x$1" = "x--no-optimize" ]; then
214 run_args="${run_args} --no-optimize"
215 shift
216 elif [ "x$1" = "x--no-precise" ]; then
217 run_args="${run_args} --no-precise"
218 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700219 elif [ "x$1" = "x--invoke-with" ]; then
220 shift
221 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700222 if [ "x$what" = "x" ]; then
223 echo "$0 missing argument to --invoke-with" 1>&2
224 usage="yes"
225 break
226 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700227 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700228 shift
229 elif [ "x$1" = "x--dev" ]; then
230 run_args="${run_args} --dev"
231 dev_mode="yes"
232 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700233 elif [ "x$1" = "x--build-only" ]; then
234 build_only="yes"
235 shift
236 elif [ "x$1" = "x--output-path" ]; then
237 shift
238 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700239 if [ "x$tmp_dir" = "x" ]; then
240 echo "$0 missing argument to --output-path" 1>&2
241 usage="yes"
242 break
243 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700244 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000245 elif [ "x$1" = "x--android-root" ]; then
246 shift
247 if [ "x$1" = "x" ]; then
248 echo "$0 missing argument to --android-root" 1>&2
249 usage="yes"
250 break
251 fi
252 android_root="$1"
253 run_args="${run_args} --android-root $1"
254 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700255 elif [ "x$1" = "x--update" ]; then
256 update_mode="yes"
257 shift
258 elif [ "x$1" = "x--help" ]; then
259 usage="yes"
260 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700261 elif [ "x$1" = "x--64" ]; then
262 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700263 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700264 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200265 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700266 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200267 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700268 elif [ "x$1" = "x--always-clean" ]; then
269 always_clean="yes"
270 shift
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800271 elif [ "x$1" = "x--dex2oat-swap" ]; then
272 run_args="${run_args} --dex2oat-swap"
273 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700274 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700275 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700276 usage="yes"
277 break
278 else
279 break
280 fi
281done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700282
283# tmp_dir may be relative, resolve.
284#
285# Cannot use realpath, as it does not exist on Mac.
286# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700287# Cannot use readlink -m, as it does not exist on Mac.
288# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700289noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700290tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700291mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700292
Alex Lighte7873ec2014-08-12 09:53:50 -0700293if [ "$basic_verify" = "true" ]; then
Hiroshi Yamauchi312baf12015-01-12 12:11:05 -0800294 # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests.
295 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0"
Alex Lighte7873ec2014-08-12 09:53:50 -0700296fi
297if [ "$gc_verify" = "true" ]; then
298 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
299fi
300if [ "$gc_stress" = "true" ]; then
301 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
302fi
Jeff Hao85139a32014-07-23 11:52:52 -0700303if [ "$trace" = "true" ]; then
304 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
305fi
306
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700307# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100308# 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 -0700309function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100310 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800311 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64|mips64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700312 if [ "x${suffix64}" = "x64" ]; then
313 target_arch_name=${grep64bit}
314 else
315 target_arch_name=${grep32bit}
316 fi
317}
318
Alex Lighta59dd802014-07-02 16:28:08 -0700319if [ "$target_mode" = "no" ]; then
320 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700321 if [ "$prebuild_mode" = "yes" ]; then
322 echo "--prebuild with --jvm is unsupported";
323 exit 1;
324 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700325 fi
326fi
327
Alex Light03a112d2014-08-25 13:25:56 -0700328if [ "$have_patchoat" = "no" ]; then
329 run_args="${run_args} --no-patchoat"
330fi
331
332if [ "$have_dex2oat" = "no" ]; then
333 run_args="${run_args} --no-dex2oat"
334fi
335
Jeff Hao201803f2013-11-20 18:11:39 -0800336if [ ! "$runtime" = "jvm" ]; then
337 run_args="${run_args} --lib $lib"
338fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700339
Jeff Hao201803f2013-11-20 18:11:39 -0800340if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700341 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100342 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700343 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
344 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
345 else
346 true # defaults to using target BOOTCLASSPATH
347 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800348elif [ "$runtime" = "art" ]; then
349 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100350 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800351 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100352 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800353 fi
354 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100355 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800356 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000357 run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700358 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800359 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700360 guess_arch_name
361 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000362 run_args="${run_args} --boot /data/art-test/core${image_suffix}${pic_image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800363 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700364 if [ "$relocate" = "yes" ]; then
365 run_args="${run_args} --relocate"
366 else
367 run_args="${run_args} --no-relocate"
368 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700369fi
370
Alex Light03a112d2014-08-25 13:25:56 -0700371if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700372 if [ "$runtime" != "art" ]; then
373 echo "--no-image is only supported on the art runtime"
374 exit 1
375 fi
376 if [ "$target_mode" = "no" ]; then
377 framework="${ANDROID_HOST_OUT}/framework"
378 bpath_suffix="-hostdex"
379 else
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000380 framework="${android_root}/framework"
Alex Light1ef4ce82014-08-27 11:13:47 -0700381 bpath_suffix=""
382 fi
383 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
384 # fail since these jar files will be stripped.
385 bpath="${framework}/core-libart${bpath_suffix}.jar"
386 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
387 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
388 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
389 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
390 # Pass down the bootclasspath
391 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700392 run_args="${run_args} --no-image"
393fi
394
jeffhao5d1ac922011-09-29 17:41:15 -0700395if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
396 echo "--dev and --update are mutually exclusive" 1>&2
397 usage="yes"
398fi
399
400if [ "$usage" = "no" ]; then
401 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
402 test_dir=`basename "$oldwd"`
403 else
404 test_dir="$1"
405 fi
406
407 if [ '!' -d "$test_dir" ]; then
408 td2=`echo ${test_dir}-*`
409 if [ '!' -d "$td2" ]; then
410 echo "${test_dir}: no such test directory" 1>&2
411 usage="yes"
412 fi
413 test_dir="$td2"
414 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700415 # Shift to get rid of the test name argument. The rest of the arguments
416 # will get passed to the test run.
417 shift
418fi
419
420if [ "$usage" = "yes" ]; then
421 prog=`basename $prog`
422 (
423 echo "usage:"
424 echo " $prog --help Print this message."
425 echo " $prog [options] [test-name] Run test normally."
426 echo " $prog --dev [options] [test-name] Development mode" \
427 "(dumps to stdout)."
428 echo " $prog --update [options] [test-name] Update mode" \
429 "(replaces expected.txt)."
430 echo ' Omitting the test name or specifying "-" will use the' \
431 "current directory."
432 echo " Runtime Options:"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000433 echo " -O Run non-debug rather than debug build (off by default)."
434 echo " -Xcompiler-option Pass an option to the compiler."
435 echo " --runtime-option Pass an option to the runtime."
436 echo " --debug Wait for a debugger to attach."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000437 echo " --debuggable Whether to compile Java code for a debugger."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000438 echo " --gdb Run under gdb; incompatible with some tests."
439 echo " --build-only Build test files only (off by default)."
440 echo " --interpreter Enable interpreter only mode (off by default)."
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800441 echo " --jit Enable jit (off by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000442 echo " --optimizing Enable optimizing compiler (off by default)."
Nicolas Geoffrayc9338b92014-12-03 13:36:10 +0000443 echo " --quick Use Quick compiler (default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000444 echo " --no-verify Turn off verification (on by default)."
445 echo " --no-optimize Turn off optimization (on by default)."
446 echo " --no-precise Turn off precise GC (on by default)."
447 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700448 "If used, then the"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000449 echo " other runtime options are ignored."
450 echo " --no-dex2oat Run as though dex2oat was failing."
451 echo " --no-patchoat Run as though patchoat was failing."
452 echo " --prebuild Run dex2oat on the files before starting test. (default)"
453 echo " --no-prebuild Do not run dex2oat on the files before starting"
454 echo " the test."
455 echo " --relocate Force the use of relocating in the test, making"
456 echo " the image and oat files be relocated to a random"
457 echo " address before running. (default)"
458 echo " --no-relocate Force the use of no relocating in the test"
459 echo " --host Use the host-mode virtual machine."
460 echo " --invoke-with Pass --invoke-with option to runtime."
461 echo " --dalvik Use Dalvik (off by default)."
462 echo " --jvm Use a host-local RI virtual machine."
463 echo " --output-path [path] Location where to store the build" \
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700464 "files."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000465 echo " --64 Run the test in 64-bit mode"
466 echo " --trace Run with method tracing"
467 echo " --gcstress Run with gc stress testing"
468 echo " --gcverify Run with gc verification"
469 echo " --always-clean Delete the test files even if the test fails."
470 echo " --android-root [path] The path on target for the android root. (/system by default)."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000471 echo " --dex2oat-swap Use a dex2oat swap file."
jeffhao5d1ac922011-09-29 17:41:15 -0700472 ) 1>&2
473 exit 1
474fi
475
476cd "$test_dir"
477test_dir=`pwd`
478
479td_info="${test_dir}/${info}"
480td_expected="${test_dir}/${expected}"
481
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700482if [ ! -r $td_info ]; then
483 echo "${test_dir}: missing file $td_info" 1>&2
484 exit 1
485fi
486
487if [ ! -r $td_expected ]; then
488 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700489 exit 1
490fi
491
492# copy the test to a temp dir and run it
493
Elliott Hughes510c8782011-10-06 10:57:34 -0700494echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700495
496rm -rf "$tmp_dir"
497cp -Rp "$test_dir" "$tmp_dir"
498cd "$tmp_dir"
499
500if [ '!' -r "$build" ]; then
501 cp "${progdir}/etc/default-build" build
502fi
503
504if [ '!' -r "$run" ]; then
505 cp "${progdir}/etc/default-run" run
506fi
507
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700508if [ '!' -r "$check_cmd" ]; then
509 cp "${progdir}/etc/default-check" check
510fi
511
jeffhao5d1ac922011-09-29 17:41:15 -0700512chmod 755 "$build"
513chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700514chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700515
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700516export TEST_NAME=`basename ${test_dir}`
517
David Brazdil4846d132015-01-15 19:07:08 +0000518# Tests named '<number>-checker-*' will also have their CFGs verified with
519# Checker when compiled with Optimizing on host.
520if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
521 # Build Checker DEX files without dx's optimizations so the input to dex2oat
522 # better resembles the Java source. We always build the DEX the same way, even
523 # if Checker is not invoked and the test only runs the program.
524 build_args="${build_args} --dx-option --no-optimize"
525
526 if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$target_mode" = "no" ]; then
527 run_checker="yes"
528 run_args="${run_args} -Xcompiler-option --dump-cfg=$tmp_dir/$cfg_output \
529 -Xcompiler-option -j1"
530 fi
531fi
532
Ian Rogers997f0f92014-06-21 22:58:05 -0700533# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
534file_size_limit=2048
535if echo "$test_dir" | grep 089; then
536 file_size_limit=5120
537elif echo "$test_dir" | grep 083; then
538 file_size_limit=5120
539fi
Alex Lighta59dd802014-07-02 16:28:08 -0700540if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700541 echo "ulimit file size setting failed"
542fi
543
jeffhao5d1ac922011-09-29 17:41:15 -0700544good="no"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000545good_build="yes"
546good_run="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700547if [ "$dev_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000548 "./${build}" $build_args 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700549 build_exit="$?"
550 echo "build exit status: $build_exit" 1>&2
551 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800552 echo "${test_dir}: running..." 1>&2
553 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700554 run_exit="$?"
Calin Juravle3cf48772015-01-26 16:47:33 +0000555
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800556 if [ "$run_exit" = "0" ]; then
Calin Juravle3cf48772015-01-26 16:47:33 +0000557 if [ "$run_checker" = "yes" ]; then
558 "$checker" "$cfg_output" "$tmp_dir" 2>&1
559 checker_exit="$?"
560 if [ "$checker_exit" = "0" ]; then
561 good="yes"
562 fi
563 echo "checker exit status: $checker_exit" 1>&2
564 else
565 good="yes"
566 fi
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800567 fi
Calin Juravle3cf48772015-01-26 16:47:33 +0000568 echo "run exit status: $run_exit" 1>&2
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700569 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700570elif [ "$update_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000571 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700572 build_exit="$?"
573 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800574 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700575 "./${run}" $run_args "$@" >"$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000576 if [ "$run_checker" = "yes" ]; then
577 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
578 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700579 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
580 good="yes"
581 else
582 cat "$build_output" 1>&2
583 echo "build exit status: $build_exit" 1>&2
584 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700585elif [ "$build_only" = "yes" ]; then
586 good="yes"
David Brazdil4846d132015-01-15 19:07:08 +0000587 "./${build}" $build_args >"$build_output" 2>&1
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700588 build_exit="$?"
589 if [ "$build_exit" '!=' '0' ]; then
590 cp "$build_output" "$output"
591 echo "build exit status: $build_exit" >>"$output"
592 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
593 if [ "$?" '!=' "0" ]; then
594 good="no"
595 echo "BUILD FAILED For ${TEST_NAME}"
596 fi
597 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700598 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700599 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700600 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700601else
David Brazdil4846d132015-01-15 19:07:08 +0000602 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700603 build_exit="$?"
604 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800605 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700606 "./${run}" $run_args "$@" >"$output" 2>&1
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000607 run_exit="$?"
608 if [ "$run_exit" != "0" ]; then
609 echo "run exit status: $run_exit" 1>&2
610 good_run="no"
David Brazdil4846d132015-01-15 19:07:08 +0000611 elif [ "$run_checker" = "yes" ]; then
612 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
613 checker_exit="$?"
614 if [ "$checker_exit" != "0" ]; then
615 echo "checker exit status: $checker_exit" 1>&2
616 good_run="no"
617 else
618 good_run="yes"
619 fi
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000620 else
621 good_run="yes"
622 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700623 else
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000624 good_build="no"
jeffhao5d1ac922011-09-29 17:41:15 -0700625 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700626 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
627 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700628 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700629 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700630 max_name_length=$(getconf NAME_MAX ${tmp_dir})
631 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
632 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700633 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700634 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700635 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700636 if [ "$?" = "0" ]; then
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000637 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
638 # output == expected
639 good="yes"
640 echo "${test_dir}: succeeded!" 1>&2
641 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700642 fi
643fi
644
jeffhao5d1ac922011-09-29 17:41:15 -0700645(
Alex Lightbfac14a2014-07-30 09:41:21 -0700646 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700647 echo "${test_dir}: FAILED!"
648 echo ' '
649 echo '#################### info'
650 cat "${td_info}" | sed 's/^/# /g'
651 echo '#################### diffs'
Ian Rogers75deec02014-11-23 20:07:39 -0800652 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 2000
jeffhao5d1ac922011-09-29 17:41:15 -0700653 echo '####################'
654 echo ' '
655 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700656
657) 1>&2
658
659# Clean up test files.
660if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
661 cd "$oldwd"
662 rm -rf "$tmp_dir"
663 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
664 adb shell rm -rf $DEX_LOCATION
665 fi
666 if [ "$good" = "yes" ]; then
667 exit 0
668 fi
669fi
670
671
672(
673 if [ "$always_clean" = "yes" ]; then
674 echo "${TEST_NAME} files deleted from host "
675 if [ "$target_mode" == "yes" ]; then
676 echo "and from target"
677 fi
678 else
679 echo "${TEST_NAME} files left in ${tmp_dir} on host"
680 if [ "$target_mode" == "yes" ]; then
681 echo "and in ${DEX_LOCATION} on target"
682 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700683 fi
684
jeffhao5d1ac922011-09-29 17:41:15 -0700685) 1>&2
686
687exit 1