blob: 1babc150f8443327ca1d2ed8d5518f846cbbf2b3 [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"
Martin Stjernholme58624f2019-09-20 15:53:40 +010017ANDROID_ART_ROOT="/apex/com.android.art"
Victor Chang64611242019-07-05 16:32:41 +010018ANDROID_I18N_ROOT="/apex/com.android.i18n"
Neil Fuller26a5dd62019-03-13 15:16:35 +000019ANDROID_TZDATA_ROOT="/apex/com.android.tzdata"
Vladimir Markobe0d3cf2020-02-12 10:52:22 +000020ARCHITECTURES_32="(arm|x86|none)"
21ARCHITECTURES_64="(arm64|x86_64|none)"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010022ARCHITECTURES_PATTERN="${ARCHITECTURES_32}"
Roland Levillain72f67742019-03-06 15:48:08 +000023GET_DEVICE_ISA_BITNESS_FLAG="--32"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000024BOOT_IMAGE=""
Roland Levillain76cfe612017-10-30 13:14:28 +000025CHROOT=
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010026COMPILE_FLAGS=""
27DALVIKVM="dalvikvm32"
28DEBUGGER="n"
Alex Light54dabfb2018-09-19 16:29:09 -070029WITH_AGENT=()
Alex Lightc281ba52017-10-11 11:35:55 -070030DEBUGGER_AGENT=""
31WRAP_DEBUGGER_AGENT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010032DEV_MODE="n"
Roland Levillain15c622d2020-02-19 16:24:10 +000033DEX2OAT_NDEBUG_BINARY="dex2oat"
34DEX2OAT_DEBUG_BINARY="dex2oatd"
Alex Light8a0e0332015-10-26 10:11:58 -070035EXPERIMENTAL=""
Nicolas Geoffray90355fe2017-02-20 09:25:40 +000036FALSE_BIN="false"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010037FLAGS=""
Alex Light7233c7e2016-07-28 10:07:45 -070038ANDROID_FLAGS=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010039GDB=""
Nicolas Geoffraybaf91022014-10-08 09:56:45 +010040GDB_ARGS=""
Alex Lighte4b4a182019-02-12 14:19:49 -080041GDBSERVER_DEVICE="gdbserver"
42GDBSERVER_HOST="gdbserver"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010043HAVE_IMAGE="y"
44HOST="n"
Alex Light680cbf22018-10-31 11:00:19 -070045BIONIC="n"
46CREATE_ANDROID_ROOT="n"
Alex Light20802ca2018-12-05 15:36:03 -080047USE_ZIPAPEX="n"
48ZIPAPEX_LOC=""
Alex Light6f342dd2019-03-27 17:15:42 +000049USE_EXTRACTED_ZIPAPEX="n"
50EXTRACTED_ZIPAPEX_LOC=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010051INTERPRETER="n"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080052JIT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010053INVOKE_WITH=""
Alex Lighte06b6342017-01-05 14:37:21 -080054IS_JVMTI_TEST="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010055ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000056LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070057TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000058MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010059OPTIMIZE="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010060PREBUILD="y"
61QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000062RELOCATE="n"
Richard Uhler76f5cb62016-04-04 13:30:16 -070063STRIP_DEX="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070064SECONDARY_DEX=""
David Srbecky352482c2019-10-16 15:59:52 +010065TIME_OUT="n" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
Andreas Gampe148c1602019-06-10 16:47:46 -070066TIMEOUT_DUMPER=signal_dumper
Andreas Gampe6ad30a22019-09-12 15:12:36 -070067# Values in seconds.
Martin Stjernholmcb497cf2019-09-27 18:42:55 +010068TIME_OUT_EXTRA=0
Andreas Gampe6ad30a22019-09-12 15:12:36 -070069TIME_OUT_VALUE=
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010070USE_GDB="n"
Alex Lighte4b4a182019-02-12 14:19:49 -080071USE_GDBSERVER="n"
72GDBSERVER_PORT=":5039"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010073USE_JVM="n"
Alex Lightc281ba52017-10-11 11:35:55 -070074USE_JVMTI="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070075VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010076ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070077DEX_VERIFY=""
Andreas Gampe4d2ef332015-08-05 09:24:45 -070078INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070079ARGS=""
David Brazdilfeb22822019-02-13 21:25:57 +000080VDEX_ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070081EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
82DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000083TEST_VDEX="n"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +000084TEST_DM="n"
Alex Lighte06b6342017-01-05 14:37:21 -080085TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000086APP_IMAGE="y"
Alex Light8f2c6d42017-04-10 16:27:35 -070087JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070088JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070089JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070090JVMTI_TRACE_STRESS="n"
91JVMTI_REDEFINE_STRESS="n"
Calin Juravle13439f02017-02-21 01:17:21 -080092PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070093RANDOM_PROFILE="n"
Alex Light483208d2017-09-26 09:31:17 -070094# The normal dex2oat timeout.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070095DEX2OAT_TIMEOUT="300" # 5 mins
Alex Light483208d2017-09-26 09:31:17 -070096# The *hard* timeout where we really start trying to kill the dex2oat.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070097DEX2OAT_RT_TIMEOUT="360" # 6 mins
Alex Light8d94ddd2019-12-18 11:13:03 -080098CREATE_RUNNER="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010099
Igor Murashkin271a0f82017-02-14 21:14:17 +0000100# if "y", run 'sync' before dalvikvm to make sure all files from
101# build step (e.g. dex2oat) were finished writing.
102SYNC_BEFORE_RUN="n"
103
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700104# When running a debug build, we want to run with all checks.
105ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
Andreas Gampee8f74ca2018-01-02 09:26:16 -0800106# The same for dex2oatd, both prebuild and runtime-driven.
107ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
108COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700109
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100110while true; do
111 if [ "x$1" = "x--quiet" ]; then
112 QUIET="y"
113 shift
Alex Light483208d2017-09-26 09:31:17 -0700114 elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
115 shift
116 if [ "x$1" = "x" ]; then
117 echo "$0 missing argument to --dex2oat-rt-timeout" 1>&2
118 exit 1
119 fi
120 DEX2OAT_RT_TIMEOUT="$1"
121 shift
122 elif [ "x$1" = "x--dex2oat-timeout" ]; then
123 shift
124 if [ "x$1" = "x" ]; then
125 echo "$0 missing argument to --dex2oat-timeout" 1>&2
126 exit 1
127 fi
128 DEX2OAT_TIMEOUT="$1"
129 shift
Alex Lighte06b6342017-01-05 14:37:21 -0800130 elif [ "x$1" = "x--jvmti" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700131 USE_JVMTI="y"
Alex Lighte06b6342017-01-05 14:37:21 -0800132 IS_JVMTI_TEST="y"
133 shift
Alex Lightfaf90b62016-08-12 14:43:48 -0700134 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -0800135 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -0700136 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100137 elif [ "x$1" = "x--lib" ]; then
138 shift
139 if [ "x$1" = "x" ]; then
140 echo "$0 missing argument to --lib" 1>&2
141 exit 1
142 fi
143 LIB="$1"
144 shift
Alex Light97acf192016-03-17 09:59:38 -0700145 elif [ "x$1" = "x--gc-stress" ]; then
David Srbecky7021c132019-10-04 12:56:22 +0100146 # Give an extra 20 mins if we are gc-stress.
147 TIME_OUT_EXTRA=$((${TIME_OUT_EXTRA} + 1200))
Alex Light97acf192016-03-17 09:59:38 -0700148 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700149 elif [ "x$1" = "x--testlib" ]; then
150 shift
151 if [ "x$1" = "x" ]; then
152 echo "$0 missing argument to --testlib" 1>&2
153 exit 1
154 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700155 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700156 shift
David Srbecky52886112016-01-22 13:56:47 +0000157 elif [ "x$1" = "x--args" ]; then
158 shift
159 if [ "x$1" = "x" ]; then
160 echo "$0 missing argument to --args" 1>&2
161 exit 1
162 fi
163 ARGS="${ARGS} $1"
164 shift
Alex Lighte2ddce32019-05-22 17:08:35 +0000165 elif [ "x$1" = "x--compiler-only-option" ]; then
166 shift
167 option="$1"
168 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
169 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100170 elif [ "x$1" = "x-Xcompiler-option" ]; then
171 shift
172 option="$1"
173 FLAGS="${FLAGS} -Xcompiler-option $option"
174 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
175 shift
Alex Light8d94ddd2019-12-18 11:13:03 -0800176 elif [ "x$1" = "x--create-runner" ]; then
177 CREATE_RUNNER="y"
178 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700179 elif [ "x$1" = "x--android-runtime-option" ]; then
180 shift
181 option="$1"
182 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
183 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100184 elif [ "x$1" = "x--runtime-option" ]; then
185 shift
186 option="$1"
187 FLAGS="${FLAGS} $option"
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100188 if [ "x$option" = "x-Xmethod-trace" ]; then
Martin Stjernholm30677102019-10-01 12:54:10 +0100189 # Method tracing can slow some tests down a lot, in particular
190 # 530-checker-lse2.
191 TIME_OUT_EXTRA=$((${TIME_OUT_EXTRA} + 1200))
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100192 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100193 shift
194 elif [ "x$1" = "x--boot" ]; then
195 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000196 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100197 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100198 elif [ "x$1" = "x--relocate" ]; then
199 RELOCATE="y"
200 shift
201 elif [ "x$1" = "x--no-relocate" ]; then
202 RELOCATE="n"
203 shift
204 elif [ "x$1" = "x--prebuild" ]; then
205 PREBUILD="y"
206 shift
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800207 elif [ "x$1" = "x--compact-dex-level" ]; then
208 shift
209 COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
210 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700211 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
212 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Lightc281ba52017-10-11 11:35:55 -0700213 USE_JVMTI="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700214 APP_IMAGE="n"
215 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700216 JVMTI_REDEFINE_STRESS="y"
217 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700218 elif [ "x$1" = "x--jvmti-step-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700219 USE_JVMTI="y"
Alex Lightc38c3692017-06-27 15:45:14 -0700220 JVMTI_STRESS="y"
221 JVMTI_STEP_STRESS="y"
222 shift
Alex Light43e935d2017-06-19 15:40:40 -0700223 elif [ "x$1" = "x--jvmti-field-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700224 USE_JVMTI="y"
Alex Light43e935d2017-06-19 15:40:40 -0700225 JVMTI_STRESS="y"
226 JVMTI_FIELD_STRESS="y"
227 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700228 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700229 USE_JVMTI="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700230 JVMTI_STRESS="y"
231 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700232 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000233 elif [ "x$1" = "x--no-app-image" ]; then
234 APP_IMAGE="n"
235 shift
Richard Uhler76f5cb62016-04-04 13:30:16 -0700236 elif [ "x$1" = "x--strip-dex" ]; then
237 STRIP_DEX="y"
238 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100239 elif [ "x$1" = "x--host" ]; then
240 HOST="y"
Roland Levillainb59f5fb2020-02-19 16:22:48 +0000241 ANDROID_ROOT="${ANDROID_HOST_OUT}"
242 ANDROID_ART_ROOT="${ANDROID_HOST_OUT}/com.android.art"
243 ANDROID_I18N_ROOT="${ANDROID_HOST_OUT}/com.android.i18n"
244 ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100245 shift
Alex Light680cbf22018-10-31 11:00:19 -0700246 elif [ "x$1" = "x--bionic" ]; then
247 BIONIC="y"
248 # We need to create an ANDROID_ROOT because currently we cannot create
249 # the frameworks/libcore with linux_bionic so we need to use the normal
250 # host ones which are in a different location.
251 CREATE_ANDROID_ROOT="y"
252 shift
Alex Light6f342dd2019-03-27 17:15:42 +0000253 elif [ "x$1" = "x--runtime-extracted-zipapex" ]; then
254 shift
255 USE_EXTRACTED_ZIPAPEX="y"
256 EXTRACTED_ZIPAPEX_LOC="$1"
257 shift
Alex Light20802ca2018-12-05 15:36:03 -0800258 elif [ "x$1" = "x--runtime-zipapex" ]; then
259 shift
260 USE_ZIPAPEX="y"
261 ZIPAPEX_LOC="$1"
Alex Light907001d2019-01-17 00:16:04 +0000262 # TODO (b/119942078): Currently apex does not support
263 # symlink_preferred_arch so we will not have a dex2oatd to execute and
264 # need to manually provide
265 # dex2oatd64.
266 DEX2OAT_DEBUG_BINARY="dex2oatd64"
Alex Light20802ca2018-12-05 15:36:03 -0800267 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100268 elif [ "x$1" = "x--no-prebuild" ]; then
269 PREBUILD="n"
270 shift
271 elif [ "x$1" = "x--no-image" ]; then
272 HAVE_IMAGE="n"
273 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700274 elif [ "x$1" = "x--secondary" ]; then
275 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100276 # Enable cfg-append to make sure we get the dump for both dex files.
277 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000278 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100279 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
280 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700281 shift
Alex Light0e151e72017-10-25 10:50:35 -0700282 elif [ "x$1" = "x--with-agent" ]; then
283 shift
284 USE_JVMTI="y"
Alex Light54dabfb2018-09-19 16:29:09 -0700285 WITH_AGENT+=("$1")
Alex Light0e151e72017-10-25 10:50:35 -0700286 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700287 elif [ "x$1" = "x--debug-wrap-agent" ]; then
288 WRAP_DEBUGGER_AGENT="y"
289 shift
290 elif [ "x$1" = "x--debug-agent" ]; then
291 shift
292 DEBUGGER="agent"
293 USE_JVMTI="y"
294 DEBUGGER_AGENT="$1"
295 TIME_OUT="n"
296 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100297 elif [ "x$1" = "x--debug" ]; then
Alex Lightfc588092020-01-23 15:39:08 -0800298 USE_JVMTI="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100299 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800300 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100301 shift
Alex Lighte4b4a182019-02-12 14:19:49 -0800302 elif [ "x$1" = "x--gdbserver-port" ]; then
303 shift
304 GDBSERVER_PORT=$1
305 shift
306 elif [ "x$1" = "x--gdbserver-bin" ]; then
307 shift
308 GDBSERVER_HOST=$1
309 GDBSERVER_DEVICE=$1
310 shift
311 elif [ "x$1" = "x--gdbserver" ]; then
312 USE_GDBSERVER="y"
313 DEV_MODE="y"
314 TIME_OUT="n"
Alex Lighte4b4a182019-02-12 14:19:49 -0800315 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100316 elif [ "x$1" = "x--gdb" ]; then
317 USE_GDB="y"
318 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800319 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100320 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700321 elif [ "x$1" = "x--gdb-arg" ]; then
322 shift
323 gdb_arg="$1"
324 GDB_ARGS="${GDB_ARGS} $gdb_arg"
325 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100326 elif [ "x$1" = "x--zygote" ]; then
327 ZYGOTE="-Xzygote"
328 msg "Spawning from zygote"
329 shift
330 elif [ "x$1" = "x--dev" ]; then
331 DEV_MODE="y"
332 shift
333 elif [ "x$1" = "x--interpreter" ]; then
334 INTERPRETER="y"
335 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800336 elif [ "x$1" = "x--jit" ]; then
337 JIT="y"
338 shift
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100339 elif [ "x$1" = "x--baseline" ]; then
340 FLAGS="${FLAGS} -Xcompiler-option --baseline"
Nicolas Geoffray9b195cc2019-04-02 08:29:00 +0100341 COMPILE_FLAGS="${COMPILE_FLAGS} --baseline"
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100342 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100343 elif [ "x$1" = "x--jvm" ]; then
344 USE_JVM="y"
345 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100346 elif [ "x$1" = "x--invoke-with" ]; then
347 shift
348 if [ "x$1" = "x" ]; then
349 echo "$0 missing argument to --invoke-with" 1>&2
350 exit 1
351 fi
352 if [ "x$INVOKE_WITH" = "x" ]; then
353 INVOKE_WITH="$1"
354 else
355 INVOKE_WITH="$INVOKE_WITH $1"
356 fi
357 shift
358 elif [ "x$1" = "x--no-verify" ]; then
359 VERIFY="n"
360 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700361 elif [ "x$1" = "x--verify-soft-fail" ]; then
362 VERIFY="s"
363 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100364 elif [ "x$1" = "x--no-optimize" ]; then
365 OPTIMIZE="n"
366 shift
Roland Levillain76cfe612017-10-30 13:14:28 +0000367 elif [ "x$1" = "x--chroot" ]; then
368 shift
369 CHROOT="$1"
370 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000371 elif [ "x$1" = "x--android-root" ]; then
372 shift
373 ANDROID_ROOT="$1"
374 shift
Victor Chang64611242019-07-05 16:32:41 +0100375 elif [ "x$1" = "x--android-i18n-root" ]; then
376 shift
377 ANDROID_I18N_ROOT="$1"
378 shift
Martin Stjernholme58624f2019-09-20 15:53:40 +0100379 elif [ "x$1" = "x--android-art-root" ]; then
Roland Levillain28076142019-01-10 16:39:25 +0000380 shift
Martin Stjernholme58624f2019-09-20 15:53:40 +0100381 ANDROID_ART_ROOT="$1"
Roland Levillain28076142019-01-10 16:39:25 +0000382 shift
Neil Fuller26a5dd62019-03-13 15:16:35 +0000383 elif [ "x$1" = "x--android-tzdata-root" ]; then
384 shift
385 ANDROID_TZDATA_ROOT="$1"
386 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700387 elif [ "x$1" = "x--instruction-set-features" ]; then
388 shift
389 INSTRUCTION_SET_FEATURES="$1"
390 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700391 elif [ "x$1" = "x--timeout" ]; then
392 shift
393 TIME_OUT_VALUE="$1"
394 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100395 elif [ "x$1" = "x--" ]; then
396 shift
397 break
398 elif [ "x$1" = "x--64" ]; then
399 ISA="x86_64"
Alex Lighte4b4a182019-02-12 14:19:49 -0800400 GDBSERVER_DEVICE="gdbserver64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100401 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000402 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700403 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100404 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
Roland Levillain72f67742019-03-06 15:48:08 +0000405 GET_DEVICE_ISA_BITNESS_FLAG="--64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100406 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700407 elif [ "x$1" = "x--experimental" ]; then
408 if [ "$#" -lt 2 ]; then
409 echo "missing --experimental option" 1>&2
410 exit 1
411 fi
412 EXPERIMENTAL="$EXPERIMENTAL $2"
413 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700414 elif [ "x$1" = "x--external-log-tags" ]; then
415 EXTERNAL_LOG_TAGS="y"
416 shift
417 elif [ "x$1" = "x--dry-run" ]; then
418 DRY_RUN="y"
419 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000420 elif [ "x$1" = "x--vdex" ]; then
421 TEST_VDEX="y"
422 shift
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000423 elif [ "x$1" = "x--dm" ]; then
424 TEST_DM="y"
425 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000426 elif [ "x$1" = "x--vdex-filter" ]; then
427 shift
428 option="$1"
David Brazdilfeb22822019-02-13 21:25:57 +0000429 VDEX_ARGS="${VDEX_ARGS} --compiler-filter=$option"
430 shift
431 elif [ "x$1" = "x--vdex-arg" ]; then
432 shift
433 VDEX_ARGS="${VDEX_ARGS} $1"
Nicolas Geoffray74981052017-01-16 17:54:09 +0000434 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000435 elif [ "x$1" = "x--sync" ]; then
436 SYNC_BEFORE_RUN="y"
437 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800438 elif [ "x$1" = "x--profile" ]; then
439 PROFILE="y"
440 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700441 elif [ "x$1" = "x--random-profile" ]; then
442 RANDOM_PROFILE="y"
443 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100444 elif expr "x$1" : "x--" >/dev/null 2>&1; then
445 echo "unknown $0 option: $1" 1>&2
446 exit 1
447 else
448 break
449 fi
450done
451
Roland Levillainb59f5fb2020-02-19 16:22:48 +0000452# HACK: Force the use of `signal_dumper` on host.
Roland Levillain505e56b2019-11-20 08:49:24 +0000453if [[ "$HOST" = "y" ]]; then
454 TIME_OUT="timeout"
455fi
456
Andreas Gampe6ad30a22019-09-12 15:12:36 -0700457# If you change this, update the timeout in testrunner.py as well.
458if [ -z "$TIME_OUT_VALUE" ] ; then
459 # 10 minutes is the default.
460 TIME_OUT_VALUE=600
461
462 # For sanitized builds use a larger base.
463 # TODO: Consider sanitized target builds?
464 if [ "x$SANITIZE_HOST" != "x" ] ; then
465 TIME_OUT_VALUE=1500 # 25 minutes.
466 fi
467
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100468 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + ${TIME_OUT_EXTRA}))
Andreas Gampe6ad30a22019-09-12 15:12:36 -0700469fi
470
Andreas Gampe29bfb0c2019-09-12 15:17:43 -0700471# Escape hatch for slow hosts or devices. Accept an environment variable as a timeout factor.
472if [ ! -z "$ART_TIME_OUT_MULTIPLIER" ] ; then
Martin Stjernholm82e61e92019-09-30 02:43:18 +0000473 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} * ${ART_TIME_OUT_MULTIPLIER}))
Andreas Gampe29bfb0c2019-09-12 15:17:43 -0700474fi
475
Roland Levillain76cfe612017-10-30 13:14:28 +0000476# The DEX_LOCATION with the chroot prefix, if any.
477CHROOT_DEX_LOCATION="$CHROOT$DEX_LOCATION"
478
Roland Levillain72f67742019-03-06 15:48:08 +0000479# If running on device, determine the ISA of the device.
480if [ "$HOST" = "n" ]; then
481 ISA=$("$ANDROID_BUILD_TOP/art/test/utils/get-device-isa" "$GET_DEVICE_ISA_BITNESS_FLAG")
482fi
483
Alex Light8a0e0332015-10-26 10:11:58 -0700484if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700485 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Lightbaac7e42018-06-08 15:30:11 +0000486 # we don't want to be trying to get adbconnections since the plugin might
487 # not have been built.
488 FLAGS="${FLAGS} -XjdwpProvider:none"
Alex Light8a0e0332015-10-26 10:11:58 -0700489 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700490 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700491 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
492 done
493fi
494
Alex Light680cbf22018-10-31 11:00:19 -0700495if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
496 ANDROID_ROOT=$DEX_LOCATION/android-root
497fi
498
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100499if [ "x$1" = "x" ] ; then
500 MAIN="Main"
501else
502 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700503 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100504fi
505
506if [ "$ZYGOTE" = "" ]; then
507 if [ "$OPTIMIZE" = "y" ]; then
508 if [ "$VERIFY" = "y" ]; then
509 DEX_OPTIMIZE="-Xdexopt:verified"
510 else
511 DEX_OPTIMIZE="-Xdexopt:all"
512 fi
513 msg "Performing optimizations"
514 else
515 DEX_OPTIMIZE="-Xdexopt:none"
516 msg "Skipping optimizations"
517 fi
518
519 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100520 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100521 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700522 elif [ "$VERIFY" = "s" ]; then
523 JVM_VERIFY_ARG="Xverify:all"
524 DEX_VERIFY="-Xverify:softfail"
525 msg "Forcing verification to be soft fail"
526 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100527 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100528 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100529 msg "Skipping verification"
530 fi
531fi
532
533msg "------------------------------"
534
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100535if [ "$DEBUGGER" = "y" ]; then
536 # Use this instead for ddms and connect by running 'ddms':
Alex Lightfc588092020-01-23 15:39:08 -0800537 # DEBUGGER_OPTS="-XjdwpOptions=server=y,suspend=y -XjdwpProvider:adbconnection"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100538 # TODO: add a separate --ddms option?
539
540 PORT=12345
541 msg "Waiting for jdb to connect:"
542 if [ "$HOST" = "n" ]; then
543 msg " adb forward tcp:$PORT tcp:$PORT"
544 fi
545 msg " jdb -attach localhost:$PORT"
Alex Light264a4862018-01-31 16:47:58 +0000546 if [ "$USE_JVM" = "n" ]; then
Alex Lightfc588092020-01-23 15:39:08 -0800547 # Use the default libjdwp agent. Use --debug-agent to use a custom one.
548 DEBUGGER_OPTS="-agentpath:libjdwp.so=transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
Alex Light264a4862018-01-31 16:47:58 +0000549 else
550 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
551 fi
Alex Lightc281ba52017-10-11 11:35:55 -0700552elif [ "$DEBUGGER" = "agent" ]; then
553 PORT=12345
554 # TODO Support ddms connection and support target.
555 if [ "$HOST" = "n" ]; then
556 echo "--debug-agent not supported yet for target!"
557 exit 1
558 fi
559 AGENTPATH=${DEBUGGER_AGENT}
560 if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
561 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
562 if [ "$TEST_IS_NDEBUG" = "y" ]; then
563 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
564 fi
565 AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
566 fi
567 msg "Connect to localhost:$PORT"
568 DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
569fi
570
Alex Light54dabfb2018-09-19 16:29:09 -0700571for agent in "${WITH_AGENT[@]}"; do
572 FLAGS="${FLAGS} -agentpath:${agent}"
573done
Alex Light0e151e72017-10-25 10:50:35 -0700574
Alex Lightc281ba52017-10-11 11:35:55 -0700575if [ "$USE_JVMTI" = "y" ]; then
576 if [ "$USE_JVM" = "n" ]; then
577 plugin=libopenjdkjvmtid.so
578 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
579 plugin=libopenjdkjvmti.so
580 fi
Alex Light2ce6fc82017-12-18 16:42:36 -0800581 # We used to add flags here that made the runtime debuggable but that is not
582 # needed anymore since the plugin can do it for us now.
Alex Lightc281ba52017-10-11 11:35:55 -0700583 FLAGS="${FLAGS} -Xplugin:${plugin}"
Alex Lightc281ba52017-10-11 11:35:55 -0700584 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100585fi
586
Alex Lightfba89fe2017-01-12 16:11:02 -0800587if [ "$IS_JVMTI_TEST" = "y" ]; then
Alex Lightfba89fe2017-01-12 16:11:02 -0800588 agent=libtiagentd.so
589 lib=tiagentd
590 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
591 agent=libtiagent.so
Alex Lightfba89fe2017-01-12 16:11:02 -0800592 lib=tiagent
593 fi
594
595 ARGS="${ARGS} ${lib}"
596 if [[ "$USE_JVM" = "y" ]]; then
597 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
598 else
Roland Levillain72f67742019-03-06 15:48:08 +0000599 if [[ "$HOST" = "y" ]]; then
600 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
601 else
Martin Stjernholme58624f2019-09-20 15:53:40 +0100602 # The linker configuration used for dalvikvm(64) in the ART APEX
Roland Levillain72f67742019-03-06 15:48:08 +0000603 # requires us to pass the full path to the agent to the runtime when
604 # running on device.
605 FLAGS="${FLAGS} -agentpath:/data/${TEST_DIRECTORY}/art/${ISA}/${agent}=${TEST_NAME},art"
606 fi
Alex Lightfba89fe2017-01-12 16:11:02 -0800607 fi
608fi
609
Alex Light8f2c6d42017-04-10 16:27:35 -0700610if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700611 agent=libtistressd.so
612 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
613 agent=libtistress.so
Alex Light42151c02017-04-20 15:54:25 -0700614 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700615
Alex Lightb7edcda2017-04-27 13:20:31 -0700616 # Just give it a default start so we can always add ',' to it.
617 agent_args="jvmti-stress"
618 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
619 # We really cannot do this on RI so don't both passing it in that case.
620 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700621 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700622 fi
623 fi
Alex Light43e935d2017-06-19 15:40:40 -0700624 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
625 agent_args="${agent_args},field"
626 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700627 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
628 agent_args="${agent_args},step"
629 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700630 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
631 agent_args="${agent_args},trace"
632 fi
633 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700634 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700635 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700636 else
Roland Levillain72f67742019-03-06 15:48:08 +0000637 if [[ "$HOST" = "y" ]]; then
638 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
639 else
Martin Stjernholme58624f2019-09-20 15:53:40 +0100640 # The linker configuration used for dalvikvm(64) in the ART APEX
Roland Levillain72f67742019-03-06 15:48:08 +0000641 # requires us to pass the full path to the agent to the runtime when
642 # running on device.
643 FLAGS="${FLAGS} -agentpath:/data/${TEST_DIRECTORY}/art/${ISA}/${agent}=${agent_args}"
644 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700645 fi
646fi
647
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100648if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700649 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700650 # Some jvmti tests are flaky without -Xint on the RI.
651 if [ "$IS_JVMTI_TEST" = "y" ]; then
652 FLAGS="${FLAGS} -Xint"
653 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700654 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000655 # We pass the classes2 path whether it's used (src-multidex) or not.
656 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700657 if [ "$DEV_MODE" = "y" ]; then
658 echo $cmdline
659 fi
Alex Light8d94ddd2019-12-18 11:13:03 -0800660 if [ "$CREATE_RUNNER" = "y" ]; then
661 echo "#!/bin/bash" > runit.sh
662 echo "export LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH\""
663 echo $cmdline "2>&1" >> runit.sh
664 chmod u+x runit.sh
665 echo "Runnable test script written to $PWD/runit.sh"
666 else
667 $cmdline
668 fi
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100669 exit
670fi
671
Vladimir Marko0ace5632018-12-14 11:11:47 +0000672# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
673# because that's what we use for compiling the core.art image.
674# It may contain additional modules from TEST_CORE_JARS.
Victor Chang759845f2019-08-06 16:04:36 +0100675bpath_modules="core-oj core-libart core-icu4j okhttp bouncycastle apache-xml conscrypt"
Vladimir Marko7a85e702018-12-03 18:47:23 +0000676if [ "${HOST}" = "y" ]; then
677 framework="${ANDROID_HOST_OUT}/framework"
678 if [ "${ANDROID_HOST_OUT:0:${#ANDROID_BUILD_TOP}+1}" = "${ANDROID_BUILD_TOP}/" ]; then
679 framework_location="${ANDROID_HOST_OUT:${#ANDROID_BUILD_TOP}+1}/framework"
680 else
681 echo "error: ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"
682 echo "ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP}"
683 echo "ANDROID_HOST_OUT=${ANDROID_HOST_OUT}"
684 exit
685 fi
686 bpath_suffix="-hostdex"
687else
688 framework="${ANDROID_ROOT}/framework"
689 framework_location="${ANDROID_ROOT}/framework"
690 bpath_suffix="-testdex"
691fi
692bpath=""
693bpath_locations=""
694bpath_separator=""
695for bpath_module in ${bpath_modules}; do
696 bpath+="${bpath_separator}${framework}/${bpath_module}${bpath_suffix}.jar"
697 bpath_locations+="${bpath_separator}${framework_location}/${bpath_module}${bpath_suffix}.jar"
698 bpath_separator=":"
699done
700# Pass down the bootclasspath
701FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
702FLAGS="${FLAGS} -Xbootclasspath-locations:${bpath_locations}"
703COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath:${bpath}"
704COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath-locations:${bpath_locations}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100705
706if [ "$HAVE_IMAGE" = "n" ]; then
Andreas Gampe1078d152017-11-07 18:00:54 -0800707 # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
708 FLAGS="${FLAGS} -Xnoimage-dex2oat"
709
710 # We'll abuse a second flag here to test different behavior. If --relocate, use the
711 # existing image - relocation will fail as patching is disallowed. If --no-relocate,
712 # pass a non-existent image - compilation will fail as dex2oat is disallowed.
713 if [ "${RELOCATE}" = "y" ] ; then
714 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
715 else
Roland Levillainef012222017-06-21 16:28:06 +0100716 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existent/core.art"
Andreas Gampe1078d152017-11-07 18:00:54 -0800717 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000718else
719 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100720fi
721
722
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100723if [ "$USE_GDB" = "y" ]; then
Alex Lighte4b4a182019-02-12 14:19:49 -0800724 if [ "$USE_GDBSERVER" = "y" ]; then
725 echo "Cannot pass both --gdb and --gdbserver at the same time!" >&2
726 exit 1
727 elif [ "$HOST" = "n" ]; then
Alex Light219420e2019-12-05 10:20:26 -0800728 # We might not have any hostname resolution if we are using a chroot.
729 GDB="$GDBSERVER_DEVICE --no-startup-with-shell 127.0.0.1$GDBSERVER_PORT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100730 else
731 if [ `uname` = "Darwin" ]; then
732 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700733 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100734 DALVIKVM=
735 else
736 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700737 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100738 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
739 # gdbargs="--annotate=3 $gdbargs"
740 fi
741 fi
Alex Lighte4b4a182019-02-12 14:19:49 -0800742elif [ "$USE_GDBSERVER" = "y" ]; then
743 if [ "$HOST" = "n" ]; then
Alex Light219420e2019-12-05 10:20:26 -0800744 # We might not have any hostname resolution if we are using a chroot.
745 GDB="$GDBSERVER_DEVICE --no-startup-with-shell 127.0.0.1$GDBSERVER_PORT"
746 else
747 GDB="$GDBSERVER_HOST $GDBSERVER_PORT"
Alex Lighte4b4a182019-02-12 14:19:49 -0800748 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100749fi
750
751if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100752 INT_OPTS="${INT_OPTS} -Xint"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700753 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100754 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
755 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700756 elif [ "$VERIFY" = "s" ]; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100757 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
758 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700759 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
760 else # VERIFY = "n"
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100761 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
762 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700763 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
764 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100765fi
766
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800767if [ "$JIT" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100768 INT_OPTS="${INT_OPTS} -Xusejit:true"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800769 if [ "$VERIFY" = "y" ] ; then
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100770 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=quicken"
771 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=quicken"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800772 else
Nicolas Geoffray49cda062017-04-21 13:08:25 +0100773 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
774 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800775 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
776 fi
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100777else
778 INT_OPTS="${INT_OPTS} -Xusejit:false"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800779fi
780
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100781JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
782
Richard Uhler020c0f32017-03-14 16:23:17 +0000783COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100784if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000785 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100786else
787 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100788fi
789
Alex Light680cbf22018-10-31 11:00:19 -0700790if [ "$BIONIC" = "y" ]; then
791 # This is the location that soong drops linux_bionic builds. Despite being
792 # called linux_bionic-x86 the build is actually amd64 (x86_64) only.
793 if [ ! -e "$OUT_DIR/soong/host/linux_bionic-x86" ]; then
794 echo "linux_bionic-x86 target doesn't seem to have been built!" >&2
795 exit 1
796 fi
Andreas Gampe148c1602019-06-10 16:47:46 -0700797 # Set TIMEOUT_DUMPER manually so it works even with apex's
798 TIMEOUT_DUMPER=$OUT_DIR/soong/host/linux_bionic-x86/bin/signal_dumper
Alex Light680cbf22018-10-31 11:00:19 -0700799fi
800
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700801# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
802# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
803# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
804# remaining '/' into '@'.
805if [ "$HOST" = "y" ]; then
806 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
807else
Roland Levillain2ae376f2018-01-30 11:35:11 +0000808 # There is no getconf on device, fallback to standard value.
809 # See NAME_MAX in kernel <linux/limits.h>
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700810 max_filename_size=255
811fi
812# Compute VDEX_NAME.
813DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
814VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
815if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000816 echo "Dex location path too long:"
817 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700818 exit 1
819fi
820
Roland Levillain72f67742019-03-06 15:48:08 +0000821if [ "$HOST" = "y" ]; then
822 # On host, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the `bin`
823 # directory under the "Android Root" (usually `out/host/linux-x86`).
824 #
825 # TODO(b/130295968): Adjust this if/when ART host artifacts are installed
Martin Stjernholme58624f2019-09-20 15:53:40 +0100826 # under the ART root (usually `out/host/linux-x86/com.android.art`).
827 ANDROID_ART_BIN_DIR=$ANDROID_ROOT/bin
Roland Levillain72f67742019-03-06 15:48:08 +0000828else
Martin Stjernholme58624f2019-09-20 15:53:40 +0100829 # On target, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the ART
830 # APEX's `bin` directory. This means the linker will observe the ART APEX
831 # linker configuration file (`/apex/com.android.art/etc/ld.config.txt`) for
832 # these binaries.
833 ANDROID_ART_BIN_DIR=$ANDROID_ART_ROOT/bin
Roland Levillain72f67742019-03-06 15:48:08 +0000834fi
Alex Light20802ca2018-12-05 15:36:03 -0800835
Calin Juravle13439f02017-02-21 01:17:21 -0800836profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100837dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000838vdex_cmdline="true"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000839dm_cmdline="true"
Andreas Gampeb09abb22018-05-03 11:51:22 -0700840mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700841strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000842sync_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700843linkroot_cmdline="true"
844linkroot_overlay_cmdline="true"
Alex Light20802ca2018-12-05 15:36:03 -0800845setupapex_cmdline="true"
846installapex_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700847
848linkdirs() {
849 find "$1" -maxdepth 1 -mindepth 1 -type d | xargs -i ln -sf '{}' "$2"
850}
851
852if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
853 mkdir_locations="${mkdir_locations} ${ANDROID_ROOT}"
854 linkroot_cmdline="linkdirs ${ANDROID_HOST_OUT} ${ANDROID_ROOT}"
855 if [ "${BIONIC}" = "y" ]; then
856 # TODO Make this overlay more generic.
857 linkroot_overlay_cmdline="linkdirs $OUT_DIR/soong/host/linux_bionic-x86 ${ANDROID_ROOT}"
858 fi
859fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100860
Alex Light20802ca2018-12-05 15:36:03 -0800861if [ "$USE_ZIPAPEX" = "y" ]; then
862 # TODO Currently this only works for linux_bionic zipapexes because those are
863 # stripped and so small enough that the ulimit doesn't kill us.
864 mkdir_locations="${mkdir_locations} $DEX_LOCATION/zipapex"
865 zip_options="-qq"
866 if [ "$DEV_MODE" = "y" ]; then
867 zip_options=""
868 fi
Alex Lightfc52ffc2019-01-31 15:48:18 -0800869 setupapex_cmdline="unzip -o -u ${zip_options} ${ZIPAPEX_LOC} apex_payload.zip -d ${DEX_LOCATION}"
870 installapex_cmdline="unzip -o -u ${zip_options} ${DEX_LOCATION}/apex_payload.zip -d ${DEX_LOCATION}/zipapex"
Martin Stjernholme58624f2019-09-20 15:53:40 +0100871 ANDROID_ART_BIN_DIR=$DEX_LOCATION/zipapex/bin
Alex Light6f342dd2019-03-27 17:15:42 +0000872elif [ "$USE_EXTRACTED_ZIPAPEX" = "y" ]; then
873 # Just symlink the zipapex binaries
Martin Stjernholme58624f2019-09-20 15:53:40 +0100874 ANDROID_ART_BIN_DIR=$DEX_LOCATION/zipapex/bin
Alex Light6f342dd2019-03-27 17:15:42 +0000875 # Force since some tests manually run this file twice.
876 ln_options=""
877 if [ "$DEV_MODE" = "y" ]; then
878 ln_options="--verbose"
879 fi
880 installapex_cmdline="ln -s -f ${ln_options} ${EXTRACTED_ZIPAPEX_LOC} ${DEX_LOCATION}/zipapex"
Alex Light20802ca2018-12-05 15:36:03 -0800881fi
882
Jeff Hao002b9312017-03-27 16:23:08 -0700883# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
884# specific profile to run properly.
885if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Martin Stjernholme58624f2019-09-20 15:53:40 +0100886 profman_cmdline="$ANDROID_ART_BIN_DIR/profman \
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000887 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700888 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Calin Juravle6df62f72017-04-28 19:58:01 -0700889 if [ -f $DEX_LOCATION/$TEST_NAME-ex.jar ]; then
890 profman_cmdline="${profman_cmdline} \
891 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
892 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
893 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000894 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
895 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700896 if [ "$PROFILE" = "y" ]; then
897 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
898 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
899 else
900 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
901 --generate-test-profile-seed=0"
902 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000903fi
904
David Srbeckyb0ec6792020-02-06 20:18:17 +0000905# Enable mini-debug-info for JIT (if JIT is used).
906FLAGS="$FLAGS -Xcompiler-option --generate-mini-debug-info"
907
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +0000908if [ "$PREBUILD" = "y" ]; then
909 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
Calin Juravle857f0582016-12-20 14:36:59 +0000910 if [ "$APP_IMAGE" = "y" ]; then
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +0000911 # Pick a base that will force the app image to get relocated.
912 app_image="--app-image-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.art --resolve-startup-const-strings=true"
Calin Juravle857f0582016-12-20 14:36:59 +0000913 fi
914
Alex Light907001d2019-01-17 00:16:04 +0000915 dex2oat_binary=${DEX2OAT_DEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +0100916 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
Alex Light907001d2019-01-17 00:16:04 +0000917 dex2oat_binary=${DEX2OAT_NDEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +0100918 fi
Martin Stjernholme58624f2019-09-20 15:53:40 +0100919 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ART_BIN_DIR/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100920 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000921 --boot-image=${BOOT_IMAGE} \
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +0000922 --dex-file=$DEX_LOCATION/$TEST_NAME.jar \
923 --oat-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.odex \
924 ${app_image} \
David Srbecky87712da2020-01-17 15:50:02 +0000925 --generate-mini-debug-info \
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +0000926 --instruction-set=$ISA"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700927 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
928 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
929 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700930
931 # Add in a timeout. This is important for testing the compilation/verification time of
932 # pathological cases.
933 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
934 # now. We should try to improve this.
935 # The current value is rather arbitrary. run-tests should compile quickly.
Alex Light483208d2017-09-26 09:31:17 -0700936 # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700937 if [ "$HOST" != "n" ]; then
938 # Use SIGRTMIN+2 to try to dump threads.
939 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Alex Light483208d2017-09-26 09:31:17 -0700940 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 -0700941 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100942 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +0000943 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 +0100944 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +0000945 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$TEST_NAME.vdex"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000946 elif [ "$TEST_DM" = "y" ]; then
947 dex2oat_cmdline="${dex2oat_cmdline} --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +0000948 dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$TEST_NAME.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
949 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$TEST_NAME.dm"
950 elif [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
951 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 +0000952 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700953fi
954
Richard Uhler76f5cb62016-04-04 13:30:16 -0700955if [ "$STRIP_DEX" = "y" ]; then
956 strip_cmdline="zip --quiet --delete $DEX_LOCATION/$TEST_NAME.jar classes.dex"
957fi
958
Igor Murashkin271a0f82017-02-14 21:14:17 +0000959if [ "$SYNC_BEFORE_RUN" = "y" ]; then
960 sync_cmdline="sync"
961fi
962
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700963DALVIKVM_ISA_FEATURES_ARGS=""
964if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
965 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100966fi
967
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000968# java.io.tmpdir can only be set at launch time.
969TMP_DIR_OPTION=""
970if [ "$HOST" = "n" ]; then
971 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
972fi
973
Alex Lightb8012102019-11-13 01:41:04 +0000974# The build servers have an ancient version of bash so we cannot use @Q.
975if [ "$USE_GDBSERVER" == "y" ]; then
976 printf -v QUOTED_DALVIKVM_BOOT_OPT "%q" "$DALVIKVM_BOOT_OPT"
977else
978 QUOTED_DALVIKVM_BOOT_OPT="$DALVIKVM_BOOT_OPT"
979fi
980
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000981# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
982# b/27185632
983# b/24664297
Martin Stjernholme58624f2019-09-20 15:53:40 +0100984dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ART_BIN_DIR/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100985 $GDB_ARGS \
986 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -0700987 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100988 -XXlib:$LIB \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100989 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700990 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100991 $ZYGOTE \
992 $JNI_OPTS \
993 $INT_OPTS \
994 $DEBUGGER_OPTS \
Alex Lightb8012102019-11-13 01:41:04 +0000995 ${QUOTED_DALVIKVM_BOOT_OPT} \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +0000996 $TMP_DIR_OPTION \
Nicolas Geoffray6ee49712018-03-30 14:39:05 +0000997 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -0700998 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100999
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -08001000# Remove whitespace.
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +00001001dex2oat_cmdline=$(echo $dex2oat_cmdline)
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -08001002dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001003dm_cmdline=$(echo $dm_cmdline)
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +00001004vdex_cmdline=$(echo $vdex_cmdline)
Calin Juravle13439f02017-02-21 01:17:21 -08001005profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001006
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001007# Use an empty ASAN_OPTIONS to enable defaults.
1008# Note: this is required as envsetup right now exports detect_leaks=0.
1009RUN_TEST_ASAN_OPTIONS=""
1010
Andreas Gampe58408392017-05-16 10:45:46 -07001011# Multiple shutdown leaks. b/38341789
1012if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
1013 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
1014fi
1015RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
1016
Vladimir Markoa497a392018-09-26 10:52:50 +01001017# For running, we must turn off logging when dex2oat is missing. Otherwise we use
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001018# the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
1019if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
1020 if [ "$DEV_MODE" = "y" ]; then
1021 export ANDROID_LOG_TAGS='*:d'
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001022 elif [ "$HAVE_IMAGE" = "n" ]; then
1023 # All tests would log the error of missing image. Be silent here and only log fatal
1024 # events.
1025 export ANDROID_LOG_TAGS='*:s'
1026 else
1027 # We are interested in LOG(ERROR) output.
1028 export ANDROID_LOG_TAGS='*:e'
1029 fi
1030fi
1031
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001032if [ "$HOST" = "n" ]; then
1033 adb root > /dev/null
1034 adb wait-for-device
1035 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001036 adb shell rm -rf $CHROOT_DEX_LOCATION
1037 adb shell mkdir -p $CHROOT_DEX_LOCATION
1038 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION
1039 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -07001040 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001041 adb push profile $CHROOT_DEX_LOCATION
Calin Juravle13439f02017-02-21 01:17:21 -08001042 fi
David Brazdil7d2ec612018-01-19 14:19:59 +00001043 # Copy resource folder
1044 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001045 adb push res $CHROOT_DEX_LOCATION
David Brazdil7d2ec612018-01-19 14:19:59 +00001046 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001047 else
Roland Levillain76cfe612017-10-30 13:14:28 +00001048 adb shell rm -rf $CHROOT_DEX_LOCATION >/dev/null 2>&1
1049 adb shell mkdir -p $CHROOT_DEX_LOCATION >/dev/null 2>&1
1050 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
1051 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -07001052 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001053 adb push profile $CHROOT_DEX_LOCATION >/dev/null 2>&1
Calin Juravle13439f02017-02-21 01:17:21 -08001054 fi
David Brazdil7d2ec612018-01-19 14:19:59 +00001055 # Copy resource folder
1056 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001057 adb push res $CHROOT_DEX_LOCATION >/dev/null 2>&1
David Brazdil7d2ec612018-01-19 14:19:59 +00001058 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001059 fi
1060
Roland Levillain72f67742019-03-06 15:48:08 +00001061 # Populate LD_LIBRARY_PATH.
1062 LD_LIBRARY_PATH=
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001063 if [ "$ANDROID_ROOT" != "/system" ]; then
1064 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
1065 # so we can only use LD_LIBRARY_PATH when testing on a local
1066 # installation.
Roland Levillain72f67742019-03-06 15:48:08 +00001067 LD_LIBRARY_PATH="$ANDROID_ROOT/$LIBRARY_DIRECTORY"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001068 fi
Roland Levillain72f67742019-03-06 15:48:08 +00001069 # Needed to access libarttest(d).so and JVMTI agent libraries.
1070 LD_LIBRARY_PATH="/data/$TEST_DIRECTORY/art/$ISA:$LD_LIBRARY_PATH"
1071 # Needed to access the boot (core) image files.
1072 LD_LIBRARY_PATH="/data/art-test/$ISA:$LD_LIBRARY_PATH"
1073 # Needed to access the test's Odex files.
1074 LD_LIBRARY_PATH="$DEX_LOCATION/oat/$ISA:$LD_LIBRARY_PATH"
1075 # Needed to access the test's native libraries (see e.g. 674-hiddenapi,
1076 # which generates `libhiddenapitest_*.so` libraries in `$DEX_LOCATION`).
1077 LD_LIBRARY_PATH="$DEX_LOCATION:$LD_LIBRARY_PATH"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001078
Dimitry Ivanov49c2c922017-02-14 11:06:14 -08001079 # System libraries needed by libarttestd.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +00001080 PUBLIC_LIBS=libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
1081 if [ "$TEST_IS_NDEBUG" = "y" ]; then
David Sehr1f010162018-05-15 08:59:32 -07001082 PUBLIC_LIBS=$PUBLIC_LIBS:libart.so:libdexfile.so:libprofile.so:libartbase.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +00001083 else
David Sehr1f010162018-05-15 08:59:32 -07001084 PUBLIC_LIBS=$PUBLIC_LIBS:libartd.so:libdexfiled.so:libprofiled.so:libartbased.so
Vladimir Marko2da72ed2018-03-07 12:58:11 +00001085 fi
Dimitry Ivanov90d48f22016-05-05 17:24:28 -07001086
Roland Levillain72f67742019-03-06 15:48:08 +00001087 # Prepend directories to the path on device.
Martin Stjernholme58624f2019-09-20 15:53:40 +01001088 PREPEND_TARGET_PATH=$ANDROID_ART_BIN_DIR
Roland Levillain72f67742019-03-06 15:48:08 +00001089 if [ "$ANDROID_ROOT" != "/system" ]; then
1090 PREPEND_TARGET_PATH="$PREPEND_TARGET_PATH:$ANDROID_ROOT/bin"
1091 fi
1092
Andreas Gampe975d70b2019-09-11 11:00:18 -07001093 timeout_dumper_cmd=
Andreas Gampea6138082019-09-11 11:08:23 -07001094
1095 # Check whether signal_dumper is available.
1096 if [ "$TIMEOUT_DUMPER" = signal_dumper ] ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001097 # Chroot? Use as prefix for tests.
1098 TIMEOUT_DUMPER_PATH_PREFIX=
1099 if [ -n "$CHROOT" ]; then
1100 TIMEOUT_DUMPER_PATH_PREFIX="$CHROOT/"
1101 fi
1102
Roland Levillain52b4dc92019-09-12 11:56:52 +01001103 # Testing APEX?
Andreas Gampe5aae3db2019-09-13 10:24:57 -07001104 if adb shell "test -x ${TIMEOUT_DUMPER_PATH_PREFIX}/apex/com.android.art/bin/signal_dumper" ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001105 TIMEOUT_DUMPER="/apex/com.android.art/bin/signal_dumper"
1106 # Is it in /system/bin?
Andreas Gampe5aae3db2019-09-13 10:24:57 -07001107 elif adb shell "test -x ${TIMEOUT_DUMPER_PATH_PREFIX}/system/bin/signal_dumper" ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001108 TIMEOUT_DUMPER="/system/bin/signal_dumper"
Andreas Gampea6138082019-09-11 11:08:23 -07001109 else
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001110 TIMEOUT_DUMPER=
Andreas Gampea6138082019-09-11 11:08:23 -07001111 fi
1112 else
1113 TIMEOUT_DUMPER=
1114 fi
1115
Andreas Gampe975d70b2019-09-11 11:00:18 -07001116 if [ ! -z "$TIMEOUT_DUMPER" ] ; then
1117 # Use "-l" to dump to logcat. That is convenience for the build bot crash symbolization.
Andreas Gampe38a28182019-09-13 11:36:11 -07001118 # Use exit code 124 for toybox timeout (b/141007616).
1119 timeout_dumper_cmd="${TIMEOUT_DUMPER} -l -s 15 -e 124"
Andreas Gampe975d70b2019-09-11 11:00:18 -07001120 fi
1121
1122 timeout_prefix=
1123 if [ "$TIME_OUT" = "timeout" ]; then
1124 # Add timeout command if time out is desired.
1125 #
1126 # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which
1127 # will induce a full thread dump before killing the process. To ensure any issues in
1128 # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the
1129 # child.
1130 # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
David Srbeckya49b04f2019-09-16 14:53:15 +00001131 timeout_prefix="timeout --foreground -k 120s ${TIME_OUT_VALUE}s ${timeout_dumper_cmd} $cmdline"
Andreas Gampe975d70b2019-09-11 11:00:18 -07001132 fi
1133
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001134 # Create a script with the command. The command can get longer than the longest
1135 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001136 # command. Dalvik cache is cleaned before running to make subsequent executions
1137 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001138 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001139 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001140 export ANDROID_DATA=$DEX_LOCATION && \
Dimitry Ivanov90d48f22016-05-05 17:24:28 -07001141 export ANDROID_ADDITIONAL_PUBLIC_LIBRARIES=$PUBLIC_LIBS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001142 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +00001143 export ANDROID_ROOT=$ANDROID_ROOT && \
Victor Chang64611242019-07-05 16:32:41 +01001144 export ANDROID_I18N_ROOT=$ANDROID_I18N_ROOT && \
Martin Stjernholme58624f2019-09-20 15:53:40 +01001145 export ANDROID_ART_ROOT=$ANDROID_ART_ROOT && \
Neil Fuller26a5dd62019-03-13 15:16:35 +00001146 export ANDROID_TZDATA_ROOT=$ANDROID_TZDATA_ROOT && \
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001147 export ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001148 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -07001149 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +01001150 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Roland Levillain72f67742019-03-06 15:48:08 +00001151 export PATH=$PREPEND_TARGET_PATH:\$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -08001152 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001153 $dex2oat_cmdline && \
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001154 $dm_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001155 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -07001156 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +00001157 $sync_cmdline && \
David Srbeckya49b04f2019-09-16 14:53:15 +00001158 $timeout_prefix $dalvikvm_cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001159
1160 cmdfile=$(tempfile -p "cmd-" -s "-$TEST_NAME")
1161 echo "$cmdline" > $cmdfile
1162
1163 if [ "$DEV_MODE" = "y" ]; then
1164 echo $cmdline
Alex Light219420e2019-12-05 10:20:26 -08001165 if [ "$USE_GDB" = "y" ] || [ "$USE_GDBSERVER" = "y" ]; then
1166 echo "Forward ${GDBSERVER_PORT} to local port and connect GDB"
1167 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001168 fi
1169
1170 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001171 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001172 else
Roland Levillain76cfe612017-10-30 13:14:28 +00001173 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh >/dev/null 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001174 fi
1175
Alex Light722d6712018-02-12 17:41:12 +00001176 exit_status=0
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001177 if [ "$DRY_RUN" != "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001178 if [ -n "$CHROOT" ]; then
1179 adb shell chroot "$CHROOT" sh $DEX_LOCATION/cmdline.sh
1180 else
1181 adb shell sh $DEX_LOCATION/cmdline.sh
1182 fi
Alex Light722d6712018-02-12 17:41:12 +00001183 exit_status=$?
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001184 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001185
1186 rm -f $cmdfile
Alex Light722d6712018-02-12 17:41:12 +00001187 exit $exit_status
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001188else
Calin Juravle24bd3f92017-05-11 00:36:53 -07001189 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001190 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -07001191
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001192 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +00001193 export ANDROID_ROOT="${ANDROID_ROOT}"
Victor Chang64611242019-07-05 16:32:41 +01001194 export ANDROID_I18N_ROOT="${ANDROID_I18N_ROOT}"
Martin Stjernholme58624f2019-09-20 15:53:40 +01001195 export ANDROID_ART_ROOT="${ANDROID_ART_ROOT}"
Neil Fuller26a5dd62019-03-13 15:16:35 +00001196 export ANDROID_TZDATA_ROOT="${ANDROID_TZDATA_ROOT}"
Alex Light6f342dd2019-03-27 17:15:42 +00001197 if [ "$USE_ZIPAPEX" = "y" ] || [ "$USE_EXRACTED_ZIPAPEX" = "y" ]; then
Alex Light20802ca2018-12-05 15:36:03 -08001198 # Put the zipapex files in front of the ld-library-path
Alex Lightf7f31522019-02-01 11:14:41 -08001199 export LD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1200 export DYLD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1201 else
1202 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1203 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Alex Light20802ca2018-12-05 15:36:03 -08001204 fi
Martin Stjernholme58624f2019-09-20 15:53:40 +01001205 export PATH="$PATH:$ANDROID_ART_BIN_DIR"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001206
David Srbeckyc9ede382015-06-20 06:03:53 +01001207 # Temporarily disable address space layout randomization (ASLR).
1208 # This is needed on the host so that the linker loads core.oat at the necessary address.
1209 export LD_USE_LOAD_BIAS=1
1210
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001211 cmdline="$dalvikvm_cmdline"
1212
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001213 if [ "$TIME_OUT" = "gdb" ]; then
1214 if [ `uname` = "Darwin" ]; then
1215 # Fall back to timeout on Mac.
1216 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -07001217 elif [ "$ISA" = "x86" ]; then
1218 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
1219 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001220 else
1221 # Check if gdb is available.
1222 gdb --eval-command="quit" > /dev/null 2>&1
1223 if [ $? != 0 ]; then
1224 # gdb isn't available. Fall back to timeout.
1225 TIME_OUT="timeout"
1226 fi
1227 fi
1228 fi
1229
1230 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001231 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -08001232 #
Andreas Gampe0df2aba2019-06-10 16:53:55 -07001233 # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which
1234 # will induce a full thread dump before killing the process. To ensure any issues in
1235 # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the
1236 # child.
Andreas Gampe4bdcf5d2018-12-14 10:48:53 -08001237 # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
Andreas Gampe0df2aba2019-06-10 16:53:55 -07001238 cmdline="timeout --foreground -k 120s ${TIME_OUT_VALUE}s ${TIMEOUT_DUMPER} -s 15 $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001239 fi
1240
1241 if [ "$DEV_MODE" = "y" ]; then
Martin Stjernholme58624f2019-09-20 15:53:40 +01001242 for var in ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT ANDROID_I18N_ROOT ANDROID_TZDATA_ROOT ANDROID_ART_ROOT LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS; do
Orion Hodsonee06c5a2018-04-23 13:46:24 +01001243 echo EXPORT $var=${!var}
1244 done
Alex Light680cbf22018-10-31 11:00:19 -07001245 echo "$(declare -f linkdirs)"
Alex Light20802ca2018-12-05 15:36:03 -08001246 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 +01001247 fi
1248
1249 cd $ANDROID_BUILD_TOP
1250
Calin Juravle24bd3f92017-05-11 00:36:53 -07001251 # Make sure we delete any existing compiler artifacts.
1252 # This enables tests to call the RUN script multiple times in a row
1253 # without worrying about interference.
1254 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +00001255 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -07001256
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001257 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
1258
Alex Lightafb5d192016-05-24 15:57:45 -07001259 mkdir -p ${mkdir_locations} || exit 1
Alex Light20802ca2018-12-05 15:36:03 -08001260 $setupapex_cmdline || { echo "zipapex extraction failed." >&2 ; exit 2; }
Alex Light7b1f8cc2019-01-31 11:04:51 -08001261 $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 -07001262 $linkroot_cmdline || { echo "create symlink android-root failed." >&2 ; exit 2; }
1263 $linkroot_overlay_cmdline || { echo "overlay android-root failed." >&2 ; exit 2; }
Calin Juravle13439f02017-02-21 01:17:21 -08001264 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Nicolas Geoffrayf0eaada2020-02-09 22:21:26 +00001265 $dex2oat_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
1266 $dm_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
1267 $vdex_cmdline || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -07001268 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +00001269 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -07001270
Alex Light8d94ddd2019-12-18 11:13:03 -08001271 if [ "$CREATE_RUNNER" = "y" ]; then
1272 echo "#!/bin/bash" > ${DEX_LOCATION}/runit.sh
1273 for var in ANDROID_PRINTF_LOG ANDROID_DATA ANDROID_ROOT ANDROID_I18N_ROOT ANDROID_TZDATA_ROOT ANDROID_ART_ROOT LD_LIBRARY_PATH DYLD_LIBRARY_PATH PATH LD_USE_LOAD_BIAS; do
1274 echo export $var="${!var}" >> ${DEX_LOCATION}/runit.sh
1275 done
Alex Light4f915d22020-01-09 17:51:25 -08001276 if [ "$DEV_MODE" = "y" ]; then
1277 echo $cmdline "2>&1" >> ${DEX_LOCATION}/runit.sh
1278 else
1279 echo 'STDERR=$(mktemp)' >> ${DEX_LOCATION}/runit.sh
1280 echo 'STDOUT=$(mktemp)' >> ${DEX_LOCATION}/runit.sh
1281 echo $cmdline '2>${STDERR} >${STDOUT}' >> ${DEX_LOCATION}/runit.sh
1282 echo 'if diff ${STDOUT} $ANDROID_DATA/expected.txt; then' >> ${DEX_LOCATION}/runit.sh
1283 echo ' rm -f ${STDOUT} ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1284 echo ' exit 0' >> ${DEX_LOCATION}/runit.sh
1285 echo 'else' >> ${DEX_LOCATION}/runit.sh
1286 echo ' echo STDOUT:' >> ${DEX_LOCATION}/runit.sh
1287 echo ' cat ${STDOUT}' >> ${DEX_LOCATION}/runit.sh
1288 echo ' echo STDERR:' >> ${DEX_LOCATION}/runit.sh
1289 echo ' cat ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1290 echo ' rm -f ${STDOUT} ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1291 echo ' exit 1' >> ${DEX_LOCATION}/runit.sh
1292 echo 'fi' >> ${DEX_LOCATION}/runit.sh
1293 fi
Alex Light8d94ddd2019-12-18 11:13:03 -08001294 chmod u+x $DEX_LOCATION/runit.sh
1295 echo "Runnable test script written to ${DEX_LOCATION}/runit.sh"
1296 fi
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001297 if [ "$DRY_RUN" = "y" ]; then
1298 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -07001299 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001300
1301 if [ "$USE_GDB" = "y" ]; then
1302 # When running under gdb, we cannot do piping and grepping...
Alex Lighte4b4a182019-02-12 14:19:49 -08001303 $cmdline "$@"
1304 elif [ "$USE_GDBSERVER" = "y" ]; then
1305 echo "Connect to $GDBSERVER_PORT"
1306 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -07001307 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001308 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001309 if [ "$TIME_OUT" != "gdb" ]; then
1310 trap 'kill -INT -$pid' INT
1311 $cmdline "$@" 2>&1 & pid=$!
1312 wait $pid
Alex Light722d6712018-02-12 17:41:12 +00001313 exit_value=$?
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001314 # Add extra detail if time out is enabled.
Alex Light722d6712018-02-12 17:41:12 +00001315 if [ $exit_value = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001316 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1317 fi
Alex Light722d6712018-02-12 17:41:12 +00001318 exit $exit_value
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001319 else
1320 # With a thread dump that uses gdb if a timeout.
1321 trap 'kill -INT -$pid' INT
1322 $cmdline "$@" 2>&1 & pid=$!
1323 # Spawn a watcher process.
1324 ( sleep $TIME_OUT_VALUE && \
1325 echo "##### Thread dump using gdb on test timeout" && \
1326 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
1327 --eval-command="call exit(124)" --eval-command=quit || \
1328 kill $pid )) 2> /dev/null & watcher=$!
1329 wait $pid
1330 test_exit_status=$?
1331 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
1332 if [ $test_exit_status = 0 ]; then
1333 # The test finished normally.
1334 exit 0
1335 else
1336 # The test failed or timed out.
1337 if [ $test_exit_status = 124 ]; then
1338 # The test timed out.
1339 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1340 fi
Alex Light722d6712018-02-12 17:41:12 +00001341 exit $test_exit_status
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001342 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001343 fi
1344 fi
1345fi