blob: c654cf636c074d48736aa8c46f54684906364651 [file] [log] [blame]
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001#!/bin/bash
2#
3# Runner for an individual run-test.
4
Roland Levillain72f67742019-03-06 15:48:08 +00005if [[ -z "$ANDROID_BUILD_TOP" ]]; then
6 echo 'ANDROID_BUILD_TOP environment variable is empty; did you forget to run `lunch`?'
7 exit 1
8fi
9
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010010msg() {
11 if [ "$QUIET" = "n" ]; then
12 echo "$@"
13 fi
14}
15
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000016ANDROID_ROOT="/system"
Neil Fuller26c43772018-11-23 17:56:43 +000017ANDROID_RUNTIME_ROOT="/apex/com.android.runtime"
Neil Fuller26a5dd62019-03-13 15:16:35 +000018ANDROID_TZDATA_ROOT="/apex/com.android.tzdata"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010019ARCHITECTURES_32="(arm|x86|mips|none)"
Andreas Gampe1a5c4062015-01-15 12:10:47 -080020ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010021ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
Roland Levillain72f67742019-03-06 15:48:08 +000022GET_DEVICE_ISA_BITNESS_FLAG="--32"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000023BOOT_IMAGE=""
Roland Levillain76cfe612017-10-30 13:14:28 +000024CHROOT=
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010025COMPILE_FLAGS=""
26DALVIKVM="dalvikvm32"
27DEBUGGER="n"
Alex Light54dabfb2018-09-19 16:29:09 -070028WITH_AGENT=()
Alex Lightc281ba52017-10-11 11:35:55 -070029DEBUGGER_AGENT=""
30WRAP_DEBUGGER_AGENT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010031DEV_MODE="n"
Alex Light907001d2019-01-17 00:16:04 +000032DEX2OAT_NDEBUG_BINARY="dex2oat"
33DEX2OAT_DEBUG_BINARY="dex2oatd"
Alex Light8a0e0332015-10-26 10:11:58 -070034EXPERIMENTAL=""
Nicolas Geoffray90355fe2017-02-20 09:25:40 +000035FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010036FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070037ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010038GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010039GDB_ARGS=""
Alex Lighte4b4a182019-02-12 14:19:49 -080040GDBSERVER_DEVICE="gdbserver"
41GDBSERVER_HOST="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010042HAVE_IMAGE="y"
43HOST="n"
Alex Light680cbf22018-10-31 11:00:19 -070044BIONIC="n"
45CREATE_ANDROID_ROOT="n"
Alex Light20802ca2018-12-05 15:36:03 -080046USE_ZIPAPEX="n"
47ZIPAPEX_LOC=""
Alex Light6f342dd2019-03-27 17:15:42 +000048USE_EXTRACTED_ZIPAPEX="n"
49EXTRACTED_ZIPAPEX_LOC=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010050INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080051JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010052INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080053IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010054ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000055LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070056TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000057MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010058OPTIMIZE="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010059PREBUILD="y"
60QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000061RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070062STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070063SECONDARY_DEX=""
Andreas Gampe52125522019-06-11 14:04:49 -070064TIME_OUT="timeout" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
Andreas Gampe148c1602019-06-10 16:47:46 -070065TIMEOUT_DUMPER=signal_dumper
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070066# Value in seconds
Hiroshi Yamauchifd3161a2017-01-18 14:47:25 -080067if [ "$ART_USE_READ_BARRIER" != "false" ]; then
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070068 TIME_OUT_VALUE=2400 # 40 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070069else
Mathieu Chartier2576be22016-05-24 10:24:53 -070070 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070071fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010072USE_GDB="n"
Alex Lighte4b4a182019-02-12 14:19:49 -080073USE_GDBSERVER="n"
74GDBSERVER_PORT=":5039"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010075USE_JVM="n"
Alex Lightc281ba52017-10-11 11:35:55 -070076USE_JVMTI="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070077VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010078ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070079DEX_VERIFY=""
Andreas Gampe4d2ef332015-08-05 09:24:45 -070080INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070081ARGS=""
David Brazdilfeb22822019-02-13 21:25:57 +000082VDEX_ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070083EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
84DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000085TEST_VDEX="n"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +000086TEST_DM="n"
Alex Lighte06b6342017-01-05 14:37:21 -080087TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000088APP_IMAGE="y"
Alex Light8f2c6d42017-04-10 16:27:35 -070089JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070090JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070091JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070092JVMTI_TRACE_STRESS="n"
93JVMTI_REDEFINE_STRESS="n"
Calin Juravle13439f02017-02-21 01:17:21 -080094PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070095RANDOM_PROFILE="n"
Alex Light483208d2017-09-26 09:31:17 -070096# The normal dex2oat timeout.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070097DEX2OAT_TIMEOUT="300" # 5 mins
Alex Light483208d2017-09-26 09:31:17 -070098# The *hard* timeout where we really start trying to kill the dex2oat.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070099DEX2OAT_RT_TIMEOUT="360" # 6 mins
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100100
Igor Murashkin271a0f82017-02-14 21:14:17 +0000101# if "y", run 'sync' before dalvikvm to make sure all files from
102# build step (e.g. dex2oat) were finished writing.
103SYNC_BEFORE_RUN="n"
104
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700105# When running a debug build, we want to run with all checks.
106ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
Andreas Gampee8f74ca2018-01-02 09:26:16 -0800107# The same for dex2oatd, both prebuild and runtime-driven.
108ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
109COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700110
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100111while true; do
112 if [ "x$1" = "x--quiet" ]; then
113 QUIET="y"
114 shift
Alex Light483208d2017-09-26 09:31:17 -0700115 elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
116 shift
117 if [ "x$1" = "x" ]; then
118 echo "$0 missing argument to --dex2oat-rt-timeout" 1>&2
119 exit 1
120 fi
121 DEX2OAT_RT_TIMEOUT="$1"
122 shift
123 elif [ "x$1" = "x--dex2oat-timeout" ]; then
124 shift
125 if [ "x$1" = "x" ]; then
126 echo "$0 missing argument to --dex2oat-timeout" 1>&2
127 exit 1
128 fi
129 DEX2OAT_TIMEOUT="$1"
130 shift
Alex Lighte06b6342017-01-05 14:37:21 -0800131 elif [ "x$1" = "x--jvmti" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700132 USE_JVMTI="y"
Alex Lighte06b6342017-01-05 14:37:21 -0800133 IS_JVMTI_TEST="y"
134 shift
Alex Lightfaf90b62016-08-12 14:43:48 -0700135 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -0800136 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -0700137 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100138 elif [ "x$1" = "x--lib" ]; then
139 shift
140 if [ "x$1" = "x" ]; then
141 echo "$0 missing argument to --lib" 1>&2
142 exit 1
143 fi
144 LIB="$1"
145 shift
Alex Light97acf192016-03-17 09:59:38 -0700146 elif [ "x$1" = "x--gc-stress" ]; then
147 # Give an extra 5 mins if we are gc-stress.
148 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
149 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700150 elif [ "x$1" = "x--testlib" ]; then
151 shift
152 if [ "x$1" = "x" ]; then
153 echo "$0 missing argument to --testlib" 1>&2
154 exit 1
155 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700156 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700157 shift
David Srbecky52886112016-01-22 13:56:47 +0000158 elif [ "x$1" = "x--args" ]; then
159 shift
160 if [ "x$1" = "x" ]; then
161 echo "$0 missing argument to --args" 1>&2
162 exit 1
163 fi
164 ARGS="${ARGS} $1"
165 shift
Alex Lighte2ddce32019-05-22 17:08:35 +0000166 elif [ "x$1" = "x--compiler-only-option" ]; then
167 shift
168 option="$1"
169 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
170 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100171 elif [ "x$1" = "x-Xcompiler-option" ]; then
172 shift
173 option="$1"
174 FLAGS="${FLAGS} -Xcompiler-option $option"
175 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
176 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700177 elif [ "x$1" = "x--android-runtime-option" ]; then
178 shift
179 option="$1"
180 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
181 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100182 elif [ "x$1" = "x--runtime-option" ]; then
183 shift
184 option="$1"
185 FLAGS="${FLAGS} $option"
186 shift
187 elif [ "x$1" = "x--boot" ]; then
188 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000189 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100190 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100191 elif [ "x$1" = "x--relocate" ]; then
192 RELOCATE="y"
193 shift
194 elif [ "x$1" = "x--no-relocate" ]; then
195 RELOCATE="n"
196 shift
197 elif [ "x$1" = "x--prebuild" ]; then
198 PREBUILD="y"
199 shift
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800200 elif [ "x$1" = "x--compact-dex-level" ]; then
201 shift
202 COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
203 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700204 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
205 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Lightc281ba52017-10-11 11:35:55 -0700206 USE_JVMTI="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700207 APP_IMAGE="n"
208 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700209 JVMTI_REDEFINE_STRESS="y"
210 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700211 elif [ "x$1" = "x--jvmti-step-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700212 USE_JVMTI="y"
Alex Lightc38c3692017-06-27 15:45:14 -0700213 JVMTI_STRESS="y"
214 JVMTI_STEP_STRESS="y"
215 shift
Alex Light43e935d2017-06-19 15:40:40 -0700216 elif [ "x$1" = "x--jvmti-field-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700217 USE_JVMTI="y"
Alex Light43e935d2017-06-19 15:40:40 -0700218 JVMTI_STRESS="y"
219 JVMTI_FIELD_STRESS="y"
220 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700221 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700222 USE_JVMTI="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700223 JVMTI_STRESS="y"
224 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700225 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000226 elif [ "x$1" = "x--no-app-image" ]; then
227 APP_IMAGE="n"
228 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700229 elif [ "x$1" = "x--strip-dex" ]; then
230 STRIP_DEX="y"
231 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100232 elif [ "x$1" = "x--host" ]; then
233 HOST="y"
Neil Fuller26c43772018-11-23 17:56:43 +0000234 ANDROID_ROOT="${ANDROID_HOST_OUT}"
235 ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
Neil Fuller26a5dd62019-03-13 15:16:35 +0000236 ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100237 shift
Alex Light680cbf22018-10-31 11:00:19 -0700238 elif [ "x$1" = "x--bionic" ]; then
239 BIONIC="y"
240 # We need to create an ANDROID_ROOT because currently we cannot create
241 # the frameworks/libcore with linux_bionic so we need to use the normal
242 # host ones which are in a different location.
243 CREATE_ANDROID_ROOT="y"
244 shift
Alex Light6f342dd2019-03-27 17:15:42 +0000245 elif [ "x$1" = "x--runtime-extracted-zipapex" ]; then
246 shift
247 USE_EXTRACTED_ZIPAPEX="y"
248 EXTRACTED_ZIPAPEX_LOC="$1"
249 shift
Alex Light20802ca2018-12-05 15:36:03 -0800250 elif [ "x$1" = "x--runtime-zipapex" ]; then
251 shift
252 USE_ZIPAPEX="y"
253 ZIPAPEX_LOC="$1"
Alex Light907001d2019-01-17 00:16:04 +0000254 # TODO (b/119942078): Currently apex does not support
255 # symlink_preferred_arch so we will not have a dex2oatd to execute and
256 # need to manually provide
257 # dex2oatd64.
258 DEX2OAT_DEBUG_BINARY="dex2oatd64"
Alex Light20802ca2018-12-05 15:36:03 -0800259 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100260 elif [ "x$1" = "x--no-prebuild" ]; then
261 PREBUILD="n"
262 shift
263 elif [ "x$1" = "x--no-image" ]; then
264 HAVE_IMAGE="n"
265 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700266 elif [ "x$1" = "x--secondary" ]; then
267 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100268 # Enable cfg-append to make sure we get the dump for both dex files.
269 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000270 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100271 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
272 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700273 shift
Alex Light0e151e72017-10-25 10:50:35 -0700274 elif [ "x$1" = "x--with-agent" ]; then
275 shift
276 USE_JVMTI="y"
Alex Light54dabfb2018-09-19 16:29:09 -0700277 WITH_AGENT+=("$1")
Alex Light0e151e72017-10-25 10:50:35 -0700278 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700279 elif [ "x$1" = "x--debug-wrap-agent" ]; then
280 WRAP_DEBUGGER_AGENT="y"
281 shift
282 elif [ "x$1" = "x--debug-agent" ]; then
283 shift
284 DEBUGGER="agent"
285 USE_JVMTI="y"
286 DEBUGGER_AGENT="$1"
287 TIME_OUT="n"
288 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100289 elif [ "x$1" = "x--debug" ]; then
290 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800291 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100292 shift
Alex Lighte4b4a182019-02-12 14:19:49 -0800293 elif [ "x$1" = "x--gdbserver-port" ]; then
294 shift
295 GDBSERVER_PORT=$1
296 shift
297 elif [ "x$1" = "x--gdbserver-bin" ]; then
298 shift
299 GDBSERVER_HOST=$1
300 GDBSERVER_DEVICE=$1
301 shift
302 elif [ "x$1" = "x--gdbserver" ]; then
303 USE_GDBSERVER="y"
304 DEV_MODE="y"
305 TIME_OUT="n"
306 HOST="y"
307 ANDROID_ROOT="${ANDROID_HOST_OUT}"
308 ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
Neil Fuller26a5dd62019-03-13 15:16:35 +0000309 ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
Alex Lighte4b4a182019-02-12 14:19:49 -0800310 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100311 elif [ "x$1" = "x--gdb" ]; then
312 USE_GDB="y"
313 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800314 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100315 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700316 elif [ "x$1" = "x--gdb-arg" ]; then
317 shift
318 gdb_arg="$1"
319 GDB_ARGS="${GDB_ARGS} $gdb_arg"
320 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100321 elif [ "x$1" = "x--zygote" ]; then
322 ZYGOTE="-Xzygote"
323 msg "Spawning from zygote"
324 shift
325 elif [ "x$1" = "x--dev" ]; then
326 DEV_MODE="y"
327 shift
328 elif [ "x$1" = "x--interpreter" ]; then
329 INTERPRETER="y"
330 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800331 elif [ "x$1" = "x--jit" ]; then
332 JIT="y"
333 shift
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100334 elif [ "x$1" = "x--baseline" ]; then
335 FLAGS="${FLAGS} -Xcompiler-option --baseline"
Nicolas Geoffray9b195cc2019-04-02 08:29:00 +0100336 COMPILE_FLAGS="${COMPILE_FLAGS} --baseline"
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100337 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100338 elif [ "x$1" = "x--jvm" ]; then
339 USE_JVM="y"
340 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100341 elif [ "x$1" = "x--invoke-with" ]; then
342 shift
343 if [ "x$1" = "x" ]; then
344 echo "$0 missing argument to --invoke-with" 1>&2
345 exit 1
346 fi
347 if [ "x$INVOKE_WITH" = "x" ]; then
348 INVOKE_WITH="$1"
349 else
350 INVOKE_WITH="$INVOKE_WITH $1"
351 fi
352 shift
353 elif [ "x$1" = "x--no-verify" ]; then
354 VERIFY="n"
355 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700356 elif [ "x$1" = "x--verify-soft-fail" ]; then
357 VERIFY="s"
358 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100359 elif [ "x$1" = "x--no-optimize" ]; then
360 OPTIMIZE="n"
361 shift
Roland Levillain76cfe612017-10-30 13:14:28 +0000362 elif [ "x$1" = "x--chroot" ]; then
363 shift
364 CHROOT="$1"
365 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000366 elif [ "x$1" = "x--android-root" ]; then
367 shift
368 ANDROID_ROOT="$1"
369 shift
Roland Levillain28076142019-01-10 16:39:25 +0000370 elif [ "x$1" = "x--android-runtime-root" ]; then
371 shift
372 ANDROID_RUNTIME_ROOT="$1"
373 shift
Neil Fuller26a5dd62019-03-13 15:16:35 +0000374 elif [ "x$1" = "x--android-tzdata-root" ]; then
375 shift
376 ANDROID_TZDATA_ROOT="$1"
377 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700378 elif [ "x$1" = "x--instruction-set-features" ]; then
379 shift
380 INSTRUCTION_SET_FEATURES="$1"
381 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700382 elif [ "x$1" = "x--timeout" ]; then
383 shift
384 TIME_OUT_VALUE="$1"
385 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100386 elif [ "x$1" = "x--" ]; then
387 shift
388 break
389 elif [ "x$1" = "x--64" ]; then
390 ISA="x86_64"
Alex Lighte4b4a182019-02-12 14:19:49 -0800391 GDBSERVER_DEVICE="gdbserver64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100392 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000393 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700394 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100395 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
Roland Levillain72f67742019-03-06 15:48:08 +0000396 GET_DEVICE_ISA_BITNESS_FLAG="--64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100397 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700398 elif [ "x$1" = "x--experimental" ]; then
399 if [ "$#" -lt 2 ]; then
400 echo "missing --experimental option" 1>&2
401 exit 1
402 fi
403 EXPERIMENTAL="$EXPERIMENTAL $2"
404 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700405 elif [ "x$1" = "x--external-log-tags" ]; then
406 EXTERNAL_LOG_TAGS="y"
407 shift
408 elif [ "x$1" = "x--dry-run" ]; then
409 DRY_RUN="y"
410 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000411 elif [ "x$1" = "x--vdex" ]; then
412 TEST_VDEX="y"
413 shift
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000414 elif [ "x$1" = "x--dm" ]; then
415 TEST_DM="y"
416 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000417 elif [ "x$1" = "x--vdex-filter" ]; then
418 shift
419 option="$1"
David Brazdilfeb22822019-02-13 21:25:57 +0000420 VDEX_ARGS="${VDEX_ARGS} --compiler-filter=$option"
421 shift
422 elif [ "x$1" = "x--vdex-arg" ]; then
423 shift
424 VDEX_ARGS="${VDEX_ARGS} $1"
Nicolas Geoffray74981052017-01-16 17:54:09 +0000425 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000426 elif [ "x$1" = "x--sync" ]; then
427 SYNC_BEFORE_RUN="y"
428 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800429 elif [ "x$1" = "x--profile" ]; then
430 PROFILE="y"
431 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700432 elif [ "x$1" = "x--random-profile" ]; then
433 RANDOM_PROFILE="y"
434 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100435 elif expr "x$1" : "x--" >/dev/null 2>&1; then
436 echo "unknown $0 option: $1" 1>&2
437 exit 1
438 else
439 break
440 fi
441done
442
Roland Levillain76cfe612017-10-30 13:14:28 +0000443# The DEX_LOCATION with the chroot prefix, if any.
444CHROOT_DEX_LOCATION="$CHROOT$DEX_LOCATION"
445
Roland Levillain72f67742019-03-06 15:48:08 +0000446# If running on device, determine the ISA of the device.
447if [ "$HOST" = "n" ]; then
448 ISA=$("$ANDROID_BUILD_TOP/art/test/utils/get-device-isa" "$GET_DEVICE_ISA_BITNESS_FLAG")
449fi
450
Alex Light8a0e0332015-10-26 10:11:58 -0700451if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700452 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Lightbaac7e42018-06-08 15:30:11 +0000453 # we don't want to be trying to get adbconnections since the plugin might
454 # not have been built.
455 FLAGS="${FLAGS} -XjdwpProvider:none"
Alex Light8a0e0332015-10-26 10:11:58 -0700456 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700457 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700458 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
459 done
460fi
461
Alex Light680cbf22018-10-31 11:00:19 -0700462if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
463 ANDROID_ROOT=$DEX_LOCATION/android-root
464fi
465
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100466if [ "x$1" = "x" ] ; then
467 MAIN="Main"
468else
469 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700470 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100471fi
472
473if [ "$ZYGOTE" = "" ]; then
474 if [ "$OPTIMIZE" = "y" ]; then
475 if [ "$VERIFY" = "y" ]; then
476 DEX_OPTIMIZE="-Xdexopt:verified"
477 else
478 DEX_OPTIMIZE="-Xdexopt:all"
479 fi
480 msg "Performing optimizations"
481 else
482 DEX_OPTIMIZE="-Xdexopt:none"
483 msg "Skipping optimizations"
484 fi
485
486 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100487 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100488 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700489 elif [ "$VERIFY" = "s" ]; then
490 JVM_VERIFY_ARG="Xverify:all"
491 DEX_VERIFY="-Xverify:softfail"
492 msg "Forcing verification to be soft fail"
493 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100494 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100495 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100496 msg "Skipping verification"
497 fi
498fi
499
500msg "------------------------------"
501
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100502if [ "$DEBUGGER" = "y" ]; then
503 # Use this instead for ddms and connect by running 'ddms':
504 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
505 # TODO: add a separate --ddms option?
506
507 PORT=12345
508 msg "Waiting for jdb to connect:"
509 if [ "$HOST" = "n" ]; then
510 msg " adb forward tcp:$PORT tcp:$PORT"
511 fi
512 msg " jdb -attach localhost:$PORT"
Alex Light264a4862018-01-31 16:47:58 +0000513 if [ "$USE_JVM" = "n" ]; then
514 # TODO We should switch over to using the jvmti agent by default.
515 # Need to tell the runtime to enable the internal jdwp implementation.
516 DEBUGGER_OPTS="-XjdwpOptions:transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
517 else
518 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
519 fi
Alex Lightc281ba52017-10-11 11:35:55 -0700520elif [ "$DEBUGGER" = "agent" ]; then
521 PORT=12345
522 # TODO Support ddms connection and support target.
523 if [ "$HOST" = "n" ]; then
524 echo "--debug-agent not supported yet for target!"
525 exit 1
526 fi
527 AGENTPATH=${DEBUGGER_AGENT}
528 if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
529 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
530 if [ "$TEST_IS_NDEBUG" = "y" ]; then
531 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
532 fi
533 AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
534 fi
535 msg "Connect to localhost:$PORT"
536 DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
537fi
538
Alex Light54dabfb2018-09-19 16:29:09 -0700539for agent in "${WITH_AGENT[@]}"; do
540 FLAGS="${FLAGS} -agentpath:${agent}"
541done
Alex Light0e151e72017-10-25 10:50:35 -0700542
Alex Lightc281ba52017-10-11 11:35:55 -0700543if [ "$USE_JVMTI" = "y" ]; then
544 if [ "$USE_JVM" = "n" ]; then
545 plugin=libopenjdkjvmtid.so
546 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
547 plugin=libopenjdkjvmti.so
548 fi
Alex Light2ce6fc82017-12-18 16:42:36 -0800549 # We used to add flags here that made the runtime debuggable but that is not
550 # needed anymore since the plugin can do it for us now.
Alex Lightc281ba52017-10-11 11:35:55 -0700551 FLAGS="${FLAGS} -Xplugin:${plugin}"
Alex Lightc281ba52017-10-11 11:35:55 -0700552 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100553fi
554
Alex Lightfba89fe2017-01-12 16:11:02 -0800555if [ "$IS_JVMTI_TEST" = "y" ]; then
Alex Lightfba89fe2017-01-12 16:11:02 -0800556 agent=libtiagentd.so
557 lib=tiagentd
558 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
559 agent=libtiagent.so
Alex Lightfba89fe2017-01-12 16:11:02 -0800560 lib=tiagent
561 fi
562
563 ARGS="${ARGS} ${lib}"
564 if [[ "$USE_JVM" = "y" ]]; then
565 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
566 else
Roland Levillain72f67742019-03-06 15:48:08 +0000567 if [[ "$HOST" = "y" ]]; then
568 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
569 else
570 # The linker configuration used for dalvikvm(64) in the Runtime APEX
571 # requires us to pass the full path to the agent to the runtime when
572 # running on device.
573 FLAGS="${FLAGS} -agentpath:/data/${TEST_DIRECTORY}/art/${ISA}/${agent}=${TEST_NAME},art"
574 fi
Alex Lightfba89fe2017-01-12 16:11:02 -0800575 fi
576fi
577
Alex Light8f2c6d42017-04-10 16:27:35 -0700578if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700579 agent=libtistressd.so
580 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
581 agent=libtistress.so
Alex Light42151c02017-04-20 15:54:25 -0700582 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700583
Alex Lightb7edcda2017-04-27 13:20:31 -0700584 # Just give it a default start so we can always add ',' to it.
585 agent_args="jvmti-stress"
586 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
587 # We really cannot do this on RI so don't both passing it in that case.
588 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700589 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700590 fi
591 fi
Alex Light43e935d2017-06-19 15:40:40 -0700592 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
593 agent_args="${agent_args},field"
594 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700595 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
596 agent_args="${agent_args},step"
597 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700598 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
599 agent_args="${agent_args},trace"
600 fi
601 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700602 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700603 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700604 else
Roland Levillain72f67742019-03-06 15:48:08 +0000605 if [[ "$HOST" = "y" ]]; then
606 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
607 else
608 # The linker configuration used for dalvikvm(64) in the Runtime APEX
609 # requires us to pass the full path to the agent to the runtime when
610 # running on device.
611 FLAGS="${FLAGS} -agentpath:/data/${TEST_DIRECTORY}/art/${ISA}/${agent}=${agent_args}"
612 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700613 fi
614fi
615
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100616if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700617 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700618 # Some jvmti tests are flaky without -Xint on the RI.
619 if [ "$IS_JVMTI_TEST" = "y" ]; then
620 FLAGS="${FLAGS} -Xint"
621 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700622 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000623 # We pass the classes2 path whether it's used (src-multidex) or not.
624 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700625 if [ "$DEV_MODE" = "y" ]; then
626 echo $cmdline
627 fi
628 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100629 exit
630fi
631
Vladimir Marko0ace5632018-12-14 11:11:47 +0000632# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
633# because that's what we use for compiling the core.art image.
634# It may contain additional modules from TEST_CORE_JARS.
Neil Fullerb4a70ce2018-11-09 15:49:05 +0000635bpath_modules="core-oj core-libart okhttp bouncycastle apache-xml conscrypt"
Vladimir Marko7a85e702018-12-03 18:47:23 +0000636if [ "${HOST}" = "y" ]; then
637 framework="${ANDROID_HOST_OUT}/framework"
638 if [ "${ANDROID_HOST_OUT:0:${#ANDROID_BUILD_TOP}+1}" = "${ANDROID_BUILD_TOP}/" ]; then
639 framework_location="${ANDROID_HOST_OUT:${#ANDROID_BUILD_TOP}+1}/framework"
640 else
641 echo "error: ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"
642 echo "ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP}"
643 echo "ANDROID_HOST_OUT=${ANDROID_HOST_OUT}"
644 exit
645 fi
646 bpath_suffix="-hostdex"
647else
648 framework="${ANDROID_ROOT}/framework"
649 framework_location="${ANDROID_ROOT}/framework"
650 bpath_suffix="-testdex"
651fi
652bpath=""
653bpath_locations=""
654bpath_separator=""
655for bpath_module in ${bpath_modules}; do
656 bpath+="${bpath_separator}${framework}/${bpath_module}${bpath_suffix}.jar"
657 bpath_locations+="${bpath_separator}${framework_location}/${bpath_module}${bpath_suffix}.jar"
658 bpath_separator=":"
659done
660# Pass down the bootclasspath
661FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
662FLAGS="${FLAGS} -Xbootclasspath-locations:${bpath_locations}"
663COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath:${bpath}"
664COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath-locations:${bpath_locations}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100665
666if [ "$HAVE_IMAGE" = "n" ]; then
Andreas Gampe1078d152017-11-07 18:00:54 -0800667 # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
668 FLAGS="${FLAGS} -Xnoimage-dex2oat"
669
670 # We'll abuse a second flag here to test different behavior. If --relocate, use the
671 # existing image - relocation will fail as patching is disallowed. If --no-relocate,
672 # pass a non-existent image - compilation will fail as dex2oat is disallowed.
673 if [ "${RELOCATE}" = "y" ] ; then
674 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
675 else
Roland Levillainef012222017-06-21 16:28:06 +0100676 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existent/core.art"
Andreas Gampe1078d152017-11-07 18:00:54 -0800677 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000678else
679 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100680fi
681
682
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100683if [ "$USE_GDB" = "y" ]; then
Alex Lighte4b4a182019-02-12 14:19:49 -0800684 if [ "$USE_GDBSERVER" = "y" ]; then
685 echo "Cannot pass both --gdb and --gdbserver at the same time!" >&2
686 exit 1
687 elif [ "$HOST" = "n" ]; then
688 GDB="$GDBSERVER_DEVICE $GDBSERVER_PORT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100689 else
690 if [ `uname` = "Darwin" ]; then
691 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700692 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100693 DALVIKVM=
694 else
695 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700696 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100697 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
698 # gdbargs="--annotate=3 $gdbargs"
699 fi
700 fi
Alex Lighte4b4a182019-02-12 14:19:49 -0800701elif [ "$USE_GDBSERVER" = "y" ]; then
702 if [ "$HOST" = "n" ]; then
703 echo "Cannot use --gdbserver in non-host configs" >&2
704 exit 1
705 fi
706 GDB="$GDBSERVER_HOST $GDBSERVER_PORT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100707fi
708
709if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100710 INT_OPTS="${INT_OPTS} -Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700711 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100712 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
713 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700714 elif [ "$VERIFY" = "s" ]; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100715 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
716 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700717 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
718 else # VERIFY = "n"
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100719 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
720 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700721 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
722 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100723fi
724
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800725if [ "$JIT" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100726 INT_OPTS="${INT_OPTS} -Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800727 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100728 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
729 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800730 else
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100731 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
732 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800733 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
734 fi
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100735else
736 INT_OPTS="${INT_OPTS} -Xusejit:false"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800737fi
738
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100739JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
740
Richard Uhler020c0f32017-03-14 16:23:17 +0000741COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100742if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000743 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100744else
745 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100746fi
747
Alex Light680cbf22018-10-31 11:00:19 -0700748if [ "$BIONIC" = "y" ]; then
749 # This is the location that soong drops linux_bionic builds. Despite being
750 # called linux_bionic-x86 the build is actually amd64 (x86_64) only.
751 if [ ! -e "$OUT_DIR/soong/host/linux_bionic-x86" ]; then
752 echo "linux_bionic-x86 target doesn't seem to have been built!" >&2
753 exit 1
754 fi
Andreas Gampe148c1602019-06-10 16:47:46 -0700755 # Set TIMEOUT_DUMPER manually so it works even with apex's
756 TIMEOUT_DUMPER=$OUT_DIR/soong/host/linux_bionic-x86/bin/signal_dumper
Alex Light680cbf22018-10-31 11:00:19 -0700757fi
758
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700759# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
760# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
761# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
762# remaining '/' into '@'.
763if [ "$HOST" = "y" ]; then
764 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
765else
Roland Levillain2ae376f2018-01-30 11:35:11 +0000766 # There is no getconf on device, fallback to standard value.
767 # See NAME_MAX in kernel <linux/limits.h>
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700768 max_filename_size=255
769fi
770# Compute VDEX_NAME.
771DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
772VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
773if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000774 echo "Dex location path too long:"
775 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700776 exit 1
777fi
778
Roland Levillain72f67742019-03-06 15:48:08 +0000779if [ "$HOST" = "y" ]; then
780 # On host, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the `bin`
781 # directory under the "Android Root" (usually `out/host/linux-x86`).
782 #
783 # TODO(b/130295968): Adjust this if/when ART host artifacts are installed
784 # under the Android Runtime Root (usually
785 # `out/host/linux-x86/com.android.runtime`).
786 ANDROID_RUNTIME_BIN_DIR=$ANDROID_ROOT/bin
787else
788 # On target, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the
789 # Runtime APEX's `bin` directory. This means the linker will observe the
790 # Runtime APEX linker configuration file
791 # (`/apex/com.android.runtime/etc/ld.config.txt`) for these binaries.
792 ANDROID_RUNTIME_BIN_DIR=$ANDROID_RUNTIME_ROOT/bin
793fi
Alex Light20802ca2018-12-05 15:36:03 -0800794
Calin Juravle13439f02017-02-21 01:17:21 -0800795profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100796dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000797vdex_cmdline="true"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000798dm_cmdline="true"
Andreas Gampeb09abb22018-05-03 11:51:22 -0700799mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700800strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000801sync_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700802linkroot_cmdline="true"
803linkroot_overlay_cmdline="true"
Alex Light20802ca2018-12-05 15:36:03 -0800804setupapex_cmdline="true"
805installapex_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700806
807linkdirs() {
808 find "$1" -maxdepth 1 -mindepth 1 -type d | xargs -i ln -sf '{}' "$2"
809}
810
811if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
812 mkdir_locations="${mkdir_locations} ${ANDROID_ROOT}"
813 linkroot_cmdline="linkdirs ${ANDROID_HOST_OUT} ${ANDROID_ROOT}"
814 if [ "${BIONIC}" = "y" ]; then
815 # TODO Make this overlay more generic.
816 linkroot_overlay_cmdline="linkdirs $OUT_DIR/soong/host/linux_bionic-x86 ${ANDROID_ROOT}"
817 fi
818fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100819
Alex Light20802ca2018-12-05 15:36:03 -0800820if [ "$USE_ZIPAPEX" = "y" ]; then
821 # TODO Currently this only works for linux_bionic zipapexes because those are
822 # stripped and so small enough that the ulimit doesn't kill us.
823 mkdir_locations="${mkdir_locations} $DEX_LOCATION/zipapex"
824 zip_options="-qq"
825 if [ "$DEV_MODE" = "y" ]; then
826 zip_options=""
827 fi
Alex Lightfc52ffc2019-01-31 15:48:18 -0800828 setupapex_cmdline="unzip -o -u ${zip_options} ${ZIPAPEX_LOC} apex_payload.zip -d ${DEX_LOCATION}"
829 installapex_cmdline="unzip -o -u ${zip_options} ${DEX_LOCATION}/apex_payload.zip -d ${DEX_LOCATION}/zipapex"
Roland Levillain72f67742019-03-06 15:48:08 +0000830 ANDROID_RUNTIME_BIN_DIR=$DEX_LOCATION/zipapex/bin
Alex Light6f342dd2019-03-27 17:15:42 +0000831elif [ "$USE_EXTRACTED_ZIPAPEX" = "y" ]; then
832 # Just symlink the zipapex binaries
Roland Levillain72f67742019-03-06 15:48:08 +0000833 ANDROID_RUNTIME_BIN_DIR=$DEX_LOCATION/zipapex/bin
Alex Light6f342dd2019-03-27 17:15:42 +0000834 # Force since some tests manually run this file twice.
835 ln_options=""
836 if [ "$DEV_MODE" = "y" ]; then
837 ln_options="--verbose"
838 fi
839 installapex_cmdline="ln -s -f ${ln_options} ${EXTRACTED_ZIPAPEX_LOC} ${DEX_LOCATION}/zipapex"
Alex Light20802ca2018-12-05 15:36:03 -0800840fi
841
Jeff Hao002b9312017-03-27 16:23:08 -0700842# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
843# specific profile to run properly.
844if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain72f67742019-03-06 15:48:08 +0000845 profman_cmdline="$ANDROID_RUNTIME_BIN_DIR/profman \
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000846 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700847 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Calin Juravle6df62f72017-04-28 19:58:01 -0700848 if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
849 profman_cmdline="${profman_cmdline} \
850 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
851 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
852 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000853 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
854 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700855 if [ "$PROFILE" = "y" ]; then
856 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
857 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
858 else
859 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
860 --generate-test-profile-seed=0"
861 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000862fi
863
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100864if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700865 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000866 if [ "$APP_IMAGE" = "y" ]; then
867 # Pick a base that will force the app image to get relocated.
Mathieu Chartier7cb707f2019-03-08 12:58:06 -0800868 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art --resolve-startup-const-strings=true"
Calin Juravle857f0582016-12-20 14:36:59 +0000869 fi
870
Alex Light907001d2019-01-17 00:16:04 +0000871 dex2oat_binary=${DEX2OAT_DEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +0100872 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
Alex Light907001d2019-01-17 00:16:04 +0000873 dex2oat_binary=${DEX2OAT_NDEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +0100874 fi
Roland Levillain72f67742019-03-06 15:48:08 +0000875 dex2oat_cmdline="$INVOKE_WITH $ANDROID_RUNTIME_BIN_DIR/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100876 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000877 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100878 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700879 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800880 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100881 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700882 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
883 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
884 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700885
886 # Add in a timeout. This is important for testing the compilation/verification time of
887 # pathological cases.
888 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
889 # now. We should try to improve this.
890 # The current value is rather arbitrary. run-tests should compile quickly.
Alex Light483208d2017-09-26 09:31:17 -0700891 # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700892 if [ "$HOST" != "n" ]; then
893 # Use SIGRTMIN+2 to try to dump threads.
894 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Alex Light483208d2017-09-26 09:31:17 -0700895 dex2oat_cmdline="timeout -k ${DEX2OAT_TIMEOUT}s -s SIGRTMIN+2 ${DEX2OAT_RT_TIMEOUT}s ${dex2oat_cmdline} --watchdog-timeout=${DEX2OAT_TIMEOUT}000"
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700896 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100897 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
David Brazdilfeb22822019-02-13 21:25:57 +0000898 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100899 elif [ "$TEST_VDEX" = "y" ]; then
David Brazdilfeb22822019-02-13 21:25:57 +0000900 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000901 elif [ "$TEST_DM" = "y" ]; then
902 dex2oat_cmdline="${dex2oat_cmdline} --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
903 dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$TEST_NAME.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
David Brazdilfeb22822019-02-13 21:25:57 +0000904 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.dm"
Nicolas Geoffraycab65572017-04-21 17:16:44 +0100905 elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
906 vdex_cmdline="${dex2oat_cmdline} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000907 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700908fi
909
Richard Uhler76f5cb62016-04-04 13:30:16 -0700910if [ "$STRIP_DEX" = "y" ]; then
911 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
912fi
913
Igor Murashkin271a0f82017-02-14 21:14:17 +0000914if [ "$SYNC_BEFORE_RUN" = "y" ]; then
915 sync_cmdline="sync"
916fi
917
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700918DALVIKVM_ISA_FEATURES_ARGS=""
919if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
920 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100921fi
922
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000923# java.io.tmpdir can only be set at launch time.
924TMP_DIR_OPTION=""
925if [ "$HOST" = "n" ]; then
926 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
927fi
928
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000929# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
930# b/27185632
931# b/24664297
Roland Levillain72f67742019-03-06 15:48:08 +0000932dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_RUNTIME_BIN_DIR/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100933 $GDB_ARGS \
934 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700935 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100936 -XXlib:$LIB \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100937 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700938 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100939 $ZYGOTE \
940 $JNI_OPTS \
941 $INT_OPTS \
942 $DEBUGGER_OPTS \
943 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000944 $TMP_DIR_OPTION \
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000945 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700946 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100947
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800948# Remove whitespace.
949dex2oat_cmdline=$(echo $dex2oat_cmdline)
950dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000951dm_cmdline=$(echo $dm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000952vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -0800953profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100954
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700955# Use an empty ASAN_OPTIONS to enable defaults.
956# Note: this is required as envsetup right now exports detect_leaks=0.
957RUN_TEST_ASAN_OPTIONS=""
958
Andreas Gampe58408392017-05-16 10:45:46 -0700959# Multiple shutdown leaks. b/38341789
960if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
961 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
962fi
963RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
964
Vladimir Markoa497a392018-09-26 10:52:50 +0100965# For running, we must turn off logging when dex2oat is missing. Otherwise we use
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +0000966# the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
967if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
968 if [ "$DEV_MODE" = "y" ]; then
969 export ANDROID_LOG_TAGS='*:d'
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +0000970 elif [ "$HAVE_IMAGE" = "n" ]; then
971 # All tests would log the error of missing image. Be silent here and only log fatal
972 # events.
973 export ANDROID_LOG_TAGS='*:s'
974 else
975 # We are interested in LOG(ERROR) output.
976 export ANDROID_LOG_TAGS='*:e'
977 fi
978fi
979
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100980if [ "$HOST" = "n" ]; then
981 adb root > /dev/null
982 adb wait-for-device
983 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000984 adb shell rm -rf $CHROOT_DEX_LOCATION
985 adb shell mkdir -p $CHROOT_DEX_LOCATION
986 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION
987 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -0700988 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000989 adb push profile $CHROOT_DEX_LOCATION
Calin Juravle13439f02017-02-21 01:17:21 -0800990 fi
David Brazdil7d2ec612018-01-19 14:19:59 +0000991 # Copy resource folder
992 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000993 adb push res $CHROOT_DEX_LOCATION
David Brazdil7d2ec612018-01-19 14:19:59 +0000994 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100995 else
Roland Levillain76cfe612017-10-30 13:14:28 +0000996 adb shell rm -rf $CHROOT_DEX_LOCATION >/dev/null 2>&1
997 adb shell mkdir -p $CHROOT_DEX_LOCATION >/dev/null 2>&1
998 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
999 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -07001000 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001001 adb push profile $CHROOT_DEX_LOCATION >/dev/null 2>&1
Calin Juravle13439f02017-02-21 01:17:21 -08001002 fi
David Brazdil7d2ec612018-01-19 14:19:59 +00001003 # Copy resource folder
1004 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001005 adb push res $CHROOT_DEX_LOCATION >/dev/null 2>&1
David Brazdil7d2ec612018-01-19 14:19:59 +00001006 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001007 fi
1008
Roland Levillain72f67742019-03-06 15:48:08 +00001009 # Populate LD_LIBRARY_PATH.
1010 LD_LIBRARY_PATH=
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001011 if [ "$ANDROID_ROOT" != "/system" ]; then
1012 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
1013 # so we can only use LD_LIBRARY_PATH when testing on a local
1014 # installation.
Roland Levillain72f67742019-03-06 15:48:08 +00001015 LD_LIBRARY_PATH="$ANDROID_ROOT/$LIBRARY_DIRECTORY"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001016 fi
Roland Levillain72f67742019-03-06 15:48:08 +00001017 # Needed to access libarttest(d).so and JVMTI agent libraries.
1018 LD_LIBRARY_PATH="/data/$TEST_DIRECTORY/art/$ISA:$LD_LIBRARY_PATH"
1019 # Needed to access the boot (core) image files.
1020 LD_LIBRARY_PATH="/data/art-test/$ISA:$LD_LIBRARY_PATH"
1021 # Needed to access the test's Odex files.
1022 LD_LIBRARY_PATH="$DEX_LOCATION/oat/$ISA:$LD_LIBRARY_PATH"
1023 # Needed to access the test's native libraries (see e.g. 674-hiddenapi,
1024 # which generates `libhiddenapitest_*.so` libraries in `$DEX_LOCATION`).
1025 LD_LIBRARY_PATH="$DEX_LOCATION:$LD_LIBRARY_PATH"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001026
Dimitry Ivanov49c2c922017-02-14 11:06:14 -08001027 # System libraries needed by libarttestd.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +00001028 PUBLIC_LIBS=libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
1029 if [ "$TEST_IS_NDEBUG" = "y" ]; then
David Sehr1f010162018-05-15 08:59:32 -07001030 PUBLIC_LIBS=$PUBLIC_LIBS:libart.so:libdexfile.so:libprofile.so:libartbase.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +00001031 else
David Sehr1f010162018-05-15 08:59:32 -07001032 PUBLIC_LIBS=$PUBLIC_LIBS:libartd.so:libdexfiled.so:libprofiled.so:libartbased.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +00001033 fi
Dimitry Ivanov90d48f22016-05-05 17:24:28 -07001034
Roland Levillain72f67742019-03-06 15:48:08 +00001035 # Prepend directories to the path on device.
1036 PREPEND_TARGET_PATH=$ANDROID_RUNTIME_BIN_DIR
1037 if [ "$ANDROID_ROOT" != "/system" ]; then
1038 PREPEND_TARGET_PATH="$PREPEND_TARGET_PATH:$ANDROID_ROOT/bin"
1039 fi
1040
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001041 # Create a script with the command. The command can get longer than the longest
1042 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001043 # command. Dalvik cache is cleaned before running to make subsequent executions
1044 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001045 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001046 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001047 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -07001048 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001049 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +00001050 export ANDROID_ROOT=$ANDROID_ROOT && \
Neil Fuller26c43772018-11-23 17:56:43 +00001051 export ANDROID_RUNTIME_ROOT=$ANDROID_RUNTIME_ROOT && \
Neil Fuller26a5dd62019-03-13 15:16:35 +00001052 export ANDROID_TZDATA_ROOT=$ANDROID_TZDATA_ROOT && \
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001053 export ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001054 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -07001055 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +01001056 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Roland Levillain72f67742019-03-06 15:48:08 +00001057 export PATH=$PREPEND_TARGET_PATH:\$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -08001058 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001059 $dex2oat_cmdline && \
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001060 $dm_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001061 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -07001062 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +00001063 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001064 $dalvikvm_cmdline"
1065
1066 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
1067 echo "$cmdline" > $cmdfile
1068
1069 if [ "$DEV_MODE" = "y" ]; then
1070 echo $cmdline
1071 fi
1072
1073 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001074 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001075 else
Roland Levillain76cfe612017-10-30 13:14:28 +00001076 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh >/dev/null 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001077 fi
1078
Alex Light722d6712018-02-12 17:41:12 +00001079 exit_status=0
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001080 if [ "$DRY_RUN" != "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001081 if [ -n "$CHROOT" ]; then
1082 adb shell chroot "$CHROOT" sh $DEX_LOCATION/cmdline.sh
1083 else
1084 adb shell sh $DEX_LOCATION/cmdline.sh
1085 fi
Alex Light722d6712018-02-12 17:41:12 +00001086 exit_status=$?
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001087 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001088
1089 rm -f $cmdfile
Alex Light722d6712018-02-12 17:41:12 +00001090 exit $exit_status
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001091else
Calin Juravle24bd3f92017-05-11 00:36:53 -07001092 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001093 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -07001094
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001095 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +00001096 export ANDROID_ROOT="${ANDROID_ROOT}"
Neil Fuller26c43772018-11-23 17:56:43 +00001097 export ANDROID_RUNTIME_ROOT="${ANDROID_RUNTIME_ROOT}"
Neil Fuller26a5dd62019-03-13 15:16:35 +00001098 export ANDROID_TZDATA_ROOT="${ANDROID_TZDATA_ROOT}"
Alex Light6f342dd2019-03-27 17:15:42 +00001099 if [ "$USE_ZIPAPEX" = "y" ] || [ "$USE_EXRACTED_ZIPAPEX" = "y" ]; then
Alex Light20802ca2018-12-05 15:36:03 -08001100 # Put the zipapex files in front of the ld-library-path
Alex Lightf7f31522019-02-01 11:14:41 -08001101 export LD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1102 export DYLD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1103 else
1104 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1105 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Alex Light20802ca2018-12-05 15:36:03 -08001106 fi
Roland Levillain72f67742019-03-06 15:48:08 +00001107 export PATH="$PATH:$ANDROID_RUNTIME_BIN_DIR"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001108
David Srbeckyc9ede382015-06-20 06:03:53 +01001109 # Temporarily disable address space layout randomization (ASLR).
1110 # This is needed on the host so that the linker loads core.oat at the necessary address.
1111 export LD_USE_LOAD_BIAS=1
1112
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001113 cmdline="$dalvikvm_cmdline"
1114
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001115 if [ "$TIME_OUT" = "gdb" ]; then
1116 if [ `uname` = "Darwin" ]; then
1117 # Fall back to timeout on Mac.
1118 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -07001119 elif [ "$ISA" = "x86" ]; then
1120 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
1121 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001122 else
1123 # Check if gdb is available.
1124 gdb --eval-command="quit" > /dev/null 2>&1
1125 if [ $? != 0 ]; then
1126 # gdb isn't available. Fall back to timeout.
1127 TIME_OUT="timeout"
1128 fi
1129 fi
1130 fi
1131
1132 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001133 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -08001134 #
Andreas Gampe0df2aba2019-06-10 16:53:55 -07001135 # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which
1136 # will induce a full thread dump before killing the process. To ensure any issues in
1137 # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the
1138 # child.
Andreas Gampe4bdcf5d2018-12-14 10:48:53 -08001139 # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
Andreas Gampe0df2aba2019-06-10 16:53:55 -07001140 cmdline="timeout --foreground -k 120s ${TIME_OUT_VALUE}s ${TIMEOUT_DUMPER} -s 15 $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001141 fi
1142
1143 if [ "$DEV_MODE" = "y" ]; then
Andreas Gampe1a6f9fc2019-07-02 14:59:00 -07001144 for var in ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT ANDROID_TZDATA_ROOT ANDROID_RUNTIME_ROOT LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS; do
Orion Hodsonee06c5a2018-04-23 13:46:24 +01001145 echo EXPORT $var=${!var}
1146 done
Alex Light680cbf22018-10-31 11:00:19 -07001147 echo "$(declare -f linkdirs)"
Alex Light20802ca2018-12-05 15:36:03 -08001148 echo "mkdir -p ${mkdir_locations} && $setupapex_cmdline && $installapex_cmdline && $linkroot_cmdline && $linkroot_overlay_cmdline && $profman_cmdline && $dex2oat_cmdline && $dm_cmdline && $vdex_cmdline && $strip_cmdline && $sync_cmdline && $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001149 fi
1150
1151 cd $ANDROID_BUILD_TOP
1152
Calin Juravle24bd3f92017-05-11 00:36:53 -07001153 # Make sure we delete any existing compiler artifacts.
1154 # This enables tests to call the RUN script multiple times in a row
1155 # without worrying about interference.
1156 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +00001157 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -07001158
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001159 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
1160
Alex Lightafb5d192016-05-24 15:57:45 -07001161 mkdir -p ${mkdir_locations} || exit 1
Alex Light20802ca2018-12-05 15:36:03 -08001162 $setupapex_cmdline || { echo "zipapex extraction failed." >&2 ; exit 2; }
Alex Light7b1f8cc2019-01-31 11:04:51 -08001163 $installapex_cmdline || { echo "zipapex install failed. cmd was: ${installapex_cmdline}." >&2; find ${mkdir_locations} -type f >&2; exit 2; }
Alex Light680cbf22018-10-31 11:00:19 -07001164 $linkroot_cmdline || { echo "create symlink android-root failed." >&2 ; exit 2; }
1165 $linkroot_overlay_cmdline || { echo "overlay android-root failed." >&2 ; exit 2; }
Calin Juravle13439f02017-02-21 01:17:21 -08001166 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampea8780822015-03-13 19:51:09 -07001167 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001168 $dm_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001169 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -07001170 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +00001171 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -07001172
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001173 if [ "$DRY_RUN" = "y" ]; then
1174 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -07001175 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001176
1177 if [ "$USE_GDB" = "y" ]; then
1178 # When running under gdb, we cannot do piping and grepping...
Alex Lighte4b4a182019-02-12 14:19:49 -08001179 $cmdline "$@"
1180 elif [ "$USE_GDBSERVER" = "y" ]; then
1181 echo "Connect to $GDBSERVER_PORT"
1182 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -07001183 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001184 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001185 if [ "$TIME_OUT" != "gdb" ]; then
1186 trap 'kill -INT -$pid' INT
1187 $cmdline "$@" 2>&1 & pid=$!
1188 wait $pid
Alex Light722d6712018-02-12 17:41:12 +00001189 exit_value=$?
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001190 # Add extra detail if time out is enabled.
Alex Light722d6712018-02-12 17:41:12 +00001191 if [ $exit_value = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001192 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1193 fi
Alex Light722d6712018-02-12 17:41:12 +00001194 exit $exit_value
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001195 else
1196 # With a thread dump that uses gdb if a timeout.
1197 trap 'kill -INT -$pid' INT
1198 $cmdline "$@" 2>&1 & pid=$!
1199 # Spawn a watcher process.
1200 ( sleep $TIME_OUT_VALUE && \
1201 echo "##### Thread dump using gdb on test timeout" && \
1202 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
1203 --eval-command="call exit(124)" --eval-command=quit || \
1204 kill $pid )) 2> /dev/null & watcher=$!
1205 wait $pid
1206 test_exit_status=$?
1207 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
1208 if [ $test_exit_status = 0 ]; then
1209 # The test finished normally.
1210 exit 0
1211 else
1212 # The test failed or timed out.
1213 if [ $test_exit_status = 124 ]; then
1214 # The test timed out.
1215 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1216 fi
Alex Light722d6712018-02-12 17:41:12 +00001217 exit $test_exit_status
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001218 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001219 fi
1220 fi
1221fi