blob: 105af417692ff5f3eb403da64cc614d2a5f4d653 [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"
Nicolas Geoffrayb0c6cb52020-04-20 15:12:42 +010033DEX2OAT_NDEBUG_BINARY="dex2oat32"
34DEX2OAT_DEBUG_BINARY="dex2oatd32"
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"
Alex Light280e6c32020-03-03 13:52:07 -080055ADD_LIBDIR_ARGUMENTS="n"
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +010056SUFFIX64=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010057ISA=x86
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000058LIBRARY_DIRECTORY="lib"
Colin Crossafd3c9e2016-09-16 13:47:21 -070059TEST_DIRECTORY="nativetest"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +000060MAIN=""
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010061OPTIMIZE="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010062PREBUILD="y"
63QUIET="n"
Nicolas Geoffray94e25db2017-01-27 14:54:28 +000064RELOCATE="n"
Jeff Hao207a37d2014-10-29 17:24:25 -070065SECONDARY_DEX=""
David Srbecky352482c2019-10-16 15:59:52 +010066TIME_OUT="n" # "n" (disabled), "timeout" (use timeout), "gdb" (use gdb)
Andreas Gampe148c1602019-06-10 16:47:46 -070067TIMEOUT_DUMPER=signal_dumper
Andreas Gampe6ad30a22019-09-12 15:12:36 -070068# Values in seconds.
Martin Stjernholmcb497cf2019-09-27 18:42:55 +010069TIME_OUT_EXTRA=0
Andreas Gampe6ad30a22019-09-12 15:12:36 -070070TIME_OUT_VALUE=
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010071USE_GDB="n"
Alex Lighte4b4a182019-02-12 14:19:49 -080072USE_GDBSERVER="n"
73GDBSERVER_PORT=":5039"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +010074USE_JVM="n"
Alex Lightc281ba52017-10-11 11:35:55 -070075USE_JVMTI="n"
Igor Murashkin7617abd2015-07-10 18:27:47 -070076VERIFY="y" # y=yes,n=no,s=softfail
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010077ZYGOTE=""
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -070078DEX_VERIFY=""
Andreas Gampe4d2ef332015-08-05 09:24:45 -070079INSTRUCTION_SET_FEATURES=""
Mathieu Chartier031768a2015-08-27 10:25:02 -070080ARGS=""
David Brazdilfeb22822019-02-13 21:25:57 +000081VDEX_ARGS=""
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -070082EXTERNAL_LOG_TAGS="n" # if y respect externally set ANDROID_LOG_TAGS.
83DRY_RUN="n" # if y prepare to run the test but don't run it.
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000084TEST_VDEX="n"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +000085TEST_DM="n"
Alex Lighte06b6342017-01-05 14:37:21 -080086TEST_IS_NDEBUG="n"
Calin Juravle857f0582016-12-20 14:36:59 +000087APP_IMAGE="y"
Andreas Gampe038a1982020-03-11 23:06:42 +000088SECONDARY_APP_IMAGE="y"
89SECONDARY_CLASS_LOADER_CONTEXT=""
90SECONDARY_COMPILATION="y"
Alex Light8f2c6d42017-04-10 16:27:35 -070091JVMTI_STRESS="n"
Alex Lightc38c3692017-06-27 15:45:14 -070092JVMTI_STEP_STRESS="n"
Alex Light43e935d2017-06-19 15:40:40 -070093JVMTI_FIELD_STRESS="n"
Alex Lightb7edcda2017-04-27 13:20:31 -070094JVMTI_TRACE_STRESS="n"
95JVMTI_REDEFINE_STRESS="n"
Calin Juravle13439f02017-02-21 01:17:21 -080096PROFILE="n"
Jeff Hao002b9312017-03-27 16:23:08 -070097RANDOM_PROFILE="n"
Alex Light483208d2017-09-26 09:31:17 -070098# The normal dex2oat timeout.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -070099DEX2OAT_TIMEOUT="300" # 5 mins
Alex Light483208d2017-09-26 09:31:17 -0700100# The *hard* timeout where we really start trying to kill the dex2oat.
Shubham Ajmeraf97cbd62017-10-11 10:00:57 -0700101DEX2OAT_RT_TIMEOUT="360" # 6 mins
Alex Light8d94ddd2019-12-18 11:13:03 -0800102CREATE_RUNNER="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100103
Igor Murashkin271a0f82017-02-14 21:14:17 +0000104# if "y", run 'sync' before dalvikvm to make sure all files from
105# build step (e.g. dex2oat) were finished writing.
106SYNC_BEFORE_RUN="n"
107
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700108# When running a debug build, we want to run with all checks.
109ANDROID_FLAGS="${ANDROID_FLAGS} -XX:SlowDebug=true"
Andreas Gampee8f74ca2018-01-02 09:26:16 -0800110# The same for dex2oatd, both prebuild and runtime-driven.
111ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --runtime-arg -Xcompiler-option -XX:SlowDebug=true"
112COMPILER_FLAGS="${COMPILER_FLAGS} --runtime-arg -XX:SlowDebug=true"
Andreas Gampe1c5b42f2017-06-15 18:20:45 -0700113
David Srbecky4fa07a52020-03-31 20:52:09 +0100114# Let the compiler and runtime know that we are running tests.
115COMPILE_FLAGS="${COMPILE_FLAGS} --compile-art-test"
Roland Levillainb7724c42020-04-21 16:51:54 +0100116ANDROID_FLAGS="${ANDROID_FLAGS} -Xcompiler-option --compile-art-test"
David Srbecky4fa07a52020-03-31 20:52:09 +0100117
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100118while true; do
119 if [ "x$1" = "x--quiet" ]; then
120 QUIET="y"
121 shift
Alex Light483208d2017-09-26 09:31:17 -0700122 elif [ "x$1" = "x--dex2oat-rt-timeout" ]; then
123 shift
124 if [ "x$1" = "x" ]; then
125 echo "$0 missing argument to --dex2oat-rt-timeout" 1>&2
126 exit 1
127 fi
128 DEX2OAT_RT_TIMEOUT="$1"
129 shift
130 elif [ "x$1" = "x--dex2oat-timeout" ]; then
131 shift
132 if [ "x$1" = "x" ]; then
133 echo "$0 missing argument to --dex2oat-timeout" 1>&2
134 exit 1
135 fi
136 DEX2OAT_TIMEOUT="$1"
137 shift
Alex Lighte06b6342017-01-05 14:37:21 -0800138 elif [ "x$1" = "x--jvmti" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700139 USE_JVMTI="y"
Alex Lighte06b6342017-01-05 14:37:21 -0800140 IS_JVMTI_TEST="y"
Andreas Gampe038a1982020-03-11 23:06:42 +0000141 # Secondary images block some tested behavior.
142 SECONDARY_APP_IMAGE="n"
Alex Lighte06b6342017-01-05 14:37:21 -0800143 shift
Alex Light280e6c32020-03-03 13:52:07 -0800144 elif [ "x$1" = "x--add-libdir-argument" ]; then
145 ADD_LIBDIR_ARGUMENTS="y"
146 shift
Alex Lightfaf90b62016-08-12 14:43:48 -0700147 elif [ "x$1" = "x-O" ]; then
Alex Lighte06b6342017-01-05 14:37:21 -0800148 TEST_IS_NDEBUG="y"
Alex Lightfaf90b62016-08-12 14:43:48 -0700149 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100150 elif [ "x$1" = "x--lib" ]; then
151 shift
152 if [ "x$1" = "x" ]; then
153 echo "$0 missing argument to --lib" 1>&2
154 exit 1
155 fi
156 LIB="$1"
157 shift
Alex Light97acf192016-03-17 09:59:38 -0700158 elif [ "x$1" = "x--gc-stress" ]; then
David Srbecky7021c132019-10-04 12:56:22 +0100159 # Give an extra 20 mins if we are gc-stress.
160 TIME_OUT_EXTRA=$((${TIME_OUT_EXTRA} + 1200))
Alex Light97acf192016-03-17 09:59:38 -0700161 shift
Mathieu Chartier031768a2015-08-27 10:25:02 -0700162 elif [ "x$1" = "x--testlib" ]; then
163 shift
164 if [ "x$1" = "x" ]; then
165 echo "$0 missing argument to --testlib" 1>&2
166 exit 1
167 fi
Mathieu Chartierde286fd2015-09-03 18:10:29 -0700168 ARGS="${ARGS} $1"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700169 shift
David Srbecky52886112016-01-22 13:56:47 +0000170 elif [ "x$1" = "x--args" ]; then
171 shift
172 if [ "x$1" = "x" ]; then
173 echo "$0 missing argument to --args" 1>&2
174 exit 1
175 fi
176 ARGS="${ARGS} $1"
177 shift
Alex Lighte2ddce32019-05-22 17:08:35 +0000178 elif [ "x$1" = "x--compiler-only-option" ]; then
179 shift
180 option="$1"
181 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
182 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100183 elif [ "x$1" = "x-Xcompiler-option" ]; then
184 shift
185 option="$1"
186 FLAGS="${FLAGS} -Xcompiler-option $option"
187 COMPILE_FLAGS="${COMPILE_FLAGS} $option"
188 shift
Alex Light8d94ddd2019-12-18 11:13:03 -0800189 elif [ "x$1" = "x--create-runner" ]; then
190 CREATE_RUNNER="y"
191 shift
Alex Light7233c7e2016-07-28 10:07:45 -0700192 elif [ "x$1" = "x--android-runtime-option" ]; then
193 shift
194 option="$1"
195 ANDROID_FLAGS="${ANDROID_FLAGS} $option"
196 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100197 elif [ "x$1" = "x--runtime-option" ]; then
198 shift
199 option="$1"
200 FLAGS="${FLAGS} $option"
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100201 if [ "x$option" = "x-Xmethod-trace" ]; then
Martin Stjernholm30677102019-10-01 12:54:10 +0100202 # Method tracing can slow some tests down a lot, in particular
203 # 530-checker-lse2.
204 TIME_OUT_EXTRA=$((${TIME_OUT_EXTRA} + 1200))
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100205 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100206 shift
207 elif [ "x$1" = "x--boot" ]; then
208 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000209 BOOT_IMAGE="$1"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100210 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100211 elif [ "x$1" = "x--relocate" ]; then
212 RELOCATE="y"
213 shift
214 elif [ "x$1" = "x--no-relocate" ]; then
215 RELOCATE="n"
216 shift
217 elif [ "x$1" = "x--prebuild" ]; then
218 PREBUILD="y"
219 shift
Mathieu Chartierdcd56c92017-11-20 20:30:24 -0800220 elif [ "x$1" = "x--compact-dex-level" ]; then
221 shift
222 COMPILE_FLAGS="${COMPILE_FLAGS} --compact-dex-level=$1"
223 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700224 elif [ "x$1" = "x--jvmti-redefine-stress" ]; then
225 # APP_IMAGE doesn't really work with jvmti redefine stress
Alex Lightc281ba52017-10-11 11:35:55 -0700226 USE_JVMTI="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700227 APP_IMAGE="n"
Andreas Gampe038a1982020-03-11 23:06:42 +0000228 SECONDARY_APP_IMAGE="n"
Alex Light8f2c6d42017-04-10 16:27:35 -0700229 JVMTI_STRESS="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700230 JVMTI_REDEFINE_STRESS="y"
231 shift
Alex Lightc38c3692017-06-27 15:45:14 -0700232 elif [ "x$1" = "x--jvmti-step-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700233 USE_JVMTI="y"
Alex Lightc38c3692017-06-27 15:45:14 -0700234 JVMTI_STRESS="y"
235 JVMTI_STEP_STRESS="y"
236 shift
Alex Light43e935d2017-06-19 15:40:40 -0700237 elif [ "x$1" = "x--jvmti-field-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700238 USE_JVMTI="y"
Alex Light43e935d2017-06-19 15:40:40 -0700239 JVMTI_STRESS="y"
240 JVMTI_FIELD_STRESS="y"
241 shift
Alex Lightb7edcda2017-04-27 13:20:31 -0700242 elif [ "x$1" = "x--jvmti-trace-stress" ]; then
Alex Lightc281ba52017-10-11 11:35:55 -0700243 USE_JVMTI="y"
Alex Lightb7edcda2017-04-27 13:20:31 -0700244 JVMTI_STRESS="y"
245 JVMTI_TRACE_STRESS="y"
Alex Light8f2c6d42017-04-10 16:27:35 -0700246 shift
Calin Juravle857f0582016-12-20 14:36:59 +0000247 elif [ "x$1" = "x--no-app-image" ]; then
248 APP_IMAGE="n"
249 shift
Andreas Gampe038a1982020-03-11 23:06:42 +0000250 elif [ "x$1" = "x--no-secondary-app-image" ]; then
251 SECONDARY_APP_IMAGE="n"
252 shift
253 elif [ "x$1" = "x--secondary-class-loader-context" ]; then
254 shift
255 SECONDARY_CLASS_LOADER_CONTEXT="$1"
256 shift
257 elif [ "x$1" = "x--no-secondary-compilation" ]; then
258 SECONDARY_COMPILATION="n"
259 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100260 elif [ "x$1" = "x--host" ]; then
261 HOST="y"
Roland Levillainb59f5fb2020-02-19 16:22:48 +0000262 ANDROID_ROOT="${ANDROID_HOST_OUT}"
263 ANDROID_ART_ROOT="${ANDROID_HOST_OUT}/com.android.art"
264 ANDROID_I18N_ROOT="${ANDROID_HOST_OUT}/com.android.i18n"
265 ANDROID_TZDATA_ROOT="${ANDROID_HOST_OUT}/com.android.tzdata"
Nicolas Geoffrayb0c6cb52020-04-20 15:12:42 +0100266 # On host, we default to using the symlink, as the PREFER_32BIT
267 # configuration is the only configuration building a 32bit version of
268 # dex2oat.
269 DEX2OAT_DEBUG_BINARY="dex2oatd"
270 DEX2OAT_NDEBUG_BINARY="dex2oat"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100271 shift
Alex Light680cbf22018-10-31 11:00:19 -0700272 elif [ "x$1" = "x--bionic" ]; then
273 BIONIC="y"
274 # We need to create an ANDROID_ROOT because currently we cannot create
275 # the frameworks/libcore with linux_bionic so we need to use the normal
276 # host ones which are in a different location.
277 CREATE_ANDROID_ROOT="y"
278 shift
Alex Light6f342dd2019-03-27 17:15:42 +0000279 elif [ "x$1" = "x--runtime-extracted-zipapex" ]; then
280 shift
281 USE_EXTRACTED_ZIPAPEX="y"
282 EXTRACTED_ZIPAPEX_LOC="$1"
283 shift
Alex Light20802ca2018-12-05 15:36:03 -0800284 elif [ "x$1" = "x--runtime-zipapex" ]; then
285 shift
286 USE_ZIPAPEX="y"
287 ZIPAPEX_LOC="$1"
Alex Light907001d2019-01-17 00:16:04 +0000288 # TODO (b/119942078): Currently apex does not support
289 # symlink_preferred_arch so we will not have a dex2oatd to execute and
290 # need to manually provide
291 # dex2oatd64.
292 DEX2OAT_DEBUG_BINARY="dex2oatd64"
Alex Light20802ca2018-12-05 15:36:03 -0800293 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100294 elif [ "x$1" = "x--no-prebuild" ]; then
295 PREBUILD="n"
296 shift
297 elif [ "x$1" = "x--no-image" ]; then
298 HAVE_IMAGE="n"
299 shift
Jeff Hao207a37d2014-10-29 17:24:25 -0700300 elif [ "x$1" = "x--secondary" ]; then
301 SECONDARY_DEX=":$DEX_LOCATION/$TEST_NAME-ex.jar"
Calin Juravle175dc732015-08-25 15:42:32 +0100302 # Enable cfg-append to make sure we get the dump for both dex files.
303 # (otherwise the runtime compilation of the secondary dex will overwrite
Roland Levillainb0103ca2016-11-01 14:48:47 +0000304 # the dump of the first one).
Calin Juravle175dc732015-08-25 15:42:32 +0100305 FLAGS="${FLAGS} -Xcompiler-option --dump-cfg-append"
306 COMPILE_FLAGS="${COMPILE_FLAGS} --dump-cfg-append"
Jeff Hao207a37d2014-10-29 17:24:25 -0700307 shift
Alex Light0e151e72017-10-25 10:50:35 -0700308 elif [ "x$1" = "x--with-agent" ]; then
309 shift
310 USE_JVMTI="y"
Alex Light54dabfb2018-09-19 16:29:09 -0700311 WITH_AGENT+=("$1")
Alex Light0e151e72017-10-25 10:50:35 -0700312 shift
Alex Lightc281ba52017-10-11 11:35:55 -0700313 elif [ "x$1" = "x--debug-wrap-agent" ]; then
314 WRAP_DEBUGGER_AGENT="y"
315 shift
316 elif [ "x$1" = "x--debug-agent" ]; then
317 shift
318 DEBUGGER="agent"
319 USE_JVMTI="y"
320 DEBUGGER_AGENT="$1"
321 TIME_OUT="n"
322 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100323 elif [ "x$1" = "x--debug" ]; then
Alex Lightfc588092020-01-23 15:39:08 -0800324 USE_JVMTI="y"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100325 DEBUGGER="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800326 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100327 shift
Alex Lighte4b4a182019-02-12 14:19:49 -0800328 elif [ "x$1" = "x--gdbserver-port" ]; then
329 shift
330 GDBSERVER_PORT=$1
331 shift
332 elif [ "x$1" = "x--gdbserver-bin" ]; then
333 shift
334 GDBSERVER_HOST=$1
335 GDBSERVER_DEVICE=$1
336 shift
337 elif [ "x$1" = "x--gdbserver" ]; then
338 USE_GDBSERVER="y"
339 DEV_MODE="y"
340 TIME_OUT="n"
Alex Lighte4b4a182019-02-12 14:19:49 -0800341 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100342 elif [ "x$1" = "x--gdb" ]; then
343 USE_GDB="y"
344 DEV_MODE="y"
Brian Carlstrom93d6ce52014-11-04 22:31:35 -0800345 TIME_OUT="n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100346 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700347 elif [ "x$1" = "x--gdb-arg" ]; then
348 shift
349 gdb_arg="$1"
350 GDB_ARGS="${GDB_ARGS} $gdb_arg"
351 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100352 elif [ "x$1" = "x--zygote" ]; then
353 ZYGOTE="-Xzygote"
354 msg "Spawning from zygote"
355 shift
356 elif [ "x$1" = "x--dev" ]; then
357 DEV_MODE="y"
358 shift
359 elif [ "x$1" = "x--interpreter" ]; then
360 INTERPRETER="y"
361 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800362 elif [ "x$1" = "x--jit" ]; then
363 JIT="y"
364 shift
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100365 elif [ "x$1" = "x--baseline" ]; then
366 FLAGS="${FLAGS} -Xcompiler-option --baseline"
Nicolas Geoffray9b195cc2019-04-02 08:29:00 +0100367 COMPILE_FLAGS="${COMPILE_FLAGS} --baseline"
Nicolas Geoffrayacc56ac2018-10-09 08:45:24 +0100368 shift
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100369 elif [ "x$1" = "x--jvm" ]; then
370 USE_JVM="y"
371 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100372 elif [ "x$1" = "x--invoke-with" ]; then
373 shift
374 if [ "x$1" = "x" ]; then
375 echo "$0 missing argument to --invoke-with" 1>&2
376 exit 1
377 fi
378 if [ "x$INVOKE_WITH" = "x" ]; then
379 INVOKE_WITH="$1"
380 else
381 INVOKE_WITH="$INVOKE_WITH $1"
382 fi
383 shift
384 elif [ "x$1" = "x--no-verify" ]; then
385 VERIFY="n"
386 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700387 elif [ "x$1" = "x--verify-soft-fail" ]; then
388 VERIFY="s"
389 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100390 elif [ "x$1" = "x--no-optimize" ]; then
391 OPTIMIZE="n"
392 shift
Roland Levillain76cfe612017-10-30 13:14:28 +0000393 elif [ "x$1" = "x--chroot" ]; then
394 shift
395 CHROOT="$1"
396 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000397 elif [ "x$1" = "x--android-root" ]; then
398 shift
399 ANDROID_ROOT="$1"
400 shift
Victor Chang64611242019-07-05 16:32:41 +0100401 elif [ "x$1" = "x--android-i18n-root" ]; then
402 shift
403 ANDROID_I18N_ROOT="$1"
404 shift
Martin Stjernholme58624f2019-09-20 15:53:40 +0100405 elif [ "x$1" = "x--android-art-root" ]; then
Roland Levillain28076142019-01-10 16:39:25 +0000406 shift
Martin Stjernholme58624f2019-09-20 15:53:40 +0100407 ANDROID_ART_ROOT="$1"
Roland Levillain28076142019-01-10 16:39:25 +0000408 shift
Neil Fuller26a5dd62019-03-13 15:16:35 +0000409 elif [ "x$1" = "x--android-tzdata-root" ]; then
410 shift
411 ANDROID_TZDATA_ROOT="$1"
412 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700413 elif [ "x$1" = "x--instruction-set-features" ]; then
414 shift
415 INSTRUCTION_SET_FEATURES="$1"
416 shift
Mathieu Chartier2576be22016-05-24 10:24:53 -0700417 elif [ "x$1" = "x--timeout" ]; then
418 shift
419 TIME_OUT_VALUE="$1"
420 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100421 elif [ "x$1" = "x--" ]; then
422 shift
423 break
424 elif [ "x$1" = "x--64" ]; then
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +0100425 SUFFIX64="64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100426 ISA="x86_64"
Alex Lighte4b4a182019-02-12 14:19:49 -0800427 GDBSERVER_DEVICE="gdbserver64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100428 DALVIKVM="dalvikvm64"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000429 LIBRARY_DIRECTORY="lib64"
Colin Crossafd3c9e2016-09-16 13:47:21 -0700430 TEST_DIRECTORY="nativetest64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100431 ARCHITECTURES_PATTERN="${ARCHITECTURES_64}"
Roland Levillain72f67742019-03-06 15:48:08 +0000432 GET_DEVICE_ISA_BITNESS_FLAG="--64"
Nicolas Geoffrayb0c6cb52020-04-20 15:12:42 +0100433 DEX2OAT_NDEBUG_BINARY="dex2oat64"
434 DEX2OAT_DEBUG_BINARY="dex2oatd64"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100435 shift
Alex Light8a0e0332015-10-26 10:11:58 -0700436 elif [ "x$1" = "x--experimental" ]; then
437 if [ "$#" -lt 2 ]; then
438 echo "missing --experimental option" 1>&2
439 exit 1
440 fi
441 EXPERIMENTAL="$EXPERIMENTAL $2"
442 shift 2
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -0700443 elif [ "x$1" = "x--external-log-tags" ]; then
444 EXTERNAL_LOG_TAGS="y"
445 shift
446 elif [ "x$1" = "x--dry-run" ]; then
447 DRY_RUN="y"
448 shift
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000449 elif [ "x$1" = "x--vdex" ]; then
450 TEST_VDEX="y"
451 shift
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000452 elif [ "x$1" = "x--dm" ]; then
453 TEST_DM="y"
454 shift
Nicolas Geoffray74981052017-01-16 17:54:09 +0000455 elif [ "x$1" = "x--vdex-filter" ]; then
456 shift
457 option="$1"
David Brazdilfeb22822019-02-13 21:25:57 +0000458 VDEX_ARGS="${VDEX_ARGS} --compiler-filter=$option"
459 shift
460 elif [ "x$1" = "x--vdex-arg" ]; then
461 shift
462 VDEX_ARGS="${VDEX_ARGS} $1"
Nicolas Geoffray74981052017-01-16 17:54:09 +0000463 shift
Igor Murashkin271a0f82017-02-14 21:14:17 +0000464 elif [ "x$1" = "x--sync" ]; then
465 SYNC_BEFORE_RUN="y"
466 shift
Calin Juravle13439f02017-02-21 01:17:21 -0800467 elif [ "x$1" = "x--profile" ]; then
468 PROFILE="y"
469 shift
Jeff Hao002b9312017-03-27 16:23:08 -0700470 elif [ "x$1" = "x--random-profile" ]; then
471 RANDOM_PROFILE="y"
472 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100473 elif expr "x$1" : "x--" >/dev/null 2>&1; then
474 echo "unknown $0 option: $1" 1>&2
475 exit 1
476 else
477 break
478 fi
479done
480
Roland Levillainb59f5fb2020-02-19 16:22:48 +0000481# HACK: Force the use of `signal_dumper` on host.
Roland Levillain505e56b2019-11-20 08:49:24 +0000482if [[ "$HOST" = "y" ]]; then
483 TIME_OUT="timeout"
484fi
485
Andreas Gampe6ad30a22019-09-12 15:12:36 -0700486# If you change this, update the timeout in testrunner.py as well.
487if [ -z "$TIME_OUT_VALUE" ] ; then
488 # 10 minutes is the default.
489 TIME_OUT_VALUE=600
490
491 # For sanitized builds use a larger base.
492 # TODO: Consider sanitized target builds?
493 if [ "x$SANITIZE_HOST" != "x" ] ; then
494 TIME_OUT_VALUE=1500 # 25 minutes.
495 fi
496
Martin Stjernholmcb497cf2019-09-27 18:42:55 +0100497 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} + ${TIME_OUT_EXTRA}))
Andreas Gampe6ad30a22019-09-12 15:12:36 -0700498fi
499
Andreas Gampe29bfb0c2019-09-12 15:17:43 -0700500# Escape hatch for slow hosts or devices. Accept an environment variable as a timeout factor.
501if [ ! -z "$ART_TIME_OUT_MULTIPLIER" ] ; then
Martin Stjernholm82e61e92019-09-30 02:43:18 +0000502 TIME_OUT_VALUE=$((${TIME_OUT_VALUE} * ${ART_TIME_OUT_MULTIPLIER}))
Andreas Gampe29bfb0c2019-09-12 15:17:43 -0700503fi
504
Roland Levillain76cfe612017-10-30 13:14:28 +0000505# The DEX_LOCATION with the chroot prefix, if any.
506CHROOT_DEX_LOCATION="$CHROOT$DEX_LOCATION"
507
Roland Levillain72f67742019-03-06 15:48:08 +0000508# If running on device, determine the ISA of the device.
Roland Levillainb7724c42020-04-21 16:51:54 +0100509if [ "$HOST" = "n" -a "$USE_JVM" = "n" ]; then
Roland Levillain72f67742019-03-06 15:48:08 +0000510 ISA=$("$ANDROID_BUILD_TOP/art/test/utils/get-device-isa" "$GET_DEVICE_ISA_BITNESS_FLAG")
511fi
512
Alex Light8a0e0332015-10-26 10:11:58 -0700513if [ "$USE_JVM" = "n" ]; then
Alex Light7233c7e2016-07-28 10:07:45 -0700514 FLAGS="${FLAGS} ${ANDROID_FLAGS}"
Alex Lightbaac7e42018-06-08 15:30:11 +0000515 # we don't want to be trying to get adbconnections since the plugin might
516 # not have been built.
517 FLAGS="${FLAGS} -XjdwpProvider:none"
Alex Light8a0e0332015-10-26 10:11:58 -0700518 for feature in ${EXPERIMENTAL}; do
Alex Lightfa022852015-10-28 09:13:20 -0700519 FLAGS="${FLAGS} -Xexperimental:${feature} -Xcompiler-option --runtime-arg -Xcompiler-option -Xexperimental:${feature}"
Alex Light8a0e0332015-10-26 10:11:58 -0700520 COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xexperimental:${feature}"
521 done
522fi
523
Alex Light680cbf22018-10-31 11:00:19 -0700524if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
525 ANDROID_ROOT=$DEX_LOCATION/android-root
526fi
527
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100528if [ "x$1" = "x" ] ; then
529 MAIN="Main"
530else
531 MAIN="$1"
Andreas Gampef2fdc732014-06-11 08:20:47 -0700532 shift
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100533fi
534
535if [ "$ZYGOTE" = "" ]; then
536 if [ "$OPTIMIZE" = "y" ]; then
537 if [ "$VERIFY" = "y" ]; then
538 DEX_OPTIMIZE="-Xdexopt:verified"
539 else
540 DEX_OPTIMIZE="-Xdexopt:all"
541 fi
542 msg "Performing optimizations"
543 else
544 DEX_OPTIMIZE="-Xdexopt:none"
545 msg "Skipping optimizations"
546 fi
547
548 if [ "$VERIFY" = "y" ]; then
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100549 JVM_VERIFY_ARG="-Xverify:all"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100550 msg "Performing verification"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700551 elif [ "$VERIFY" = "s" ]; then
552 JVM_VERIFY_ARG="Xverify:all"
553 DEX_VERIFY="-Xverify:softfail"
554 msg "Forcing verification to be soft fail"
555 else # VERIFY = "n"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100556 DEX_VERIFY="-Xverify:none"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100557 JVM_VERIFY_ARG="-Xverify:none"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100558 msg "Skipping verification"
559 fi
560fi
561
562msg "------------------------------"
563
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100564if [ "$DEBUGGER" = "y" ]; then
565 # Use this instead for ddms and connect by running 'ddms':
Alex Lightfc588092020-01-23 15:39:08 -0800566 # DEBUGGER_OPTS="-XjdwpOptions=server=y,suspend=y -XjdwpProvider:adbconnection"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100567 # TODO: add a separate --ddms option?
568
569 PORT=12345
570 msg "Waiting for jdb to connect:"
571 if [ "$HOST" = "n" ]; then
572 msg " adb forward tcp:$PORT tcp:$PORT"
573 fi
574 msg " jdb -attach localhost:$PORT"
Alex Light264a4862018-01-31 16:47:58 +0000575 if [ "$USE_JVM" = "n" ]; then
Alex Lightfc588092020-01-23 15:39:08 -0800576 # Use the default libjdwp agent. Use --debug-agent to use a custom one.
577 DEBUGGER_OPTS="-agentpath:libjdwp.so=transport=dt_socket,address=$PORT,server=y,suspend=y -XjdwpProvider:internal"
Alex Light264a4862018-01-31 16:47:58 +0000578 else
579 DEBUGGER_OPTS="-agentlib:jdwp=transport=dt_socket,address=$PORT,server=y,suspend=y"
580 fi
Alex Lightc281ba52017-10-11 11:35:55 -0700581elif [ "$DEBUGGER" = "agent" ]; then
582 PORT=12345
583 # TODO Support ddms connection and support target.
584 if [ "$HOST" = "n" ]; then
585 echo "--debug-agent not supported yet for target!"
586 exit 1
587 fi
588 AGENTPATH=${DEBUGGER_AGENT}
589 if [ "$WRAP_DEBUGGER_AGENT" = "y" ]; then
590 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentpropertiesd.so"
591 if [ "$TEST_IS_NDEBUG" = "y" ]; then
592 WRAPPROPS="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}/libwrapagentproperties.so"
593 fi
594 AGENTPATH="${WRAPPROPS}=${ANDROID_BUILD_TOP}/art/tools/libjdwp-compat.props,${AGENTPATH}"
595 fi
596 msg "Connect to localhost:$PORT"
597 DEBUGGER_OPTS="-agentpath:${AGENTPATH}=transport=dt_socket,address=$PORT,server=y,suspend=y"
598fi
599
Alex Light54dabfb2018-09-19 16:29:09 -0700600for agent in "${WITH_AGENT[@]}"; do
601 FLAGS="${FLAGS} -agentpath:${agent}"
602done
Alex Light0e151e72017-10-25 10:50:35 -0700603
Alex Lightc281ba52017-10-11 11:35:55 -0700604if [ "$USE_JVMTI" = "y" ]; then
605 if [ "$USE_JVM" = "n" ]; then
606 plugin=libopenjdkjvmtid.so
607 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
608 plugin=libopenjdkjvmti.so
609 fi
Alex Light2ce6fc82017-12-18 16:42:36 -0800610 # We used to add flags here that made the runtime debuggable but that is not
611 # needed anymore since the plugin can do it for us now.
Alex Lightc281ba52017-10-11 11:35:55 -0700612 FLAGS="${FLAGS} -Xplugin:${plugin}"
Alex Lightc281ba52017-10-11 11:35:55 -0700613 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100614fi
615
Alex Light280e6c32020-03-03 13:52:07 -0800616# Add the libdir to the argv passed to the main function.
617if [ "$ADD_LIBDIR_ARGUMENTS" = "y" ]; then
618 if [[ "$HOST" = "y" ]]; then
619 ARGS="${ARGS} ${ANDROID_HOST_OUT}/${TEST_DIRECTORY}/"
620 else
621 ARGS="${ARGS} /data/${TEST_DIRECTORY}/art/${ISA}/"
622 fi
623fi
Alex Lightfba89fe2017-01-12 16:11:02 -0800624if [ "$IS_JVMTI_TEST" = "y" ]; then
Alex Lightfba89fe2017-01-12 16:11:02 -0800625 agent=libtiagentd.so
626 lib=tiagentd
627 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
628 agent=libtiagent.so
Alex Lightfba89fe2017-01-12 16:11:02 -0800629 lib=tiagent
630 fi
631
632 ARGS="${ARGS} ${lib}"
633 if [[ "$USE_JVM" = "y" ]]; then
634 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${TEST_NAME},jvm"
635 else
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +0100636 FLAGS="${FLAGS} -agentpath:${agent}=${TEST_NAME},art"
Alex Lightfba89fe2017-01-12 16:11:02 -0800637 fi
638fi
639
Alex Light8f2c6d42017-04-10 16:27:35 -0700640if [[ "$JVMTI_STRESS" = "y" ]]; then
Alex Light42151c02017-04-20 15:54:25 -0700641 agent=libtistressd.so
642 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
643 agent=libtistress.so
Alex Light42151c02017-04-20 15:54:25 -0700644 fi
Alex Light8f2c6d42017-04-10 16:27:35 -0700645
Alex Lightb7edcda2017-04-27 13:20:31 -0700646 # Just give it a default start so we can always add ',' to it.
647 agent_args="jvmti-stress"
648 if [[ "$JVMTI_REDEFINE_STRESS" = "y" ]]; then
649 # We really cannot do this on RI so don't both passing it in that case.
650 if [[ "$USE_JVM" = "n" ]]; then
Alex Lightceae9542017-09-07 13:28:00 -0700651 agent_args="${agent_args},redefine"
Alex Lightb7edcda2017-04-27 13:20:31 -0700652 fi
653 fi
Alex Light43e935d2017-06-19 15:40:40 -0700654 if [[ "$JVMTI_FIELD_STRESS" = "y" ]]; then
655 agent_args="${agent_args},field"
656 fi
Alex Lightc38c3692017-06-27 15:45:14 -0700657 if [[ "$JVMTI_STEP_STRESS" = "y" ]]; then
658 agent_args="${agent_args},step"
659 fi
Alex Lightb7edcda2017-04-27 13:20:31 -0700660 if [[ "$JVMTI_TRACE_STRESS" = "y" ]]; then
661 agent_args="${agent_args},trace"
662 fi
663 # In the future add onto this;
Alex Light42151c02017-04-20 15:54:25 -0700664 if [[ "$USE_JVM" = "y" ]]; then
Alex Lightb7edcda2017-04-27 13:20:31 -0700665 FLAGS="${FLAGS} -agentpath:${ANDROID_HOST_OUT}/nativetest64/${agent}=${agent_args}"
Alex Light42151c02017-04-20 15:54:25 -0700666 else
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +0100667 FLAGS="${FLAGS} -agentpath:${agent}=${agent_args}"
Alex Light8f2c6d42017-04-10 16:27:35 -0700668 fi
669fi
670
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100671if [ "$USE_JVM" = "y" ]; then
Alex Light9c20a142016-08-23 15:05:12 -0700672 export LD_LIBRARY_PATH=${ANDROID_HOST_OUT}/lib64
Alex Light47d49b82017-07-25 14:06:34 -0700673 # Some jvmti tests are flaky without -Xint on the RI.
674 if [ "$IS_JVMTI_TEST" = "y" ]; then
675 FLAGS="${FLAGS} -Xint"
676 fi
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700677 # Xmx is necessary since we don't pass down the ART flags to JVM.
Vladimir Markoc5798bf2016-12-09 10:20:54 +0000678 # We pass the classes2 path whether it's used (src-multidex) or not.
679 cmdline="${JAVA} ${DEBUGGER_OPTS} ${JVM_VERIFY_ARG} -Xmx256m -classpath classes:classes2 ${FLAGS} $MAIN $@ ${ARGS}"
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700680 if [ "$DEV_MODE" = "y" ]; then
681 echo $cmdline
682 fi
Alex Light8d94ddd2019-12-18 11:13:03 -0800683 if [ "$CREATE_RUNNER" = "y" ]; then
684 echo "#!/bin/bash" > runit.sh
685 echo "export LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH\""
Roland Levillainb15e8792020-10-28 12:20:59 +0000686 echo $cmdline >> runit.sh
Alex Light8d94ddd2019-12-18 11:13:03 -0800687 chmod u+x runit.sh
688 echo "Runnable test script written to $PWD/runit.sh"
689 else
690 $cmdline
691 fi
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100692 exit
693fi
694
Vladimir Marko0ace5632018-12-14 11:11:47 +0000695# Note: This must start with the CORE_IMG_JARS in Android.common_path.mk
David Srbecky6355d692020-03-26 14:10:26 +0000696# because that's what we use for compiling the boot.art image.
Vladimir Marko0ace5632018-12-14 11:11:47 +0000697# It may contain additional modules from TEST_CORE_JARS.
Victor Changd20e51d2020-05-05 16:01:19 +0100698bpath_modules="core-oj core-libart okhttp bouncycastle apache-xml core-icu4j conscrypt"
Nicolas Geoffray31e0dc22020-03-20 15:48:09 +0000699bpath=""
700bpath_locations=""
701bpath_separator=""
David Srbecky928d28e2020-04-01 17:50:51 +0100702bpath_prefix=""
703bpath_location_prefix=""
Ulya Trafimovich5439f052020-07-29 10:03:46 +0100704if [ "${HOST}" = "y" ]; then
David Srbecky928d28e2020-04-01 17:50:51 +0100705 bpath_prefix="${ANDROID_HOST_OUT}"
706 if [ "${ANDROID_HOST_OUT:0:${#ANDROID_BUILD_TOP}+1}" = "${ANDROID_BUILD_TOP}/" ]; then
707 bpath_location_prefix="${ANDROID_HOST_OUT:${#ANDROID_BUILD_TOP}+1}"
708 else
709 echo "error: ANDROID_BUILD_TOP/ is not a prefix of ANDROID_HOST_OUT"
710 echo "ANDROID_BUILD_TOP=${ANDROID_BUILD_TOP}"
711 echo "ANDROID_HOST_OUT=${ANDROID_HOST_OUT}"
712 exit
713 fi
Vladimir Marko7a85e702018-12-03 18:47:23 +0000714fi
David Srbecky928d28e2020-04-01 17:50:51 +0100715for bpath_module in ${bpath_modules}; do
716 apex_module="com.android.art"
717 case "$bpath_module" in
718 (conscrypt) apex_module="com.android.conscrypt";;
719 (core-icu4j) apex_module="com.android.i18n";;
720 (*) apex_module="com.android.art";;
721 esac
722 bpath_jar="/apex/${apex_module}/javalib/${bpath_module}.jar"
723 bpath+="${bpath_separator}${bpath_prefix}${bpath_jar}"
724 bpath_locations+="${bpath_separator}${bpath_location_prefix}${bpath_jar}"
725 bpath_separator=":"
726done
Vladimir Marko7a85e702018-12-03 18:47:23 +0000727# Pass down the bootclasspath
728FLAGS="${FLAGS} -Xbootclasspath:${bpath}"
729FLAGS="${FLAGS} -Xbootclasspath-locations:${bpath_locations}"
730COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath:${bpath}"
731COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xbootclasspath-locations:${bpath_locations}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100732
733if [ "$HAVE_IMAGE" = "n" ]; then
Andreas Gampe1078d152017-11-07 18:00:54 -0800734 # Disable image dex2oat - this will forbid the runtime to patch or compile an image.
735 FLAGS="${FLAGS} -Xnoimage-dex2oat"
736
737 # We'll abuse a second flag here to test different behavior. If --relocate, use the
738 # existing image - relocation will fail as patching is disallowed. If --no-relocate,
739 # pass a non-existent image - compilation will fail as dex2oat is disallowed.
740 if [ "${RELOCATE}" = "y" ] ; then
741 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
742 else
David Srbecky6355d692020-03-26 14:10:26 +0000743 DALVIKVM_BOOT_OPT="-Ximage:/system/non-existent/boot.art"
Andreas Gampe1078d152017-11-07 18:00:54 -0800744 fi
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000745else
746 DALVIKVM_BOOT_OPT="-Ximage:${BOOT_IMAGE}"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100747fi
748
749
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100750if [ "$USE_GDB" = "y" ]; then
Alex Lighte4b4a182019-02-12 14:19:49 -0800751 if [ "$USE_GDBSERVER" = "y" ]; then
752 echo "Cannot pass both --gdb and --gdbserver at the same time!" >&2
753 exit 1
754 elif [ "$HOST" = "n" ]; then
Alex Light219420e2019-12-05 10:20:26 -0800755 # We might not have any hostname resolution if we are using a chroot.
756 GDB="$GDBSERVER_DEVICE --no-startup-with-shell 127.0.0.1$GDBSERVER_PORT"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100757 else
758 if [ `uname` = "Darwin" ]; then
759 GDB=lldb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700760 GDB_ARGS="$GDB_ARGS -- $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100761 DALVIKVM=
762 else
763 GDB=gdb
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700764 GDB_ARGS="$GDB_ARGS --args $DALVIKVM"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100765 # Enable for Emacs "M-x gdb" support. TODO: allow extra gdb arguments on command line.
766 # gdbargs="--annotate=3 $gdbargs"
767 fi
768 fi
Alex Lighte4b4a182019-02-12 14:19:49 -0800769elif [ "$USE_GDBSERVER" = "y" ]; then
770 if [ "$HOST" = "n" ]; then
Alex Light219420e2019-12-05 10:20:26 -0800771 # We might not have any hostname resolution if we are using a chroot.
772 GDB="$GDBSERVER_DEVICE --no-startup-with-shell 127.0.0.1$GDBSERVER_PORT"
773 else
774 GDB="$GDBSERVER_HOST $GDBSERVER_PORT"
Alex Lighte4b4a182019-02-12 14:19:49 -0800775 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100776fi
777
778if [ "$INTERPRETER" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100779 INT_OPTS="${INT_OPTS} -Xint"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100780fi
781
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800782if [ "$JIT" = "y" ]; then
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100783 INT_OPTS="${INT_OPTS} -Xusejit:true"
Nicolas Geoffraya5ca8eb2018-08-24 13:39:13 +0100784else
785 INT_OPTS="${INT_OPTS} -Xusejit:false"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800786fi
787
Nicolas Geoffrayc76fbf02021-04-06 08:59:17 +0100788if [ "$INTERPRETER" = "y" ] || [ "$JIT" = "y" ]; then
789 if [ "$VERIFY" = "y" ] ; then
790 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=verify"
791 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=verify"
792 elif [ "$VERIFY" = "s" ]; then
793 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=extract"
794 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=extract"
795 DEX_VERIFY="${DEX_VERIFY} -Xverify:softfail"
796 else # VERIFY = "n"
797 INT_OPTS="${INT_OPTS} -Xcompiler-option --compiler-filter=assume-verified"
798 COMPILE_FLAGS="${COMPILE_FLAGS} --compiler-filter=assume-verified"
799 DEX_VERIFY="${DEX_VERIFY} -Xverify:none"
800 fi
801fi
802
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100803JNI_OPTS="-Xjnigreflimit:512 -Xcheck:jni"
804
Richard Uhler020c0f32017-03-14 16:23:17 +0000805COMPILE_FLAGS="${COMPILE_FLAGS} --runtime-arg -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100806if [ "$RELOCATE" = "y" ]; then
Richard Uhlerc52f3032017-03-02 13:45:45 +0000807 FLAGS="${FLAGS} -Xrelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100808else
809 FLAGS="$FLAGS -Xnorelocate"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100810fi
811
Alex Light680cbf22018-10-31 11:00:19 -0700812if [ "$BIONIC" = "y" ]; then
813 # This is the location that soong drops linux_bionic builds. Despite being
814 # called linux_bionic-x86 the build is actually amd64 (x86_64) only.
815 if [ ! -e "$OUT_DIR/soong/host/linux_bionic-x86" ]; then
816 echo "linux_bionic-x86 target doesn't seem to have been built!" >&2
817 exit 1
818 fi
Andreas Gampe148c1602019-06-10 16:47:46 -0700819 # Set TIMEOUT_DUMPER manually so it works even with apex's
820 TIMEOUT_DUMPER=$OUT_DIR/soong/host/linux_bionic-x86/bin/signal_dumper
Alex Light680cbf22018-10-31 11:00:19 -0700821fi
822
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700823# Prevent test from silently falling back to interpreter in no-prebuild mode. This happens
824# when DEX_LOCATION path is too long, because vdex/odex filename is constructed by taking
825# full path to dex, stripping leading '/', appending '@classes.vdex' and changing every
826# remaining '/' into '@'.
827if [ "$HOST" = "y" ]; then
828 max_filename_size=$(getconf NAME_MAX $DEX_LOCATION)
829else
Roland Levillain2ae376f2018-01-30 11:35:11 +0000830 # There is no getconf on device, fallback to standard value.
831 # See NAME_MAX in kernel <linux/limits.h>
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700832 max_filename_size=255
833fi
834# Compute VDEX_NAME.
835DEX_LOCATION_STRIPPED="${DEX_LOCATION#/}"
836VDEX_NAME="${DEX_LOCATION_STRIPPED//\//@}@$TEST_NAME.jar@classes.vdex"
837if [ ${#VDEX_NAME} -gt $max_filename_size ]; then
Nicolas Geoffraybea3e312017-03-07 09:59:05 +0000838 echo "Dex location path too long:"
839 echo "$VDEX_NAME is ${#VDEX_NAME} character long, and the limit is $max_filename_size."
Wojciech Staszkiewicze6636532016-09-23 10:59:55 -0700840 exit 1
841fi
842
Ulya Trafimovich5439f052020-07-29 10:03:46 +0100843if [ "$HOST" = "y" ]; then
Roland Levillain72f67742019-03-06 15:48:08 +0000844 # On host, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the `bin`
845 # directory under the "Android Root" (usually `out/host/linux-x86`).
846 #
847 # TODO(b/130295968): Adjust this if/when ART host artifacts are installed
Martin Stjernholme58624f2019-09-20 15:53:40 +0100848 # under the ART root (usually `out/host/linux-x86/com.android.art`).
849 ANDROID_ART_BIN_DIR=$ANDROID_ROOT/bin
Roland Levillain72f67742019-03-06 15:48:08 +0000850else
Martin Stjernholme58624f2019-09-20 15:53:40 +0100851 # On target, run binaries (`dex2oat(d)`, `dalvikvm`, `profman`) from the ART
852 # APEX's `bin` directory. This means the linker will observe the ART APEX
853 # linker configuration file (`/apex/com.android.art/etc/ld.config.txt`) for
854 # these binaries.
855 ANDROID_ART_BIN_DIR=$ANDROID_ART_ROOT/bin
Roland Levillain72f67742019-03-06 15:48:08 +0000856fi
Alex Light20802ca2018-12-05 15:36:03 -0800857
Calin Juravle13439f02017-02-21 01:17:21 -0800858profman_cmdline="true"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100859dex2oat_cmdline="true"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000860vdex_cmdline="true"
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000861dm_cmdline="true"
Andreas Gampeb09abb22018-05-03 11:51:22 -0700862mkdir_locations="${DEX_LOCATION}/dalvik-cache/$ISA"
Richard Uhler76f5cb62016-04-04 13:30:16 -0700863strip_cmdline="true"
Igor Murashkin271a0f82017-02-14 21:14:17 +0000864sync_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700865linkroot_cmdline="true"
866linkroot_overlay_cmdline="true"
Alex Light20802ca2018-12-05 15:36:03 -0800867setupapex_cmdline="true"
868installapex_cmdline="true"
Alex Light5e1ffcd2021-03-31 16:46:02 -0700869installapex_test_cmdline="true"
Alex Light680cbf22018-10-31 11:00:19 -0700870
871linkdirs() {
872 find "$1" -maxdepth 1 -mindepth 1 -type d | xargs -i ln -sf '{}' "$2"
873}
874
875if [ "$CREATE_ANDROID_ROOT" = "y" ]; then
876 mkdir_locations="${mkdir_locations} ${ANDROID_ROOT}"
877 linkroot_cmdline="linkdirs ${ANDROID_HOST_OUT} ${ANDROID_ROOT}"
878 if [ "${BIONIC}" = "y" ]; then
879 # TODO Make this overlay more generic.
880 linkroot_overlay_cmdline="linkdirs $OUT_DIR/soong/host/linux_bionic-x86 ${ANDROID_ROOT}"
881 fi
882fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100883
Alex Light20802ca2018-12-05 15:36:03 -0800884if [ "$USE_ZIPAPEX" = "y" ]; then
885 # TODO Currently this only works for linux_bionic zipapexes because those are
886 # stripped and so small enough that the ulimit doesn't kill us.
887 mkdir_locations="${mkdir_locations} $DEX_LOCATION/zipapex"
888 zip_options="-qq"
889 if [ "$DEV_MODE" = "y" ]; then
890 zip_options=""
891 fi
Alex Lightfc52ffc2019-01-31 15:48:18 -0800892 setupapex_cmdline="unzip -o -u ${zip_options} ${ZIPAPEX_LOC} apex_payload.zip -d ${DEX_LOCATION}"
893 installapex_cmdline="unzip -o -u ${zip_options} ${DEX_LOCATION}/apex_payload.zip -d ${DEX_LOCATION}/zipapex"
Martin Stjernholme58624f2019-09-20 15:53:40 +0100894 ANDROID_ART_BIN_DIR=$DEX_LOCATION/zipapex/bin
Alex Light6f342dd2019-03-27 17:15:42 +0000895elif [ "$USE_EXTRACTED_ZIPAPEX" = "y" ]; then
896 # Just symlink the zipapex binaries
Martin Stjernholme58624f2019-09-20 15:53:40 +0100897 ANDROID_ART_BIN_DIR=$DEX_LOCATION/zipapex/bin
Alex Light6f342dd2019-03-27 17:15:42 +0000898 # Force since some tests manually run this file twice.
899 ln_options=""
900 if [ "$DEV_MODE" = "y" ]; then
901 ln_options="--verbose"
902 fi
Alex Light5e1ffcd2021-03-31 16:46:02 -0700903 # If the ${RUN} is executed multiple times we don't need to recreate the link
904 installapex_test_cmdline="test -L ${DEX_LOCATION}/zipapex"
Alex Light6f342dd2019-03-27 17:15:42 +0000905 installapex_cmdline="ln -s -f ${ln_options} ${EXTRACTED_ZIPAPEX_LOC} ${DEX_LOCATION}/zipapex"
Alex Light20802ca2018-12-05 15:36:03 -0800906fi
907
Jeff Hao002b9312017-03-27 16:23:08 -0700908# PROFILE takes precedence over RANDOM_PROFILE, since PROFILE tests require a
909# specific profile to run properly.
910if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Martin Stjernholme58624f2019-09-20 15:53:40 +0100911 profman_cmdline="$ANDROID_ART_BIN_DIR/profman \
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000912 --apk=$DEX_LOCATION/$TEST_NAME.jar \
Jeff Hao002b9312017-03-27 16:23:08 -0700913 --dex-location=$DEX_LOCATION/$TEST_NAME.jar"
Andreas Gampe038a1982020-03-11 23:06:42 +0000914 if [ -f "$TEST_NAME-ex.jar" ] && [ "$SECONDARY_COMPILATION" = "y" ] ; then
Calin Juravle6df62f72017-04-28 19:58:01 -0700915 profman_cmdline="${profman_cmdline} \
916 --apk=$DEX_LOCATION/$TEST_NAME-ex.jar \
917 --dex-location=$DEX_LOCATION/$TEST_NAME-ex.jar"
918 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000919 COMPILE_FLAGS="${COMPILE_FLAGS} --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
920 FLAGS="${FLAGS} -Xcompiler-option --profile-file=$DEX_LOCATION/$TEST_NAME.prof"
Jeff Hao002b9312017-03-27 16:23:08 -0700921 if [ "$PROFILE" = "y" ]; then
922 profman_cmdline="${profman_cmdline} --create-profile-from=$DEX_LOCATION/profile \
923 --reference-profile-file=$DEX_LOCATION/$TEST_NAME.prof"
924 else
925 profman_cmdline="${profman_cmdline} --generate-test-profile=$DEX_LOCATION/$TEST_NAME.prof \
926 --generate-test-profile-seed=0"
927 fi
Nicolas Geoffray0b6a6382017-03-10 09:38:35 +0000928fi
929
Andreas Gampe038a1982020-03-11 23:06:42 +0000930function write_dex2oat_cmdlines {
931 local name="$1"
David Srbeckyb0ec6792020-02-06 20:18:17 +0000932
Andreas Gampe038a1982020-03-11 23:06:42 +0000933 local class_loader_context=""
934 local enable_app_image=false
Calin Juravle857f0582016-12-20 14:36:59 +0000935 if [ "$APP_IMAGE" = "y" ]; then
Andreas Gampe038a1982020-03-11 23:06:42 +0000936 enable_app_image=true
Calin Juravle857f0582016-12-20 14:36:59 +0000937 fi
938
Andreas Gampe038a1982020-03-11 23:06:42 +0000939 # If the name ends in -ex then this is a secondary dex file
940 if [ "${name:${#name}-3}" = "-ex" ]; then
941 # Lazily realize the default value in case DEX_LOCATION/TEST_NAME change
942 [ -z "$SECONDARY_CLASS_LOADER_CONTEXT" ] && SECONDARY_CLASS_LOADER_CONTEXT="PCL[];PCL[$DEX_LOCATION/$TEST_NAME.jar]"
943 class_loader_context="'--class-loader-context=$SECONDARY_CLASS_LOADER_CONTEXT'"
944 $enable_app_image && [ "$SECONDARY_APP_IMAGE" = "y" ] || enable_app_image=false
945 fi
946
947 local app_image=""
948 $enable_app_image && app_image="--app-image-file=$DEX_LOCATION/oat/$ISA/$name.art --resolve-startup-const-strings=true"
949
950 local dex2oat_binary
Alex Light907001d2019-01-17 00:16:04 +0000951 dex2oat_binary=${DEX2OAT_DEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +0100952 if [[ "$TEST_IS_NDEBUG" = "y" ]]; then
Alex Light907001d2019-01-17 00:16:04 +0000953 dex2oat_binary=${DEX2OAT_NDEBUG_BINARY}
Roland Levillain6c3af162017-04-27 11:18:56 +0100954 fi
Martin Stjernholme58624f2019-09-20 15:53:40 +0100955 dex2oat_cmdline="$INVOKE_WITH $ANDROID_ART_BIN_DIR/$dex2oat_binary \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100956 $COMPILE_FLAGS \
Nicolas Geoffray68e25eb2014-10-29 23:02:11 +0000957 --boot-image=${BOOT_IMAGE} \
Andreas Gampe038a1982020-03-11 23:06:42 +0000958 --dex-file=$DEX_LOCATION/$name.jar \
959 --oat-file=$DEX_LOCATION/oat/$ISA/$name.odex \
960 "$app_image" \
David Srbecky87712da2020-01-17 15:50:02 +0000961 --generate-mini-debug-info \
Andreas Gampe038a1982020-03-11 23:06:42 +0000962 --instruction-set=$ISA \
963 $class_loader_context"
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700964 if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
965 dex2oat_cmdline="${dex2oat_cmdline} --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
966 fi
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700967
968 # Add in a timeout. This is important for testing the compilation/verification time of
969 # pathological cases.
970 # Note: as we don't know how decent targets are (e.g., emulator), only do this on the host for
971 # now. We should try to improve this.
972 # The current value is rather arbitrary. run-tests should compile quickly.
Alex Light483208d2017-09-26 09:31:17 -0700973 # Watchdog timeout is in milliseconds so add 3 '0's to the dex2oat timeout.
Andreas Gampe2ea7b702015-08-07 08:07:16 -0700974 if [ "$HOST" != "n" ]; then
975 # Use SIGRTMIN+2 to try to dump threads.
976 # Use -k 1m to SIGKILL it a minute later if it hasn't ended.
Alex Light483208d2017-09-26 09:31:17 -0700977 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 -0700978 fi
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100979 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Andreas Gampe038a1982020-03-11 23:06:42 +0000980 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex --output-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex"
Nicolas Geoffrayfbc4f112017-04-27 21:45:35 +0100981 elif [ "$TEST_VDEX" = "y" ]; then
Nicolas Geoffrayc6c6a152021-03-01 13:51:22 +0000982 if [ "$VDEX_ARGS" = "" ]; then
983 # If no arguments need to be passed, just delete the odex file so that the runtime only picks up the vdex file.
984 vdex_cmdline="rm $DEX_LOCATION/oat/$ISA/$name.odex"
985 else
986 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --input-vdex=$DEX_LOCATION/oat/$ISA/$name.vdex"
987 fi
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +0000988 elif [ "$TEST_DM" = "y" ]; then
Calin Juravle046cecf2020-12-07 18:31:28 -0800989 dex2oat_cmdline="${dex2oat_cmdline} --copy-dex-files=false --output-vdex=$DEX_LOCATION/oat/$ISA/primary.vdex"
Andreas Gampe038a1982020-03-11 23:06:42 +0000990 dm_cmdline="zip -qj $DEX_LOCATION/oat/$ISA/$name.dm $DEX_LOCATION/oat/$ISA/primary.vdex"
991 vdex_cmdline="${dex2oat_cmdline} ${VDEX_ARGS} --dump-timings --dm-file=$DEX_LOCATION/oat/$ISA/$name.dm"
992 fi
993}
994
995# Enable mini-debug-info for JIT (if JIT is used).
996FLAGS="$FLAGS -Xcompiler-option --generate-mini-debug-info"
997
998if [ "$PREBUILD" = "y" ]; then
999 mkdir_locations="${mkdir_locations} ${DEX_LOCATION}/oat/$ISA"
1000
1001 # "Primary".
1002 write_dex2oat_cmdlines "$TEST_NAME"
1003 dex2oat_cmdline=$(echo $dex2oat_cmdline)
1004 dm_cmdline=$(echo $dm_cmdline)
1005 vdex_cmdline=$(echo $vdex_cmdline)
1006
1007 # Enable mini-debug-info for JIT (if JIT is used).
1008 FLAGS="$FLAGS -Xcompiler-option --generate-mini-debug-info"
1009
1010 if [ -f "$TEST_NAME-ex.jar" ] && [ "$SECONDARY_COMPILATION" = "y" ] ; then
1011 # "Secondary" for test coverage.
1012
1013 # Store primary values.
1014 base_dex2oat_cmdline="$dex2oat_cmdline"
1015 base_dm_cmdline="$dm_cmdline"
1016 base_vdex_cmdline="$vdex_cmdline"
1017
1018 write_dex2oat_cmdlines "$TEST_NAME-ex"
1019 dex2oat_cmdline=$(echo $dex2oat_cmdline)
1020 dm_cmdline=$(echo $dm_cmdline)
1021 vdex_cmdline=$(echo $vdex_cmdline)
1022
1023 # Concatenate.
1024 dex2oat_cmdline="$base_dex2oat_cmdline && $dex2oat_cmdline"
1025 dm_cmdline="$base_dm_cmdline" # Only use primary dm.
1026 vdex_cmdline="$base_vdex_cmdline && $vdex_cmdline"
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001027 fi
Andreas Gampe4d2ef332015-08-05 09:24:45 -07001028fi
1029
Igor Murashkin271a0f82017-02-14 21:14:17 +00001030if [ "$SYNC_BEFORE_RUN" = "y" ]; then
1031 sync_cmdline="sync"
1032fi
1033
Andreas Gampe4d2ef332015-08-05 09:24:45 -07001034DALVIKVM_ISA_FEATURES_ARGS=""
1035if [ "x$INSTRUCTION_SET_FEATURES" != "x" ] ; then
1036 DALVIKVM_ISA_FEATURES_ARGS="-Xcompiler-option --instruction-set-features=${INSTRUCTION_SET_FEATURES}"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001037fi
1038
Nicolas Geoffrayc5256042015-12-26 19:41:37 +00001039# java.io.tmpdir can only be set at launch time.
1040TMP_DIR_OPTION=""
1041if [ "$HOST" = "n" ]; then
1042 TMP_DIR_OPTION="-Djava.io.tmpdir=/data/local/tmp"
1043fi
1044
Alex Lightb8012102019-11-13 01:41:04 +00001045# The build servers have an ancient version of bash so we cannot use @Q.
1046if [ "$USE_GDBSERVER" == "y" ]; then
1047 printf -v QUOTED_DALVIKVM_BOOT_OPT "%q" "$DALVIKVM_BOOT_OPT"
1048else
1049 QUOTED_DALVIKVM_BOOT_OPT="$DALVIKVM_BOOT_OPT"
1050fi
1051
Nicolas Geoffray6ee49712018-03-30 14:39:05 +00001052# We set DumpNativeStackOnSigQuit to false to avoid stressing libunwind.
1053# b/27185632
1054# b/24664297
Martin Stjernholme58624f2019-09-20 15:53:40 +01001055dalvikvm_cmdline="$INVOKE_WITH $GDB $ANDROID_ART_BIN_DIR/$DALVIKVM \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001056 $GDB_ARGS \
1057 $FLAGS \
Andreas Gampe2b0fa5b2014-10-31 18:12:30 -07001058 $DEX_VERIFY \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001059 -XXlib:$LIB \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001060 $DEX2OAT \
Andreas Gampe4d2ef332015-08-05 09:24:45 -07001061 $DALVIKVM_ISA_FEATURES_ARGS \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001062 $ZYGOTE \
1063 $JNI_OPTS \
1064 $INT_OPTS \
1065 $DEBUGGER_OPTS \
Alex Lightb8012102019-11-13 01:41:04 +00001066 ${QUOTED_DALVIKVM_BOOT_OPT} \
Nicolas Geoffrayc5256042015-12-26 19:41:37 +00001067 $TMP_DIR_OPTION \
Nicolas Geoffray6ee49712018-03-30 14:39:05 +00001068 -XX:DumpNativeStackOnSigQuit:false \
Mathieu Chartier031768a2015-08-27 10:25:02 -07001069 -cp $DEX_LOCATION/$TEST_NAME.jar$SECONDARY_DEX $MAIN $ARGS"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001070
Andreas Gampe038a1982020-03-11 23:06:42 +00001071sanitize_dex2oat_cmdline() {
1072 local args=()
1073 for arg in "$@"; do
1074 if [ "$arg" = "--class-loader-context=&" ]; then
1075 arg="--class-loader-context=\&"
1076 fi
1077 args+=("$arg")
1078 done
1079 echo -n "${args[@]}"
1080}
1081
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -08001082# Remove whitespace.
Andreas Gampe038a1982020-03-11 23:06:42 +00001083dex2oat_cmdline=$(sanitize_dex2oat_cmdline $(echo $dex2oat_cmdline))
Andreas Gampe3ad5d5e2015-02-03 18:26:55 -08001084dalvikvm_cmdline=$(echo $dalvikvm_cmdline)
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001085dm_cmdline=$(echo $dm_cmdline)
Andreas Gampe038a1982020-03-11 23:06:42 +00001086vdex_cmdline=$(sanitize_dex2oat_cmdline $(echo $vdex_cmdline))
Calin Juravle13439f02017-02-21 01:17:21 -08001087profman_cmdline=$(echo $profman_cmdline)
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001088
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001089# Use an empty ASAN_OPTIONS to enable defaults.
1090# Note: this is required as envsetup right now exports detect_leaks=0.
1091RUN_TEST_ASAN_OPTIONS=""
1092
Andreas Gampe58408392017-05-16 10:45:46 -07001093# Multiple shutdown leaks. b/38341789
1094if [ "x$RUN_TEST_ASAN_OPTIONS" != "x" ] ; then
1095 RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}:"
1096fi
1097RUN_TEST_ASAN_OPTIONS="${RUN_TEST_ASAN_OPTIONS}detect_leaks=0"
1098
Vladimir Markoa497a392018-09-26 10:52:50 +01001099# For running, we must turn off logging when dex2oat is missing. Otherwise we use
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001100# the same defaults as for prebuilt: everything when --dev, otherwise errors and above only.
1101if [ "$EXTERNAL_LOG_TAGS" = "n" ]; then
1102 if [ "$DEV_MODE" = "y" ]; then
1103 export ANDROID_LOG_TAGS='*:d'
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001104 elif [ "$HAVE_IMAGE" = "n" ]; then
1105 # All tests would log the error of missing image. Be silent here and only log fatal
1106 # events.
1107 export ANDROID_LOG_TAGS='*:s'
1108 else
1109 # We are interested in LOG(ERROR) output.
1110 export ANDROID_LOG_TAGS='*:e'
1111 fi
1112fi
1113
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001114if [ "$HOST" = "n" ]; then
1115 adb root > /dev/null
1116 adb wait-for-device
1117 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001118 adb shell rm -rf $CHROOT_DEX_LOCATION
1119 adb shell mkdir -p $CHROOT_DEX_LOCATION
1120 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION
1121 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION
Jeff Hao002b9312017-03-27 16:23:08 -07001122 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001123 adb push profile $CHROOT_DEX_LOCATION
Calin Juravle13439f02017-02-21 01:17:21 -08001124 fi
David Brazdil7d2ec612018-01-19 14:19:59 +00001125 # Copy resource folder
1126 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001127 adb push res $CHROOT_DEX_LOCATION
David Brazdil7d2ec612018-01-19 14:19:59 +00001128 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001129 else
Roland Levillain76cfe612017-10-30 13:14:28 +00001130 adb shell rm -rf $CHROOT_DEX_LOCATION >/dev/null 2>&1
1131 adb shell mkdir -p $CHROOT_DEX_LOCATION >/dev/null 2>&1
1132 adb push $TEST_NAME.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
1133 adb push $TEST_NAME-ex.jar $CHROOT_DEX_LOCATION >/dev/null 2>&1
Jeff Hao002b9312017-03-27 16:23:08 -07001134 if [ "$PROFILE" = "y" ] || [ "$RANDOM_PROFILE" = "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001135 adb push profile $CHROOT_DEX_LOCATION >/dev/null 2>&1
Calin Juravle13439f02017-02-21 01:17:21 -08001136 fi
David Brazdil7d2ec612018-01-19 14:19:59 +00001137 # Copy resource folder
1138 if [ -d res ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001139 adb push res $CHROOT_DEX_LOCATION >/dev/null 2>&1
David Brazdil7d2ec612018-01-19 14:19:59 +00001140 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001141 fi
1142
Roland Levillain72f67742019-03-06 15:48:08 +00001143 # Populate LD_LIBRARY_PATH.
1144 LD_LIBRARY_PATH=
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001145 if [ "$ANDROID_ROOT" != "/system" ]; then
1146 # Current default installation is dalvikvm 64bits and dex2oat 32bits,
1147 # so we can only use LD_LIBRARY_PATH when testing on a local
1148 # installation.
Roland Levillain72f67742019-03-06 15:48:08 +00001149 LD_LIBRARY_PATH="$ANDROID_ROOT/$LIBRARY_DIRECTORY"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001150 fi
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +01001151
1152 # This adds libarttest(d).so to the default linker namespace when dalvikvm
1153 # is run from /apex/com.android.art/bin. Since that namespace is essentially
1154 # an alias for the com_android_art namespace, that gives libarttest(d).so
1155 # full access to the internal ART libraries.
1156 LD_LIBRARY_PATH="/data/$TEST_DIRECTORY/com.android.art/lib${SUFFIX64}:$LD_LIBRARY_PATH"
1157 if [ "$TEST_IS_NDEBUG" = "y" ]; then dlib=""; else dlib="d"; fi
1158 art_test_internal_libraries=(
1159 libartagent${dlib}.so
1160 libarttest${dlib}.so
1161 libtiagent${dlib}.so
1162 libtistress${dlib}.so
1163 )
1164 art_test_internal_libraries="${art_test_internal_libraries[*]}"
1165 NATIVELOADER_DEFAULT_NAMESPACE_LIBS="${art_test_internal_libraries// /:}"
1166 dlib=
1167 art_test_internal_libraries=
1168
Roland Levillain72f67742019-03-06 15:48:08 +00001169 # Needed to access the test's Odex files.
1170 LD_LIBRARY_PATH="$DEX_LOCATION/oat/$ISA:$LD_LIBRARY_PATH"
1171 # Needed to access the test's native libraries (see e.g. 674-hiddenapi,
1172 # which generates `libhiddenapitest_*.so` libraries in `$DEX_LOCATION`).
1173 LD_LIBRARY_PATH="$DEX_LOCATION:$LD_LIBRARY_PATH"
Nicolas Geoffrayeb441dd2014-10-31 15:34:50 +00001174
Roland Levillain72f67742019-03-06 15:48:08 +00001175 # Prepend directories to the path on device.
Martin Stjernholme58624f2019-09-20 15:53:40 +01001176 PREPEND_TARGET_PATH=$ANDROID_ART_BIN_DIR
Roland Levillain72f67742019-03-06 15:48:08 +00001177 if [ "$ANDROID_ROOT" != "/system" ]; then
1178 PREPEND_TARGET_PATH="$PREPEND_TARGET_PATH:$ANDROID_ROOT/bin"
1179 fi
1180
Andreas Gampe975d70b2019-09-11 11:00:18 -07001181 timeout_dumper_cmd=
Andreas Gampea6138082019-09-11 11:08:23 -07001182
1183 # Check whether signal_dumper is available.
1184 if [ "$TIMEOUT_DUMPER" = signal_dumper ] ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001185 # Chroot? Use as prefix for tests.
1186 TIMEOUT_DUMPER_PATH_PREFIX=
1187 if [ -n "$CHROOT" ]; then
1188 TIMEOUT_DUMPER_PATH_PREFIX="$CHROOT/"
1189 fi
1190
Roland Levillain52b4dc92019-09-12 11:56:52 +01001191 # Testing APEX?
Andreas Gampe5aae3db2019-09-13 10:24:57 -07001192 if adb shell "test -x ${TIMEOUT_DUMPER_PATH_PREFIX}/apex/com.android.art/bin/signal_dumper" ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001193 TIMEOUT_DUMPER="/apex/com.android.art/bin/signal_dumper"
1194 # Is it in /system/bin?
Andreas Gampe5aae3db2019-09-13 10:24:57 -07001195 elif adb shell "test -x ${TIMEOUT_DUMPER_PATH_PREFIX}/system/bin/signal_dumper" ; then
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001196 TIMEOUT_DUMPER="/system/bin/signal_dumper"
Andreas Gampea6138082019-09-11 11:08:23 -07001197 else
Andreas Gampe5d775eb2019-09-13 09:54:55 -07001198 TIMEOUT_DUMPER=
Andreas Gampea6138082019-09-11 11:08:23 -07001199 fi
1200 else
1201 TIMEOUT_DUMPER=
1202 fi
1203
Andreas Gampe975d70b2019-09-11 11:00:18 -07001204 if [ ! -z "$TIMEOUT_DUMPER" ] ; then
1205 # Use "-l" to dump to logcat. That is convenience for the build bot crash symbolization.
Andreas Gampe38a28182019-09-13 11:36:11 -07001206 # Use exit code 124 for toybox timeout (b/141007616).
1207 timeout_dumper_cmd="${TIMEOUT_DUMPER} -l -s 15 -e 124"
Andreas Gampe975d70b2019-09-11 11:00:18 -07001208 fi
1209
1210 timeout_prefix=
1211 if [ "$TIME_OUT" = "timeout" ]; then
1212 # Add timeout command if time out is desired.
1213 #
1214 # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which
1215 # will induce a full thread dump before killing the process. To ensure any issues in
1216 # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the
1217 # child.
1218 # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
David Srbeckya49b04f2019-09-16 14:53:15 +00001219 timeout_prefix="timeout --foreground -k 120s ${TIME_OUT_VALUE}s ${timeout_dumper_cmd} $cmdline"
Andreas Gampe975d70b2019-09-11 11:00:18 -07001220 fi
1221
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001222 # Create a script with the command. The command can get longer than the longest
1223 # allowed adb command and there is no way to get the exit status from a adb shell
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001224 # command. Dalvik cache is cleaned before running to make subsequent executions
1225 # of the script follow the same runtime path.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001226 cmdline="cd $DEX_LOCATION && \
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001227 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001228 export ANDROID_DATA=$DEX_LOCATION && \
1229 export DEX_LOCATION=$DEX_LOCATION && \
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +00001230 export ANDROID_ROOT=$ANDROID_ROOT && \
Victor Chang64611242019-07-05 16:32:41 +01001231 export ANDROID_I18N_ROOT=$ANDROID_I18N_ROOT && \
Martin Stjernholme58624f2019-09-20 15:53:40 +01001232 export ANDROID_ART_ROOT=$ANDROID_ART_ROOT && \
Neil Fuller26a5dd62019-03-13 15:16:35 +00001233 export ANDROID_TZDATA_ROOT=$ANDROID_TZDATA_ROOT && \
Nicolas Geoffrayf39f04c2018-03-05 15:42:11 +00001234 export ANDROID_LOG_TAGS=$ANDROID_LOG_TAGS && \
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001235 rm -rf ${DEX_LOCATION}/dalvik-cache/ && \
Alex Lightafb5d192016-05-24 15:57:45 -07001236 mkdir -p ${mkdir_locations} && \
Sebastien Hertz7cde48c2015-01-20 16:06:43 +01001237 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH && \
Martin Stjernholm0d0f8df2021-04-28 16:47:01 +01001238 export NATIVELOADER_DEFAULT_NAMESPACE_LIBS=$NATIVELOADER_DEFAULT_NAMESPACE_LIBS && \
Roland Levillain72f67742019-03-06 15:48:08 +00001239 export PATH=$PREPEND_TARGET_PATH:\$PATH && \
Calin Juravle13439f02017-02-21 01:17:21 -08001240 $profman_cmdline && \
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001241 $dex2oat_cmdline && \
Nicolas Geoffraybaeaa9b2018-01-26 14:31:17 +00001242 $dm_cmdline && \
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +00001243 $vdex_cmdline && \
Richard Uhler76f5cb62016-04-04 13:30:16 -07001244 $strip_cmdline && \
Igor Murashkin271a0f82017-02-14 21:14:17 +00001245 $sync_cmdline && \
David Srbeckya49b04f2019-09-16 14:53:15 +00001246 $timeout_prefix $dalvikvm_cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001247
Orion Hodsonecd94cf2020-12-03 13:58:33 +00001248 cmdfile=$(mktemp cmd-XXXX --suffix "-$TEST_NAME")
1249 echo "$cmdline" >> $cmdfile
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001250
1251 if [ "$DEV_MODE" = "y" ]; then
1252 echo $cmdline
Alex Light219420e2019-12-05 10:20:26 -08001253 if [ "$USE_GDB" = "y" ] || [ "$USE_GDBSERVER" = "y" ]; then
1254 echo "Forward ${GDBSERVER_PORT} to local port and connect GDB"
1255 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001256 fi
1257
1258 if [ "$QUIET" = "n" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001259 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001260 else
Roland Levillain76cfe612017-10-30 13:14:28 +00001261 adb push $cmdfile $CHROOT_DEX_LOCATION/cmdline.sh >/dev/null 2>&1
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001262 fi
1263
Alex Light722d6712018-02-12 17:41:12 +00001264 exit_status=0
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001265 if [ "$DRY_RUN" != "y" ]; then
Roland Levillain76cfe612017-10-30 13:14:28 +00001266 if [ -n "$CHROOT" ]; then
1267 adb shell chroot "$CHROOT" sh $DEX_LOCATION/cmdline.sh
1268 else
1269 adb shell sh $DEX_LOCATION/cmdline.sh
1270 fi
Alex Light722d6712018-02-12 17:41:12 +00001271 exit_status=$?
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001272 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001273
1274 rm -f $cmdfile
Alex Light722d6712018-02-12 17:41:12 +00001275 exit $exit_status
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001276else
Calin Juravle24bd3f92017-05-11 00:36:53 -07001277 # Host run.
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001278 export ANDROID_PRINTF_LOG=brief
Andreas Gampea8780822015-03-13 19:51:09 -07001279
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001280 export ANDROID_DATA="$DEX_LOCATION"
Nicolas Geoffray8eedb472014-10-29 14:05:59 +00001281 export ANDROID_ROOT="${ANDROID_ROOT}"
Victor Chang64611242019-07-05 16:32:41 +01001282 export ANDROID_I18N_ROOT="${ANDROID_I18N_ROOT}"
Martin Stjernholme58624f2019-09-20 15:53:40 +01001283 export ANDROID_ART_ROOT="${ANDROID_ART_ROOT}"
Neil Fuller26a5dd62019-03-13 15:16:35 +00001284 export ANDROID_TZDATA_ROOT="${ANDROID_TZDATA_ROOT}"
Alex Light6f342dd2019-03-27 17:15:42 +00001285 if [ "$USE_ZIPAPEX" = "y" ] || [ "$USE_EXRACTED_ZIPAPEX" = "y" ]; then
Alex Light20802ca2018-12-05 15:36:03 -08001286 # Put the zipapex files in front of the ld-library-path
Alex Lightf7f31522019-02-01 11:14:41 -08001287 export LD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1288 export DYLD_LIBRARY_PATH="${ANDROID_DATA}/zipapex/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1289 else
1290 export LD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
1291 export DYLD_LIBRARY_PATH="${ANDROID_ROOT}/${LIBRARY_DIRECTORY}:${ANDROID_ROOT}/${TEST_DIRECTORY}"
Alex Light20802ca2018-12-05 15:36:03 -08001292 fi
Martin Stjernholme58624f2019-09-20 15:53:40 +01001293 export PATH="$PATH:$ANDROID_ART_BIN_DIR"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001294
David Srbeckyc9ede382015-06-20 06:03:53 +01001295 # Temporarily disable address space layout randomization (ASLR).
1296 # This is needed on the host so that the linker loads core.oat at the necessary address.
1297 export LD_USE_LOAD_BIAS=1
1298
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001299 cmdline="$dalvikvm_cmdline"
1300
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001301 if [ "$TIME_OUT" = "gdb" ]; then
1302 if [ `uname` = "Darwin" ]; then
1303 # Fall back to timeout on Mac.
1304 TIME_OUT="timeout"
Hiroshi Yamauchic823eff2015-09-01 16:21:35 -07001305 elif [ "$ISA" = "x86" ]; then
1306 # prctl call may fail in 32-bit on an older (3.2) 64-bit Linux kernel. Fall back to timeout.
1307 TIME_OUT="timeout"
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001308 else
1309 # Check if gdb is available.
1310 gdb --eval-command="quit" > /dev/null 2>&1
1311 if [ $? != 0 ]; then
1312 # gdb isn't available. Fall back to timeout.
1313 TIME_OUT="timeout"
1314 fi
1315 fi
1316 fi
1317
1318 if [ "$TIME_OUT" = "timeout" ]; then
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001319 # Add timeout command if time out is desired.
Andreas Gampe038bb222015-01-13 19:48:14 -08001320 #
Andreas Gampe0df2aba2019-06-10 16:53:55 -07001321 # Note: We first send SIGTERM (the timeout default, signal 15) to the signal dumper, which
1322 # will induce a full thread dump before killing the process. To ensure any issues in
1323 # dumping do not lead to a deadlock, we also use the "-k" option to definitely kill the
1324 # child.
Andreas Gampe4bdcf5d2018-12-14 10:48:53 -08001325 # Note: Using "--foreground" to not propagate the signal to children, i.e., the runtime.
Andreas Gampe0df2aba2019-06-10 16:53:55 -07001326 cmdline="timeout --foreground -k 120s ${TIME_OUT_VALUE}s ${TIMEOUT_DUMPER} -s 15 $cmdline"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001327 fi
1328
1329 if [ "$DEV_MODE" = "y" ]; then
Martin Stjernholme58624f2019-09-20 15:53:40 +01001330 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 +01001331 echo EXPORT $var=${!var}
1332 done
Alex Light680cbf22018-10-31 11:00:19 -07001333 echo "$(declare -f linkdirs)"
Alex Light5e1ffcd2021-03-31 16:46:02 -07001334 echo "mkdir -p ${mkdir_locations} && $setupapex_cmdline && ( $installapex_test_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 +01001335 fi
1336
1337 cd $ANDROID_BUILD_TOP
1338
Calin Juravle24bd3f92017-05-11 00:36:53 -07001339 # Make sure we delete any existing compiler artifacts.
1340 # This enables tests to call the RUN script multiple times in a row
1341 # without worrying about interference.
1342 rm -rf ${DEX_LOCATION}/oat
David Srbecky2e4afe82016-01-27 18:42:06 +00001343 rm -rf ${DEX_LOCATION}/dalvik-cache/
Calin Juravle24bd3f92017-05-11 00:36:53 -07001344
Andreas Gampeb31a8e72017-05-16 10:30:24 -07001345 export ASAN_OPTIONS=$RUN_TEST_ASAN_OPTIONS
1346
Alex Lightafb5d192016-05-24 15:57:45 -07001347 mkdir -p ${mkdir_locations} || exit 1
Alex Light20802ca2018-12-05 15:36:03 -08001348 $setupapex_cmdline || { echo "zipapex extraction failed." >&2 ; exit 2; }
Alex Light5e1ffcd2021-03-31 16:46:02 -07001349 $installapex_test_cmdline || $installapex_cmdline || { echo "zipapex install failed. cmd was: ${installapex_test_cmdline} || ${installapex_cmdline}." >&2; find ${mkdir_locations} -type f >&2; exit 2; }
Alex Light680cbf22018-10-31 11:00:19 -07001350 $linkroot_cmdline || { echo "create symlink android-root failed." >&2 ; exit 2; }
1351 $linkroot_overlay_cmdline || { echo "overlay android-root failed." >&2 ; exit 2; }
Calin Juravle13439f02017-02-21 01:17:21 -08001352 $profman_cmdline || { echo "Profman failed." >&2 ; exit 2; }
Andreas Gampe038a1982020-03-11 23:06:42 +00001353 eval "$dex2oat_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
1354 eval "$dm_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
1355 eval "$vdex_cmdline" || { echo "Dex2oat failed." >&2 ; exit 2; }
Richard Uhler76f5cb62016-04-04 13:30:16 -07001356 $strip_cmdline || { echo "Strip failed." >&2 ; exit 3; }
Igor Murashkin271a0f82017-02-14 21:14:17 +00001357 $sync_cmdline || { echo "Sync failed." >&2 ; exit 4; }
Andreas Gampea8780822015-03-13 19:51:09 -07001358
Alex Light8d94ddd2019-12-18 11:13:03 -08001359 if [ "$CREATE_RUNNER" = "y" ]; then
1360 echo "#!/bin/bash" > ${DEX_LOCATION}/runit.sh
1361 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
1362 echo export $var="${!var}" >> ${DEX_LOCATION}/runit.sh
1363 done
Alex Light4f915d22020-01-09 17:51:25 -08001364 if [ "$DEV_MODE" = "y" ]; then
Roland Levillainb15e8792020-10-28 12:20:59 +00001365 echo $cmdline >> ${DEX_LOCATION}/runit.sh
Alex Light4f915d22020-01-09 17:51:25 -08001366 else
1367 echo 'STDERR=$(mktemp)' >> ${DEX_LOCATION}/runit.sh
1368 echo 'STDOUT=$(mktemp)' >> ${DEX_LOCATION}/runit.sh
Roland Levillainb15e8792020-10-28 12:20:59 +00001369 echo $cmdline '>${STDOUT} 2>${STDERR}' >> ${DEX_LOCATION}/runit.sh
1370 echo 'if diff ${STDOUT} $ANDROID_DATA/expected-stdout.txt; then' \
1371 >> ${DEX_LOCATION}/runit.sh
1372 echo ' rm -f ${STDOUT} ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1373 echo ' exit 0' >> ${DEX_LOCATION}/runit.sh
1374 echo 'elif diff ${STDERR} $ANDROID_DATA/expected-stderr.txt; then' \
1375 >> ${DEX_LOCATION}/runit.sh
Alex Light4f915d22020-01-09 17:51:25 -08001376 echo ' rm -f ${STDOUT} ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1377 echo ' exit 0' >> ${DEX_LOCATION}/runit.sh
1378 echo 'else' >> ${DEX_LOCATION}/runit.sh
1379 echo ' echo STDOUT:' >> ${DEX_LOCATION}/runit.sh
1380 echo ' cat ${STDOUT}' >> ${DEX_LOCATION}/runit.sh
1381 echo ' echo STDERR:' >> ${DEX_LOCATION}/runit.sh
1382 echo ' cat ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1383 echo ' rm -f ${STDOUT} ${STDERR}' >> ${DEX_LOCATION}/runit.sh
1384 echo ' exit 1' >> ${DEX_LOCATION}/runit.sh
1385 echo 'fi' >> ${DEX_LOCATION}/runit.sh
1386 fi
Alex Light8d94ddd2019-12-18 11:13:03 -08001387 chmod u+x $DEX_LOCATION/runit.sh
1388 echo "Runnable test script written to ${DEX_LOCATION}/runit.sh"
1389 fi
Wojciech Staszkiewiczd7a819a2016-09-01 14:43:39 -07001390 if [ "$DRY_RUN" = "y" ]; then
1391 exit 0
Andreas Gampea8780822015-03-13 19:51:09 -07001392 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001393
1394 if [ "$USE_GDB" = "y" ]; then
1395 # When running under gdb, we cannot do piping and grepping...
Alex Lighte4b4a182019-02-12 14:19:49 -08001396 $cmdline "$@"
1397 elif [ "$USE_GDBSERVER" = "y" ]; then
1398 echo "Connect to $GDBSERVER_PORT"
1399 # When running under gdb, we cannot do piping and grepping...
Dmitriy Ivanovf57874d2014-10-07 13:43:23 -07001400 $cmdline "$@"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001401 else
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001402 if [ "$TIME_OUT" != "gdb" ]; then
1403 trap 'kill -INT -$pid' INT
Roland Levillainb15e8792020-10-28 12:20:59 +00001404 $cmdline "$@" & pid=$!
Orion Hodson16e7e572020-10-30 09:40:41 +00001405 wait $pid
1406 exit_value=$?
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001407 # Add extra detail if time out is enabled.
Alex Light722d6712018-02-12 17:41:12 +00001408 if [ $exit_value = 124 ] && [ "$TIME_OUT" = "timeout" ]; then
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001409 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1410 fi
Alex Light722d6712018-02-12 17:41:12 +00001411 exit $exit_value
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001412 else
1413 # With a thread dump that uses gdb if a timeout.
1414 trap 'kill -INT -$pid' INT
Roland Levillainb15e8792020-10-28 12:20:59 +00001415 $cmdline "$@" & pid=$!
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001416 # Spawn a watcher process.
1417 ( sleep $TIME_OUT_VALUE && \
1418 echo "##### Thread dump using gdb on test timeout" && \
1419 ( gdb -q -p $pid --eval-command="info thread" --eval-command="thread apply all bt" \
1420 --eval-command="call exit(124)" --eval-command=quit || \
1421 kill $pid )) 2> /dev/null & watcher=$!
1422 wait $pid
1423 test_exit_status=$?
1424 pkill -P $watcher 2> /dev/null # kill the sleep which will in turn end the watcher as well
1425 if [ $test_exit_status = 0 ]; then
1426 # The test finished normally.
1427 exit 0
1428 else
1429 # The test failed or timed out.
1430 if [ $test_exit_status = 124 ]; then
1431 # The test timed out.
1432 echo -e "\e[91mTEST TIMED OUT!\e[0m" >&2
1433 fi
Alex Light722d6712018-02-12 17:41:12 +00001434 exit $test_exit_status
Hiroshi Yamauchi6ffb9cc2015-08-31 15:14:17 -07001435 fi
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +01001436 fi
1437 fi
1438fi