blob: ed3309923b0e47c59c5d6b85ab10057ee23050fd [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 Brazdil2c27f2c2015-05-12 18:06:38 +010042checker="${progdir}/../tools/checker/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 Brazdil24128c62015-05-21 12:06:13 +010078cfg_output="graph.cfg"
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
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +000083debuggable="no"
Alex Light9d722532014-07-22 18:07:12 -070084prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -070085target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070086dev_mode="no"
87update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -070088debug_mode="no"
89relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -080090runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070091usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070092build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070093suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -070094trace="false"
Alex Lighte7873ec2014-08-12 09:53:50 -070095basic_verify="false"
96gc_verify="false"
97gc_stress="false"
Alex Lightbfac14a2014-07-30 09:41:21 -070098always_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -070099have_dex2oat="yes"
100have_patchoat="yes"
101have_image="yes"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700102image_suffix=""
Andreas Gampec23c9c92014-10-28 14:47:25 -0700103pic_image_suffix=""
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000104android_root="/system"
jeffhao5d1ac922011-09-29 17:41:15 -0700105
106while true; do
107 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700108 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700109 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100110 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700111 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800112 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700113 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800114 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700115 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700116 NEED_DEX="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100117 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700118 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800119 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700120 lib="libart.so"
121 shift
122 elif [ "x$1" = "x--dalvik" ]; then
123 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800124 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700125 shift
Alex Light03a112d2014-08-25 13:25:56 -0700126 elif [ "x$1" = "x--no-dex2oat" ]; then
127 have_dex2oat="no"
128 shift
129 elif [ "x$1" = "x--no-patchoat" ]; then
130 have_patchoat="no"
131 shift
132 elif [ "x$1" = "x--no-image" ]; then
133 have_image="no"
134 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700135 elif [ "x$1" = "x--pic-image" ]; then
136 pic_image_suffix="-pic"
137 shift
138 elif [ "x$1" = "x--pic-test" ]; then
139 run_args="${run_args} --pic-test"
140 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700141 elif [ "x$1" = "x--relocate" ]; then
142 relocate="yes"
143 shift
144 elif [ "x$1" = "x--no-relocate" ]; then
145 relocate="no"
146 shift
147 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100148 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700149 prebuild_mode="yes"
150 shift;
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000151 elif [ "x$1" = "x--debuggable" ]; then
152 run_args="${run_args} -Xcompiler-option --debuggable"
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +0000153 debuggable="yes"
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000154 shift;
Alex Lighta59dd802014-07-02 16:28:08 -0700155 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100156 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700157 prebuild_mode="no"
158 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700159 elif [ "x$1" = "x--gcverify" ]; then
160 basic_verify="true"
161 gc_verify="true"
162 shift
163 elif [ "x$1" = "x--gcstress" ]; then
164 basic_verify="true"
165 gc_stress="true"
166 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700167 elif [ "x$1" = "x--image" ]; then
168 shift
169 image="$1"
170 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700171 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000172 elif [ "x$1" = "x-Xcompiler-option" ]; then
173 shift
174 option="$1"
175 run_args="${run_args} -Xcompiler-option $option"
176 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700177 elif [ "x$1" = "x--runtime-option" ]; then
178 shift
179 option="$1"
180 run_args="${run_args} --runtime-option $option"
181 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700182 elif [ "x$1" = "x--gdb-arg" ]; then
183 shift
184 gdb_arg="$1"
185 run_args="${run_args} --gdb-arg $gdb_arg"
186 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700187 elif [ "x$1" = "x--debug" ]; then
188 run_args="${run_args} --debug"
189 shift
190 elif [ "x$1" = "x--gdb" ]; then
191 run_args="${run_args} --gdb"
192 dev_mode="yes"
193 shift
194 elif [ "x$1" = "x--zygote" ]; then
195 run_args="${run_args} --zygote"
196 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800197 elif [ "x$1" = "x--interpreter" ]; then
198 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700199 image_suffix="-interpreter"
200 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800201 elif [ "x$1" = "x--jit" ]; then
202 run_args="${run_args} --jit"
Mathieu Chartiere2a12c02015-02-27 13:21:15 -0800203 image_suffix="-interpreter"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800204 shift
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700205 elif [ "x$1" = "x--optimizing" ]; then
206 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
207 image_suffix="-optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800208 shift
Nicolas Geoffrayc9338b92014-12-03 13:36:10 +0000209 elif [ "x$1" = "x--quick" ]; then
210 run_args="${run_args} -Xcompiler-option --compiler-backend=Quick"
211 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700212 elif [ "x$1" = "x--no-verify" ]; then
213 run_args="${run_args} --no-verify"
214 shift
215 elif [ "x$1" = "x--no-optimize" ]; then
216 run_args="${run_args} --no-optimize"
217 shift
218 elif [ "x$1" = "x--no-precise" ]; then
219 run_args="${run_args} --no-precise"
220 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700221 elif [ "x$1" = "x--invoke-with" ]; then
222 shift
223 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700224 if [ "x$what" = "x" ]; then
225 echo "$0 missing argument to --invoke-with" 1>&2
226 usage="yes"
227 break
228 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700229 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700230 shift
231 elif [ "x$1" = "x--dev" ]; then
232 run_args="${run_args} --dev"
233 dev_mode="yes"
234 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700235 elif [ "x$1" = "x--build-only" ]; then
236 build_only="yes"
237 shift
238 elif [ "x$1" = "x--output-path" ]; then
239 shift
240 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700241 if [ "x$tmp_dir" = "x" ]; then
242 echo "$0 missing argument to --output-path" 1>&2
243 usage="yes"
244 break
245 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700246 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000247 elif [ "x$1" = "x--android-root" ]; then
248 shift
249 if [ "x$1" = "x" ]; then
250 echo "$0 missing argument to --android-root" 1>&2
251 usage="yes"
252 break
253 fi
254 android_root="$1"
255 run_args="${run_args} --android-root $1"
256 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700257 elif [ "x$1" = "x--update" ]; then
258 update_mode="yes"
259 shift
260 elif [ "x$1" = "x--help" ]; then
261 usage="yes"
262 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700263 elif [ "x$1" = "x--64" ]; then
264 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700265 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700266 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200267 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700268 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200269 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700270 elif [ "x$1" = "x--always-clean" ]; then
271 always_clean="yes"
272 shift
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800273 elif [ "x$1" = "x--dex2oat-swap" ]; then
274 run_args="${run_args} --dex2oat-swap"
275 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700276 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700277 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700278 usage="yes"
279 break
280 else
281 break
282 fi
283done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700284
285# tmp_dir may be relative, resolve.
286#
287# Cannot use realpath, as it does not exist on Mac.
288# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700289# Cannot use readlink -m, as it does not exist on Mac.
290# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700291noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700292tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700293mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700294
Alex Lighte7873ec2014-08-12 09:53:50 -0700295if [ "$basic_verify" = "true" ]; then
Hiroshi Yamauchi312baf12015-01-12 12:11:05 -0800296 # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests.
297 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0"
Alex Lighte7873ec2014-08-12 09:53:50 -0700298fi
299if [ "$gc_verify" = "true" ]; then
300 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
301fi
302if [ "$gc_stress" = "true" ]; then
303 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
304fi
Jeff Hao85139a32014-07-23 11:52:52 -0700305if [ "$trace" = "true" ]; then
306 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
307fi
308
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700309# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100310# 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 -0700311function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100312 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800313 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64|mips64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700314 if [ "x${suffix64}" = "x64" ]; then
315 target_arch_name=${grep64bit}
316 else
317 target_arch_name=${grep32bit}
318 fi
319}
320
Alex Lighta59dd802014-07-02 16:28:08 -0700321if [ "$target_mode" = "no" ]; then
322 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700323 if [ "$prebuild_mode" = "yes" ]; then
324 echo "--prebuild with --jvm is unsupported";
325 exit 1;
326 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700327 fi
328fi
329
Alex Light03a112d2014-08-25 13:25:56 -0700330if [ "$have_patchoat" = "no" ]; then
331 run_args="${run_args} --no-patchoat"
332fi
333
334if [ "$have_dex2oat" = "no" ]; then
335 run_args="${run_args} --no-dex2oat"
336fi
337
Jeff Hao201803f2013-11-20 18:11:39 -0800338if [ ! "$runtime" = "jvm" ]; then
339 run_args="${run_args} --lib $lib"
340fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700341
Jeff Hao201803f2013-11-20 18:11:39 -0800342if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700343 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100344 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700345 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
346 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
347 else
348 true # defaults to using target BOOTCLASSPATH
349 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800350elif [ "$runtime" = "art" ]; then
351 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100352 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800353 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100354 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800355 fi
356 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100357 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800358 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000359 run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700360 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800361 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700362 guess_arch_name
363 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000364 run_args="${run_args} --boot /data/art-test/core${image_suffix}${pic_image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800365 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700366 if [ "$relocate" = "yes" ]; then
367 run_args="${run_args} --relocate"
368 else
369 run_args="${run_args} --no-relocate"
370 fi
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700371elif [ "$runtime" = "jvm" ]; then
372 # TODO: Detect whether the host is 32-bit or 64-bit.
373 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib64"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700374fi
375
Alex Light03a112d2014-08-25 13:25:56 -0700376if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700377 if [ "$runtime" != "art" ]; then
378 echo "--no-image is only supported on the art runtime"
379 exit 1
380 fi
381 if [ "$target_mode" = "no" ]; then
382 framework="${ANDROID_HOST_OUT}/framework"
383 bpath_suffix="-hostdex"
384 else
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000385 framework="${android_root}/framework"
Alex Light1ef4ce82014-08-27 11:13:47 -0700386 bpath_suffix=""
387 fi
388 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
389 # fail since these jar files will be stripped.
390 bpath="${framework}/core-libart${bpath_suffix}.jar"
391 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
392 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
393 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
394 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
395 # Pass down the bootclasspath
396 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700397 run_args="${run_args} --no-image"
398fi
399
jeffhao5d1ac922011-09-29 17:41:15 -0700400if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
401 echo "--dev and --update are mutually exclusive" 1>&2
402 usage="yes"
403fi
404
405if [ "$usage" = "no" ]; then
406 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
407 test_dir=`basename "$oldwd"`
408 else
409 test_dir="$1"
410 fi
411
412 if [ '!' -d "$test_dir" ]; then
413 td2=`echo ${test_dir}-*`
414 if [ '!' -d "$td2" ]; then
415 echo "${test_dir}: no such test directory" 1>&2
416 usage="yes"
417 fi
418 test_dir="$td2"
419 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700420 # Shift to get rid of the test name argument. The rest of the arguments
421 # will get passed to the test run.
422 shift
423fi
424
425if [ "$usage" = "yes" ]; then
426 prog=`basename $prog`
427 (
428 echo "usage:"
429 echo " $prog --help Print this message."
430 echo " $prog [options] [test-name] Run test normally."
431 echo " $prog --dev [options] [test-name] Development mode" \
432 "(dumps to stdout)."
433 echo " $prog --update [options] [test-name] Update mode" \
434 "(replaces expected.txt)."
435 echo ' Omitting the test name or specifying "-" will use the' \
436 "current directory."
437 echo " Runtime Options:"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000438 echo " -O Run non-debug rather than debug build (off by default)."
439 echo " -Xcompiler-option Pass an option to the compiler."
440 echo " --runtime-option Pass an option to the runtime."
441 echo " --debug Wait for a debugger to attach."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000442 echo " --debuggable Whether to compile Java code for a debugger."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000443 echo " --gdb Run under gdb; incompatible with some tests."
444 echo " --build-only Build test files only (off by default)."
445 echo " --interpreter Enable interpreter only mode (off by default)."
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800446 echo " --jit Enable jit (off by default)."
Nicolas Geoffray0e071252015-03-21 13:43:15 +0000447 echo " --optimizing Enable optimizing compiler (default)."
448 echo " --quick Use Quick compiler (off by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000449 echo " --no-verify Turn off verification (on by default)."
450 echo " --no-optimize Turn off optimization (on by default)."
451 echo " --no-precise Turn off precise GC (on by default)."
452 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700453 "If used, then the"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000454 echo " other runtime options are ignored."
455 echo " --no-dex2oat Run as though dex2oat was failing."
456 echo " --no-patchoat Run as though patchoat was failing."
457 echo " --prebuild Run dex2oat on the files before starting test. (default)"
458 echo " --no-prebuild Do not run dex2oat on the files before starting"
459 echo " the test."
460 echo " --relocate Force the use of relocating in the test, making"
461 echo " the image and oat files be relocated to a random"
462 echo " address before running. (default)"
463 echo " --no-relocate Force the use of no relocating in the test"
464 echo " --host Use the host-mode virtual machine."
465 echo " --invoke-with Pass --invoke-with option to runtime."
466 echo " --dalvik Use Dalvik (off by default)."
467 echo " --jvm Use a host-local RI virtual machine."
468 echo " --output-path [path] Location where to store the build" \
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700469 "files."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000470 echo " --64 Run the test in 64-bit mode"
471 echo " --trace Run with method tracing"
472 echo " --gcstress Run with gc stress testing"
473 echo " --gcverify Run with gc verification"
474 echo " --always-clean Delete the test files even if the test fails."
475 echo " --android-root [path] The path on target for the android root. (/system by default)."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000476 echo " --dex2oat-swap Use a dex2oat swap file."
jeffhao5d1ac922011-09-29 17:41:15 -0700477 ) 1>&2
478 exit 1
479fi
480
481cd "$test_dir"
482test_dir=`pwd`
483
484td_info="${test_dir}/${info}"
485td_expected="${test_dir}/${expected}"
486
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700487if [ ! -r $td_info ]; then
488 echo "${test_dir}: missing file $td_info" 1>&2
489 exit 1
490fi
491
492if [ ! -r $td_expected ]; then
493 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700494 exit 1
495fi
496
497# copy the test to a temp dir and run it
498
Elliott Hughes510c8782011-10-06 10:57:34 -0700499echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700500
501rm -rf "$tmp_dir"
502cp -Rp "$test_dir" "$tmp_dir"
503cd "$tmp_dir"
504
505if [ '!' -r "$build" ]; then
506 cp "${progdir}/etc/default-build" build
Zheng Xuc6667102015-05-15 16:08:45 +0800507else
508 cp "${progdir}/etc/default-build" .
jeffhao5d1ac922011-09-29 17:41:15 -0700509fi
510
511if [ '!' -r "$run" ]; then
512 cp "${progdir}/etc/default-run" run
Zheng Xuc6667102015-05-15 16:08:45 +0800513else
514 cp "${progdir}/etc/default-run" .
jeffhao5d1ac922011-09-29 17:41:15 -0700515fi
516
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700517if [ '!' -r "$check_cmd" ]; then
518 cp "${progdir}/etc/default-check" check
Zheng Xuc6667102015-05-15 16:08:45 +0800519else
520 cp "${progdir}/etc/default-check" .
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700521fi
522
jeffhao5d1ac922011-09-29 17:41:15 -0700523chmod 755 "$build"
524chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700525chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700526
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700527export TEST_NAME=`basename ${test_dir}`
528
David Brazdil4846d132015-01-15 19:07:08 +0000529# Tests named '<number>-checker-*' will also have their CFGs verified with
530# Checker when compiled with Optimizing on host.
531if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
532 # Build Checker DEX files without dx's optimizations so the input to dex2oat
533 # better resembles the Java source. We always build the DEX the same way, even
534 # if Checker is not invoked and the test only runs the program.
535 build_args="${build_args} --dx-option --no-optimize"
536
Nicolas Geoffraye7307292015-03-17 18:12:06 +0000537 if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$target_mode" = "no" -a "$debuggable" = "no" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000538 run_checker="yes"
539 run_args="${run_args} -Xcompiler-option --dump-cfg=$tmp_dir/$cfg_output \
540 -Xcompiler-option -j1"
541 fi
542fi
543
Ian Rogers997f0f92014-06-21 22:58:05 -0700544# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
545file_size_limit=2048
546if echo "$test_dir" | grep 089; then
547 file_size_limit=5120
548elif echo "$test_dir" | grep 083; then
549 file_size_limit=5120
550fi
Alex Lighta59dd802014-07-02 16:28:08 -0700551if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700552 echo "ulimit file size setting failed"
553fi
554
jeffhao5d1ac922011-09-29 17:41:15 -0700555good="no"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000556good_build="yes"
557good_run="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700558if [ "$dev_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000559 "./${build}" $build_args 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700560 build_exit="$?"
561 echo "build exit status: $build_exit" 1>&2
562 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800563 echo "${test_dir}: running..." 1>&2
564 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700565 run_exit="$?"
Calin Juravle3cf48772015-01-26 16:47:33 +0000566
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800567 if [ "$run_exit" = "0" ]; then
Calin Juravle3cf48772015-01-26 16:47:33 +0000568 if [ "$run_checker" = "yes" ]; then
569 "$checker" "$cfg_output" "$tmp_dir" 2>&1
570 checker_exit="$?"
571 if [ "$checker_exit" = "0" ]; then
572 good="yes"
573 fi
574 echo "checker exit status: $checker_exit" 1>&2
575 else
576 good="yes"
577 fi
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800578 fi
Calin Juravle3cf48772015-01-26 16:47:33 +0000579 echo "run exit status: $run_exit" 1>&2
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700580 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700581elif [ "$update_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000582 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700583 build_exit="$?"
584 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800585 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700586 "./${run}" $run_args "$@" >"$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000587 if [ "$run_checker" = "yes" ]; then
588 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
589 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700590 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
591 good="yes"
592 else
593 cat "$build_output" 1>&2
594 echo "build exit status: $build_exit" 1>&2
595 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700596elif [ "$build_only" = "yes" ]; then
597 good="yes"
David Brazdil4846d132015-01-15 19:07:08 +0000598 "./${build}" $build_args >"$build_output" 2>&1
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700599 build_exit="$?"
600 if [ "$build_exit" '!=' '0' ]; then
601 cp "$build_output" "$output"
602 echo "build exit status: $build_exit" >>"$output"
603 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
604 if [ "$?" '!=' "0" ]; then
605 good="no"
606 echo "BUILD FAILED For ${TEST_NAME}"
607 fi
608 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700609 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700610 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700611 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700612else
David Brazdil4846d132015-01-15 19:07:08 +0000613 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700614 build_exit="$?"
615 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800616 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700617 "./${run}" $run_args "$@" >"$output" 2>&1
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000618 run_exit="$?"
619 if [ "$run_exit" != "0" ]; then
620 echo "run exit status: $run_exit" 1>&2
621 good_run="no"
David Brazdil4846d132015-01-15 19:07:08 +0000622 elif [ "$run_checker" = "yes" ]; then
623 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
624 checker_exit="$?"
625 if [ "$checker_exit" != "0" ]; then
626 echo "checker exit status: $checker_exit" 1>&2
627 good_run="no"
628 else
629 good_run="yes"
630 fi
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000631 else
632 good_run="yes"
633 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700634 else
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000635 good_build="no"
jeffhao5d1ac922011-09-29 17:41:15 -0700636 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700637 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
638 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700639 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700640 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700641 max_name_length=$(getconf NAME_MAX ${tmp_dir})
642 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
643 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700644 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700645 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700646 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700647 if [ "$?" = "0" ]; then
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000648 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
649 # output == expected
650 good="yes"
651 echo "${test_dir}: succeeded!" 1>&2
652 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700653 fi
654fi
655
jeffhao5d1ac922011-09-29 17:41:15 -0700656(
Alex Lightbfac14a2014-07-30 09:41:21 -0700657 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700658 echo "${test_dir}: FAILED!"
659 echo ' '
660 echo '#################### info'
661 cat "${td_info}" | sed 's/^/# /g'
662 echo '#################### diffs'
Ian Rogers75deec02014-11-23 20:07:39 -0800663 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 2000
jeffhao5d1ac922011-09-29 17:41:15 -0700664 echo '####################'
665 echo ' '
666 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700667
668) 1>&2
669
670# Clean up test files.
671if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
672 cd "$oldwd"
673 rm -rf "$tmp_dir"
674 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
675 adb shell rm -rf $DEX_LOCATION
676 fi
677 if [ "$good" = "yes" ]; then
678 exit 0
679 fi
680fi
681
682
683(
684 if [ "$always_clean" = "yes" ]; then
685 echo "${TEST_NAME} files deleted from host "
686 if [ "$target_mode" == "yes" ]; then
687 echo "and from target"
688 fi
689 else
690 echo "${TEST_NAME} files left in ${tmp_dir} on host"
691 if [ "$target_mode" == "yes" ]; then
692 echo "and in ${DEX_LOCATION} on target"
693 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700694 fi
695
jeffhao5d1ac922011-09-29 17:41:15 -0700696) 1>&2
697
698exit 1