blob: b9df1f51ed13cc890179e23649b54313c6926990 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/bin/bash
2#
3# Copyright (C) 2007 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Set up prog to be the path of this script, including following symlinks,
18# and set up progdir to be the fully-qualified pathname of its directory.
19prog="$0"
Andreas Gampedeb48a02014-10-22 00:44:35 -070020args="$@"
jeffhao5d1ac922011-09-29 17:41:15 -070021while [ -h "${prog}" ]; do
22 newProg=`/bin/ls -ld "${prog}"`
23 newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
24 if expr "x${newProg}" : 'x/' >/dev/null; then
25 prog="${newProg}"
26 else
27 progdir=`dirname "${prog}"`
28 prog="${progdir}/${newProg}"
29 fi
30done
31oldwd=`pwd`
32progdir=`dirname "${prog}"`
33cd "${progdir}"
34progdir=`pwd`
35prog="${progdir}"/`basename "${prog}"`
Brian Carlstrom105215d2012-06-14 12:50:44 -070036test_dir="test-$$"
Andreas Gampe5a79fde2014-08-06 13:12:26 -070037if [ -z "$TMPDIR" ]; then
38 tmp_dir="/tmp/$USER/${test_dir}"
39else
40 tmp_dir="${TMPDIR}/$USER/${test_dir}"
41fi
David Brazdil4846d132015-01-15 19:07:08 +000042checker="${progdir}/../tools/checker.py"
jeffhao5d1ac922011-09-29 17:41:15 -070043
44export JAVA="java"
Brian Carlstrom5103ce62014-03-30 16:17:42 -070045export JAVAC="javac -g"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010046export RUN="${progdir}/etc/run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070047export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070048export NEED_DEX="true"
Sebastien Hertz5ee94542015-02-24 17:39:50 +010049export USE_JACK="false"
jeffhao5d1ac922011-09-29 17:41:15 -070050
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070051# If dx was not set by the environment variable, assume it is in the path.
52if [ -z "$DX" ]; then
53 export DX="dx"
54fi
55
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080056# If jasmin was not set by the environment variable, assume it is in the path.
57if [ -z "$JASMIN" ]; then
58 export JASMIN="jasmin"
59fi
60
Andreas Gampe8fda9f22014-10-03 16:15:37 -070061# If smali was not set by the environment variable, assume it is in the path.
62if [ -z "$SMALI" ]; then
63 export SMALI="smali"
64fi
65
66# If dexmerger was not set by the environment variable, assume it is in the path.
67if [ -z "$DXMERGER" ]; then
68 export DXMERGER="dexmerger"
69fi
70
Sebastien Hertz5ee94542015-02-24 17:39:50 +010071# If jack was not set by the environment variable, assume it is in the path.
72if [ -z "$JACK" ]; then
73 export JACK="jack"
74fi
75
76# If the tree is compiled with Jack, build test with Jack by default.
77if [ "$ANDROID_COMPILE_WITH_JACK" = "true" ]; then
78 USE_JACK="true"
79fi
80
81# ANDROID_BUILD_TOP is not set in a build environment.
82if [ -z "$ANDROID_BUILD_TOP" ]; then
83 export ANDROID_BUILD_TOP=$oldwd
84fi
85
86# If JACK_VM_COMMAND is not set, assume it launches the prebuilt jack-launcher.
87if [ -z "$JACK_VM_COMMAND" ]; then
88 if [ ! -z "$TMPDIR" ]; then
89 jack_temp_dir="-Djava.io.tmpdir=$TMPDIR"
90 fi
91 export JACK_VM_COMMAND="java -Dfile.encoding=UTF-8 -Xms2560m -XX:+TieredCompilation $jack_temp_dir -jar $ANDROID_BUILD_TOP/prebuilts/sdk/tools/jack-launcher.jar"
92fi
93
94# If JACK_CLASSPATH is not set, assume it only contains core-libart.
95if [ -z "$JACK_CLASSPATH" ]; then
Narayan Kamathd50687e2015-11-17 12:37:27 +000096 export JACK_CLASSPATH="$ANDROID_BUILD_TOP/out/host/common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack:$ANDROID_BUILD_TOP/out/host/common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/classes.jack:"
Sebastien Hertz5ee94542015-02-24 17:39:50 +010097fi
98
99# If JACK_JAR is not set, assume it is located in the prebuilts directory.
100if [ -z "$JACK_JAR" ]; then
101 export JACK_JAR="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/jack.jar"
102fi
103
104# If JILL_JAR is not set, assume it is located in the prebuilts directory.
105if [ -z "$JILL_JAR" ]; then
106 export JILL_JAR="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/jill.jar"
107fi
108
109export JACK="$JACK -g -cp $JACK_CLASSPATH"
110export JILL="java -jar $JILL_JAR"
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -0800111
jeffhao5d1ac922011-09-29 17:41:15 -0700112info="info.txt"
113build="build"
114run="run"
115expected="expected.txt"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700116check_cmd="check"
jeffhao5d1ac922011-09-29 17:41:15 -0700117output="output.txt"
118build_output="build-output.txt"
David Brazdil4846d132015-01-15 19:07:08 +0000119cfg_output="cfg-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700120lib="libartd.so"
jeffhao5d1ac922011-09-29 17:41:15 -0700121run_args="--quiet"
David Brazdil4846d132015-01-15 19:07:08 +0000122build_args=""
jeffhao5d1ac922011-09-29 17:41:15 -0700123
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +0000124debuggable="no"
Alex Light9d722532014-07-22 18:07:12 -0700125prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -0700126target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700127dev_mode="no"
128update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -0700129debug_mode="no"
130relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -0800131runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -0700132usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700133build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700134suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -0700135trace="false"
Andreas Gampeb91205e2015-06-22 22:53:45 -0700136trace_stream="false"
Alex Lighte7873ec2014-08-12 09:53:50 -0700137basic_verify="false"
138gc_verify="false"
139gc_stress="false"
Alex Lightbfac14a2014-07-30 09:41:21 -0700140always_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -0700141have_dex2oat="yes"
142have_patchoat="yes"
143have_image="yes"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700144image_suffix=""
Andreas Gampec23c9c92014-10-28 14:47:25 -0700145pic_image_suffix=""
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000146android_root="/system"
jeffhao5d1ac922011-09-29 17:41:15 -0700147
148while true; do
149 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700150 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700151 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100152 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700153 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800154 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700155 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800156 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700157 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700158 NEED_DEX="false"
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100159 USE_JACK="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100160 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700161 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800162 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700163 lib="libart.so"
164 shift
165 elif [ "x$1" = "x--dalvik" ]; then
166 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800167 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700168 shift
Alex Light03a112d2014-08-25 13:25:56 -0700169 elif [ "x$1" = "x--no-dex2oat" ]; then
170 have_dex2oat="no"
171 shift
172 elif [ "x$1" = "x--no-patchoat" ]; then
173 have_patchoat="no"
174 shift
175 elif [ "x$1" = "x--no-image" ]; then
176 have_image="no"
177 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700178 elif [ "x$1" = "x--pic-image" ]; then
179 pic_image_suffix="-pic"
180 shift
181 elif [ "x$1" = "x--pic-test" ]; then
182 run_args="${run_args} --pic-test"
183 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700184 elif [ "x$1" = "x--relocate" ]; then
185 relocate="yes"
186 shift
187 elif [ "x$1" = "x--no-relocate" ]; then
188 relocate="no"
189 shift
190 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100191 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700192 prebuild_mode="yes"
193 shift;
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000194 elif [ "x$1" = "x--debuggable" ]; then
195 run_args="${run_args} -Xcompiler-option --debuggable"
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +0000196 debuggable="yes"
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000197 shift;
Alex Lighta59dd802014-07-02 16:28:08 -0700198 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100199 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700200 prebuild_mode="no"
201 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700202 elif [ "x$1" = "x--gcverify" ]; then
203 basic_verify="true"
204 gc_verify="true"
205 shift
206 elif [ "x$1" = "x--gcstress" ]; then
207 basic_verify="true"
208 gc_stress="true"
209 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700210 elif [ "x$1" = "x--image" ]; then
211 shift
212 image="$1"
213 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700214 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000215 elif [ "x$1" = "x-Xcompiler-option" ]; then
216 shift
217 option="$1"
218 run_args="${run_args} -Xcompiler-option $option"
219 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700220 elif [ "x$1" = "x--runtime-option" ]; then
221 shift
222 option="$1"
223 run_args="${run_args} --runtime-option $option"
224 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700225 elif [ "x$1" = "x--gdb-arg" ]; then
226 shift
227 gdb_arg="$1"
228 run_args="${run_args} --gdb-arg $gdb_arg"
229 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700230 elif [ "x$1" = "x--debug" ]; then
231 run_args="${run_args} --debug"
232 shift
233 elif [ "x$1" = "x--gdb" ]; then
234 run_args="${run_args} --gdb"
235 dev_mode="yes"
236 shift
237 elif [ "x$1" = "x--zygote" ]; then
238 run_args="${run_args} --zygote"
239 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800240 elif [ "x$1" = "x--interpreter" ]; then
241 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700242 image_suffix="-interpreter"
243 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800244 elif [ "x$1" = "x--jit" ]; then
245 run_args="${run_args} --jit"
Mathieu Chartiere2a12c02015-02-27 13:21:15 -0800246 image_suffix="-interpreter"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800247 shift
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700248 elif [ "x$1" = "x--optimizing" ]; then
249 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
250 image_suffix="-optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800251 shift
Nicolas Geoffrayc9338b92014-12-03 13:36:10 +0000252 elif [ "x$1" = "x--quick" ]; then
253 run_args="${run_args} -Xcompiler-option --compiler-backend=Quick"
254 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700255 elif [ "x$1" = "x--no-verify" ]; then
256 run_args="${run_args} --no-verify"
257 shift
258 elif [ "x$1" = "x--no-optimize" ]; then
259 run_args="${run_args} --no-optimize"
260 shift
261 elif [ "x$1" = "x--no-precise" ]; then
262 run_args="${run_args} --no-precise"
263 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700264 elif [ "x$1" = "x--invoke-with" ]; then
265 shift
266 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700267 if [ "x$what" = "x" ]; then
268 echo "$0 missing argument to --invoke-with" 1>&2
269 usage="yes"
270 break
271 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700272 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700273 shift
274 elif [ "x$1" = "x--dev" ]; then
275 run_args="${run_args} --dev"
276 dev_mode="yes"
277 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700278 elif [ "x$1" = "x--build-only" ]; then
279 build_only="yes"
280 shift
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100281 elif [ "x$1" = "x--build-with-javac-dx" ]; then
282 USE_JACK="false"
283 shift
284 elif [ "x$1" = "x--build-with-jack" ]; then
285 USE_JACK="true"
286 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700287 elif [ "x$1" = "x--output-path" ]; then
288 shift
289 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700290 if [ "x$tmp_dir" = "x" ]; then
291 echo "$0 missing argument to --output-path" 1>&2
292 usage="yes"
293 break
294 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700295 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000296 elif [ "x$1" = "x--android-root" ]; then
297 shift
298 if [ "x$1" = "x" ]; then
299 echo "$0 missing argument to --android-root" 1>&2
300 usage="yes"
301 break
302 fi
303 android_root="$1"
304 run_args="${run_args} --android-root $1"
305 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700306 elif [ "x$1" = "x--update" ]; then
307 update_mode="yes"
308 shift
309 elif [ "x$1" = "x--help" ]; then
310 usage="yes"
311 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700312 elif [ "x$1" = "x--64" ]; then
313 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700314 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700315 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200316 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700317 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200318 shift
Andreas Gampeb91205e2015-06-22 22:53:45 -0700319 elif [ "x$1" = "x--stream" ]; then
320 trace_stream="true"
321 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700322 elif [ "x$1" = "x--always-clean" ]; then
323 always_clean="yes"
324 shift
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800325 elif [ "x$1" = "x--dex2oat-swap" ]; then
326 run_args="${run_args} --dex2oat-swap"
327 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700328 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700329 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700330 usage="yes"
331 break
332 else
333 break
334 fi
335done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700336
337# tmp_dir may be relative, resolve.
338#
339# Cannot use realpath, as it does not exist on Mac.
340# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700341# Cannot use readlink -m, as it does not exist on Mac.
342# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700343noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700344tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700345mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700346
Alex Lighte7873ec2014-08-12 09:53:50 -0700347if [ "$basic_verify" = "true" ]; then
Hiroshi Yamauchi312baf12015-01-12 12:11:05 -0800348 # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests.
349 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0"
Alex Lighte7873ec2014-08-12 09:53:50 -0700350fi
351if [ "$gc_verify" = "true" ]; then
352 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
353fi
354if [ "$gc_stress" = "true" ]; then
355 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
356fi
Jeff Hao85139a32014-07-23 11:52:52 -0700357if [ "$trace" = "true" ]; then
Andreas Gampeb91205e2015-06-22 22:53:45 -0700358 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file-size:2000000"
359 if [ "$trace_stream" = "true" ]; then
360 # Streaming mode uses the file size as the buffer size. So output gets really large. Drop
361 # the ability to analyze the file and just write to /dev/null.
362 run_args="${run_args} --runtime-option -Xmethod-trace-file:/dev/null"
363 # Enable streaming mode.
364 run_args="${run_args} --runtime-option -Xmethod-trace-stream"
365 else
366 run_args="${run_args} --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin"
367 fi
368elif [ "$trace_stream" = "true" ]; then
369 echo "Cannot use --stream without --trace."
370 exit 1
Jeff Hao85139a32014-07-23 11:52:52 -0700371fi
372
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700373# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100374# 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 -0700375function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100376 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800377 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64|mips64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700378 if [ "x${suffix64}" = "x64" ]; then
379 target_arch_name=${grep64bit}
380 else
381 target_arch_name=${grep32bit}
382 fi
383}
384
Alex Lighta59dd802014-07-02 16:28:08 -0700385if [ "$target_mode" = "no" ]; then
386 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700387 if [ "$prebuild_mode" = "yes" ]; then
388 echo "--prebuild with --jvm is unsupported";
389 exit 1;
390 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700391 fi
392fi
393
Alex Light03a112d2014-08-25 13:25:56 -0700394if [ "$have_patchoat" = "no" ]; then
395 run_args="${run_args} --no-patchoat"
396fi
397
398if [ "$have_dex2oat" = "no" ]; then
399 run_args="${run_args} --no-dex2oat"
400fi
401
Jeff Hao201803f2013-11-20 18:11:39 -0800402if [ ! "$runtime" = "jvm" ]; then
403 run_args="${run_args} --lib $lib"
404fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700405
Jeff Hao201803f2013-11-20 18:11:39 -0800406if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700407 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100408 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Narayan Kamathd50687e2015-11-17 12:37:27 +0000409 bpath="${framework}/core-libart.jar:${framework}/core-oj.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar:"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700410 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
411 else
412 true # defaults to using target BOOTCLASSPATH
413 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800414elif [ "$runtime" = "art" ]; then
415 if [ "$target_mode" = "no" ]; then
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100416 # ANDROID_HOST_OUT is not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800417 if [ -z "$ANDROID_HOST_OUT" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100418 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800419 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000420 run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700421 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800422 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700423 guess_arch_name
424 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000425 run_args="${run_args} --boot /data/art-test/core${image_suffix}${pic_image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800426 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700427 if [ "$relocate" = "yes" ]; then
428 run_args="${run_args} --relocate"
429 else
430 run_args="${run_args} --no-relocate"
431 fi
Andreas Gampe82566092015-05-18 15:52:22 -0700432elif [ "$runtime" = "jvm" ]; then
433 # TODO: Detect whether the host is 32-bit or 64-bit.
434 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib64"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700435fi
436
Alex Light03a112d2014-08-25 13:25:56 -0700437if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700438 if [ "$runtime" != "art" ]; then
439 echo "--no-image is only supported on the art runtime"
440 exit 1
441 fi
442 if [ "$target_mode" = "no" ]; then
443 framework="${ANDROID_HOST_OUT}/framework"
444 bpath_suffix="-hostdex"
445 else
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000446 framework="${android_root}/framework"
Alex Light1ef4ce82014-08-27 11:13:47 -0700447 bpath_suffix=""
448 fi
449 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
450 # fail since these jar files will be stripped.
451 bpath="${framework}/core-libart${bpath_suffix}.jar"
Narayan Kamathd50687e2015-11-17 12:37:27 +0000452 bpath="${bpath}:${framework}/core-oj${bpath_suffix}.jar"
Alex Light1ef4ce82014-08-27 11:13:47 -0700453 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
454 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
455 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
456 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
457 # Pass down the bootclasspath
458 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700459 run_args="${run_args} --no-image"
460fi
461
jeffhao5d1ac922011-09-29 17:41:15 -0700462if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
463 echo "--dev and --update are mutually exclusive" 1>&2
464 usage="yes"
465fi
466
467if [ "$usage" = "no" ]; then
468 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
469 test_dir=`basename "$oldwd"`
470 else
471 test_dir="$1"
472 fi
473
474 if [ '!' -d "$test_dir" ]; then
475 td2=`echo ${test_dir}-*`
476 if [ '!' -d "$td2" ]; then
477 echo "${test_dir}: no such test directory" 1>&2
478 usage="yes"
479 fi
480 test_dir="$td2"
481 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700482 # Shift to get rid of the test name argument. The rest of the arguments
483 # will get passed to the test run.
484 shift
485fi
486
487if [ "$usage" = "yes" ]; then
488 prog=`basename $prog`
489 (
490 echo "usage:"
491 echo " $prog --help Print this message."
492 echo " $prog [options] [test-name] Run test normally."
493 echo " $prog --dev [options] [test-name] Development mode" \
494 "(dumps to stdout)."
495 echo " $prog --update [options] [test-name] Update mode" \
496 "(replaces expected.txt)."
497 echo ' Omitting the test name or specifying "-" will use the' \
498 "current directory."
499 echo " Runtime Options:"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000500 echo " -O Run non-debug rather than debug build (off by default)."
501 echo " -Xcompiler-option Pass an option to the compiler."
502 echo " --runtime-option Pass an option to the runtime."
503 echo " --debug Wait for a debugger to attach."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000504 echo " --debuggable Whether to compile Java code for a debugger."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000505 echo " --gdb Run under gdb; incompatible with some tests."
506 echo " --build-only Build test files only (off by default)."
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100507 echo " --build-with-javac-dx Build test files with javac and dx (on by default)."
508 echo " --build-with-jack Build test files with jack and jill (off by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000509 echo " --interpreter Enable interpreter only mode (off by default)."
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800510 echo " --jit Enable jit (off by default)."
Nicolas Geoffray0e071252015-03-21 13:43:15 +0000511 echo " --optimizing Enable optimizing compiler (default)."
512 echo " --quick Use Quick compiler (off by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000513 echo " --no-verify Turn off verification (on by default)."
514 echo " --no-optimize Turn off optimization (on by default)."
515 echo " --no-precise Turn off precise GC (on by default)."
516 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700517 "If used, then the"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000518 echo " other runtime options are ignored."
519 echo " --no-dex2oat Run as though dex2oat was failing."
520 echo " --no-patchoat Run as though patchoat was failing."
521 echo " --prebuild Run dex2oat on the files before starting test. (default)"
522 echo " --no-prebuild Do not run dex2oat on the files before starting"
523 echo " the test."
524 echo " --relocate Force the use of relocating in the test, making"
525 echo " the image and oat files be relocated to a random"
526 echo " address before running. (default)"
527 echo " --no-relocate Force the use of no relocating in the test"
528 echo " --host Use the host-mode virtual machine."
529 echo " --invoke-with Pass --invoke-with option to runtime."
530 echo " --dalvik Use Dalvik (off by default)."
531 echo " --jvm Use a host-local RI virtual machine."
532 echo " --output-path [path] Location where to store the build" \
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700533 "files."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000534 echo " --64 Run the test in 64-bit mode"
535 echo " --trace Run with method tracing"
Andreas Gampeb91205e2015-06-22 22:53:45 -0700536 echo " --stream Run method tracing in streaming mode (requires --trace)"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000537 echo " --gcstress Run with gc stress testing"
538 echo " --gcverify Run with gc verification"
539 echo " --always-clean Delete the test files even if the test fails."
540 echo " --android-root [path] The path on target for the android root. (/system by default)."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000541 echo " --dex2oat-swap Use a dex2oat swap file."
jeffhao5d1ac922011-09-29 17:41:15 -0700542 ) 1>&2
543 exit 1
544fi
545
546cd "$test_dir"
547test_dir=`pwd`
548
549td_info="${test_dir}/${info}"
550td_expected="${test_dir}/${expected}"
551
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700552if [ ! -r $td_info ]; then
553 echo "${test_dir}: missing file $td_info" 1>&2
554 exit 1
555fi
556
557if [ ! -r $td_expected ]; then
558 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700559 exit 1
560fi
561
562# copy the test to a temp dir and run it
563
Elliott Hughes510c8782011-10-06 10:57:34 -0700564echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700565
566rm -rf "$tmp_dir"
567cp -Rp "$test_dir" "$tmp_dir"
568cd "$tmp_dir"
569
570if [ '!' -r "$build" ]; then
571 cp "${progdir}/etc/default-build" build
572fi
573
574if [ '!' -r "$run" ]; then
575 cp "${progdir}/etc/default-run" run
576fi
577
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700578if [ '!' -r "$check_cmd" ]; then
579 cp "${progdir}/etc/default-check" check
580fi
581
jeffhao5d1ac922011-09-29 17:41:15 -0700582chmod 755 "$build"
583chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700584chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700585
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700586export TEST_NAME=`basename ${test_dir}`
587
David Brazdil4846d132015-01-15 19:07:08 +0000588# Tests named '<number>-checker-*' will also have their CFGs verified with
589# Checker when compiled with Optimizing on host.
590if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
591 # Build Checker DEX files without dx's optimizations so the input to dex2oat
592 # better resembles the Java source. We always build the DEX the same way, even
593 # if Checker is not invoked and the test only runs the program.
594 build_args="${build_args} --dx-option --no-optimize"
595
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100596 # Jack does not necessarily generate the same DEX output than dx. Because these tests depend
597 # on a particular DEX output, keep building them with dx for now (b/19467889).
598 USE_JACK="false"
599
Nicolas Geoffraye7307292015-03-17 18:12:06 +0000600 if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" -a "$target_mode" = "no" -a "$debuggable" = "no" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000601 run_checker="yes"
602 run_args="${run_args} -Xcompiler-option --dump-cfg=$tmp_dir/$cfg_output \
603 -Xcompiler-option -j1"
604 fi
605fi
606
Ian Rogers997f0f92014-06-21 22:58:05 -0700607# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100608build_file_size_limit=2048
609run_file_size_limit=2048
Ian Rogers997f0f92014-06-21 22:58:05 -0700610if echo "$test_dir" | grep 089; then
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100611 build_file_size_limit=5120
612 run_file_size_limit=5120
Ian Rogers997f0f92014-06-21 22:58:05 -0700613elif echo "$test_dir" | grep 083; then
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100614 build_file_size_limit=5120
615 run_file_size_limit=5120
Ian Rogers997f0f92014-06-21 22:58:05 -0700616fi
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100617if [ ${USE_JACK} = "false" ]; then
618 # Set ulimit if we build with dx only, Jack can generate big temp files.
619 if ! ulimit -S "$build_file_size_limit"; then
620 echo "ulimit file size setting failed"
621 fi
Ian Rogers997f0f92014-06-21 22:58:05 -0700622fi
623
jeffhao5d1ac922011-09-29 17:41:15 -0700624good="no"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000625good_build="yes"
626good_run="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700627if [ "$dev_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000628 "./${build}" $build_args 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700629 build_exit="$?"
630 echo "build exit status: $build_exit" 1>&2
631 if [ "$build_exit" = '0' ]; then
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100632 if ! ulimit -S "$run_file_size_limit"; then
633 echo "ulimit file size setting failed"
634 fi
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800635 echo "${test_dir}: running..." 1>&2
636 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700637 run_exit="$?"
Calin Juravle3cf48772015-01-26 16:47:33 +0000638
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800639 if [ "$run_exit" = "0" ]; then
Calin Juravle3cf48772015-01-26 16:47:33 +0000640 if [ "$run_checker" = "yes" ]; then
641 "$checker" "$cfg_output" "$tmp_dir" 2>&1
642 checker_exit="$?"
643 if [ "$checker_exit" = "0" ]; then
644 good="yes"
645 fi
646 echo "checker exit status: $checker_exit" 1>&2
647 else
648 good="yes"
649 fi
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800650 fi
Calin Juravle3cf48772015-01-26 16:47:33 +0000651 echo "run exit status: $run_exit" 1>&2
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700652 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700653elif [ "$update_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000654 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700655 build_exit="$?"
656 if [ "$build_exit" = '0' ]; then
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100657 if ! ulimit -S "$run_file_size_limit"; then
658 echo "ulimit file size setting failed"
659 fi
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800660 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700661 "./${run}" $run_args "$@" >"$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000662 if [ "$run_checker" = "yes" ]; then
663 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
664 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700665 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
666 good="yes"
667 else
668 cat "$build_output" 1>&2
669 echo "build exit status: $build_exit" 1>&2
670 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700671elif [ "$build_only" = "yes" ]; then
672 good="yes"
David Brazdil4846d132015-01-15 19:07:08 +0000673 "./${build}" $build_args >"$build_output" 2>&1
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700674 build_exit="$?"
675 if [ "$build_exit" '!=' '0' ]; then
676 cp "$build_output" "$output"
677 echo "build exit status: $build_exit" >>"$output"
678 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
679 if [ "$?" '!=' "0" ]; then
680 good="no"
681 echo "BUILD FAILED For ${TEST_NAME}"
682 fi
683 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700684 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700685 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700686 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700687else
David Brazdil4846d132015-01-15 19:07:08 +0000688 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700689 build_exit="$?"
690 if [ "$build_exit" = '0' ]; then
Sebastien Hertz5ee94542015-02-24 17:39:50 +0100691 if ! ulimit -S "$run_file_size_limit"; then
692 echo "ulimit file size setting failed"
693 fi
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800694 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700695 "./${run}" $run_args "$@" >"$output" 2>&1
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000696 run_exit="$?"
697 if [ "$run_exit" != "0" ]; then
698 echo "run exit status: $run_exit" 1>&2
699 good_run="no"
David Brazdil4846d132015-01-15 19:07:08 +0000700 elif [ "$run_checker" = "yes" ]; then
701 "$checker" -q "$cfg_output" "$tmp_dir" >> "$output" 2>&1
702 checker_exit="$?"
703 if [ "$checker_exit" != "0" ]; then
704 echo "checker exit status: $checker_exit" 1>&2
705 good_run="no"
706 else
707 good_run="yes"
708 fi
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000709 else
710 good_run="yes"
711 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700712 else
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000713 good_build="no"
jeffhao5d1ac922011-09-29 17:41:15 -0700714 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700715 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
716 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700717 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700718 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700719 max_name_length=$(getconf NAME_MAX ${tmp_dir})
720 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
721 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700722 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700723 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700724 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700725 if [ "$?" = "0" ]; then
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000726 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
727 # output == expected
728 good="yes"
729 echo "${test_dir}: succeeded!" 1>&2
730 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700731 fi
732fi
733
jeffhao5d1ac922011-09-29 17:41:15 -0700734(
Alex Lightbfac14a2014-07-30 09:41:21 -0700735 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700736 echo "${test_dir}: FAILED!"
737 echo ' '
738 echo '#################### info'
739 cat "${td_info}" | sed 's/^/# /g'
740 echo '#################### diffs'
Ian Rogers75deec02014-11-23 20:07:39 -0800741 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 2000
jeffhao5d1ac922011-09-29 17:41:15 -0700742 echo '####################'
743 echo ' '
744 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700745
746) 1>&2
747
748# Clean up test files.
749if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
750 cd "$oldwd"
751 rm -rf "$tmp_dir"
752 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
753 adb shell rm -rf $DEX_LOCATION
754 fi
755 if [ "$good" = "yes" ]; then
756 exit 0
757 fi
758fi
759
760
761(
762 if [ "$always_clean" = "yes" ]; then
763 echo "${TEST_NAME} files deleted from host "
764 if [ "$target_mode" == "yes" ]; then
765 echo "and from target"
766 fi
767 else
768 echo "${TEST_NAME} files left in ${tmp_dir} on host"
769 if [ "$target_mode" == "yes" ]; then
770 echo "and in ${DEX_LOCATION} on target"
771 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700772 fi
773
jeffhao5d1ac922011-09-29 17:41:15 -0700774) 1>&2
775
776exit 1