blob: 995d30f545acce83d11718a0e7f9d99b434e703c [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"
Andreas Gampe7526d782015-06-22 22:53:45 -070095trace_stream="false"
Alex Lighte7873ec2014-08-12 09:53:50 -070096basic_verify="false"
97gc_verify="false"
98gc_stress="false"
Alex Lightbfac14a2014-07-30 09:41:21 -070099always_clean="no"
Igor Murashkin05f30e12015-06-10 15:57:17 -0700100never_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -0700101have_dex2oat="yes"
102have_patchoat="yes"
103have_image="yes"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700104image_suffix=""
Andreas Gampec23c9c92014-10-28 14:47:25 -0700105pic_image_suffix=""
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000106android_root="/system"
jeffhao5d1ac922011-09-29 17:41:15 -0700107
108while true; do
109 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700110 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700111 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100112 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700113 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800114 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700115 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800116 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700117 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700118 NEED_DEX="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100119 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700120 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800121 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700122 lib="libart.so"
123 shift
124 elif [ "x$1" = "x--dalvik" ]; then
125 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800126 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700127 shift
Alex Light03a112d2014-08-25 13:25:56 -0700128 elif [ "x$1" = "x--no-dex2oat" ]; then
129 have_dex2oat="no"
130 shift
131 elif [ "x$1" = "x--no-patchoat" ]; then
132 have_patchoat="no"
133 shift
134 elif [ "x$1" = "x--no-image" ]; then
135 have_image="no"
136 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700137 elif [ "x$1" = "x--pic-image" ]; then
138 pic_image_suffix="-pic"
139 shift
140 elif [ "x$1" = "x--pic-test" ]; then
141 run_args="${run_args} --pic-test"
142 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700143 elif [ "x$1" = "x--relocate" ]; then
144 relocate="yes"
145 shift
146 elif [ "x$1" = "x--no-relocate" ]; then
147 relocate="no"
148 shift
149 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100150 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700151 prebuild_mode="yes"
152 shift;
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000153 elif [ "x$1" = "x--debuggable" ]; then
154 run_args="${run_args} -Xcompiler-option --debuggable"
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +0000155 debuggable="yes"
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000156 shift;
Alex Lighta59dd802014-07-02 16:28:08 -0700157 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100158 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700159 prebuild_mode="no"
160 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700161 elif [ "x$1" = "x--gcverify" ]; then
162 basic_verify="true"
163 gc_verify="true"
164 shift
165 elif [ "x$1" = "x--gcstress" ]; then
166 basic_verify="true"
167 gc_stress="true"
168 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700169 elif [ "x$1" = "x--image" ]; then
170 shift
171 image="$1"
172 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700173 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000174 elif [ "x$1" = "x-Xcompiler-option" ]; then
175 shift
176 option="$1"
177 run_args="${run_args} -Xcompiler-option $option"
178 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700179 elif [ "x$1" = "x--runtime-option" ]; then
180 shift
181 option="$1"
182 run_args="${run_args} --runtime-option $option"
183 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700184 elif [ "x$1" = "x--gdb-arg" ]; then
185 shift
186 gdb_arg="$1"
187 run_args="${run_args} --gdb-arg $gdb_arg"
188 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700189 elif [ "x$1" = "x--debug" ]; then
190 run_args="${run_args} --debug"
191 shift
192 elif [ "x$1" = "x--gdb" ]; then
193 run_args="${run_args} --gdb"
194 dev_mode="yes"
195 shift
196 elif [ "x$1" = "x--zygote" ]; then
197 run_args="${run_args} --zygote"
198 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800199 elif [ "x$1" = "x--interpreter" ]; then
200 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700201 image_suffix="-interpreter"
202 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800203 elif [ "x$1" = "x--jit" ]; then
204 run_args="${run_args} --jit"
Mathieu Chartiere2a12c02015-02-27 13:21:15 -0800205 image_suffix="-interpreter"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800206 shift
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700207 elif [ "x$1" = "x--optimizing" ]; then
208 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
209 image_suffix="-optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800210 shift
Nicolas Geoffrayc9338b92014-12-03 13:36:10 +0000211 elif [ "x$1" = "x--quick" ]; then
212 run_args="${run_args} -Xcompiler-option --compiler-backend=Quick"
213 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700214 elif [ "x$1" = "x--no-verify" ]; then
215 run_args="${run_args} --no-verify"
216 shift
217 elif [ "x$1" = "x--no-optimize" ]; then
218 run_args="${run_args} --no-optimize"
219 shift
220 elif [ "x$1" = "x--no-precise" ]; then
221 run_args="${run_args} --no-precise"
222 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700223 elif [ "x$1" = "x--invoke-with" ]; then
224 shift
225 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700226 if [ "x$what" = "x" ]; then
227 echo "$0 missing argument to --invoke-with" 1>&2
228 usage="yes"
229 break
230 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700231 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700232 shift
233 elif [ "x$1" = "x--dev" ]; then
234 run_args="${run_args} --dev"
235 dev_mode="yes"
236 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700237 elif [ "x$1" = "x--build-only" ]; then
238 build_only="yes"
239 shift
240 elif [ "x$1" = "x--output-path" ]; then
241 shift
242 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700243 if [ "x$tmp_dir" = "x" ]; then
244 echo "$0 missing argument to --output-path" 1>&2
245 usage="yes"
246 break
247 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700248 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000249 elif [ "x$1" = "x--android-root" ]; then
250 shift
251 if [ "x$1" = "x" ]; then
252 echo "$0 missing argument to --android-root" 1>&2
253 usage="yes"
254 break
255 fi
256 android_root="$1"
257 run_args="${run_args} --android-root $1"
258 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700259 elif [ "x$1" = "x--update" ]; then
260 update_mode="yes"
261 shift
262 elif [ "x$1" = "x--help" ]; then
263 usage="yes"
264 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700265 elif [ "x$1" = "x--64" ]; then
266 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700267 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700268 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200269 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700270 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200271 shift
Andreas Gampe7526d782015-06-22 22:53:45 -0700272 elif [ "x$1" = "x--stream" ]; then
273 trace_stream="true"
274 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700275 elif [ "x$1" = "x--always-clean" ]; then
276 always_clean="yes"
277 shift
Igor Murashkin05f30e12015-06-10 15:57:17 -0700278 elif [ "x$1" = "x--never-clean" ]; then
279 never_clean="yes"
280 shift
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800281 elif [ "x$1" = "x--dex2oat-swap" ]; then
282 run_args="${run_args} --dex2oat-swap"
283 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700284 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700285 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700286 usage="yes"
287 break
288 else
289 break
290 fi
291done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700292
293# tmp_dir may be relative, resolve.
294#
295# Cannot use realpath, as it does not exist on Mac.
296# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700297# Cannot use readlink -m, as it does not exist on Mac.
298# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700299noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700300tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700301mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700302
Alex Lighte7873ec2014-08-12 09:53:50 -0700303if [ "$basic_verify" = "true" ]; then
Hiroshi Yamauchi312baf12015-01-12 12:11:05 -0800304 # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests.
305 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0"
Alex Lighte7873ec2014-08-12 09:53:50 -0700306fi
307if [ "$gc_verify" = "true" ]; then
308 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
309fi
310if [ "$gc_stress" = "true" ]; then
311 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
312fi
Jeff Hao85139a32014-07-23 11:52:52 -0700313if [ "$trace" = "true" ]; then
Andreas Gampe7526d782015-06-22 22:53:45 -0700314 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file-size:2000000"
315 if [ "$trace_stream" = "true" ]; then
316 # Streaming mode uses the file size as the buffer size. So output gets really large. Drop
317 # the ability to analyze the file and just write to /dev/null.
318 run_args="${run_args} --runtime-option -Xmethod-trace-file:/dev/null"
319 # Enable streaming mode.
320 run_args="${run_args} --runtime-option -Xmethod-trace-stream"
321 else
322 run_args="${run_args} --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin"
323 fi
324elif [ "$trace_stream" = "true" ]; then
325 echo "Cannot use --stream without --trace."
326 exit 1
Jeff Hao85139a32014-07-23 11:52:52 -0700327fi
328
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700329# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100330# 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 -0700331function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100332 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800333 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64|mips64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700334 if [ "x${suffix64}" = "x64" ]; then
335 target_arch_name=${grep64bit}
336 else
337 target_arch_name=${grep32bit}
338 fi
339}
340
Alex Lighta59dd802014-07-02 16:28:08 -0700341if [ "$target_mode" = "no" ]; then
342 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700343 if [ "$prebuild_mode" = "yes" ]; then
344 echo "--prebuild with --jvm is unsupported";
345 exit 1;
346 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700347 fi
348fi
349
Alex Light03a112d2014-08-25 13:25:56 -0700350if [ "$have_patchoat" = "no" ]; then
351 run_args="${run_args} --no-patchoat"
352fi
353
354if [ "$have_dex2oat" = "no" ]; then
355 run_args="${run_args} --no-dex2oat"
356fi
357
Jeff Hao201803f2013-11-20 18:11:39 -0800358if [ ! "$runtime" = "jvm" ]; then
359 run_args="${run_args} --lib $lib"
360fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700361
Jeff Hao201803f2013-11-20 18:11:39 -0800362if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700363 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100364 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700365 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
366 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
367 else
368 true # defaults to using target BOOTCLASSPATH
369 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800370elif [ "$runtime" = "art" ]; then
371 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100372 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800373 if [ -z "$ANDROID_BUILD_TOP" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100374 export ANDROID_BUILD_TOP=$oldwd
Brian Carlstrom43534862014-02-19 01:13:52 -0800375 fi
376 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100377 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800378 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000379 run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700380 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800381 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700382 guess_arch_name
383 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000384 run_args="${run_args} --boot /data/art-test/core${image_suffix}${pic_image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800385 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700386 if [ "$relocate" = "yes" ]; then
387 run_args="${run_args} --relocate"
388 else
389 run_args="${run_args} --no-relocate"
390 fi
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700391elif [ "$runtime" = "jvm" ]; then
392 # TODO: Detect whether the host is 32-bit or 64-bit.
393 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib64"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700394fi
395
Alex Light03a112d2014-08-25 13:25:56 -0700396if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700397 if [ "$runtime" != "art" ]; then
398 echo "--no-image is only supported on the art runtime"
399 exit 1
400 fi
401 if [ "$target_mode" = "no" ]; then
402 framework="${ANDROID_HOST_OUT}/framework"
403 bpath_suffix="-hostdex"
404 else
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000405 framework="${android_root}/framework"
Alex Light1ef4ce82014-08-27 11:13:47 -0700406 bpath_suffix=""
407 fi
408 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
409 # fail since these jar files will be stripped.
410 bpath="${framework}/core-libart${bpath_suffix}.jar"
411 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
412 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
413 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
414 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
415 # Pass down the bootclasspath
416 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700417 run_args="${run_args} --no-image"
418fi
419
jeffhao5d1ac922011-09-29 17:41:15 -0700420if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
421 echo "--dev and --update are mutually exclusive" 1>&2
422 usage="yes"
423fi
424
425if [ "$usage" = "no" ]; then
426 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
427 test_dir=`basename "$oldwd"`
428 else
429 test_dir="$1"
430 fi
431
432 if [ '!' -d "$test_dir" ]; then
433 td2=`echo ${test_dir}-*`
434 if [ '!' -d "$td2" ]; then
435 echo "${test_dir}: no such test directory" 1>&2
436 usage="yes"
437 fi
438 test_dir="$td2"
439 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700440 # Shift to get rid of the test name argument. The rest of the arguments
441 # will get passed to the test run.
442 shift
443fi
444
445if [ "$usage" = "yes" ]; then
446 prog=`basename $prog`
447 (
448 echo "usage:"
449 echo " $prog --help Print this message."
450 echo " $prog [options] [test-name] Run test normally."
451 echo " $prog --dev [options] [test-name] Development mode" \
452 "(dumps to stdout)."
453 echo " $prog --update [options] [test-name] Update mode" \
454 "(replaces expected.txt)."
455 echo ' Omitting the test name or specifying "-" will use the' \
456 "current directory."
457 echo " Runtime Options:"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000458 echo " -O Run non-debug rather than debug build (off by default)."
459 echo " -Xcompiler-option Pass an option to the compiler."
460 echo " --runtime-option Pass an option to the runtime."
461 echo " --debug Wait for a debugger to attach."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000462 echo " --debuggable Whether to compile Java code for a debugger."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000463 echo " --gdb Run under gdb; incompatible with some tests."
464 echo " --build-only Build test files only (off by default)."
465 echo " --interpreter Enable interpreter only mode (off by default)."
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800466 echo " --jit Enable jit (off by default)."
Nicolas Geoffray0e071252015-03-21 13:43:15 +0000467 echo " --optimizing Enable optimizing compiler (default)."
468 echo " --quick Use Quick compiler (off by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000469 echo " --no-verify Turn off verification (on by default)."
470 echo " --no-optimize Turn off optimization (on by default)."
471 echo " --no-precise Turn off precise GC (on by default)."
472 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700473 "If used, then the"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000474 echo " other runtime options are ignored."
475 echo " --no-dex2oat Run as though dex2oat was failing."
476 echo " --no-patchoat Run as though patchoat was failing."
477 echo " --prebuild Run dex2oat on the files before starting test. (default)"
478 echo " --no-prebuild Do not run dex2oat on the files before starting"
479 echo " the test."
480 echo " --relocate Force the use of relocating in the test, making"
481 echo " the image and oat files be relocated to a random"
482 echo " address before running. (default)"
483 echo " --no-relocate Force the use of no relocating in the test"
484 echo " --host Use the host-mode virtual machine."
485 echo " --invoke-with Pass --invoke-with option to runtime."
486 echo " --dalvik Use Dalvik (off by default)."
487 echo " --jvm Use a host-local RI virtual machine."
488 echo " --output-path [path] Location where to store the build" \
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700489 "files."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000490 echo " --64 Run the test in 64-bit mode"
491 echo " --trace Run with method tracing"
Andreas Gampe7526d782015-06-22 22:53:45 -0700492 echo " --stream Run method tracing in streaming mode (requires --trace)"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000493 echo " --gcstress Run with gc stress testing"
494 echo " --gcverify Run with gc verification"
495 echo " --always-clean Delete the test files even if the test fails."
Igor Murashkin05f30e12015-06-10 15:57:17 -0700496 echo " --never-clean Keep the test files even if the test succeeds."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000497 echo " --android-root [path] The path on target for the android root. (/system by default)."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000498 echo " --dex2oat-swap Use a dex2oat swap file."
jeffhao5d1ac922011-09-29 17:41:15 -0700499 ) 1>&2
500 exit 1
501fi
502
503cd "$test_dir"
504test_dir=`pwd`
505
506td_info="${test_dir}/${info}"
507td_expected="${test_dir}/${expected}"
508
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700509if [ ! -r $td_info ]; then
510 echo "${test_dir}: missing file $td_info" 1>&2
511 exit 1
512fi
513
514if [ ! -r $td_expected ]; then
515 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700516 exit 1
517fi
518
519# copy the test to a temp dir and run it
520
Elliott Hughes510c8782011-10-06 10:57:34 -0700521echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700522
523rm -rf "$tmp_dir"
524cp -Rp "$test_dir" "$tmp_dir"
525cd "$tmp_dir"
526
527if [ '!' -r "$build" ]; then
528 cp "${progdir}/etc/default-build" build
Zheng Xuc6667102015-05-15 16:08:45 +0800529else
530 cp "${progdir}/etc/default-build" .
jeffhao5d1ac922011-09-29 17:41:15 -0700531fi
532
533if [ '!' -r "$run" ]; then
534 cp "${progdir}/etc/default-run" run
Zheng Xuc6667102015-05-15 16:08:45 +0800535else
536 cp "${progdir}/etc/default-run" .
jeffhao5d1ac922011-09-29 17:41:15 -0700537fi
538
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700539if [ '!' -r "$check_cmd" ]; then
540 cp "${progdir}/etc/default-check" check
Zheng Xuc6667102015-05-15 16:08:45 +0800541else
542 cp "${progdir}/etc/default-check" .
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700543fi
544
jeffhao5d1ac922011-09-29 17:41:15 -0700545chmod 755 "$build"
546chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700547chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700548
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700549export TEST_NAME=`basename ${test_dir}`
550
David Brazdil4846d132015-01-15 19:07:08 +0000551# Tests named '<number>-checker-*' will also have their CFGs verified with
552# Checker when compiled with Optimizing on host.
553if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
554 # Build Checker DEX files without dx's optimizations so the input to dex2oat
555 # better resembles the Java source. We always build the DEX the same way, even
556 # if Checker is not invoked and the test only runs the program.
557 build_args="${build_args} --dx-option --no-optimize"
558
Nicolas Geoffraye7307292015-03-17 18:12:06 +0000559 if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$target_mode" = "no" -a "$debuggable" = "no" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000560 run_checker="yes"
561 run_args="${run_args} -Xcompiler-option --dump-cfg=$tmp_dir/$cfg_output \
562 -Xcompiler-option -j1"
563 fi
564fi
565
Ian Rogers997f0f92014-06-21 22:58:05 -0700566# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
567file_size_limit=2048
568if echo "$test_dir" | grep 089; then
569 file_size_limit=5120
570elif echo "$test_dir" | grep 083; then
571 file_size_limit=5120
572fi
Alex Lighta59dd802014-07-02 16:28:08 -0700573if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700574 echo "ulimit file size setting failed"
575fi
576
jeffhao5d1ac922011-09-29 17:41:15 -0700577good="no"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000578good_build="yes"
579good_run="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700580if [ "$dev_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000581 "./${build}" $build_args 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700582 build_exit="$?"
583 echo "build exit status: $build_exit" 1>&2
584 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800585 echo "${test_dir}: running..." 1>&2
586 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700587 run_exit="$?"
Calin Juravle3cf48772015-01-26 16:47:33 +0000588
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800589 if [ "$run_exit" = "0" ]; then
Calin Juravle3cf48772015-01-26 16:47:33 +0000590 if [ "$run_checker" = "yes" ]; then
591 "$checker" "$cfg_output" "$tmp_dir" 2>&1
592 checker_exit="$?"
593 if [ "$checker_exit" = "0" ]; then
594 good="yes"
595 fi
596 echo "checker exit status: $checker_exit" 1>&2
597 else
598 good="yes"
599 fi
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800600 fi
Calin Juravle3cf48772015-01-26 16:47:33 +0000601 echo "run exit status: $run_exit" 1>&2
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700602 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700603elif [ "$update_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000604 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700605 build_exit="$?"
606 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800607 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700608 "./${run}" $run_args "$@" >"$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000609 if [ "$run_checker" = "yes" ]; then
610 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
611 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700612 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
613 good="yes"
614 else
615 cat "$build_output" 1>&2
616 echo "build exit status: $build_exit" 1>&2
617 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700618elif [ "$build_only" = "yes" ]; then
619 good="yes"
David Brazdil4846d132015-01-15 19:07:08 +0000620 "./${build}" $build_args >"$build_output" 2>&1
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700621 build_exit="$?"
622 if [ "$build_exit" '!=' '0' ]; then
623 cp "$build_output" "$output"
624 echo "build exit status: $build_exit" >>"$output"
625 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
626 if [ "$?" '!=' "0" ]; then
627 good="no"
628 echo "BUILD FAILED For ${TEST_NAME}"
629 fi
630 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700631 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700632 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700633 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700634else
David Brazdil4846d132015-01-15 19:07:08 +0000635 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700636 build_exit="$?"
637 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800638 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700639 "./${run}" $run_args "$@" >"$output" 2>&1
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000640 run_exit="$?"
641 if [ "$run_exit" != "0" ]; then
642 echo "run exit status: $run_exit" 1>&2
643 good_run="no"
David Brazdil4846d132015-01-15 19:07:08 +0000644 elif [ "$run_checker" = "yes" ]; then
645 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
646 checker_exit="$?"
647 if [ "$checker_exit" != "0" ]; then
648 echo "checker exit status: $checker_exit" 1>&2
649 good_run="no"
650 else
651 good_run="yes"
652 fi
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000653 else
654 good_run="yes"
655 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700656 else
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000657 good_build="no"
jeffhao5d1ac922011-09-29 17:41:15 -0700658 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700659 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
660 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700661 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700662 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700663 max_name_length=$(getconf NAME_MAX ${tmp_dir})
664 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
665 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700666 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700667 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700668 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700669 if [ "$?" = "0" ]; then
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000670 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
671 # output == expected
672 good="yes"
673 echo "${test_dir}: succeeded!" 1>&2
674 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700675 fi
676fi
677
jeffhao5d1ac922011-09-29 17:41:15 -0700678(
Alex Lightbfac14a2014-07-30 09:41:21 -0700679 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700680 echo "${test_dir}: FAILED!"
681 echo ' '
682 echo '#################### info'
683 cat "${td_info}" | sed 's/^/# /g'
684 echo '#################### diffs'
Ian Rogers75deec02014-11-23 20:07:39 -0800685 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 2000
jeffhao5d1ac922011-09-29 17:41:15 -0700686 echo '####################'
687 echo ' '
688 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700689
690) 1>&2
691
692# Clean up test files.
Igor Murashkin05f30e12015-06-10 15:57:17 -0700693if [ "$always_clean" = "yes" -o "$good" = "yes" ] && [ "$never_clean" = "no" ]; then
Alex Lightbfac14a2014-07-30 09:41:21 -0700694 cd "$oldwd"
695 rm -rf "$tmp_dir"
696 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
697 adb shell rm -rf $DEX_LOCATION
698 fi
699 if [ "$good" = "yes" ]; then
700 exit 0
701 fi
702fi
703
704
705(
706 if [ "$always_clean" = "yes" ]; then
707 echo "${TEST_NAME} files deleted from host "
708 if [ "$target_mode" == "yes" ]; then
709 echo "and from target"
710 fi
711 else
712 echo "${TEST_NAME} files left in ${tmp_dir} on host"
713 if [ "$target_mode" == "yes" ]; then
714 echo "and in ${DEX_LOCATION} on target"
715 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700716 fi
717
jeffhao5d1ac922011-09-29 17:41:15 -0700718) 1>&2
719
720exit 1