blob: 9d79a0b99e4c5ae60b614e13368a75789ceb3a02 [file] [log] [blame]
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001#!/bin/bash
2#
3# Runner for an individual run-test.
4
5msg() {
6 if [ "$QUIET" = "n" ]; then
7 echo "$@"
8 fi
9}
10
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000011ANDROID_ROOT="/system"
Neil Fuller26c43772018-11-23 17:56:43 +000012ANDROID_RUNTIME_ROOT="/apex/com.android.runtime"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010013ARCHITECTURES_32="(arm|x86|mips|none)"
Andreas Gampe1a5c4062015-01-15 12:10:47 -080014ARCHITECTURES_64="(arm64|x86_64|mips64|none)"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010015ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000016BOOT_IMAGE=""
Roland Levillain76cfe612017-10-30 13:14:28 +000017CHROOT=
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010018COMPILE_FLAGS=""
19DALVIKVM="dalvikvm32"
20DEBUGGER="n"
Alex Light54dabfb2018-09-19 16:29:09 -070021WITH_AGENT=()
Alex Lightc281ba52017-10-11 11:35:55 -070022DEBUGGER_AGENT=""
23WRAP_DEBUGGER_AGENT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010024DEV_MODE="n"
Alex Light907001d2019-01-17 00:16:04 +000025DEX2OAT_NDEBUG_BINARY="dex2oat"
26DEX2OAT_DEBUG_BINARY="dex2oatd"
Alex Light8a0e0332015-10-26 10:11:58 -070027EXPERIMENTAL=""
Nicolas Geoffray90355fe2017-02-20 09:25:40 +000028FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010029FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070030ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010031GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010032GDB_ARGS=""
Alex Lighte4b4a182019-02-12 14:19:49 -080033GDBSERVER_DEVICE="gdbserver"
34GDBSERVER_HOST="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010035HAVE_IMAGE="y"
36HOST="n"
Alex Light680cbf22018-10-31 11:00:19 -070037BIONIC="n"
38CREATE_ANDROID_ROOT="n"
Alex Light20802ca2018-12-05 15:36:03 -080039USE_ZIPAPEX="n"
40ZIPAPEX_LOC=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010041INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080042JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010043INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080044IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010045ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000046LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070047TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000048MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010049OPTIMIZE="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010050PREBUILD="y"
51QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000052RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070053STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070054SECONDARY_DEX=""
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070055TIME_OUT="gdb" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
Alex Light8c5476a2018-12-17 16:10:58 -080056TIMEOUT_DUMPER=timeout_dumper
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -070057# Value in seconds
Hiroshi Yamauchifd3161a2017-01-18 14:47:25 -080058if [ "$ART_USE_READ_BARRIER" != "false" ]; then
Hiroshi Yamauchia9b296c2016-10-07 17:07:03 -070059 TIME_OUT_VALUE=2400 # 40 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070060else
Mathieu Chartier2576be22016-05-24 10:24:53 -070061 TIME_OUT_VALUE=1200 # 20 minutes.
Hiroshi Yamauchidcf0d4b2015-09-09 18:59:42 -070062fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010063USE_GDB="n"
Alex Lighte4b4a182019-02-12 14:19:49 -080064USE_GDBSERVER="n"
65GDBSERVER_PORT=":5039"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010066USE_JVM="n"
Alex Lightc281ba52017-10-11 11:35:55 -070067USE_JVMTI="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070068VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010069ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070070DEX_VERIFY=""
Andreas Gampe4d2ef332015-08-05 09:24:45 -070071INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070072ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070073EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
74DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000075TEST_VDEX="n"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +000076TEST_DM="n"
Alex Lighte06b6342017-01-05 14:37:21 -080077TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000078APP_IMAGE="y"
Alex Light8f2c6d42017-04-10 16:27:35 -070079JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070080JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070081JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070082JVMTI_TRACE_STRESS="n"
83JVMTI_REDEFINE_STRESS="n"
Nicolas Geoffray74981052017-01-16 17:54:09 +000084VDEX_FILTER=""
Calin Juravle13439f02017-02-21 01:17:21 -080085PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070086RANDOM_PROFILE="n"
Alex Light483208d2017-09-26 09:31:17 -070087# The normal dex2oat timeout.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070088DEX2OAT_TIMEOUT="300" # 5 mins
Alex Light483208d2017-09-26 09:31:17 -070089# The *hard* timeout where we really start trying to kill the dex2oat.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070090DEX2OAT_RT_TIMEOUT="360" # 6 mins
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010091
Igor Murashkin271a0f82017-02-14 21:14:17 +000092# if "y", run 'sync' before dalvikvm to make sure all files from
93# build step (e.g. dex2oat) were finished writing.
94SYNC_BEFORE_RUN="n"
95
Andreas Gampe1c5b42f2017-06-15 18:20:45 -070096# When running a debug build, we want to run with all checks.
97ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
Andreas Gampee8f74ca2018-01-02 09:26:16 -080098# The same for dex2oatd, both prebuild and runtime-driven.
99ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
100COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700101
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100102while true; do
103 if [ "x$1" = "x--quiet" ]; then
104 QUIET="y"
105 shift
Alex Light483208d2017-09-26 09:31:17 -0700106 elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
107 shift
108 if [ "x$1" = "x" ]; then
109 echo "$0 missing argument to --dex2oat-rt-timeout" 1>&2
110 exit 1
111 fi
112 DEX2OAT_RT_TIMEOUT="$1"
113 shift
114 elif [ "x$1" = "x--dex2oat-timeout" ]; then
115 shift
116 if [ "x$1" = "x" ]; then
117 echo "$0 missing argument to --dex2oat-timeout" 1>&2
118 exit 1
119 fi
120 DEX2OAT_TIMEOUT="$1"
121 shift
Alex Lighte06b6342017-01-05 14:37:21 -0800122 elif [ "x$1" = "x--jvmti" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700123 USE_JVMTI="y"
Alex Lighte06b6342017-01-05 14:37:21 -0800124 IS_JVMTI_TEST="y"
125 shift
Alex Lightfaf90b62016-08-12 14:43:48 -0700126 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -0800127 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -0700128 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100129 elif [ "x$1" = "x--lib" ]; then
130 shift
131 if [ "x$1" = "x" ]; then
132 echo "$0 missing argument to --lib" 1>&2
133 exit 1
134 fi
135 LIB="$1"
136 shift
Alex Light97acf192016-03-17 09:59:38 -0700137 elif [ "x$1" = "x--gc-stress" ]; then
138 # Give an extra 5 mins if we are gc-stress.
139 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + 300))
140 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700141 elif [ "x$1" = "x--testlib" ]; then
142 shift
143 if [ "x$1" = "x" ]; then
144 echo "$0 missing argument to --testlib" 1>&2
145 exit 1
146 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700147 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700148 shift
David Srbecky52886112016-01-22 13:56:47 +0000149 elif [ "x$1" = "x--args" ]; then
150 shift
151 if [ "x$1" = "x" ]; then
152 echo "$0 missing argument to --args" 1>&2
153 exit 1
154 fi
155 ARGS="${ARGS} $1"
156 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100157 elif [ "x$1" = "x-Xcompiler-option" ]; then
158 shift
159 option="$1"
160 FLAGS="${FLAGS} -Xcompiler-option $option"
161 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
162 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700163 elif [ "x$1" = "x--android-runtime-option" ]; then
164 shift
165 option="$1"
166 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
167 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100168 elif [ "x$1" = "x--runtime-option" ]; then
169 shift
170 option="$1"
171 FLAGS="${FLAGS} $option"
172 shift
173 elif [ "x$1" = "x--boot" ]; then
174 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000175 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100176 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100177 elif [ "x$1" = "x--relocate" ]; then
178 RELOCATE="y"
179 shift
180 elif [ "x$1" = "x--no-relocate" ]; then
181 RELOCATE="n"
182 shift
183 elif [ "x$1" = "x--prebuild" ]; then
184 PREBUILD="y"
185 shift
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800186 elif [ "x$1" = "x--compact-dex-level" ]; then
187 shift
188 COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
189 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700190 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
191 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Lightc281ba52017-10-11 11:35:55 -0700192 USE_JVMTI="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700193 APP_IMAGE="n"
194 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700195 JVMTI_REDEFINE_STRESS="y"
196 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700197 elif [ "x$1" = "x--jvmti-step-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700198 USE_JVMTI="y"
Alex Lightc38c3692017-06-27 15:45:14 -0700199 JVMTI_STRESS="y"
200 JVMTI_STEP_STRESS="y"
201 shift
Alex Light43e935d2017-06-19 15:40:40 -0700202 elif [ "x$1" = "x--jvmti-field-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700203 USE_JVMTI="y"
Alex Light43e935d2017-06-19 15:40:40 -0700204 JVMTI_STRESS="y"
205 JVMTI_FIELD_STRESS="y"
206 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700207 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700208 USE_JVMTI="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700209 JVMTI_STRESS="y"
210 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700211 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000212 elif [ "x$1" = "x--no-app-image" ]; then
213 APP_IMAGE="n"
214 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700215 elif [ "x$1" = "x--strip-dex" ]; then
216 STRIP_DEX="y"
217 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100218 elif [ "x$1" = "x--host" ]; then
219 HOST="y"
Neil Fuller26c43772018-11-23 17:56:43 +0000220 ANDROID_ROOT="${ANDROID_HOST_OUT}"
221 ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100222 shift
Alex Light680cbf22018-10-31 11:00:19 -0700223 elif [ "x$1" = "x--bionic" ]; then
224 BIONIC="y"
225 # We need to create an ANDROID_ROOT because currently we cannot create
226 # the frameworks/libcore with linux_bionic so we need to use the normal
227 # host ones which are in a different location.
228 CREATE_ANDROID_ROOT="y"
229 shift
Alex Light20802ca2018-12-05 15:36:03 -0800230 elif [ "x$1" = "x--runtime-zipapex" ]; then
231 shift
232 USE_ZIPAPEX="y"
233 ZIPAPEX_LOC="$1"
Alex Light907001d2019-01-17 00:16:04 +0000234 # TODO (b/119942078): Currently apex does not support
235 # symlink_preferred_arch so we will not have a dex2oatd to execute and
236 # need to manually provide
237 # dex2oatd64.
238 DEX2OAT_DEBUG_BINARY="dex2oatd64"
Alex Light20802ca2018-12-05 15:36:03 -0800239 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100240 elif [ "x$1" = "x--no-prebuild" ]; then
241 PREBUILD="n"
242 shift
243 elif [ "x$1" = "x--no-image" ]; then
244 HAVE_IMAGE="n"
245 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700246 elif [ "x$1" = "x--secondary" ]; then
247 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100248 # Enable cfg-append to make sure we get the dump for both dex files.
249 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000250 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100251 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
252 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700253 shift
Alex Light0e151e72017-10-25 10:50:35 -0700254 elif [ "x$1" = "x--with-agent" ]; then
255 shift
256 USE_JVMTI="y"
Alex Light54dabfb2018-09-19 16:29:09 -0700257 WITH_AGENT+=("$1")
Alex Light0e151e72017-10-25 10:50:35 -0700258 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700259 elif [ "x$1" = "x--debug-wrap-agent" ]; then
260 WRAP_DEBUGGER_AGENT="y"
261 shift
262 elif [ "x$1" = "x--debug-agent" ]; then
263 shift
264 DEBUGGER="agent"
265 USE_JVMTI="y"
266 DEBUGGER_AGENT="$1"
267 TIME_OUT="n"
268 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100269 elif [ "x$1" = "x--debug" ]; then
270 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800271 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100272 shift
Alex Lighte4b4a182019-02-12 14:19:49 -0800273 elif [ "x$1" = "x--gdbserver-port" ]; then
274 shift
275 GDBSERVER_PORT=$1
276 shift
277 elif [ "x$1" = "x--gdbserver-bin" ]; then
278 shift
279 GDBSERVER_HOST=$1
280 GDBSERVER_DEVICE=$1
281 shift
282 elif [ "x$1" = "x--gdbserver" ]; then
283 USE_GDBSERVER="y"
284 DEV_MODE="y"
285 TIME_OUT="n"
286 HOST="y"
287 ANDROID_ROOT="${ANDROID_HOST_OUT}"
288 ANDROID_RUNTIME_ROOT="${ANDROID_HOST_OUT}/com.android.runtime"
289 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100290 elif [ "x$1" = "x--gdb" ]; then
291 USE_GDB="y"
292 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800293 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100294 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700295 elif [ "x$1" = "x--gdb-arg" ]; then
296 shift
297 gdb_arg="$1"
298 GDB_ARGS="${GDB_ARGS} $gdb_arg"
299 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100300 elif [ "x$1" = "x--zygote" ]; then
301 ZYGOTE="-Xzygote"
302 msg "Spawning from zygote"
303 shift
304 elif [ "x$1" = "x--dev" ]; then
305 DEV_MODE="y"
306 shift
307 elif [ "x$1" = "x--interpreter" ]; then
308 INTERPRETER="y"
309 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800310 elif [ "x$1" = "x--jit" ]; then
311 JIT="y"
312 shift
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100313 elif [ "x$1" = "x--baseline" ]; then
314 FLAGS="${FLAGS} -Xcompiler-option --baseline"
315 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100316 elif [ "x$1" = "x--jvm" ]; then
317 USE_JVM="y"
318 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100319 elif [ "x$1" = "x--invoke-with" ]; then
320 shift
321 if [ "x$1" = "x" ]; then
322 echo "$0 missing argument to --invoke-with" 1>&2
323 exit 1
324 fi
325 if [ "x$INVOKE_WITH" = "x" ]; then
326 INVOKE_WITH="$1"
327 else
328 INVOKE_WITH="$INVOKE_WITH $1"
329 fi
330 shift
331 elif [ "x$1" = "x--no-verify" ]; then
332 VERIFY="n"
333 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700334 elif [ "x$1" = "x--verify-soft-fail" ]; then
335 VERIFY="s"
336 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100337 elif [ "x$1" = "x--no-optimize" ]; then
338 OPTIMIZE="n"
339 shift
Roland Levillain76cfe612017-10-30 13:14:28 +0000340 elif [ "x$1" = "x--chroot" ]; then
341 shift
342 CHROOT="$1"
343 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000344 elif [ "x$1" = "x--android-root" ]; then
345 shift
346 ANDROID_ROOT="$1"
347 shift
Roland Levillain28076142019-01-10 16:39:25 +0000348 elif [ "x$1" = "x--android-runtime-root" ]; then
349 shift
350 ANDROID_RUNTIME_ROOT="$1"
351 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700352 elif [ "x$1" = "x--instruction-set-features" ]; then
353 shift
354 INSTRUCTION_SET_FEATURES="$1"
355 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700356 elif [ "x$1" = "x--timeout" ]; then
357 shift
358 TIME_OUT_VALUE="$1"
359 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100360 elif [ "x$1" = "x--" ]; then
361 shift
362 break
363 elif [ "x$1" = "x--64" ]; then
364 ISA="x86_64"
Alex Lighte4b4a182019-02-12 14:19:49 -0800365 GDBSERVER_DEVICE="gdbserver64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100366 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000367 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700368 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100369 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
370 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700371 elif [ "x$1" = "x--experimental" ]; then
372 if [ "$#" -lt 2 ]; then
373 echo "missing --experimental option" 1>&2
374 exit 1
375 fi
376 EXPERIMENTAL="$EXPERIMENTAL $2"
377 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700378 elif [ "x$1" = "x--external-log-tags" ]; then
379 EXTERNAL_LOG_TAGS="y"
380 shift
381 elif [ "x$1" = "x--dry-run" ]; then
382 DRY_RUN="y"
383 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000384 elif [ "x$1" = "x--vdex" ]; then
385 TEST_VDEX="y"
386 shift
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000387 elif [ "x$1" = "x--dm" ]; then
388 TEST_DM="y"
389 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000390 elif [ "x$1" = "x--vdex-filter" ]; then
391 shift
392 option="$1"
393 VDEX_FILTER="--compiler-filter=$option"
394 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000395 elif [ "x$1" = "x--sync" ]; then
396 SYNC_BEFORE_RUN="y"
397 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800398 elif [ "x$1" = "x--profile" ]; then
399 PROFILE="y"
400 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700401 elif [ "x$1" = "x--random-profile" ]; then
402 RANDOM_PROFILE="y"
403 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100404 elif expr "x$1" : "x--" >/dev/null 2>&1; then
405 echo "unknown $0 option: $1" 1>&2
406 exit 1
407 else
408 break
409 fi
410done
411
Roland Levillain76cfe612017-10-30 13:14:28 +0000412# The DEX_LOCATION with the chroot prefix, if any.
413CHROOT_DEX_LOCATION="$CHROOT$DEX_LOCATION"
414
Alex Light8a0e0332015-10-26 10:11:58 -0700415if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700416 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Lightbaac7e42018-06-08 15:30:11 +0000417 # we don't want to be trying to get adbconnections since the plugin might
418 # not have been built.
419 FLAGS="${FLAGS} -XjdwpProvider:none"
Alex Light8a0e0332015-10-26 10:11:58 -0700420 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700421 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700422 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
423 done
424fi
425
Alex Light680cbf22018-10-31 11:00:19 -0700426if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
427 ANDROID_ROOT=$DEX_LOCATION/android-root
428fi
429
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100430if [ "x$1" = "x" ] ; then
431 MAIN="Main"
432else
433 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700434 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100435fi
436
437if [ "$ZYGOTE" = "" ]; then
438 if [ "$OPTIMIZE" = "y" ]; then
439 if [ "$VERIFY" = "y" ]; then
440 DEX_OPTIMIZE="-Xdexopt:verified"
441 else
442 DEX_OPTIMIZE="-Xdexopt:all"
443 fi
444 msg "Performing optimizations"
445 else
446 DEX_OPTIMIZE="-Xdexopt:none"
447 msg "Skipping optimizations"
448 fi
449
450 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100451 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100452 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700453 elif [ "$VERIFY" = "s" ]; then
454 JVM_VERIFY_ARG="Xverify:all"
455 DEX_VERIFY="-Xverify:softfail"
456 msg "Forcing verification to be soft fail"
457 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100458 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100459 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100460 msg "Skipping verification"
461 fi
462fi
463
464msg "------------------------------"
465
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100466if [ "$DEBUGGER" = "y" ]; then
467 # Use this instead for ddms and connect by running 'ddms':
468 # DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_android_adb,server=y,suspend=y"
469 # TODO: add a separate --ddms option?
470
471 PORT=12345
472 msg "Waiting for jdb to connect:"
473 if [ "$HOST" = "n" ]; then
474 msg " adb forward tcp:$PORT tcp:$PORT"
475 fi
476 msg " jdb -attach localhost:$PORT"
Alex Light264a4862018-01-31 16:47:58 +0000477 if [ "$USE_JVM" = "n" ]; then
478 # TODO We should switch over to using the jvmti agent by default.
479 # Need to tell the runtime to enable the internal jdwp implementation.
480 DEBUGGER_OPTS="-XjdwpOptions:transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
481 else
482 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
483 fi
Alex Lightc281ba52017-10-11 11:35:55 -0700484elif [ "$DEBUGGER" = "agent" ]; then
485 PORT=12345
486 # TODO Support ddms connection and support target.
487 if [ "$HOST" = "n" ]; then
488 echo "--debug-agent not supported yet for target!"
489 exit 1
490 fi
491 AGENTPATH=${DEBUGGER_AGENT}
492 if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
493 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
494 if [ "$TEST_IS_NDEBUG" = "y" ]; then
495 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
496 fi
497 AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
498 fi
499 msg "Connect to localhost:$PORT"
500 DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
501fi
502
Alex Light54dabfb2018-09-19 16:29:09 -0700503for agent in "${WITH_AGENT[@]}"; do
504 FLAGS="${FLAGS} -agentpath:${agent}"
505done
Alex Light0e151e72017-10-25 10:50:35 -0700506
Alex Lightc281ba52017-10-11 11:35:55 -0700507if [ "$USE_JVMTI" = "y" ]; then
508 if [ "$USE_JVM" = "n" ]; then
509 plugin=libopenjdkjvmtid.so
510 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
511 plugin=libopenjdkjvmti.so
512 fi
Alex Light2ce6fc82017-12-18 16:42:36 -0800513 # We used to add flags here that made the runtime debuggable but that is not
514 # needed anymore since the plugin can do it for us now.
Alex Lightc281ba52017-10-11 11:35:55 -0700515 FLAGS="${FLAGS} -Xplugin:${plugin}"
Alex Lightc281ba52017-10-11 11:35:55 -0700516 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100517fi
518
Alex Lightfba89fe2017-01-12 16:11:02 -0800519if [ "$IS_JVMTI_TEST" = "y" ]; then
Alex Lightfba89fe2017-01-12 16:11:02 -0800520 agent=libtiagentd.so
521 lib=tiagentd
522 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
523 agent=libtiagent.so
Alex Lightfba89fe2017-01-12 16:11:02 -0800524 lib=tiagent
525 fi
526
527 ARGS="${ARGS} ${lib}"
528 if [[ "$USE_JVM" = "y" ]]; then
529 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
530 else
531 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
Alex Lightfba89fe2017-01-12 16:11:02 -0800532 fi
533fi
534
Alex Light8f2c6d42017-04-10 16:27:35 -0700535if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700536 agent=libtistressd.so
537 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
538 agent=libtistress.so
Alex Light42151c02017-04-20 15:54:25 -0700539 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700540
Alex Lightb7edcda2017-04-27 13:20:31 -0700541 # Just give it a default start so we can always add ',' to it.
542 agent_args="jvmti-stress"
543 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
544 # We really cannot do this on RI so don't both passing it in that case.
545 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700546 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700547 fi
548 fi
Alex Light43e935d2017-06-19 15:40:40 -0700549 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
550 agent_args="${agent_args},field"
551 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700552 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
553 agent_args="${agent_args},step"
554 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700555 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
556 agent_args="${agent_args},trace"
557 fi
558 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700559 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700560 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700561 else
Alex Lightb7edcda2017-04-27 13:20:31 -0700562 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
Alex Light8f2c6d42017-04-10 16:27:35 -0700563 fi
564fi
565
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100566if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700567 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700568 # Some jvmti tests are flaky without -Xint on the RI.
569 if [ "$IS_JVMTI_TEST" = "y" ]; then
570 FLAGS="${FLAGS} -Xint"
571 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700572 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000573 # We pass the classes2 path whether it's used (src-multidex) or not.
574 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700575 if [ "$DEV_MODE" = "y" ]; then
576 echo $cmdline
577 fi
578 $cmdline
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100579 exit
580fi
581
Vladimir Marko0ace5632018-12-14 11:11:47 +0000582# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
583# because that's what we use for compiling the core.art image.
584# It may contain additional modules from TEST_CORE_JARS.
Neil Fullerb4a70ce2018-11-09 15:49:05 +0000585bpath_modules="core-oj core-libart okhttp bouncycastle apache-xml conscrypt"
Vladimir Marko7a85e702018-12-03 18:47:23 +0000586if [ "${HOST}" = "y" ]; then
587 framework="${ANDROID_HOST_OUT}/framework"
588 if [ "${ANDROID_HOST_OUT:0:${#ANDROID_BUILD_TOP}+1}" = "${ANDROID_BUILD_TOP}/" ]; then
589 framework_location="${ANDROID_HOST_OUT:${#ANDROID_BUILD_TOP}+1}/framework"
590 else
591 echo "error: ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"
592 echo "ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP}"
593 echo "ANDROID_HOST_OUT=${ANDROID_HOST_OUT}"
594 exit
595 fi
596 bpath_suffix="-hostdex"
597else
598 framework="${ANDROID_ROOT}/framework"
599 framework_location="${ANDROID_ROOT}/framework"
600 bpath_suffix="-testdex"
601fi
602bpath=""
603bpath_locations=""
604bpath_separator=""
605for bpath_module in ${bpath_modules}; do
606 bpath+="${bpath_separator}${framework}/${bpath_module}${bpath_suffix}.jar"
607 bpath_locations+="${bpath_separator}${framework_location}/${bpath_module}${bpath_suffix}.jar"
608 bpath_separator=":"
609done
610# Pass down the bootclasspath
611FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
612FLAGS="${FLAGS} -Xbootclasspath-locations:${bpath_locations}"
613COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath:${bpath}"
614COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath-locations:${bpath_locations}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100615
616if [ "$HAVE_IMAGE" = "n" ]; then
Andreas Gampe1078d152017-11-07 18:00:54 -0800617 # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
618 FLAGS="${FLAGS} -Xnoimage-dex2oat"
619
620 # We'll abuse a second flag here to test different behavior. If --relocate, use the
621 # existing image - relocation will fail as patching is disallowed. If --no-relocate,
622 # pass a non-existent image - compilation will fail as dex2oat is disallowed.
623 if [ "${RELOCATE}" = "y" ] ; then
624 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
625 else
Roland Levillainef012222017-06-21 16:28:06 +0100626 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existent/core.art"
Andreas Gampe1078d152017-11-07 18:00:54 -0800627 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000628else
629 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100630fi
631
632
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100633if [ "$USE_GDB" = "y" ]; then
Alex Lighte4b4a182019-02-12 14:19:49 -0800634 if [ "$USE_GDBSERVER" = "y" ]; then
635 echo "Cannot pass both --gdb and --gdbserver at the same time!" >&2
636 exit 1
637 elif [ "$HOST" = "n" ]; then
638 GDB="$GDBSERVER_DEVICE $GDBSERVER_PORT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100639 else
640 if [ `uname` = "Darwin" ]; then
641 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700642 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100643 DALVIKVM=
644 else
645 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700646 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100647 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
648 # gdbargs="--annotate=3 $gdbargs"
649 fi
650 fi
Alex Lighte4b4a182019-02-12 14:19:49 -0800651elif [ "$USE_GDBSERVER" = "y" ]; then
652 if [ "$HOST" = "n" ]; then
653 echo "Cannot use --gdbserver in non-host configs" >&2
654 exit 1
655 fi
656 GDB="$GDBSERVER_HOST $GDBSERVER_PORT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100657fi
658
659if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100660 INT_OPTS="${INT_OPTS} -Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700661 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100662 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
663 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700664 elif [ "$VERIFY" = "s" ]; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100665 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
666 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700667 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
668 else # VERIFY = "n"
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100669 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
670 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700671 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
672 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100673fi
674
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800675if [ "$JIT" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100676 INT_OPTS="${INT_OPTS} -Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800677 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100678 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
679 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800680 else
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100681 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
682 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800683 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
684 fi
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100685else
686 INT_OPTS="${INT_OPTS} -Xusejit:false"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800687fi
688
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100689JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
690
Richard Uhler020c0f32017-03-14 16:23:17 +0000691COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100692if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000693 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100694else
695 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100696fi
697
698if [ "$HOST" = "n" ]; then
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000699 # Need to be root to query /data/dalvik-cache
700 adb root > /dev/null
701 adb wait-for-device
702 ISA=
703 ISA_adb_invocation=
704 ISA_outcome=
705 # We iterate a few times to workaround an adb issue. b/32655576
706 for i in {1..10}; do
707 ISA_adb_invocation=$(adb shell ls -F /data/dalvik-cache)
708 ISA_outcome=$?
709 ISA=$(echo $ISA_adb_invocation | grep -Ewo "${ARCHITECTURES_PATTERN}")
710 if [ x"$ISA" != "x" ]; then
711 break;
712 fi
713 done
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100714 if [ x"$ISA" = "x" ]; then
715 echo "Unable to determine architecture"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000716 # Print a few things for helping diagnosing the problem.
Nicolas Geoffrayd295bc82016-11-04 13:03:05 +0000717 echo "adb invocation output: $ISA_adb_invocation"
718 echo "adb invocation outcome: $ISA_outcome"
Nicolas Geoffray8f500fa2016-11-03 11:18:48 +0000719 echo $(adb shell ls -F /data/dalvik-cache)
720 echo $(adb shell ls /data/dalvik-cache)
721 echo ${ARCHITECTURES_PATTERN}
722 echo $(adb shell ls -F /data/dalvik-cache | grep -Ewo "${ARCHITECTURES_PATTERN}")
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100723 exit 1
724 fi
725fi
726
Alex Light680cbf22018-10-31 11:00:19 -0700727if [ "$BIONIC" = "y" ]; then
728 # This is the location that soong drops linux_bionic builds. Despite being
729 # called linux_bionic-x86 the build is actually amd64 (x86_64) only.
730 if [ ! -e "$OUT_DIR/soong/host/linux_bionic-x86" ]; then
731 echo "linux_bionic-x86 target doesn't seem to have been built!" >&2
732 exit 1
733 fi
Alex Light8c5476a2018-12-17 16:10:58 -0800734 # Set timeout_dumper manually so it works even with apex's
735 TIMEOUT_DUMPER=$OUT_DIR/soong/host/linux_bionic-x86/bin/timeout_dumper
Alex Light680cbf22018-10-31 11:00:19 -0700736fi
737
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700738# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
739# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
740# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
741# remaining '/' into '@'.
742if [ "$HOST" = "y" ]; then
743 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
744else
Roland Levillain2ae376f2018-01-30 11:35:11 +0000745 # There is no getconf on device, fallback to standard value.
746 # See NAME_MAX in kernel <linux/limits.h>
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700747 max_filename_size=255
748fi
749# Compute VDEX_NAME.
750DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
751VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
752if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000753 echo "Dex location path too long:"
754 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700755 exit 1
756fi
757
Alex Light20802ca2018-12-05 15:36:03 -0800758BIN_DIR=$ANDROID_ROOT/bin
759
Calin Juravle13439f02017-02-21 01:17:21 -0800760profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100761dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000762vdex_cmdline="true"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000763dm_cmdline="true"
Andreas Gampeb09abb22018-05-03 11:51:22 -0700764mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700765strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000766sync_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700767linkroot_cmdline="true"
768linkroot_overlay_cmdline="true"
Alex Light20802ca2018-12-05 15:36:03 -0800769setupapex_cmdline="true"
770installapex_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700771
772linkdirs() {
773 find "$1" -maxdepth 1 -mindepth 1 -type d | xargs -i ln -sf '{}' "$2"
774}
775
776if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
777 mkdir_locations="${mkdir_locations} ${ANDROID_ROOT}"
778 linkroot_cmdline="linkdirs ${ANDROID_HOST_OUT} ${ANDROID_ROOT}"
779 if [ "${BIONIC}" = "y" ]; then
780 # TODO Make this overlay more generic.
781 linkroot_overlay_cmdline="linkdirs $OUT_DIR/soong/host/linux_bionic-x86 ${ANDROID_ROOT}"
782 fi
783fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100784
Alex Light20802ca2018-12-05 15:36:03 -0800785if [ "$USE_ZIPAPEX" = "y" ]; then
786 # TODO Currently this only works for linux_bionic zipapexes because those are
787 # stripped and so small enough that the ulimit doesn't kill us.
788 mkdir_locations="${mkdir_locations} $DEX_LOCATION/zipapex"
789 zip_options="-qq"
790 if [ "$DEV_MODE" = "y" ]; then
791 zip_options=""
792 fi
Alex Lightfc52ffc2019-01-31 15:48:18 -0800793 setupapex_cmdline="unzip -o -u ${zip_options} ${ZIPAPEX_LOC} apex_payload.zip -d ${DEX_LOCATION}"
794 installapex_cmdline="unzip -o -u ${zip_options} ${DEX_LOCATION}/apex_payload.zip -d ${DEX_LOCATION}/zipapex"
Alex Light20802ca2018-12-05 15:36:03 -0800795 BIN_DIR=$DEX_LOCATION/zipapex/bin
796fi
797
Jeff Hao002b9312017-03-27 16:23:08 -0700798# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
799# specific profile to run properly.
800if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Alex Light20802ca2018-12-05 15:36:03 -0800801 profman_cmdline="$BIN_DIR/profman \
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000802 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700803 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Calin Juravle6df62f72017-04-28 19:58:01 -0700804 if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
805 profman_cmdline="${profman_cmdline} \
806 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
807 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
808 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000809 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
810 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700811 if [ "$PROFILE" = "y" ]; then
812 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
813 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
814 else
815 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
816 --generate-test-profile-seed=0"
817 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000818fi
819
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100820if [ "$PREBUILD" = "y" ]; then
Alex Lightafb5d192016-05-24 15:57:45 -0700821 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000822 if [ "$APP_IMAGE" = "y" ]; then
823 # Pick a base that will force the app image to get relocated.
824 app_image="--base=0x4000 --app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art"
825 fi
826
Alex Light907001d2019-01-17 00:16:04 +0000827 dex2oat_binary=${DEX2OAT_DEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +0100828 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
Alex Light907001d2019-01-17 00:16:04 +0000829 dex2oat_binary=${DEX2OAT_NDEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +0100830 fi
Alex Light20802ca2018-12-05 15:36:03 -0800831 dex2oat_cmdline="$INVOKE_WITH $BIN_DIR/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100832 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000833 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100834 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
Andreas Gampe14759242016-03-23 10:54:21 -0700835 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
Jeff Haodcdc85b2015-12-04 14:06:18 -0800836 ${app_image} \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100837 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700838 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
839 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
840 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700841
842 # Add in a timeout. This is important for testing the compilation/verification time of
843 # pathological cases.
844 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
845 # now. We should try to improve this.
846 # The current value is rather arbitrary. run-tests should compile quickly.
Alex Light483208d2017-09-26 09:31:17 -0700847 # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700848 if [ "$HOST" != "n" ]; then
849 # Use SIGRTMIN+2 to try to dump threads.
850 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Alex Light483208d2017-09-26 09:31:17 -0700851 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 -0700852 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100853 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
854 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
855 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffray74981052017-01-16 17:54:09 +0000856 vdex_cmdline="${dex2oat_cmdline} ${VDEX_FILTER} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000857 elif [ "$TEST_DM" = "y" ]; then
858 dex2oat_cmdline="${dex2oat_cmdline} --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
859 dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$TEST_NAME.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
860 vdex_cmdline="${dex2oat_cmdline} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.dm"
Nicolas Geoffraycab65572017-04-21 17:16:44 +0100861 elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
862 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 +0000863 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700864fi
865
Richard Uhler76f5cb62016-04-04 13:30:16 -0700866if [ "$STRIP_DEX" = "y" ]; then
867 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
868fi
869
Igor Murashkin271a0f82017-02-14 21:14:17 +0000870if [ "$SYNC_BEFORE_RUN" = "y" ]; then
871 sync_cmdline="sync"
872fi
873
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700874DALVIKVM_ISA_FEATURES_ARGS=""
875if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
876 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100877fi
878
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000879# java.io.tmpdir can only be set at launch time.
880TMP_DIR_OPTION=""
881if [ "$HOST" = "n" ]; then
882 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
883fi
884
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000885# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
886# b/27185632
887# b/24664297
Alex Light20802ca2018-12-05 15:36:03 -0800888dalvikvm_cmdline="$INVOKE_WITH $GDB $BIN_DIR/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100889 $GDB_ARGS \
890 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700891 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100892 -XXlib:$LIB \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100893 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700894 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100895 $ZYGOTE \
896 $JNI_OPTS \
897 $INT_OPTS \
898 $DEBUGGER_OPTS \
899 $DALVIKVM_BOOT_OPT \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000900 $TMP_DIR_OPTION \
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000901 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700902 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100903
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -0800904# Remove whitespace.
905dex2oat_cmdline=$(echo $dex2oat_cmdline)
906dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000907dm_cmdline=$(echo $dm_cmdline)
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000908vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -0800909profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100910
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700911# Use an empty ASAN_OPTIONS to enable defaults.
912# Note: this is required as envsetup right now exports detect_leaks=0.
913RUN_TEST_ASAN_OPTIONS=""
914
Andreas Gampe58408392017-05-16 10:45:46 -0700915# Multiple shutdown leaks. b/38341789
916if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
917 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
918fi
919RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
920
Vladimir Markoa497a392018-09-26 10:52:50 +0100921# For running, we must turn off logging when dex2oat is missing. Otherwise we use
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +0000922# the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
923if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
924 if [ "$DEV_MODE" = "y" ]; then
925 export ANDROID_LOG_TAGS='*:d'
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +0000926 elif [ "$HAVE_IMAGE" = "n" ]; then
927 # All tests would log the error of missing image. Be silent here and only log fatal
928 # events.
929 export ANDROID_LOG_TAGS='*:s'
930 else
931 # We are interested in LOG(ERROR) output.
932 export ANDROID_LOG_TAGS='*:e'
933 fi
934fi
935
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100936if [ "$HOST" = "n" ]; then
937 adb root > /dev/null
938 adb wait-for-device
939 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000940 adb shell rm -rf $CHROOT_DEX_LOCATION
941 adb shell mkdir -p $CHROOT_DEX_LOCATION
942 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION
943 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -0700944 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000945 adb push profile $CHROOT_DEX_LOCATION
Calin Juravle13439f02017-02-21 01:17:21 -0800946 fi
David Brazdil7d2ec612018-01-19 14:19:59 +0000947 # Copy resource folder
948 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000949 adb push res $CHROOT_DEX_LOCATION
David Brazdil7d2ec612018-01-19 14:19:59 +0000950 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100951 else
Roland Levillain76cfe612017-10-30 13:14:28 +0000952 adb shell rm -rf $CHROOT_DEX_LOCATION >/dev/null 2>&1
953 adb shell mkdir -p $CHROOT_DEX_LOCATION >/dev/null 2>&1
954 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
955 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -0700956 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000957 adb push profile $CHROOT_DEX_LOCATION >/dev/null 2>&1
Calin Juravle13439f02017-02-21 01:17:21 -0800958 fi
David Brazdil7d2ec612018-01-19 14:19:59 +0000959 # Copy resource folder
960 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +0000961 adb push res $CHROOT_DEX_LOCATION >/dev/null 2>&1
David Brazdil7d2ec612018-01-19 14:19:59 +0000962 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100963 fi
964
Colin Crossafd3c9e2016-09-16 13:47:21 -0700965 LD_LIBRARY_PATH=/data/$TEST_DIRECTORY/art/$ISA
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000966 if [ "$ANDROID_ROOT" != "/system" ]; then
967 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
968 # so we can only use LD_LIBRARY_PATH when testing on a local
969 # installation.
Roland Levillain76cfe612017-10-30 13:14:28 +0000970 LD_LIBRARY_PATH="$ANDROID_ROOT/$LIBRARY_DIRECTORY:$LD_LIBRARY_PATH"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +0000971 fi
972
Dimitry Ivanov49c2c922017-02-14 11:06:14 -0800973 # System libraries needed by libarttestd.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +0000974 PUBLIC_LIBS=libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
975 if [ "$TEST_IS_NDEBUG" = "y" ]; then
David Sehr1f010162018-05-15 08:59:32 -0700976 PUBLIC_LIBS=$PUBLIC_LIBS:libart.so:libdexfile.so:libprofile.so:libartbase.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +0000977 else
David Sehr1f010162018-05-15 08:59:32 -0700978 PUBLIC_LIBS=$PUBLIC_LIBS:libartd.so:libdexfiled.so:libprofiled.so:libartbased.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +0000979 fi
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700980
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100981 # Create a script with the command. The command can get longer than the longest
982 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700983 # command. Dalvik cache is cleaned before running to make subsequent executions
984 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100985 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -0700986 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100987 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -0700988 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100989 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000990 export ANDROID_ROOT=$ANDROID_ROOT && \
Neil Fuller26c43772018-11-23 17:56:43 +0000991 export ANDROID_RUNTIME_ROOT=$ANDROID_RUNTIME_ROOT && \
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +0000992 export ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700993 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -0700994 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +0100995 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Alex Light20802ca2018-12-05 15:36:03 -0800996 export PATH=$BIN_DIR:$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -0800997 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100998 $dex2oat_cmdline && \
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000999 $dm_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001000 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -07001001 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +00001002 $sync_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001003 $dalvikvm_cmdline"
1004
1005 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
1006 echo "$cmdline" > $cmdfile
1007
1008 if [ "$DEV_MODE" = "y" ]; then
1009 echo $cmdline
1010 fi
1011
1012 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001013 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001014 else
Roland Levillain76cfe612017-10-30 13:14:28 +00001015 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh >/dev/null 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001016 fi
1017
Alex Light722d6712018-02-12 17:41:12 +00001018 exit_status=0
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001019 if [ "$DRY_RUN" != "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001020 if [ -n "$CHROOT" ]; then
1021 adb shell chroot "$CHROOT" sh $DEX_LOCATION/cmdline.sh
1022 else
1023 adb shell sh $DEX_LOCATION/cmdline.sh
1024 fi
Alex Light722d6712018-02-12 17:41:12 +00001025 exit_status=$?
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001026 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001027
1028 rm -f $cmdfile
Alex Light722d6712018-02-12 17:41:12 +00001029 exit $exit_status
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001030else
Calin Juravle24bd3f92017-05-11 00:36:53 -07001031 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001032 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -07001033
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001034 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +00001035 export ANDROID_ROOT="${ANDROID_ROOT}"
Neil Fuller26c43772018-11-23 17:56:43 +00001036 export ANDROID_RUNTIME_ROOT="${ANDROID_RUNTIME_ROOT}"
Alex Light20802ca2018-12-05 15:36:03 -08001037 if [ "$USE_ZIPAPEX" = "y" ]; then
1038 # Put the zipapex files in front of the ld-library-path
Alex Lightf7f31522019-02-01 11:14:41 -08001039 export LD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1040 export DYLD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1041 else
1042 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1043 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Alex Light20802ca2018-12-05 15:36:03 -08001044 fi
Alex Light20802ca2018-12-05 15:36:03 -08001045 export PATH="$PATH:$BIN_DIR"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001046
David Srbeckyc9ede382015-06-20 06:03:53 +01001047 # Temporarily disable address space layout randomization (ASLR).
1048 # This is needed on the host so that the linker loads core.oat at the necessary address.
1049 export LD_USE_LOAD_BIAS=1
1050
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001051 cmdline="$dalvikvm_cmdline"
1052
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001053 if [ "$TIME_OUT" = "gdb" ]; then
1054 if [ `uname` = "Darwin" ]; then
1055 # Fall back to timeout on Mac.
1056 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -07001057 elif [ "$ISA" = "x86" ]; then
1058 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
1059 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001060 else
1061 # Check if gdb is available.
1062 gdb --eval-command="quit" > /dev/null 2>&1
1063 if [ $? != 0 ]; then
1064 # gdb isn't available. Fall back to timeout.
1065 TIME_OUT="timeout"
1066 fi
1067 fi
1068 fi
1069
1070 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001071 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -08001072 #
Andreas Gampe6fb92562016-08-01 21:53:57 -07001073 # Note: We first send SIGRTMIN+2 (usually 36) to ART, which will induce a full thread dump
1074 # before abort. However, dumping threads might deadlock, so we also use the "-k"
1075 # option to definitely kill the child.
Andreas Gampe4bdcf5d2018-12-14 10:48:53 -08001076 # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
Alex Light4520b062018-12-19 09:59:39 -08001077 cmdline="timeout --foreground -k 120s -s SIGRTMIN+2 ${TIME_OUT_VALUE}s ${TIMEOUT_DUMPER} $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001078 fi
1079
1080 if [ "$DEV_MODE" = "y" ]; then
Orion Hodsonee06c5a2018-04-23 13:46:24 +01001081 for var in ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS; do
1082 echo EXPORT $var=${!var}
1083 done
Alex Light680cbf22018-10-31 11:00:19 -07001084 echo "$(declare -f linkdirs)"
Alex Light20802ca2018-12-05 15:36:03 -08001085 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 +01001086 fi
1087
1088 cd $ANDROID_BUILD_TOP
1089
Calin Juravle24bd3f92017-05-11 00:36:53 -07001090 # Make sure we delete any existing compiler artifacts.
1091 # This enables tests to call the RUN script multiple times in a row
1092 # without worrying about interference.
1093 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +00001094 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -07001095
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001096 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
1097
Alex Lightafb5d192016-05-24 15:57:45 -07001098 mkdir -p ${mkdir_locations} || exit 1
Alex Light20802ca2018-12-05 15:36:03 -08001099 $setupapex_cmdline || { echo "zipapex extraction failed." >&2 ; exit 2; }
Alex Light7b1f8cc2019-01-31 11:04:51 -08001100 $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 -07001101 $linkroot_cmdline || { echo "create symlink android-root failed." >&2 ; exit 2; }
1102 $linkroot_overlay_cmdline || { echo "overlay android-root failed." >&2 ; exit 2; }
Calin Juravle13439f02017-02-21 01:17:21 -08001103 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampea8780822015-03-13 19:51:09 -07001104 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001105 $dm_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001106 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -07001107 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +00001108 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -07001109
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001110 if [ "$DRY_RUN" = "y" ]; then
1111 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -07001112 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001113
1114 if [ "$USE_GDB" = "y" ]; then
1115 # When running under gdb, we cannot do piping and grepping...
Alex Lighte4b4a182019-02-12 14:19:49 -08001116 $cmdline "$@"
1117 elif [ "$USE_GDBSERVER" = "y" ]; then
1118 echo "Connect to $GDBSERVER_PORT"
1119 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -07001120 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001121 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001122 if [ "$TIME_OUT" != "gdb" ]; then
1123 trap 'kill -INT -$pid' INT
1124 $cmdline "$@" 2>&1 & pid=$!
1125 wait $pid
Alex Light722d6712018-02-12 17:41:12 +00001126 exit_value=$?
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001127 # Add extra detail if time out is enabled.
Alex Light722d6712018-02-12 17:41:12 +00001128 if [ $exit_value = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001129 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1130 fi
Alex Light722d6712018-02-12 17:41:12 +00001131 exit $exit_value
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001132 else
1133 # With a thread dump that uses gdb if a timeout.
1134 trap 'kill -INT -$pid' INT
1135 $cmdline "$@" 2>&1 & pid=$!
1136 # Spawn a watcher process.
1137 ( sleep $TIME_OUT_VALUE && \
1138 echo "##### Thread dump using gdb on test timeout" && \
1139 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
1140 --eval-command="call exit(124)" --eval-command=quit || \
1141 kill $pid )) 2> /dev/null & watcher=$!
1142 wait $pid
1143 test_exit_status=$?
1144 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
1145 if [ $test_exit_status = 0 ]; then
1146 # The test finished normally.
1147 exit 0
1148 else
1149 # The test failed or timed out.
1150 if [ $test_exit_status = 124 ]; then
1151 # The test timed out.
1152 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1153 fi
Alex Light722d6712018-02-12 17:41:12 +00001154 exit $test_exit_status
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001155 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001156 fi
1157 fi
1158fi