blob: 5b43b52b41f89ac5ffca989c439106920341b61a [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
Andreas Gampe34a8a0f2016-07-20 21:09:29 -070040 tmp_dir="${TMPDIR}/${test_dir}"
Andreas Gampe5a79fde2014-08-06 13:12:26 -070041fi
David Brazdil2c27f2c2015-05-12 18:06:38 +010042checker="${progdir}/../tools/checker/checker.py"
jeffhao5d1ac922011-09-29 17:41:15 -070043export JAVA="java"
Alex Lightea1e7702016-07-11 13:39:55 -070044export JAVAC="javac -g -Xlint:-options"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010045export RUN="${progdir}/etc/run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070046export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070047export NEED_DEX="true"
Alan Leung0afa07a2017-10-03 16:56:30 -070048export USE_D8="false"
Colin Crosse0ef0a82017-07-27 21:29:18 +000049export USE_JACK="false"
Igor Murashkin2a337752017-06-16 14:34:40 +000050export USE_DESUGAR="true"
Ben Gruver14fc9db2017-04-28 15:30:49 -070051export SMALI_ARGS=""
jeffhao5d1ac922011-09-29 17:41:15 -070052
Alan Leungd5cbc562018-03-15 14:02:46 -070053# If d8 was not set by the environment variable, assume it is in the path.
54if [ -z "$D8" ]; then
55 export D8="d8"
56fi
57
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070058# If dx was not set by the environment variable, assume it is in the path.
59if [ -z "$DX" ]; then
60 export DX="dx"
61fi
62
Alan Leungd5cbc562018-03-15 14:02:46 -070063export DXMERGER="$D8"
64
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080065# If jasmin was not set by the environment variable, assume it is in the path.
66if [ -z "$JASMIN" ]; then
67 export JASMIN="jasmin"
68fi
69
Andreas Gampe8fda9f22014-10-03 16:15:37 -070070# If smali was not set by the environment variable, assume it is in the path.
71if [ -z "$SMALI" ]; then
72 export SMALI="smali"
73fi
74
Sebastien Hertz19ac0272015-02-24 17:39:50 +010075# If jack was not set by the environment variable, assume it is in the path.
76if [ -z "$JACK" ]; then
77 export JACK="jack"
78fi
79
Sebastien Hertz19ac0272015-02-24 17:39:50 +010080# ANDROID_BUILD_TOP is not set in a build environment.
81if [ -z "$ANDROID_BUILD_TOP" ]; then
82 export ANDROID_BUILD_TOP=$oldwd
83fi
84
Andreas Gampef47fb2f2016-06-24 22:30:29 -070085# ANDROID_HOST_OUT is not set in a build environment.
86if [ -z "$ANDROID_HOST_OUT" ]; then
Dan Willemsenf325e012017-03-03 12:35:30 -080087 export ANDROID_HOST_OUT=${OUT_DIR:-$ANDROID_BUILD_TOP/out}/host/linux-x86
Andreas Gampef47fb2f2016-06-24 22:30:29 -070088fi
89
Sebastien Hertz19ac0272015-02-24 17:39:50 +010090# If JACK_CLASSPATH is not set, assume it only contains core-libart.
91if [ -z "$JACK_CLASSPATH" ]; then
Andreas Gampef47fb2f2016-06-24 22:30:29 -070092 export JACK_CLASSPATH="${ANDROID_HOST_OUT}/../common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack:${ANDROID_HOST_OUT}/../common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/classes.jack"
Sebastien Hertz19ac0272015-02-24 17:39:50 +010093fi
94
Sebastien Hertz19ac0272015-02-24 17:39:50 +010095export JACK="$JACK -g -cp $JACK_CLASSPATH"
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080096
Igor Murashkine5181932017-06-15 16:03:50 -070097# Allow changing DESUGAR script to something else, or to disable it with DESUGAR=false.
Igor Murashkind3232772017-06-22 14:54:13 -070098if [ -z "$DESUGAR" ]; then
Igor Murashkine5181932017-06-15 16:03:50 -070099 export DESUGAR="$ANDROID_BUILD_TOP/art/tools/desugar.sh"
100fi
101
Igor Murashkin271a0f82017-02-14 21:14:17 +0000102# Zipalign is not on the PATH in some configs, auto-detect it.
103if [ -z "$ZIPALIGN" ]; then
104 if which zipalign >/dev/null; then
105 ZIPALIGN="zipalign";
106 else
107 # TODO: Add a dependency for zipalign in Android.run-test.mk
108 # once it doesn't depend on libandroidfw (b/35246701)
109 case "$OSTYPE" in
110 darwin*) ZIPALIGN="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/darwin/bin/zipalign" ;;
111 linux*) ZIPALIGN="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/linux/bin/zipalign" ;;
112 *) echo "Can't find zipalign: unknown: $OSTYPE" >&2;;
113 esac
114 fi
115fi
116export ZIPALIGN
117
David Brazdil122c6632018-01-24 17:32:49 +0000118# If hiddenapi was not set by the environment variable, assume it is in
119# ANDROID_HOST_OUT.
David Brazdil11b67b22018-01-18 16:41:40 +0000120if [ -z "$HIDDENAPI" ]; then
David Brazdil122c6632018-01-24 17:32:49 +0000121 export HIDDENAPI="${ANDROID_HOST_OUT}/bin/hiddenapi"
David Brazdil11b67b22018-01-18 16:41:40 +0000122fi
123
jeffhao5d1ac922011-09-29 17:41:15 -0700124info="info.txt"
125build="build"
126run="run"
127expected="expected.txt"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700128check_cmd="check"
jeffhao5d1ac922011-09-29 17:41:15 -0700129output="output.txt"
130build_output="build-output.txt"
David Brazdil24128c62015-05-21 12:06:13 +0100131cfg_output="graph.cfg"
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700132strace_output="strace-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700133lib="libartd.so"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700134testlib="arttestd"
jeffhao5d1ac922011-09-29 17:41:15 -0700135run_args="--quiet"
David Brazdil4846d132015-01-15 19:07:08 +0000136build_args=""
jeffhao5d1ac922011-09-29 17:41:15 -0700137
Alex Light91de25f2015-10-28 17:00:06 -0700138quiet="no"
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +0000139debuggable="no"
Alex Light9d722532014-07-22 18:07:12 -0700140prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -0700141target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700142dev_mode="no"
143update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -0700144debug_mode="no"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +0000145relocate="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800146runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -0700147usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700148build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700149suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -0700150trace="false"
Andreas Gampe7526d782015-06-22 22:53:45 -0700151trace_stream="false"
Alex Lighte7873ec2014-08-12 09:53:50 -0700152basic_verify="false"
153gc_verify="false"
154gc_stress="false"
Alex Lightb7edcda2017-04-27 13:20:31 -0700155jvmti_trace_stress="false"
Alex Light43e935d2017-06-19 15:40:40 -0700156jvmti_field_stress="false"
Alex Lightc38c3692017-06-27 15:45:14 -0700157jvmti_step_stress="false"
Alex Lightb7edcda2017-04-27 13:20:31 -0700158jvmti_redefine_stress="false"
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700159strace="false"
Alex Lightbfac14a2014-07-30 09:41:21 -0700160always_clean="no"
Igor Murashkin05f30e12015-06-10 15:57:17 -0700161never_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -0700162have_dex2oat="yes"
163have_patchoat="yes"
164have_image="yes"
Jeff Haodcdc85b2015-12-04 14:06:18 -0800165multi_image_suffix=""
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000166android_root="/system"
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700167bisection_search="no"
Mathieu Chartier3fceaf52017-01-22 13:33:40 -0800168suspend_timeout="500000"
Alex Light10bc5a42016-05-10 10:01:22 -0700169# By default we will use optimizing.
170image_args=""
Nicolas Geoffrayb76bc782016-09-14 12:33:34 +0000171image_suffix=""
jeffhao5d1ac922011-09-29 17:41:15 -0700172
173while true; do
174 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700175 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700176 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100177 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700178 shift
Alex Light91de25f2015-10-28 17:00:06 -0700179 elif [ "x$1" = "x--quiet" ]; then
180 quiet="yes"
181 shift
Alex Lighteb7c1442015-08-31 13:17:42 -0700182 elif [ "x$1" = "x--use-java-home" ]; then
183 if [ -n "${JAVA_HOME}" ]; then
184 export JAVA="${JAVA_HOME}/bin/java"
185 export JAVAC="${JAVA_HOME}/bin/javac -g"
186 else
187 echo "Passed --use-java-home without JAVA_HOME variable set!"
188 usage="yes"
189 fi
190 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800191 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700192 target_mode="no"
Alex Light2c7aaeb2017-01-27 14:08:17 -0800193 DEX_LOCATION="$tmp_dir"
Jeff Hao201803f2013-11-20 18:11:39 -0800194 runtime="jvm"
Alex Lightbc90d0f2016-05-09 16:21:09 -0700195 image_args=""
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700196 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700197 NEED_DEX="false"
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100198 USE_JACK="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100199 run_args="${run_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700200 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800201 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700202 lib="libart.so"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700203 testlib="arttest"
Alex Lightfaf90b62016-08-12 14:43:48 -0700204 run_args="${run_args} -O"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700205 shift
206 elif [ "x$1" = "x--dalvik" ]; then
207 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800208 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700209 shift
Alex Light03a112d2014-08-25 13:25:56 -0700210 elif [ "x$1" = "x--no-dex2oat" ]; then
211 have_dex2oat="no"
212 shift
213 elif [ "x$1" = "x--no-patchoat" ]; then
214 have_patchoat="no"
215 shift
216 elif [ "x$1" = "x--no-image" ]; then
217 have_image="no"
218 shift
Jeff Haodcdc85b2015-12-04 14:06:18 -0800219 elif [ "x$1" = "x--multi-image" ]; then
220 multi_image_suffix="-multi"
221 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700222 elif [ "x$1" = "x--pic-test" ]; then
223 run_args="${run_args} --pic-test"
224 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700225 elif [ "x$1" = "x--relocate" ]; then
226 relocate="yes"
227 shift
228 elif [ "x$1" = "x--no-relocate" ]; then
229 relocate="no"
230 shift
231 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100232 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700233 prebuild_mode="yes"
234 shift;
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800235 elif [ "x$1" = "x--compact-dex-level" ]; then
236 option="$1"
237 shift
238 run_args="${run_args} $option $1"
239 shift;
Richard Uhler76f5cb62016-04-04 13:30:16 -0700240 elif [ "x$1" = "x--strip-dex" ]; then
241 run_args="${run_args} --strip-dex"
242 shift;
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000243 elif [ "x$1" = "x--debuggable" ]; then
244 run_args="${run_args} -Xcompiler-option --debuggable"
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +0000245 debuggable="yes"
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000246 shift;
Alex Lighta59dd802014-07-02 16:28:08 -0700247 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100248 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700249 prebuild_mode="no"
250 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700251 elif [ "x$1" = "x--gcverify" ]; then
252 basic_verify="true"
253 gc_verify="true"
254 shift
255 elif [ "x$1" = "x--gcstress" ]; then
256 basic_verify="true"
257 gc_stress="true"
258 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700259 elif [ "x$1" = "x--jvmti-step-stress" ]; then
260 jvmti_step_stress="true"
261 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700262 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
263 jvmti_redefine_stress="true"
264 shift
Alex Light43e935d2017-06-19 15:40:40 -0700265 elif [ "x$1" = "x--jvmti-field-stress" ]; then
266 jvmti_field_stress="true"
267 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700268 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
269 jvmti_trace_stress="true"
Alex Light8f2c6d42017-04-10 16:27:35 -0700270 shift
Mathieu Chartier3fceaf52017-01-22 13:33:40 -0800271 elif [ "x$1" = "x--suspend-timeout" ]; then
272 shift
273 suspend_timeout="$1"
274 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700275 elif [ "x$1" = "x--image" ]; then
276 shift
277 image="$1"
278 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700279 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000280 elif [ "x$1" = "x-Xcompiler-option" ]; then
281 shift
282 option="$1"
283 run_args="${run_args} -Xcompiler-option $option"
284 shift
Orion Hodsone1fb77f2017-02-27 13:57:18 +0000285 elif [ "x$1" = "x--build-option" ]; then
286 shift
287 option="$1"
288 build_args="${build_args} $option"
289 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700290 elif [ "x$1" = "x--runtime-option" ]; then
291 shift
292 option="$1"
293 run_args="${run_args} --runtime-option $option"
294 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700295 elif [ "x$1" = "x--gdb-arg" ]; then
296 shift
297 gdb_arg="$1"
298 run_args="${run_args} --gdb-arg $gdb_arg"
299 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700300 elif [ "x$1" = "x--debug" ]; then
301 run_args="${run_args} --debug"
302 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700303 elif [ "x$1" = "x--debug-wrap-agent" ]; then
304 run_args="${run_args} --debug-wrap-agent"
305 shift
Alex Light0e151e72017-10-25 10:50:35 -0700306 elif [ "x$1" = "x--with-agent" ]; then
307 shift
308 option="$1"
309 run_args="${run_args} --with-agent $1"
310 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700311 elif [ "x$1" = "x--debug-agent" ]; then
312 shift
313 option="$1"
314 run_args="${run_args} --debug-agent $1"
315 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700316 elif [ "x$1" = "x--gdb" ]; then
317 run_args="${run_args} --gdb"
318 dev_mode="yes"
319 shift
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700320 elif [ "x$1" = "x--strace" ]; then
321 strace="yes"
Mathieu Chartier2576be22016-05-24 10:24:53 -0700322 run_args="${run_args} --timeout 1800 --invoke-with strace --invoke-with -o --invoke-with $tmp_dir/$strace_output"
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700323 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700324 elif [ "x$1" = "x--zygote" ]; then
325 run_args="${run_args} --zygote"
326 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800327 elif [ "x$1" = "x--interpreter" ]; then
Nicolas Geoffray4650c932016-05-10 09:13:13 +0000328 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700329 image_suffix="-interpreter"
330 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800331 elif [ "x$1" = "x--jit" ]; then
Alex Light10bc5a42016-05-10 10:01:22 -0700332 image_args="--jit"
Nicolas Geoffrayb76bc782016-09-14 12:33:34 +0000333 image_suffix="-interpreter"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800334 shift
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700335 elif [ "x$1" = "x--optimizing" ]; then
Alex Light10bc5a42016-05-10 10:01:22 -0700336 image_args="-Xcompiler-option --compiler-backend=Optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800337 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700338 elif [ "x$1" = "x--no-verify" ]; then
Richard Uhlerf4b34872016-04-13 11:03:46 -0700339 run_args="${run_args} --no-verify"
jeffhao5d1ac922011-09-29 17:41:15 -0700340 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700341 elif [ "x$1" = "x--verify-soft-fail" ]; then
Alex Light10bc5a42016-05-10 10:01:22 -0700342 image_args="--verify-soft-fail"
Andreas Gampe825570c2015-07-26 10:26:03 -0700343 image_suffix="-interp-ac"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700344 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700345 elif [ "x$1" = "x--no-optimize" ]; then
346 run_args="${run_args} --no-optimize"
347 shift
348 elif [ "x$1" = "x--no-precise" ]; then
349 run_args="${run_args} --no-precise"
350 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700351 elif [ "x$1" = "x--invoke-with" ]; then
352 shift
353 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700354 if [ "x$what" = "x" ]; then
355 echo "$0 missing argument to --invoke-with" 1>&2
356 usage="yes"
357 break
358 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700359 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700360 shift
361 elif [ "x$1" = "x--dev" ]; then
362 run_args="${run_args} --dev"
363 dev_mode="yes"
364 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700365 elif [ "x$1" = "x--build-only" ]; then
366 build_only="yes"
367 shift
Alan Leung0afa07a2017-10-03 16:56:30 -0700368 elif [ "x$1" = "x--build-with-d8" ]; then
369 USE_D8="true"
370 shift
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100371 elif [ "x$1" = "x--build-with-javac-dx" ]; then
372 USE_JACK="false"
373 shift
374 elif [ "x$1" = "x--build-with-jack" ]; then
375 USE_JACK="true"
376 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700377 elif [ "x$1" = "x--output-path" ]; then
378 shift
379 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700380 if [ "x$tmp_dir" = "x" ]; then
381 echo "$0 missing argument to --output-path" 1>&2
382 usage="yes"
383 break
384 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700385 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000386 elif [ "x$1" = "x--android-root" ]; then
387 shift
388 if [ "x$1" = "x" ]; then
389 echo "$0 missing argument to --android-root" 1>&2
390 usage="yes"
391 break
392 fi
393 android_root="$1"
394 run_args="${run_args} --android-root $1"
395 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700396 elif [ "x$1" = "x--update" ]; then
397 update_mode="yes"
398 shift
399 elif [ "x$1" = "x--help" ]; then
400 usage="yes"
401 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700402 elif [ "x$1" = "x--64" ]; then
403 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700404 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700405 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200406 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700407 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200408 shift
Andreas Gampe7526d782015-06-22 22:53:45 -0700409 elif [ "x$1" = "x--stream" ]; then
410 trace_stream="true"
411 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700412 elif [ "x$1" = "x--always-clean" ]; then
413 always_clean="yes"
414 shift
Igor Murashkin05f30e12015-06-10 15:57:17 -0700415 elif [ "x$1" = "x--never-clean" ]; then
416 never_clean="yes"
417 shift
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800418 elif [ "x$1" = "x--dex2oat-swap" ]; then
419 run_args="${run_args} --dex2oat-swap"
420 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700421 elif [ "x$1" = "x--instruction-set-features" ]; then
422 shift
423 run_args="${run_args} --instruction-set-features $1"
424 shift
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700425 elif [ "x$1" = "x--bisection-search" ]; then
426 bisection_search="yes"
427 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000428 elif [ "x$1" = "x--vdex" ]; then
429 run_args="${run_args} --vdex"
430 shift
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000431 elif [ "x$1" = "x--dm" ]; then
432 run_args="${run_args} --dm"
433 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000434 elif [ "x$1" = "x--vdex-filter" ]; then
435 shift
436 filter=$1
437 run_args="${run_args} --vdex-filter $filter"
438 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700439 elif [ "x$1" = "x--random-profile" ]; then
440 run_args="${run_args} --random-profile"
441 shift
Shubham Ajmera981d99c2017-08-17 14:11:08 -0700442 elif [ "x$1" = "x--dex2oat-jobs" ]; then
443 shift
444 run_args="${run_args} -Xcompiler-option -j$1"
445 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700446 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700447 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700448 usage="yes"
449 break
450 else
451 break
452 fi
453done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700454
Alex Light10bc5a42016-05-10 10:01:22 -0700455run_args="${run_args} ${image_args}"
Alex Light91de25f2015-10-28 17:00:06 -0700456# Allocate file descriptor real_stderr and redirect it to the shell's error
457# output (fd 2).
458if [ ${BASH_VERSINFO[1]} -ge 4 ] && [ ${BASH_VERSINFO[2]} -ge 1 ]; then
459 exec {real_stderr}>&2
460else
461 # In bash before version 4.1 we need to do a manual search for free file
462 # descriptors.
463 FD=3
464 while [ -e /dev/fd/$FD ]; do FD=$((FD + 1)); done
465 real_stderr=$FD
466 eval "exec ${real_stderr}>&2"
467fi
468if [ "$quiet" = "yes" ]; then
469 # Force the default standard output and error to go to /dev/null so we will
470 # not print them.
471 exec 1>/dev/null
472 exec 2>/dev/null
473fi
474
475function err_echo() {
476 echo "$@" 1>&${real_stderr}
477}
478
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700479# tmp_dir may be relative, resolve.
480#
481# Cannot use realpath, as it does not exist on Mac.
482# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700483# Cannot use readlink -m, as it does not exist on Mac.
484# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700485noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700486tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700487mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700488
Mathieu Chartier3fceaf52017-01-22 13:33:40 -0800489# Add thread suspend timeout flag
Narayan Kamathf86c3932017-01-24 17:40:47 +0000490if [ ! "$runtime" = "jvm" ]; then
491 run_args="${run_args} --runtime-option -XX:ThreadSuspendTimeout=$suspend_timeout"
492fi
Mathieu Chartier3fceaf52017-01-22 13:33:40 -0800493
Alex Lighte7873ec2014-08-12 09:53:50 -0700494if [ "$basic_verify" = "true" ]; then
Hiroshi Yamauchi312baf12015-01-12 12:11:05 -0800495 # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests.
496 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0"
Alex Lighte7873ec2014-08-12 09:53:50 -0700497fi
498if [ "$gc_verify" = "true" ]; then
499 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
500fi
501if [ "$gc_stress" = "true" ]; then
Mathieu Chartierd9eb2842016-08-12 16:11:24 -0700502 run_args="${run_args} --gc-stress --runtime-option -Xgc:gcstress --runtime-option -Xms2m --runtime-option -Xmx16m"
Alex Lighte7873ec2014-08-12 09:53:50 -0700503fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700504if [ "$jvmti_redefine_stress" = "true" ]; then
505 run_args="${run_args} --no-app-image --jvmti-redefine-stress"
506fi
Alex Lightc38c3692017-06-27 15:45:14 -0700507if [ "$jvmti_step_stress" = "true" ]; then
508 run_args="${run_args} --no-app-image --jvmti-step-stress"
509fi
Alex Light43e935d2017-06-19 15:40:40 -0700510if [ "$jvmti_field_stress" = "true" ]; then
511 run_args="${run_args} --no-app-image --jvmti-field-stress"
512fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700513if [ "$jvmti_trace_stress" = "true" ]; then
514 run_args="${run_args} --no-app-image --jvmti-trace-stress"
Alex Light8f2c6d42017-04-10 16:27:35 -0700515fi
Jeff Hao85139a32014-07-23 11:52:52 -0700516if [ "$trace" = "true" ]; then
Andreas Gampe7526d782015-06-22 22:53:45 -0700517 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file-size:2000000"
518 if [ "$trace_stream" = "true" ]; then
519 # Streaming mode uses the file size as the buffer size. So output gets really large. Drop
520 # the ability to analyze the file and just write to /dev/null.
521 run_args="${run_args} --runtime-option -Xmethod-trace-file:/dev/null"
522 # Enable streaming mode.
523 run_args="${run_args} --runtime-option -Xmethod-trace-stream"
524 else
525 run_args="${run_args} --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin"
526 fi
527elif [ "$trace_stream" = "true" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700528 err_echo "Cannot use --stream without --trace."
Andreas Gampe7526d782015-06-22 22:53:45 -0700529 exit 1
Jeff Hao85139a32014-07-23 11:52:52 -0700530fi
531
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700532# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray93d68462018-01-02 11:59:45 +0000533# Try to map the suffix64 flag and what we find in ${ANDROID_PRODUCT_OUT}/data/art-test to an architecture name.
David Brazdil853a4c32015-09-28 16:15:50 +0100534function guess_target_arch_name() {
Nicolas Geoffray93d68462018-01-02 11:59:45 +0000535 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
536 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64|mips64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700537 if [ "x${suffix64}" = "x64" ]; then
538 target_arch_name=${grep64bit}
539 else
540 target_arch_name=${grep32bit}
541 fi
542}
543
David Brazdil853a4c32015-09-28 16:15:50 +0100544function guess_host_arch_name() {
545 if [ "x${suffix64}" = "x64" ]; then
546 host_arch_name="x86_64"
547 else
548 host_arch_name="x86"
549 fi
550}
551
Alex Lighta59dd802014-07-02 16:28:08 -0700552if [ "$target_mode" = "no" ]; then
553 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700554 if [ "$prebuild_mode" = "yes" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700555 err_echo "--prebuild with --jvm is unsupported"
Alex Lighta59dd802014-07-02 16:28:08 -0700556 exit 1;
557 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700558 fi
559fi
560
Alex Light03a112d2014-08-25 13:25:56 -0700561if [ "$have_patchoat" = "no" ]; then
562 run_args="${run_args} --no-patchoat"
563fi
564
565if [ "$have_dex2oat" = "no" ]; then
566 run_args="${run_args} --no-dex2oat"
567fi
568
Jeff Hao201803f2013-11-20 18:11:39 -0800569if [ ! "$runtime" = "jvm" ]; then
570 run_args="${run_args} --lib $lib"
571fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700572
Jeff Hao201803f2013-11-20 18:11:39 -0800573if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700574 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray93d68462018-01-02 11:59:45 +0000575 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Andreas Gampe50be66f2015-12-28 14:31:06 -0800576 bpath="${framework}/core-libart.jar:${framework}/core-oj.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700577 run_args="${run_args} --boot --runtime-option -Xbootclasspath:${bpath}"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700578 else
579 true # defaults to using target BOOTCLASSPATH
580 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800581elif [ "$runtime" = "art" ]; then
582 if [ "$target_mode" = "no" ]; then
David Brazdil853a4c32015-09-28 16:15:50 +0100583 guess_host_arch_name
Richard Uhlerbb00f812017-02-16 14:21:10 +0000584 run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${multi_image_suffix}.art"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700585 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}:${ANDROID_HOST_OUT}/nativetest${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800586 else
David Brazdil853a4c32015-09-28 16:15:50 +0100587 guess_target_arch_name
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800588 run_args="${run_args} --runtime-option -Djava.library.path=/data/nativetest${suffix64}/art/${target_arch_name}"
Richard Uhlerbb00f812017-02-16 14:21:10 +0000589 run_args="${run_args} --boot /data/art-test/core${image_suffix}${multi_image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800590 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700591 if [ "$relocate" = "yes" ]; then
592 run_args="${run_args} --relocate"
593 else
594 run_args="${run_args} --no-relocate"
595 fi
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700596elif [ "$runtime" = "jvm" ]; then
597 # TODO: Detect whether the host is 32-bit or 64-bit.
Alex Lightfba89fe2017-01-12 16:11:02 -0800598 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib64:${ANDROID_HOST_OUT}/nativetest64"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700599fi
600
Alex Light03a112d2014-08-25 13:25:56 -0700601if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700602 if [ "$runtime" != "art" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700603 err_echo "--no-image is only supported on the art runtime"
Alex Light1ef4ce82014-08-27 11:13:47 -0700604 exit 1
605 fi
Alex Light03a112d2014-08-25 13:25:56 -0700606 run_args="${run_args} --no-image"
607fi
608
jeffhao5d1ac922011-09-29 17:41:15 -0700609if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700610 err_echo "--dev and --update are mutually exclusive"
611 usage="yes"
612fi
613
614if [ "$dev_mode" = "yes" -a "$quiet" = "yes" ]; then
615 err_echo "--dev and --quiet are mutually exclusive"
jeffhao5d1ac922011-09-29 17:41:15 -0700616 usage="yes"
617fi
618
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700619if [ "$bisection_search" = "yes" -a "$prebuild_mode" = "yes" ]; then
620 err_echo "--bisection-search and --prebuild are mutually exclusive"
621 usage="yes"
622fi
623
624if [ "$bisection_search" = "yes" -a "$have_dex2oat" = "no" ]; then
625 err_echo "--bisection-search and --no-dex2oat are mutually exclusive"
626 usage="yes"
627fi
628
629if [ "$bisection_search" = "yes" -a "$have_patchoat" = "no" ]; then
630 err_echo "--bisection-search and --no-patchoat are mutually exclusive"
631 usage="yes"
632fi
633
jeffhao5d1ac922011-09-29 17:41:15 -0700634if [ "$usage" = "no" ]; then
635 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
636 test_dir=`basename "$oldwd"`
637 else
638 test_dir="$1"
639 fi
640
641 if [ '!' -d "$test_dir" ]; then
642 td2=`echo ${test_dir}-*`
643 if [ '!' -d "$td2" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700644 err_echo "${test_dir}: no such test directory"
jeffhao5d1ac922011-09-29 17:41:15 -0700645 usage="yes"
646 fi
647 test_dir="$td2"
648 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700649 # Shift to get rid of the test name argument. The rest of the arguments
650 # will get passed to the test run.
651 shift
652fi
653
Søren Gjesse620d0a52016-09-19 11:12:51 +0200654# For building with javac and dx always use Java 7. The dx compiler
655# only support byte codes from Java 7 or earlier (class file major
656# version 51 or lower).
657if [ "$USE_JACK" != "true" ] && [ "$NEED_DEX" = "true" ]; then
658 export JAVAC="${JAVAC} -source 1.7 -target 1.7"
659fi
660
jeffhao5d1ac922011-09-29 17:41:15 -0700661if [ "$usage" = "yes" ]; then
662 prog=`basename $prog`
663 (
664 echo "usage:"
665 echo " $prog --help Print this message."
666 echo " $prog [options] [test-name] Run test normally."
667 echo " $prog --dev [options] [test-name] Development mode" \
668 "(dumps to stdout)."
669 echo " $prog --update [options] [test-name] Update mode" \
670 "(replaces expected.txt)."
671 echo ' Omitting the test name or specifying "-" will use the' \
672 "current directory."
673 echo " Runtime Options:"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000674 echo " -O Run non-debug rather than debug build (off by default)."
675 echo " -Xcompiler-option Pass an option to the compiler."
Orion Hodsone1fb77f2017-02-27 13:57:18 +0000676 echo " --build-option Pass an option to the build script."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000677 echo " --runtime-option Pass an option to the runtime."
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800678 echo " --compact-dex-level Specify a compact dex level to the compiler."
Alex Lightc281ba52017-10-11 11:35:55 -0700679 echo " --debug Wait for the default debugger to attach."
680 echo " --debug-agent <agent-path>"
681 echo " Wait for the given debugger agent to attach. Currently"
682 echo " only supported on host."
683 echo " --debug-wrap-agent use libwrapagentproperties and tools/libjdwp-compat.props"
684 echo " to load the debugger agent specified by --debug-agent."
Alex Light0e151e72017-10-25 10:50:35 -0700685 echo " --with-agent <agent> Run the test with the given agent loaded with -agentpath:"
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000686 echo " --debuggable Whether to compile Java code for a debugger."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000687 echo " --gdb Run under gdb; incompatible with some tests."
Alex Lightfadfee92015-10-28 09:40:10 -0700688 echo " --gdb-arg Pass an option to gdb."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000689 echo " --build-only Build test files only (off by default)."
Alan Leung0afa07a2017-10-03 16:56:30 -0700690 echo " --build-with-d8 Build test files with javac and d8 (off by default)."
Søren Gjesse620d0a52016-09-19 11:12:51 +0200691 echo " --build-with-javac-dx Build test files with javac and dx (off by default)."
692 echo " --build-with-jack Build test files with jack and jill (on by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000693 echo " --interpreter Enable interpreter only mode (off by default)."
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800694 echo " --jit Enable jit (off by default)."
Nicolas Geoffray0e071252015-03-21 13:43:15 +0000695 echo " --optimizing Enable optimizing compiler (default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000696 echo " --no-verify Turn off verification (on by default)."
Igor Murashkin7617abd2015-07-10 18:27:47 -0700697 echo " --verify-soft-fail Force soft fail verification (off by default)."
698 echo " Verification is enabled if neither --no-verify"
699 echo " nor --verify-soft-fail is specified."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000700 echo " --no-optimize Turn off optimization (on by default)."
701 echo " --no-precise Turn off precise GC (on by default)."
702 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700703 "If used, then the"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000704 echo " other runtime options are ignored."
705 echo " --no-dex2oat Run as though dex2oat was failing."
706 echo " --no-patchoat Run as though patchoat was failing."
707 echo " --prebuild Run dex2oat on the files before starting test. (default)"
708 echo " --no-prebuild Do not run dex2oat on the files before starting"
709 echo " the test."
Richard Uhler76f5cb62016-04-04 13:30:16 -0700710 echo " --strip-dex Strip the dex files before starting test."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000711 echo " --relocate Force the use of relocating in the test, making"
712 echo " the image and oat files be relocated to a random"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +0000713 echo " address before running."
714 echo " --no-relocate Force the use of no relocating in the test. (default)"
Alex Lightfadfee92015-10-28 09:40:10 -0700715 echo " --image Run the test using a precompiled boot image. (default)"
716 echo " --no-image Run the test without a precompiled boot image."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000717 echo " --host Use the host-mode virtual machine."
718 echo " --invoke-with Pass --invoke-with option to runtime."
719 echo " --dalvik Use Dalvik (off by default)."
720 echo " --jvm Use a host-local RI virtual machine."
Alex Lighteb7c1442015-08-31 13:17:42 -0700721 echo " --use-java-home Use the JAVA_HOME environment variable"
722 echo " to find the java compiler and runtime"
723 echo " (if applicable) to run the test with."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000724 echo " --output-path [path] Location where to store the build" \
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700725 "files."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000726 echo " --64 Run the test in 64-bit mode"
727 echo " --trace Run with method tracing"
Alex Lightfadfee92015-10-28 09:40:10 -0700728 echo " --strace Run with syscall tracing from strace."
Andreas Gampe7526d782015-06-22 22:53:45 -0700729 echo " --stream Run method tracing in streaming mode (requires --trace)"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000730 echo " --gcstress Run with gc stress testing"
731 echo " --gcverify Run with gc verification"
Alex Lightb7edcda2017-04-27 13:20:31 -0700732 echo " --jvmti-trace-stress Run with jvmti method tracing stress testing"
Alex Lightc38c3692017-06-27 15:45:14 -0700733 echo " --jvmti-step-stress Run with jvmti single step stress testing"
Alex Lightb7edcda2017-04-27 13:20:31 -0700734 echo " --jvmti-redefine-stress"
735 echo " Run with jvmti method redefinition stress testing"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000736 echo " --always-clean Delete the test files even if the test fails."
Igor Murashkin05f30e12015-06-10 15:57:17 -0700737 echo " --never-clean Keep the test files even if the test succeeds."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000738 echo " --android-root [path] The path on target for the android root. (/system by default)."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000739 echo " --dex2oat-swap Use a dex2oat swap file."
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700740 echo " --instruction-set-features [string]"
741 echo " Set instruction-set-features for compilation."
Jeff Haodcdc85b2015-12-04 14:06:18 -0800742 echo " --multi-image Use a set of images compiled with dex2oat multi-image for"
743 echo " the boot class path."
Alex Lightfadfee92015-10-28 09:40:10 -0700744 echo " --pic-test Compile the test code position independent."
Alex Light91de25f2015-10-28 17:00:06 -0700745 echo " --quiet Don't print anything except failure messages"
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700746 echo " --bisection-search Perform bisection bug search."
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000747 echo " --vdex Test using vdex as in input to dex2oat. Only works with --prebuild."
Mathieu Chartier3fceaf52017-01-22 13:33:40 -0800748 echo " --suspend-timeout Change thread suspend timeout ms (default 500000)."
Shubham Ajmera981d99c2017-08-17 14:11:08 -0700749 echo " --dex2oat-jobs Number of dex2oat jobs."
Alex Light91de25f2015-10-28 17:00:06 -0700750 ) 1>&2 # Direct to stderr so usage is not printed if --quiet is set.
jeffhao5d1ac922011-09-29 17:41:15 -0700751 exit 1
752fi
753
754cd "$test_dir"
755test_dir=`pwd`
756
757td_info="${test_dir}/${info}"
758td_expected="${test_dir}/${expected}"
759
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700760if [ ! -r $td_info ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700761 err_echo "${test_dir}: missing file $td_info"
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700762 exit 1
763fi
764
765if [ ! -r $td_expected ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700766 err_echo "${test_dir}: missing file $td_expected"
jeffhao5d1ac922011-09-29 17:41:15 -0700767 exit 1
768fi
769
770# copy the test to a temp dir and run it
771
Elliott Hughes510c8782011-10-06 10:57:34 -0700772echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700773
774rm -rf "$tmp_dir"
775cp -Rp "$test_dir" "$tmp_dir"
776cd "$tmp_dir"
777
778if [ '!' -r "$build" ]; then
779 cp "${progdir}/etc/default-build" build
Zheng Xuc6667102015-05-15 16:08:45 +0800780else
781 cp "${progdir}/etc/default-build" .
jeffhao5d1ac922011-09-29 17:41:15 -0700782fi
783
784if [ '!' -r "$run" ]; then
785 cp "${progdir}/etc/default-run" run
Zheng Xuc6667102015-05-15 16:08:45 +0800786else
787 cp "${progdir}/etc/default-run" .
jeffhao5d1ac922011-09-29 17:41:15 -0700788fi
789
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700790if [ '!' -r "$check_cmd" ]; then
791 cp "${progdir}/etc/default-check" check
Zheng Xuc6667102015-05-15 16:08:45 +0800792else
793 cp "${progdir}/etc/default-check" .
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700794fi
795
jeffhao5d1ac922011-09-29 17:41:15 -0700796chmod 755 "$build"
797chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700798chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700799
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700800export TEST_NAME=`basename ${test_dir}`
801
Nicolas Geoffray1949baf2017-10-17 12:14:53 +0000802# Tests named '<number>-checker-*' will also have their CFGs verified with
803# Checker when compiled with Optimizing on host.
804if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
805 if [ "$runtime" = "art" -a "$image_suffix" = "" ]; then
806 # In no-prebuild or no-image mode, the compiler only quickens so disable the checker.
807 if [ "$prebuild_mode" = "yes" -a "$have_image" = "yes" ]; then
808 run_checker="yes"
809
810 if [ "$target_mode" = "no" ]; then
811 cfg_output_dir="$tmp_dir"
812 checker_args="--arch=${host_arch_name^^}"
813 else
814 cfg_output_dir="$DEX_LOCATION"
815 checker_args="--arch=${target_arch_name^^}"
816 fi
817
818 if [ "$debuggable" = "yes" ]; then
819 checker_args="$checker_args --debuggable"
820 fi
821
822 run_args="${run_args} -Xcompiler-option --dump-cfg=$cfg_output_dir/$cfg_output \
823 -Xcompiler-option -j1"
824 fi
825 fi
826fi
827
Mathieu Chartier031768a2015-08-27 10:25:02 -0700828 run_args="${run_args} --testlib ${testlib}"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700829
Richard Uhler020c0f32017-03-14 16:23:17 +0000830# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and
831# ART output to approximately 128MB. This should be more than sufficient
832# for any test while still catching cases of runaway output.
833# Set a hard limit to encourage ART developers to increase the ulimit here if
834# needed to support a test case rather than resetting the limit in the run
835# script for the particular test in question.
Orion Hodsonbd328d32017-03-24 11:24:10 +0000836if ! ulimit -f 128000; then
Richard Uhler020c0f32017-03-14 16:23:17 +0000837 err_echo "ulimit file size setting failed"
Ian Rogers997f0f92014-06-21 22:58:05 -0700838fi
839
Igor Murashkin2de6e082018-02-28 15:25:23 -0800840# Tell the build script which mode (target, host, jvm) we are building for
841# to determine the bootclasspath at build time.
Igor Murashkin2a337752017-06-16 14:34:40 +0000842if [[ "$target_mode" == "yes" ]]; then
843 build_args="$build_args --target"
844else
Igor Murashkin2de6e082018-02-28 15:25:23 -0800845 if [[ $runtime == "jvm" ]]; then
846 build_args="$build_args --jvm"
847 else
848 build_args="$build_args --host"
849 fi
Igor Murashkin2a337752017-06-16 14:34:40 +0000850fi
851
852if [[ "$dev_mode" == "yes" ]]; then
853 build_args="$build_args --dev"
854fi
855
jeffhao5d1ac922011-09-29 17:41:15 -0700856good="no"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000857good_build="yes"
858good_run="yes"
Alex Light77fee872017-09-05 14:51:49 -0700859export TEST_RUNTIME="${runtime}"
jeffhao5d1ac922011-09-29 17:41:15 -0700860if [ "$dev_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000861 "./${build}" $build_args 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700862 build_exit="$?"
863 echo "build exit status: $build_exit" 1>&2
864 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800865 echo "${test_dir}: running..." 1>&2
866 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700867 run_exit="$?"
Calin Juravle3cf48772015-01-26 16:47:33 +0000868
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800869 if [ "$run_exit" = "0" ]; then
Calin Juravle3cf48772015-01-26 16:47:33 +0000870 if [ "$run_checker" = "yes" ]; then
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100871 if [ "$target_mode" = "yes" ]; then
872 adb pull $cfg_output_dir/$cfg_output &> /dev/null
873 fi
David Brazdil5cc343d2015-10-08 11:35:32 +0100874 "$checker" $checker_args "$cfg_output" "$tmp_dir" 2>&1
Calin Juravle3cf48772015-01-26 16:47:33 +0000875 checker_exit="$?"
876 if [ "$checker_exit" = "0" ]; then
877 good="yes"
878 fi
Alex Light91de25f2015-10-28 17:00:06 -0700879 err_echo "checker exit status: $checker_exit"
Calin Juravle3cf48772015-01-26 16:47:33 +0000880 else
881 good="yes"
882 fi
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800883 fi
Calin Juravle3cf48772015-01-26 16:47:33 +0000884 echo "run exit status: $run_exit" 1>&2
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700885 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700886elif [ "$update_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000887 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700888 build_exit="$?"
889 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800890 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700891 "./${run}" $run_args "$@" >"$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000892 if [ "$run_checker" = "yes" ]; then
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100893 if [ "$target_mode" = "yes" ]; then
894 adb pull $cfg_output_dir/$cfg_output &> /dev/null
895 fi
David Brazdil5cc343d2015-10-08 11:35:32 +0100896 "$checker" -q $checker_args "$cfg_output" "$tmp_dir" >> "$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000897 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700898 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
899 good="yes"
900 else
Alex Light91de25f2015-10-28 17:00:06 -0700901 cat "$build_output" 1>&${real_stderr} 1>&2
902 err_echo "build exit status: $build_exit"
jeffhao5d1ac922011-09-29 17:41:15 -0700903 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700904elif [ "$build_only" = "yes" ]; then
905 good="yes"
David Brazdil4846d132015-01-15 19:07:08 +0000906 "./${build}" $build_args >"$build_output" 2>&1
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700907 build_exit="$?"
908 if [ "$build_exit" '!=' '0' ]; then
909 cp "$build_output" "$output"
910 echo "build exit status: $build_exit" >>"$output"
911 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
912 if [ "$?" '!=' "0" ]; then
913 good="no"
Alex Light91de25f2015-10-28 17:00:06 -0700914 err_echo "BUILD FAILED For ${TEST_NAME}"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700915 fi
916 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700917 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700918 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700919 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700920else
David Brazdil4846d132015-01-15 19:07:08 +0000921 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700922 build_exit="$?"
923 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800924 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700925 "./${run}" $run_args "$@" >"$output" 2>&1
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000926 run_exit="$?"
927 if [ "$run_exit" != "0" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700928 err_echo "run exit status: $run_exit"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000929 good_run="no"
David Brazdil4846d132015-01-15 19:07:08 +0000930 elif [ "$run_checker" = "yes" ]; then
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100931 if [ "$target_mode" = "yes" ]; then
932 adb pull $cfg_output_dir/$cfg_output &> /dev/null
933 fi
David Brazdil5cc343d2015-10-08 11:35:32 +0100934 "$checker" -q $checker_args "$cfg_output" "$tmp_dir" >> "$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000935 checker_exit="$?"
936 if [ "$checker_exit" != "0" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700937 err_echo "checker exit status: $checker_exit"
David Brazdil4846d132015-01-15 19:07:08 +0000938 good_run="no"
939 else
940 good_run="yes"
941 fi
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000942 else
943 good_run="yes"
944 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700945 else
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000946 good_build="no"
jeffhao5d1ac922011-09-29 17:41:15 -0700947 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700948 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
949 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700950 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700951 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700952 max_name_length=$(getconf NAME_MAX ${tmp_dir})
953 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
954 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700955 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700956 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700957 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700958 if [ "$?" = "0" ]; then
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000959 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
960 # output == expected
961 good="yes"
962 echo "${test_dir}: succeeded!" 1>&2
963 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700964 fi
965fi
966
jeffhao5d1ac922011-09-29 17:41:15 -0700967(
Alex Lightbfac14a2014-07-30 09:41:21 -0700968 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700969 echo "${test_dir}: FAILED!"
970 echo ' '
971 echo '#################### info'
972 cat "${td_info}" | sed 's/^/# /g'
973 echo '#################### diffs'
Hiroshi Yamauchid630fd62015-09-04 12:52:03 -0700974 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 3000
jeffhao5d1ac922011-09-29 17:41:15 -0700975 echo '####################'
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700976 if [ "$strace" = "yes" ]; then
977 echo '#################### strace output'
Hiroshi Yamauchid630fd62015-09-04 12:52:03 -0700978 tail -n 3000 "$tmp_dir/$strace_output"
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700979 echo '####################'
980 fi
Andreas Gampee79ca192017-07-31 10:30:16 -0700981 if [ "x$target_mode" = "xno" -a "x$SANITIZE_HOST" = "xaddress" ]; then
982 # Run the stack script to symbolize any ASAN aborts on the host for SANITIZE_HOST. The
983 # tools used by the given ABI work for both x86 and x86-64.
984 echo "ABI: 'x86_64'" | cat - "$output" | $ANDROID_BUILD_TOP/development/scripts/stack | tail -n 3000
985 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700986 echo ' '
987 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700988
Alex Light91de25f2015-10-28 17:00:06 -0700989) 2>&${real_stderr} 1>&2
Alex Lightbfac14a2014-07-30 09:41:21 -0700990
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700991# Attempt bisection only if the test failed.
992if [ "$bisection_search" = "yes" -a "$good" != "yes" ]; then
993 # Bisecting works by skipping different optimization passes which breaks checker assertions.
994 if [ "$run_checker" == "yes" ]; then
995 echo "${test_dir}: not bisecting, checker test." 1>&2
996 else
997 # Increase file size limit, bisection search can generate large logfiles.
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700998 echo "${test_dir}: bisecting..." 1>&2
999 cwd=`pwd`
1000 maybe_device_mode=""
1001 raw_cmd=""
1002 if [ "$target_mode" = "yes" ]; then
1003 # Produce cmdline.sh in $DEX_LOCATION. "$@" is passed as a runtime option
1004 # so that cmdline.sh forwards its arguments to dalvikvm. invoke-with is set
1005 # to exec in order to preserve pid when calling dalvikvm. This is required
1006 # for bisection search to correctly retrieve logs from device.
1007 "./${run}" $run_args --runtime-option '"$@"' --invoke-with exec --dry-run "$@" &> /dev/null
1008 adb shell chmod u+x "$DEX_LOCATION/cmdline.sh"
1009 maybe_device_mode="--device"
1010 raw_cmd="$DEX_LOCATION/cmdline.sh"
1011 else
1012 raw_cmd="$cwd/${run} --external-log-tags $run_args $@"
1013 fi
1014 $ANDROID_BUILD_TOP/art/tools/bisection_search/bisection_search.py \
1015 $maybe_device_mode \
1016 --raw-cmd="$raw_cmd" \
1017 --check-script="$cwd/check" \
1018 --expected-output="$cwd/expected.txt" \
Wojciech Staszkiewicz0c883832016-09-26 17:51:52 -07001019 --logfile="$cwd/bisection_log.txt" \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001020 --timeout=300
1021 fi
1022fi
1023
Alex Lightbfac14a2014-07-30 09:41:21 -07001024# Clean up test files.
Igor Murashkin05f30e12015-06-10 15:57:17 -07001025if [ "$always_clean" = "yes" -o "$good" = "yes" ] && [ "$never_clean" = "no" ]; then
Alex Lightbfac14a2014-07-30 09:41:21 -07001026 cd "$oldwd"
1027 rm -rf "$tmp_dir"
1028 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
1029 adb shell rm -rf $DEX_LOCATION
1030 fi
1031 if [ "$good" = "yes" ]; then
1032 exit 0
1033 fi
1034fi
1035
1036
1037(
1038 if [ "$always_clean" = "yes" ]; then
1039 echo "${TEST_NAME} files deleted from host "
1040 if [ "$target_mode" == "yes" ]; then
1041 echo "and from target"
1042 fi
1043 else
1044 echo "${TEST_NAME} files left in ${tmp_dir} on host"
1045 if [ "$target_mode" == "yes" ]; then
1046 echo "and in ${DEX_LOCATION} on target"
1047 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -07001048 fi
1049
Alex Light91de25f2015-10-28 17:00:06 -07001050) 2>&${real_stderr} 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -07001051
Alex Light6a870fa2016-05-31 16:36:19 -07001052if [ "$never_clean" = "yes" ] && [ "$good" = "yes" ]; then
1053 exit 0
1054else
1055 exit 1
1056fi