blob: 54c6bbda125954b7c649b9a1fc2544e707da8ba0 [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 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
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
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700371fi
372
Alex Light03a112d2014-08-25 13:25:56 -0700373if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700374 if [ "$runtime" != "art" ]; then
375 echo "--no-image is only supported on the art runtime"
376 exit 1
377 fi
378 if [ "$target_mode" = "no" ]; then
379 framework="${ANDROID_HOST_OUT}/framework"
380 bpath_suffix="-hostdex"
381 else
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000382 framework="${android_root}/framework"
Alex Light1ef4ce82014-08-27 11:13:47 -0700383 bpath_suffix=""
384 fi
385 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
386 # fail since these jar files will be stripped.
387 bpath="${framework}/core-libart${bpath_suffix}.jar"
388 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
389 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
390 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
391 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
392 # Pass down the bootclasspath
393 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700394 run_args="${run_args} --no-image"
395fi
396
jeffhao5d1ac922011-09-29 17:41:15 -0700397if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
398 echo "--dev and --update are mutually exclusive" 1>&2
399 usage="yes"
400fi
401
402if [ "$usage" = "no" ]; then
403 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
404 test_dir=`basename "$oldwd"`
405 else
406 test_dir="$1"
407 fi
408
409 if [ '!' -d "$test_dir" ]; then
410 td2=`echo ${test_dir}-*`
411 if [ '!' -d "$td2" ]; then
412 echo "${test_dir}: no such test directory" 1>&2
413 usage="yes"
414 fi
415 test_dir="$td2"
416 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700417 # Shift to get rid of the test name argument. The rest of the arguments
418 # will get passed to the test run.
419 shift
420fi
421
422if [ "$usage" = "yes" ]; then
423 prog=`basename $prog`
424 (
425 echo "usage:"
426 echo " $prog --help Print this message."
427 echo " $prog [options] [test-name] Run test normally."
428 echo " $prog --dev [options] [test-name] Development mode" \
429 "(dumps to stdout)."
430 echo " $prog --update [options] [test-name] Update mode" \
431 "(replaces expected.txt)."
432 echo ' Omitting the test name or specifying "-" will use the' \
433 "current directory."
434 echo " Runtime Options:"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000435 echo " -O Run non-debug rather than debug build (off by default)."
436 echo " -Xcompiler-option Pass an option to the compiler."
437 echo " --runtime-option Pass an option to the runtime."
438 echo " --debug Wait for a debugger to attach."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000439 echo " --debuggable Whether to compile Java code for a debugger."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000440 echo " --gdb Run under gdb; incompatible with some tests."
441 echo " --build-only Build test files only (off by default)."
442 echo " --interpreter Enable interpreter only mode (off by default)."
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800443 echo " --jit Enable jit (off by default)."
Nicolas Geoffray0e071252015-03-21 13:43:15 +0000444 echo " --optimizing Enable optimizing compiler (default)."
445 echo " --quick Use Quick compiler (off by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000446 echo " --no-verify Turn off verification (on by default)."
447 echo " --no-optimize Turn off optimization (on by default)."
448 echo " --no-precise Turn off precise GC (on by default)."
449 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700450 "If used, then the"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000451 echo " other runtime options are ignored."
452 echo " --no-dex2oat Run as though dex2oat was failing."
453 echo " --no-patchoat Run as though patchoat was failing."
454 echo " --prebuild Run dex2oat on the files before starting test. (default)"
455 echo " --no-prebuild Do not run dex2oat on the files before starting"
456 echo " the test."
457 echo " --relocate Force the use of relocating in the test, making"
458 echo " the image and oat files be relocated to a random"
459 echo " address before running. (default)"
460 echo " --no-relocate Force the use of no relocating in the test"
461 echo " --host Use the host-mode virtual machine."
462 echo " --invoke-with Pass --invoke-with option to runtime."
463 echo " --dalvik Use Dalvik (off by default)."
464 echo " --jvm Use a host-local RI virtual machine."
465 echo " --output-path [path] Location where to store the build" \
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700466 "files."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000467 echo " --64 Run the test in 64-bit mode"
468 echo " --trace Run with method tracing"
469 echo " --gcstress Run with gc stress testing"
470 echo " --gcverify Run with gc verification"
471 echo " --always-clean Delete the test files even if the test fails."
472 echo " --android-root [path] The path on target for the android root. (/system by default)."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000473 echo " --dex2oat-swap Use a dex2oat swap file."
jeffhao5d1ac922011-09-29 17:41:15 -0700474 ) 1>&2
475 exit 1
476fi
477
478cd "$test_dir"
479test_dir=`pwd`
480
481td_info="${test_dir}/${info}"
482td_expected="${test_dir}/${expected}"
483
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700484if [ ! -r $td_info ]; then
485 echo "${test_dir}: missing file $td_info" 1>&2
486 exit 1
487fi
488
489if [ ! -r $td_expected ]; then
490 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700491 exit 1
492fi
493
494# copy the test to a temp dir and run it
495
Elliott Hughes510c8782011-10-06 10:57:34 -0700496echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700497
498rm -rf "$tmp_dir"
499cp -Rp "$test_dir" "$tmp_dir"
500cd "$tmp_dir"
501
502if [ '!' -r "$build" ]; then
503 cp "${progdir}/etc/default-build" build
Zheng Xuc6667102015-05-15 16:08:45 +0800504else
505 cp "${progdir}/etc/default-build" .
jeffhao5d1ac922011-09-29 17:41:15 -0700506fi
507
508if [ '!' -r "$run" ]; then
509 cp "${progdir}/etc/default-run" run
Zheng Xuc6667102015-05-15 16:08:45 +0800510else
511 cp "${progdir}/etc/default-run" .
jeffhao5d1ac922011-09-29 17:41:15 -0700512fi
513
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700514if [ '!' -r "$check_cmd" ]; then
515 cp "${progdir}/etc/default-check" check
Zheng Xuc6667102015-05-15 16:08:45 +0800516else
517 cp "${progdir}/etc/default-check" .
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700518fi
519
jeffhao5d1ac922011-09-29 17:41:15 -0700520chmod 755 "$build"
521chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700522chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700523
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700524export TEST_NAME=`basename ${test_dir}`
525
David Brazdil4846d132015-01-15 19:07:08 +0000526# Tests named '<number>-checker-*' will also have their CFGs verified with
527# Checker when compiled with Optimizing on host.
528if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
529 # Build Checker DEX files without dx's optimizations so the input to dex2oat
530 # better resembles the Java source. We always build the DEX the same way, even
531 # if Checker is not invoked and the test only runs the program.
532 build_args="${build_args} --dx-option --no-optimize"
533
Nicolas Geoffraye7307292015-03-17 18:12:06 +0000534 if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$target_mode" = "no" -a "$debuggable" = "no" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000535 run_checker="yes"
536 run_args="${run_args} -Xcompiler-option --dump-cfg=$tmp_dir/$cfg_output \
537 -Xcompiler-option -j1"
538 fi
539fi
540
Ian Rogers997f0f92014-06-21 22:58:05 -0700541# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
542file_size_limit=2048
543if echo "$test_dir" | grep 089; then
544 file_size_limit=5120
545elif echo "$test_dir" | grep 083; then
546 file_size_limit=5120
547fi
Alex Lighta59dd802014-07-02 16:28:08 -0700548if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700549 echo "ulimit file size setting failed"
550fi
551
jeffhao5d1ac922011-09-29 17:41:15 -0700552good="no"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000553good_build="yes"
554good_run="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700555if [ "$dev_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000556 "./${build}" $build_args 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700557 build_exit="$?"
558 echo "build exit status: $build_exit" 1>&2
559 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800560 echo "${test_dir}: running..." 1>&2
561 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700562 run_exit="$?"
Calin Juravle3cf48772015-01-26 16:47:33 +0000563
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800564 if [ "$run_exit" = "0" ]; then
Calin Juravle3cf48772015-01-26 16:47:33 +0000565 if [ "$run_checker" = "yes" ]; then
566 "$checker" "$cfg_output" "$tmp_dir" 2>&1
567 checker_exit="$?"
568 if [ "$checker_exit" = "0" ]; then
569 good="yes"
570 fi
571 echo "checker exit status: $checker_exit" 1>&2
572 else
573 good="yes"
574 fi
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800575 fi
Calin Juravle3cf48772015-01-26 16:47:33 +0000576 echo "run exit status: $run_exit" 1>&2
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700577 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700578elif [ "$update_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000579 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700580 build_exit="$?"
581 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800582 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700583 "./${run}" $run_args "$@" >"$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000584 if [ "$run_checker" = "yes" ]; then
585 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
586 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700587 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
588 good="yes"
589 else
590 cat "$build_output" 1>&2
591 echo "build exit status: $build_exit" 1>&2
592 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700593elif [ "$build_only" = "yes" ]; then
594 good="yes"
David Brazdil4846d132015-01-15 19:07:08 +0000595 "./${build}" $build_args >"$build_output" 2>&1
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700596 build_exit="$?"
597 if [ "$build_exit" '!=' '0' ]; then
598 cp "$build_output" "$output"
599 echo "build exit status: $build_exit" >>"$output"
600 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
601 if [ "$?" '!=' "0" ]; then
602 good="no"
603 echo "BUILD FAILED For ${TEST_NAME}"
604 fi
605 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700606 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700607 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700608 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700609else
David Brazdil4846d132015-01-15 19:07:08 +0000610 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700611 build_exit="$?"
612 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800613 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700614 "./${run}" $run_args "$@" >"$output" 2>&1
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000615 run_exit="$?"
616 if [ "$run_exit" != "0" ]; then
617 echo "run exit status: $run_exit" 1>&2
618 good_run="no"
David Brazdil4846d132015-01-15 19:07:08 +0000619 elif [ "$run_checker" = "yes" ]; then
620 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
621 checker_exit="$?"
622 if [ "$checker_exit" != "0" ]; then
623 echo "checker exit status: $checker_exit" 1>&2
624 good_run="no"
625 else
626 good_run="yes"
627 fi
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000628 else
629 good_run="yes"
630 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700631 else
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000632 good_build="no"
jeffhao5d1ac922011-09-29 17:41:15 -0700633 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700634 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
635 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700636 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700637 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700638 max_name_length=$(getconf NAME_MAX ${tmp_dir})
639 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
640 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700641 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700642 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700643 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700644 if [ "$?" = "0" ]; then
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000645 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
646 # output == expected
647 good="yes"
648 echo "${test_dir}: succeeded!" 1>&2
649 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700650 fi
651fi
652
jeffhao5d1ac922011-09-29 17:41:15 -0700653(
Alex Lightbfac14a2014-07-30 09:41:21 -0700654 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700655 echo "${test_dir}: FAILED!"
656 echo ' '
657 echo '#################### info'
658 cat "${td_info}" | sed 's/^/# /g'
659 echo '#################### diffs'
Ian Rogers75deec02014-11-23 20:07:39 -0800660 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 2000
jeffhao5d1ac922011-09-29 17:41:15 -0700661 echo '####################'
662 echo ' '
663 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700664
665) 1>&2
666
667# Clean up test files.
668if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
669 cd "$oldwd"
670 rm -rf "$tmp_dir"
671 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
672 adb shell rm -rf $DEX_LOCATION
673 fi
674 if [ "$good" = "yes" ]; then
675 exit 0
676 fi
677fi
678
679
680(
681 if [ "$always_clean" = "yes" ]; then
682 echo "${TEST_NAME} files deleted from host "
683 if [ "$target_mode" == "yes" ]; then
684 echo "and from target"
685 fi
686 else
687 echo "${TEST_NAME} files left in ${tmp_dir} on host"
688 if [ "$target_mode" == "yes" ]; then
689 echo "and in ${DEX_LOCATION} on target"
690 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700691 fi
692
jeffhao5d1ac922011-09-29 17:41:15 -0700693) 1>&2
694
695exit 1