blob: 9b0261ed314838bceefd75cfbe9f07bc6ade8d27 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/bin/bash
2#
3# Copyright (C) 2007 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Set up prog to be the path of this script, including following symlinks,
18# and set up progdir to be the fully-qualified pathname of its directory.
19prog="$0"
Andreas Gampedeb48a02014-10-22 00:44:35 -070020args="$@"
jeffhao5d1ac922011-09-29 17:41:15 -070021while [ -h "${prog}" ]; do
22 newProg=`/bin/ls -ld "${prog}"`
23 newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
24 if expr "x${newProg}" : 'x/' >/dev/null; then
25 prog="${newProg}"
26 else
27 progdir=`dirname "${prog}"`
28 prog="${progdir}/${newProg}"
29 fi
30done
31oldwd=`pwd`
32progdir=`dirname "${prog}"`
33cd "${progdir}"
34progdir=`pwd`
35prog="${progdir}"/`basename "${prog}"`
Brian Carlstrom105215d2012-06-14 12:50:44 -070036test_dir="test-$$"
Andreas Gampe5a79fde2014-08-06 13:12:26 -070037if [ -z "$TMPDIR" ]; then
38 tmp_dir="/tmp/$USER/${test_dir}"
39else
40 tmp_dir="${TMPDIR}/$USER/${test_dir}"
41fi
David Brazdil2c27f2c2015-05-12 18:06:38 +010042checker="${progdir}/../tools/checker/checker.py"
jeffhao5d1ac922011-09-29 17:41:15 -070043export JAVA="java"
Brian Carlstrom5103ce62014-03-30 16:17:42 -070044export JAVAC="javac -g"
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +010045export RUN="${progdir}/etc/run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070046export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070047export NEED_DEX="true"
Sebastien Hertz19ac0272015-02-24 17:39:50 +010048export USE_JACK="false"
Alex Light8a0e0332015-10-26 10:11:58 -070049export SMALI_ARGS="--experimental --api-level 23"
jeffhao5d1ac922011-09-29 17:41:15 -070050
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070051# If dx was not set by the environment variable, assume it is in the path.
52if [ -z "$DX" ]; then
53 export DX="dx"
54fi
55
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080056# If jasmin was not set by the environment variable, assume it is in the path.
57if [ -z "$JASMIN" ]; then
58 export JASMIN="jasmin"
59fi
60
Andreas Gampe8fda9f22014-10-03 16:15:37 -070061# If smali was not set by the environment variable, assume it is in the path.
62if [ -z "$SMALI" ]; then
63 export SMALI="smali"
64fi
65
66# If dexmerger was not set by the environment variable, assume it is in the path.
67if [ -z "$DXMERGER" ]; then
68 export DXMERGER="dexmerger"
69fi
70
Sebastien Hertz19ac0272015-02-24 17:39:50 +010071# If jack was not set by the environment variable, assume it is in the path.
72if [ -z "$JACK" ]; then
73 export JACK="jack"
74fi
75
76# If the tree is compiled with Jack, build test with Jack by default.
77if [ "$ANDROID_COMPILE_WITH_JACK" = "true" ]; then
78 USE_JACK="true"
79fi
80
81# ANDROID_BUILD_TOP is not set in a build environment.
82if [ -z "$ANDROID_BUILD_TOP" ]; then
83 export ANDROID_BUILD_TOP=$oldwd
84fi
85
Sebastien Hertz19ac0272015-02-24 17:39:50 +010086# If JACK_CLASSPATH is not set, assume it only contains core-libart.
87if [ -z "$JACK_CLASSPATH" ]; then
Alex Light6a439bc2015-10-26 17:52:36 -070088 export JACK_CLASSPATH="${OUT_DIR:-$ANDROID_BUILD_TOP/out}/host/common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack"
Sebastien Hertz19ac0272015-02-24 17:39:50 +010089fi
90
Sebastien Hertz19ac0272015-02-24 17:39:50 +010091# If JILL_JAR is not set, assume it is located in the prebuilts directory.
92if [ -z "$JILL_JAR" ]; then
93 export JILL_JAR="$ANDROID_BUILD_TOP/prebuilts/sdk/tools/jill.jar"
94fi
95
96export JACK="$JACK -g -cp $JACK_CLASSPATH"
97export JILL="java -jar $JILL_JAR"
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080098
jeffhao5d1ac922011-09-29 17:41:15 -070099info="info.txt"
100build="build"
101run="run"
102expected="expected.txt"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700103check_cmd="check"
jeffhao5d1ac922011-09-29 17:41:15 -0700104output="output.txt"
105build_output="build-output.txt"
David Brazdil24128c62015-05-21 12:06:13 +0100106cfg_output="graph.cfg"
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700107strace_output="strace-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700108lib="libartd.so"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700109testlib="arttestd"
jeffhao5d1ac922011-09-29 17:41:15 -0700110run_args="--quiet"
David Brazdil4846d132015-01-15 19:07:08 +0000111build_args=""
jeffhao5d1ac922011-09-29 17:41:15 -0700112
Alex Light91de25f2015-10-28 17:00:06 -0700113quiet="no"
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +0000114debuggable="no"
Alex Light9d722532014-07-22 18:07:12 -0700115prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -0700116target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700117dev_mode="no"
118update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -0700119debug_mode="no"
120relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -0800121runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -0700122usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700123build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700124suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -0700125trace="false"
Andreas Gampe7526d782015-06-22 22:53:45 -0700126trace_stream="false"
Alex Lighte7873ec2014-08-12 09:53:50 -0700127basic_verify="false"
128gc_verify="false"
129gc_stress="false"
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700130strace="false"
Alex Lightbfac14a2014-07-30 09:41:21 -0700131always_clean="no"
Igor Murashkin05f30e12015-06-10 15:57:17 -0700132never_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -0700133have_dex2oat="yes"
134have_patchoat="yes"
135have_image="yes"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700136image_suffix=""
Andreas Gampec23c9c92014-10-28 14:47:25 -0700137pic_image_suffix=""
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000138android_root="/system"
jeffhao5d1ac922011-09-29 17:41:15 -0700139
140while true; do
141 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700142 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -0700143 DEX_LOCATION=$tmp_dir
Nicolas Geoffray1a58b7f2014-10-06 12:23:04 +0100144 run_args="${run_args} --host"
jeffhao5d1ac922011-09-29 17:41:15 -0700145 shift
Alex Light91de25f2015-10-28 17:00:06 -0700146 elif [ "x$1" = "x--quiet" ]; then
147 quiet="yes"
148 shift
Alex Lighteb7c1442015-08-31 13:17:42 -0700149 elif [ "x$1" = "x--use-java-home" ]; then
150 if [ -n "${JAVA_HOME}" ]; then
151 export JAVA="${JAVA_HOME}/bin/java"
152 export JAVAC="${JAVA_HOME}/bin/javac -g"
153 else
154 echo "Passed --use-java-home without JAVA_HOME variable set!"
155 usage="yes"
156 fi
157 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800158 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -0700159 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -0800160 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -0700161 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -0700162 NEED_DEX="false"
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100163 USE_JACK="false"
Nicolas Geoffray288a4a22014-10-07 11:02:40 +0100164 run_args="${run_args} --jvm"
Alex Lighteb7c1442015-08-31 13:17:42 -0700165 build_args="${build_args} --jvm"
jeffhao5d1ac922011-09-29 17:41:15 -0700166 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -0800167 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700168 lib="libart.so"
Mathieu Chartier031768a2015-08-27 10:25:02 -0700169 testlib="arttest"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700170 shift
171 elif [ "x$1" = "x--dalvik" ]; then
172 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800173 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700174 shift
Alex Light03a112d2014-08-25 13:25:56 -0700175 elif [ "x$1" = "x--no-dex2oat" ]; then
176 have_dex2oat="no"
177 shift
178 elif [ "x$1" = "x--no-patchoat" ]; then
179 have_patchoat="no"
180 shift
181 elif [ "x$1" = "x--no-image" ]; then
182 have_image="no"
183 shift
Andreas Gampec23c9c92014-10-28 14:47:25 -0700184 elif [ "x$1" = "x--pic-image" ]; then
185 pic_image_suffix="-pic"
186 shift
187 elif [ "x$1" = "x--pic-test" ]; then
188 run_args="${run_args} --pic-test"
189 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700190 elif [ "x$1" = "x--relocate" ]; then
191 relocate="yes"
192 shift
193 elif [ "x$1" = "x--no-relocate" ]; then
194 relocate="no"
195 shift
196 elif [ "x$1" = "x--prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100197 run_args="${run_args} --prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700198 prebuild_mode="yes"
199 shift;
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000200 elif [ "x$1" = "x--debuggable" ]; then
201 run_args="${run_args} -Xcompiler-option --debuggable"
Nicolas Geoffraya3d90fb2015-03-16 13:55:40 +0000202 debuggable="yes"
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000203 shift;
Alex Lighta59dd802014-07-02 16:28:08 -0700204 elif [ "x$1" = "x--no-prebuild" ]; then
Nicolas Geoffray5fd18ba2014-10-03 12:08:38 +0100205 run_args="${run_args} --no-prebuild"
Alex Lighta59dd802014-07-02 16:28:08 -0700206 prebuild_mode="no"
207 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700208 elif [ "x$1" = "x--gcverify" ]; then
209 basic_verify="true"
210 gc_verify="true"
211 shift
212 elif [ "x$1" = "x--gcstress" ]; then
213 basic_verify="true"
214 gc_stress="true"
215 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700216 elif [ "x$1" = "x--image" ]; then
217 shift
218 image="$1"
219 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700220 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000221 elif [ "x$1" = "x-Xcompiler-option" ]; then
222 shift
223 option="$1"
224 run_args="${run_args} -Xcompiler-option $option"
225 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700226 elif [ "x$1" = "x--runtime-option" ]; then
227 shift
228 option="$1"
229 run_args="${run_args} --runtime-option $option"
230 shift
Mathieu Chartierc0a8a802014-10-17 15:58:01 -0700231 elif [ "x$1" = "x--gdb-arg" ]; then
232 shift
233 gdb_arg="$1"
234 run_args="${run_args} --gdb-arg $gdb_arg"
235 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700236 elif [ "x$1" = "x--debug" ]; then
237 run_args="${run_args} --debug"
238 shift
239 elif [ "x$1" = "x--gdb" ]; then
240 run_args="${run_args} --gdb"
241 dev_mode="yes"
242 shift
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700243 elif [ "x$1" = "x--strace" ]; then
244 strace="yes"
245 run_args="${run_args} --invoke-with strace --invoke-with -o --invoke-with $tmp_dir/$strace_output"
246 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700247 elif [ "x$1" = "x--zygote" ]; then
248 run_args="${run_args} --zygote"
249 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800250 elif [ "x$1" = "x--interpreter" ]; then
251 run_args="${run_args} --interpreter"
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700252 image_suffix="-interpreter"
253 shift
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800254 elif [ "x$1" = "x--jit" ]; then
255 run_args="${run_args} --jit"
Andreas Gampe8a159fd2015-09-21 15:14:38 -0700256 image_suffix="-jit"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800257 shift
Andreas Gampe63fc30e2014-10-24 21:58:16 -0700258 elif [ "x$1" = "x--optimizing" ]; then
259 run_args="${run_args} -Xcompiler-option --compiler-backend=Optimizing"
260 image_suffix="-optimizing"
jeffhao0dff3f42012-11-20 15:13:43 -0800261 shift
Nicolas Geoffrayc9338b92014-12-03 13:36:10 +0000262 elif [ "x$1" = "x--quick" ]; then
263 run_args="${run_args} -Xcompiler-option --compiler-backend=Quick"
264 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700265 elif [ "x$1" = "x--no-verify" ]; then
266 run_args="${run_args} --no-verify"
267 shift
Igor Murashkin7617abd2015-07-10 18:27:47 -0700268 elif [ "x$1" = "x--verify-soft-fail" ]; then
269 run_args="${run_args} --verify-soft-fail"
Andreas Gampe825570c2015-07-26 10:26:03 -0700270 image_suffix="-interp-ac"
Igor Murashkin7617abd2015-07-10 18:27:47 -0700271 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700272 elif [ "x$1" = "x--no-optimize" ]; then
273 run_args="${run_args} --no-optimize"
274 shift
275 elif [ "x$1" = "x--no-precise" ]; then
276 run_args="${run_args} --no-precise"
277 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700278 elif [ "x$1" = "x--invoke-with" ]; then
279 shift
280 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700281 if [ "x$what" = "x" ]; then
282 echo "$0 missing argument to --invoke-with" 1>&2
283 usage="yes"
284 break
285 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700286 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700287 shift
288 elif [ "x$1" = "x--dev" ]; then
289 run_args="${run_args} --dev"
290 dev_mode="yes"
291 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700292 elif [ "x$1" = "x--build-only" ]; then
293 build_only="yes"
294 shift
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100295 elif [ "x$1" = "x--build-with-javac-dx" ]; then
296 USE_JACK="false"
297 shift
298 elif [ "x$1" = "x--build-with-jack" ]; then
299 USE_JACK="true"
300 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700301 elif [ "x$1" = "x--output-path" ]; then
302 shift
303 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700304 if [ "x$tmp_dir" = "x" ]; then
305 echo "$0 missing argument to --output-path" 1>&2
306 usage="yes"
307 break
308 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700309 shift
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000310 elif [ "x$1" = "x--android-root" ]; then
311 shift
312 if [ "x$1" = "x" ]; then
313 echo "$0 missing argument to --android-root" 1>&2
314 usage="yes"
315 break
316 fi
317 android_root="$1"
318 run_args="${run_args} --android-root $1"
319 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700320 elif [ "x$1" = "x--update" ]; then
321 update_mode="yes"
322 shift
323 elif [ "x$1" = "x--help" ]; then
324 usage="yes"
325 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700326 elif [ "x$1" = "x--64" ]; then
327 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700328 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700329 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200330 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700331 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200332 shift
Andreas Gampe7526d782015-06-22 22:53:45 -0700333 elif [ "x$1" = "x--stream" ]; then
334 trace_stream="true"
335 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700336 elif [ "x$1" = "x--always-clean" ]; then
337 always_clean="yes"
338 shift
Igor Murashkin05f30e12015-06-10 15:57:17 -0700339 elif [ "x$1" = "x--never-clean" ]; then
340 never_clean="yes"
341 shift
Andreas Gampee21dc3d2014-12-08 16:59:43 -0800342 elif [ "x$1" = "x--dex2oat-swap" ]; then
343 run_args="${run_args} --dex2oat-swap"
344 shift
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700345 elif [ "x$1" = "x--instruction-set-features" ]; then
346 shift
347 run_args="${run_args} --instruction-set-features $1"
348 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700349 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700350 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700351 usage="yes"
352 break
353 else
354 break
355 fi
356done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700357
Alex Light91de25f2015-10-28 17:00:06 -0700358# Allocate file descriptor real_stderr and redirect it to the shell's error
359# output (fd 2).
360if [ ${BASH_VERSINFO[1]} -ge 4 ] && [ ${BASH_VERSINFO[2]} -ge 1 ]; then
361 exec {real_stderr}>&2
362else
363 # In bash before version 4.1 we need to do a manual search for free file
364 # descriptors.
365 FD=3
366 while [ -e /dev/fd/$FD ]; do FD=$((FD + 1)); done
367 real_stderr=$FD
368 eval "exec ${real_stderr}>&2"
369fi
370if [ "$quiet" = "yes" ]; then
371 # Force the default standard output and error to go to /dev/null so we will
372 # not print them.
373 exec 1>/dev/null
374 exec 2>/dev/null
375fi
376
377function err_echo() {
378 echo "$@" 1>&${real_stderr}
379}
380
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700381# tmp_dir may be relative, resolve.
382#
383# Cannot use realpath, as it does not exist on Mac.
384# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700385# Cannot use readlink -m, as it does not exist on Mac.
386# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700387noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700388tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700389mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700390
Alex Lighte7873ec2014-08-12 09:53:50 -0700391if [ "$basic_verify" = "true" ]; then
Hiroshi Yamauchi312baf12015-01-12 12:11:05 -0800392 # Set HspaceCompactForOOMMinIntervalMs to zero to run hspace compaction for OOM more frequently in tests.
393 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify --runtime-option -XX:HspaceCompactForOOMMinIntervalMs=0"
Alex Lighte7873ec2014-08-12 09:53:50 -0700394fi
395if [ "$gc_verify" = "true" ]; then
396 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
397fi
398if [ "$gc_stress" = "true" ]; then
Mathieu Chartiereb193622015-06-27 15:42:27 -0700399 run_args="${run_args} --runtime-option -Xgc:SS,gcstress --runtime-option -Xms2m --runtime-option -Xmx16m"
Alex Lighte7873ec2014-08-12 09:53:50 -0700400fi
Jeff Hao85139a32014-07-23 11:52:52 -0700401if [ "$trace" = "true" ]; then
Andreas Gampe7526d782015-06-22 22:53:45 -0700402 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file-size:2000000"
403 if [ "$trace_stream" = "true" ]; then
404 # Streaming mode uses the file size as the buffer size. So output gets really large. Drop
405 # the ability to analyze the file and just write to /dev/null.
406 run_args="${run_args} --runtime-option -Xmethod-trace-file:/dev/null"
407 # Enable streaming mode.
408 run_args="${run_args} --runtime-option -Xmethod-trace-stream"
409 else
410 run_args="${run_args} --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin"
411 fi
412elif [ "$trace_stream" = "true" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700413 err_echo "Cannot use --stream without --trace."
Andreas Gampe7526d782015-06-22 22:53:45 -0700414 exit 1
Jeff Hao85139a32014-07-23 11:52:52 -0700415fi
416
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700417# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100418# Try to map the suffix64 flag and what we find in ${ANDROID_PRODUCT_OUT}/data/art-test to an architecture name.
David Brazdil853a4c32015-09-28 16:15:50 +0100419function guess_target_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100420 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800421 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64|mips64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700422 if [ "x${suffix64}" = "x64" ]; then
423 target_arch_name=${grep64bit}
424 else
425 target_arch_name=${grep32bit}
426 fi
427}
428
David Brazdil853a4c32015-09-28 16:15:50 +0100429function guess_host_arch_name() {
430 if [ "x${suffix64}" = "x64" ]; then
431 host_arch_name="x86_64"
432 else
433 host_arch_name="x86"
434 fi
435}
436
Alex Lighta59dd802014-07-02 16:28:08 -0700437if [ "$target_mode" = "no" ]; then
438 if [ "$runtime" = "jvm" ]; then
Alex Lighta59dd802014-07-02 16:28:08 -0700439 if [ "$prebuild_mode" = "yes" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700440 err_echo "--prebuild with --jvm is unsupported"
Alex Lighta59dd802014-07-02 16:28:08 -0700441 exit 1;
442 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700443 fi
444fi
445
Alex Light03a112d2014-08-25 13:25:56 -0700446if [ "$have_patchoat" = "no" ]; then
447 run_args="${run_args} --no-patchoat"
448fi
449
450if [ "$have_dex2oat" = "no" ]; then
451 run_args="${run_args} --no-dex2oat"
452fi
453
Jeff Hao201803f2013-11-20 18:11:39 -0800454if [ ! "$runtime" = "jvm" ]; then
455 run_args="${run_args} --lib $lib"
456fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700457
Jeff Hao201803f2013-11-20 18:11:39 -0800458if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700459 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100460 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700461 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
462 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
463 else
464 true # defaults to using target BOOTCLASSPATH
465 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800466elif [ "$runtime" = "art" ]; then
467 if [ "$target_mode" = "no" ]; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100468 # ANDROID_HOST_OUT is not set in a build environment.
Brian Carlstrom43534862014-02-19 01:13:52 -0800469 if [ -z "$ANDROID_HOST_OUT" ]; then
Alex Light6a439bc2015-10-26 17:52:36 -0700470 export ANDROID_HOST_OUT=${OUT_DIR:-$ANDROID_BUILD_TOP/out/}host/linux-x86
Brian Carlstrom43534862014-02-19 01:13:52 -0800471 fi
David Brazdil853a4c32015-09-28 16:15:50 +0100472 guess_host_arch_name
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000473 run_args="${run_args} --boot ${ANDROID_HOST_OUT}/framework/core${image_suffix}${pic_image_suffix}.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700474 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800475 else
David Brazdil853a4c32015-09-28 16:15:50 +0100476 guess_target_arch_name
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700477 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000478 run_args="${run_args} --boot /data/art-test/core${image_suffix}${pic_image_suffix}.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800479 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700480 if [ "$relocate" = "yes" ]; then
481 run_args="${run_args} --relocate"
482 else
483 run_args="${run_args} --no-relocate"
484 fi
Andreas Gampe3f1dc562015-05-18 15:52:22 -0700485elif [ "$runtime" = "jvm" ]; then
486 # TODO: Detect whether the host is 32-bit or 64-bit.
487 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib64"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700488fi
489
Alex Light03a112d2014-08-25 13:25:56 -0700490if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700491 if [ "$runtime" != "art" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700492 err_echo "--no-image is only supported on the art runtime"
Alex Light1ef4ce82014-08-27 11:13:47 -0700493 exit 1
494 fi
495 if [ "$target_mode" = "no" ]; then
496 framework="${ANDROID_HOST_OUT}/framework"
497 bpath_suffix="-hostdex"
498 else
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000499 framework="${android_root}/framework"
Alex Light1ef4ce82014-08-27 11:13:47 -0700500 bpath_suffix=""
501 fi
502 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
503 # fail since these jar files will be stripped.
504 bpath="${framework}/core-libart${bpath_suffix}.jar"
505 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
506 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
507 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
508 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
509 # Pass down the bootclasspath
510 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700511 run_args="${run_args} --no-image"
512fi
513
jeffhao5d1ac922011-09-29 17:41:15 -0700514if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700515 err_echo "--dev and --update are mutually exclusive"
516 usage="yes"
517fi
518
519if [ "$dev_mode" = "yes" -a "$quiet" = "yes" ]; then
520 err_echo "--dev and --quiet are mutually exclusive"
jeffhao5d1ac922011-09-29 17:41:15 -0700521 usage="yes"
522fi
523
524if [ "$usage" = "no" ]; then
525 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
526 test_dir=`basename "$oldwd"`
527 else
528 test_dir="$1"
529 fi
530
531 if [ '!' -d "$test_dir" ]; then
532 td2=`echo ${test_dir}-*`
533 if [ '!' -d "$td2" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700534 err_echo "${test_dir}: no such test directory"
jeffhao5d1ac922011-09-29 17:41:15 -0700535 usage="yes"
536 fi
537 test_dir="$td2"
538 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700539 # Shift to get rid of the test name argument. The rest of the arguments
540 # will get passed to the test run.
541 shift
542fi
543
544if [ "$usage" = "yes" ]; then
545 prog=`basename $prog`
546 (
547 echo "usage:"
548 echo " $prog --help Print this message."
549 echo " $prog [options] [test-name] Run test normally."
550 echo " $prog --dev [options] [test-name] Development mode" \
551 "(dumps to stdout)."
552 echo " $prog --update [options] [test-name] Update mode" \
553 "(replaces expected.txt)."
554 echo ' Omitting the test name or specifying "-" will use the' \
555 "current directory."
556 echo " Runtime Options:"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000557 echo " -O Run non-debug rather than debug build (off by default)."
558 echo " -Xcompiler-option Pass an option to the compiler."
559 echo " --runtime-option Pass an option to the runtime."
560 echo " --debug Wait for a debugger to attach."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000561 echo " --debuggable Whether to compile Java code for a debugger."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000562 echo " --gdb Run under gdb; incompatible with some tests."
Alex Lightfadfee92015-10-28 09:40:10 -0700563 echo " --gdb-arg Pass an option to gdb."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000564 echo " --build-only Build test files only (off by default)."
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100565 echo " --build-with-javac-dx Build test files with javac and dx (on by default)."
566 echo " --build-with-jack Build test files with jack and jill (off by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000567 echo " --interpreter Enable interpreter only mode (off by default)."
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800568 echo " --jit Enable jit (off by default)."
Nicolas Geoffray0e071252015-03-21 13:43:15 +0000569 echo " --optimizing Enable optimizing compiler (default)."
570 echo " --quick Use Quick compiler (off by default)."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000571 echo " --no-verify Turn off verification (on by default)."
Igor Murashkin7617abd2015-07-10 18:27:47 -0700572 echo " --verify-soft-fail Force soft fail verification (off by default)."
573 echo " Verification is enabled if neither --no-verify"
574 echo " nor --verify-soft-fail is specified."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000575 echo " --no-optimize Turn off optimization (on by default)."
576 echo " --no-precise Turn off precise GC (on by default)."
577 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700578 "If used, then the"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000579 echo " other runtime options are ignored."
580 echo " --no-dex2oat Run as though dex2oat was failing."
581 echo " --no-patchoat Run as though patchoat was failing."
582 echo " --prebuild Run dex2oat on the files before starting test. (default)"
583 echo " --no-prebuild Do not run dex2oat on the files before starting"
584 echo " the test."
585 echo " --relocate Force the use of relocating in the test, making"
586 echo " the image and oat files be relocated to a random"
587 echo " address before running. (default)"
588 echo " --no-relocate Force the use of no relocating in the test"
Alex Lightfadfee92015-10-28 09:40:10 -0700589 echo " --image Run the test using a precompiled boot image. (default)"
590 echo " --no-image Run the test without a precompiled boot image."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000591 echo " --host Use the host-mode virtual machine."
592 echo " --invoke-with Pass --invoke-with option to runtime."
593 echo " --dalvik Use Dalvik (off by default)."
594 echo " --jvm Use a host-local RI virtual machine."
Alex Lighteb7c1442015-08-31 13:17:42 -0700595 echo " --use-java-home Use the JAVA_HOME environment variable"
596 echo " to find the java compiler and runtime"
597 echo " (if applicable) to run the test with."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000598 echo " --output-path [path] Location where to store the build" \
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700599 "files."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000600 echo " --64 Run the test in 64-bit mode"
601 echo " --trace Run with method tracing"
Alex Lightfadfee92015-10-28 09:40:10 -0700602 echo " --strace Run with syscall tracing from strace."
Andreas Gampe7526d782015-06-22 22:53:45 -0700603 echo " --stream Run method tracing in streaming mode (requires --trace)"
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000604 echo " --gcstress Run with gc stress testing"
605 echo " --gcverify Run with gc verification"
606 echo " --always-clean Delete the test files even if the test fails."
Igor Murashkin05f30e12015-06-10 15:57:17 -0700607 echo " --never-clean Keep the test files even if the test succeeds."
Nicolas Geoffrayc8f23fc2014-10-28 17:59:47 +0000608 echo " --android-root [path] The path on target for the android root. (/system by default)."
Nicolas Geoffray43c162f2015-03-09 12:21:26 +0000609 echo " --dex2oat-swap Use a dex2oat swap file."
Andreas Gampe4d2ef332015-08-05 09:24:45 -0700610 echo " --instruction-set-features [string]"
611 echo " Set instruction-set-features for compilation."
Alex Lightfadfee92015-10-28 09:40:10 -0700612 echo " --pic-image Use an image compiled with position independent code for the"
613 echo " boot class path."
614 echo " --pic-test Compile the test code position independent."
Alex Light91de25f2015-10-28 17:00:06 -0700615 echo " --quiet Don't print anything except failure messages"
616 ) 1>&2 # Direct to stderr so usage is not printed if --quiet is set.
jeffhao5d1ac922011-09-29 17:41:15 -0700617 exit 1
618fi
619
620cd "$test_dir"
621test_dir=`pwd`
622
623td_info="${test_dir}/${info}"
624td_expected="${test_dir}/${expected}"
625
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700626if [ ! -r $td_info ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700627 err_echo "${test_dir}: missing file $td_info"
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700628 exit 1
629fi
630
631if [ ! -r $td_expected ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700632 err_echo "${test_dir}: missing file $td_expected"
jeffhao5d1ac922011-09-29 17:41:15 -0700633 exit 1
634fi
635
636# copy the test to a temp dir and run it
637
Elliott Hughes510c8782011-10-06 10:57:34 -0700638echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700639
640rm -rf "$tmp_dir"
641cp -Rp "$test_dir" "$tmp_dir"
642cd "$tmp_dir"
643
644if [ '!' -r "$build" ]; then
645 cp "${progdir}/etc/default-build" build
Zheng Xuc6667102015-05-15 16:08:45 +0800646else
647 cp "${progdir}/etc/default-build" .
jeffhao5d1ac922011-09-29 17:41:15 -0700648fi
649
650if [ '!' -r "$run" ]; then
651 cp "${progdir}/etc/default-run" run
Zheng Xuc6667102015-05-15 16:08:45 +0800652else
653 cp "${progdir}/etc/default-run" .
jeffhao5d1ac922011-09-29 17:41:15 -0700654fi
655
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700656if [ '!' -r "$check_cmd" ]; then
657 cp "${progdir}/etc/default-check" check
Zheng Xuc6667102015-05-15 16:08:45 +0800658else
659 cp "${progdir}/etc/default-check" .
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700660fi
661
jeffhao5d1ac922011-09-29 17:41:15 -0700662chmod 755 "$build"
663chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700664chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700665
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700666export TEST_NAME=`basename ${test_dir}`
667
David Brazdil4846d132015-01-15 19:07:08 +0000668# Tests named '<number>-checker-*' will also have their CFGs verified with
669# Checker when compiled with Optimizing on host.
670if [[ "$TEST_NAME" =~ ^[0-9]+-checker- ]]; then
671 # Build Checker DEX files without dx's optimizations so the input to dex2oat
672 # better resembles the Java source. We always build the DEX the same way, even
673 # if Checker is not invoked and the test only runs the program.
674 build_args="${build_args} --dx-option --no-optimize"
675
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100676 # Jack does not necessarily generate the same DEX output than dx. Because these tests depend
677 # on a particular DEX output, keep building them with dx for now (b/19467889).
678 USE_JACK="false"
679
David Brazdil5cc343d2015-10-08 11:35:32 +0100680 if [ "$runtime" = "art" -a "$image_suffix" = "-optimizing" ]; then
David Brazdil80fb3942015-07-23 11:53:42 +0100681 # In no-prebuild mode, the compiler is only invoked if both dex2oat and
682 # patchoat are available. Disable Checker otherwise (b/22552692).
683 if [ "$prebuild_mode" = "yes" ] || [ "$have_patchoat" = "yes" -a "$have_dex2oat" = "yes" ]; then
684 run_checker="yes"
David Brazdil5cc343d2015-10-08 11:35:32 +0100685
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100686 if [ "$target_mode" = "no" ]; then
687 cfg_output_dir="$tmp_dir"
David Brazdil5cc343d2015-10-08 11:35:32 +0100688 checker_args="--arch=${host_arch_name^^}"
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100689 else
690 cfg_output_dir="$DEX_LOCATION"
David Brazdil5cc343d2015-10-08 11:35:32 +0100691 checker_args="--arch=${target_arch_name^^}"
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100692 fi
David Brazdil5cc343d2015-10-08 11:35:32 +0100693
694 if [ "$debuggable" = "yes" ]; then
695 checker_args="$checker_args --debuggable"
696 fi
697
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100698 run_args="${run_args} -Xcompiler-option --dump-cfg=$cfg_output_dir/$cfg_output \
David Brazdil80fb3942015-07-23 11:53:42 +0100699 -Xcompiler-option -j1"
700 fi
David Brazdil4846d132015-01-15 19:07:08 +0000701 fi
702fi
703
Mathieu Chartier031768a2015-08-27 10:25:02 -0700704if [ "$runtime" != "jvm" ]; then
705 run_args="${run_args} --testlib ${testlib}"
706fi
707
Ian Rogers997f0f92014-06-21 22:58:05 -0700708# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100709build_file_size_limit=2048
710run_file_size_limit=2048
Ian Rogers997f0f92014-06-21 22:58:05 -0700711if echo "$test_dir" | grep 089; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100712 build_file_size_limit=5120
713 run_file_size_limit=5120
Ian Rogers997f0f92014-06-21 22:58:05 -0700714elif echo "$test_dir" | grep 083; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100715 build_file_size_limit=5120
716 run_file_size_limit=5120
Ian Rogers997f0f92014-06-21 22:58:05 -0700717fi
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100718if [ "$run_checker" = "yes" -a "$target_mode" = "yes" ]; then
719 # We will need to `adb pull` the .cfg output from the target onto the host to
720 # run checker on it. This file can be big.
721 build_file_size_limit=16384
722 run_file_size_limit=16384
723fi
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100724if [ ${USE_JACK} = "false" ]; then
725 # Set ulimit if we build with dx only, Jack can generate big temp files.
726 if ! ulimit -S "$build_file_size_limit"; then
Alex Light91de25f2015-10-28 17:00:06 -0700727 err_echo "ulimit file size setting failed"
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100728 fi
Ian Rogers997f0f92014-06-21 22:58:05 -0700729fi
730
jeffhao5d1ac922011-09-29 17:41:15 -0700731good="no"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000732good_build="yes"
733good_run="yes"
jeffhao5d1ac922011-09-29 17:41:15 -0700734if [ "$dev_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000735 "./${build}" $build_args 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700736 build_exit="$?"
737 echo "build exit status: $build_exit" 1>&2
738 if [ "$build_exit" = '0' ]; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100739 if ! ulimit -S "$run_file_size_limit"; then
Alex Light91de25f2015-10-28 17:00:06 -0700740 err_echo "ulimit file size setting failed"
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100741 fi
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800742 echo "${test_dir}: running..." 1>&2
743 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700744 run_exit="$?"
Calin Juravle3cf48772015-01-26 16:47:33 +0000745
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800746 if [ "$run_exit" = "0" ]; then
Calin Juravle3cf48772015-01-26 16:47:33 +0000747 if [ "$run_checker" = "yes" ]; then
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100748 if [ "$target_mode" = "yes" ]; then
749 adb pull $cfg_output_dir/$cfg_output &> /dev/null
750 fi
David Brazdil5cc343d2015-10-08 11:35:32 +0100751 "$checker" $checker_args "$cfg_output" "$tmp_dir" 2>&1
Calin Juravle3cf48772015-01-26 16:47:33 +0000752 checker_exit="$?"
753 if [ "$checker_exit" = "0" ]; then
754 good="yes"
755 fi
Alex Light91de25f2015-10-28 17:00:06 -0700756 err_echo "checker exit status: $checker_exit"
Calin Juravle3cf48772015-01-26 16:47:33 +0000757 else
758 good="yes"
759 fi
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800760 fi
Calin Juravle3cf48772015-01-26 16:47:33 +0000761 echo "run exit status: $run_exit" 1>&2
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700762 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700763elif [ "$update_mode" = "yes" ]; then
David Brazdil4846d132015-01-15 19:07:08 +0000764 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700765 build_exit="$?"
766 if [ "$build_exit" = '0' ]; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100767 if ! ulimit -S "$run_file_size_limit"; then
Alex Light91de25f2015-10-28 17:00:06 -0700768 err_echo "ulimit file size setting failed"
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100769 fi
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800770 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700771 "./${run}" $run_args "$@" >"$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000772 if [ "$run_checker" = "yes" ]; then
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100773 if [ "$target_mode" = "yes" ]; then
774 adb pull $cfg_output_dir/$cfg_output &> /dev/null
775 fi
David Brazdil5cc343d2015-10-08 11:35:32 +0100776 "$checker" -q $checker_args "$cfg_output" "$tmp_dir" >> "$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000777 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700778 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
779 good="yes"
780 else
Alex Light91de25f2015-10-28 17:00:06 -0700781 cat "$build_output" 1>&${real_stderr} 1>&2
782 err_echo "build exit status: $build_exit"
jeffhao5d1ac922011-09-29 17:41:15 -0700783 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700784elif [ "$build_only" = "yes" ]; then
785 good="yes"
David Brazdil4846d132015-01-15 19:07:08 +0000786 "./${build}" $build_args >"$build_output" 2>&1
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700787 build_exit="$?"
788 if [ "$build_exit" '!=' '0' ]; then
789 cp "$build_output" "$output"
790 echo "build exit status: $build_exit" >>"$output"
791 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
792 if [ "$?" '!=' "0" ]; then
793 good="no"
Alex Light91de25f2015-10-28 17:00:06 -0700794 err_echo "BUILD FAILED For ${TEST_NAME}"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700795 fi
796 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700797 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700798 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700799 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700800else
David Brazdil4846d132015-01-15 19:07:08 +0000801 "./${build}" $build_args >"$build_output" 2>&1
jeffhao5d1ac922011-09-29 17:41:15 -0700802 build_exit="$?"
803 if [ "$build_exit" = '0' ]; then
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100804 if ! ulimit -S "$run_file_size_limit"; then
Alex Light91de25f2015-10-28 17:00:06 -0700805 err_echo "ulimit file size setting failed"
Sebastien Hertz19ac0272015-02-24 17:39:50 +0100806 fi
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800807 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700808 "./${run}" $run_args "$@" >"$output" 2>&1
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000809 run_exit="$?"
810 if [ "$run_exit" != "0" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700811 err_echo "run exit status: $run_exit"
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000812 good_run="no"
David Brazdil4846d132015-01-15 19:07:08 +0000813 elif [ "$run_checker" = "yes" ]; then
Alexandre Rames5e2c8d32015-08-06 14:49:28 +0100814 if [ "$target_mode" = "yes" ]; then
815 adb pull $cfg_output_dir/$cfg_output &> /dev/null
816 fi
David Brazdil5cc343d2015-10-08 11:35:32 +0100817 "$checker" -q $checker_args "$cfg_output" "$tmp_dir" >> "$output" 2>&1
David Brazdil4846d132015-01-15 19:07:08 +0000818 checker_exit="$?"
819 if [ "$checker_exit" != "0" ]; then
Alex Light91de25f2015-10-28 17:00:06 -0700820 err_echo "checker exit status: $checker_exit"
David Brazdil4846d132015-01-15 19:07:08 +0000821 good_run="no"
822 else
823 good_run="yes"
824 fi
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000825 else
826 good_run="yes"
827 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700828 else
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000829 good_build="no"
jeffhao5d1ac922011-09-29 17:41:15 -0700830 cp "$build_output" "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700831 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`" >> "$output"
832 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}" >> "$output"
Ian Rogersd9ad27d2014-10-27 13:48:21 -0700833 echo "Args: ${args}" >> "$output"
Andreas Gampef6930a82014-10-21 09:33:08 -0700834 echo "build exit status: $build_exit" >> "$output"
Andreas Gampe5c114902014-10-27 17:03:58 -0700835 max_name_length=$(getconf NAME_MAX ${tmp_dir})
836 echo "Max filename (NAME_MAX): ${max_name_length}" >> "$output"
837 max_path_length=$(getconf PATH_MAX ${tmp_dir})
Andreas Gampe602fbcd2014-10-27 17:06:29 -0700838 echo "Max pathlength (PATH_MAX): ${max_path_length}" >> "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700839 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700840 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700841 if [ "$?" = "0" ]; then
Nicolas Geoffray1ed097d2014-11-13 15:15:39 +0000842 if [ "$good_build" = "no" -o "$good_run" = "yes" ]; then
843 # output == expected
844 good="yes"
845 echo "${test_dir}: succeeded!" 1>&2
846 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700847 fi
848fi
849
jeffhao5d1ac922011-09-29 17:41:15 -0700850(
Alex Lightbfac14a2014-07-30 09:41:21 -0700851 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700852 echo "${test_dir}: FAILED!"
853 echo ' '
854 echo '#################### info'
855 cat "${td_info}" | sed 's/^/# /g'
856 echo '#################### diffs'
Hiroshi Yamauchid630fd62015-09-04 12:52:03 -0700857 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 3000
jeffhao5d1ac922011-09-29 17:41:15 -0700858 echo '####################'
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700859 if [ "$strace" = "yes" ]; then
860 echo '#################### strace output'
Hiroshi Yamauchid630fd62015-09-04 12:52:03 -0700861 tail -n 3000 "$tmp_dir/$strace_output"
Hiroshi Yamauchi1d4184d2015-07-13 17:11:22 -0700862 echo '####################'
863 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700864 echo ' '
865 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700866
Alex Light91de25f2015-10-28 17:00:06 -0700867) 2>&${real_stderr} 1>&2
Alex Lightbfac14a2014-07-30 09:41:21 -0700868
869# Clean up test files.
Igor Murashkin05f30e12015-06-10 15:57:17 -0700870if [ "$always_clean" = "yes" -o "$good" = "yes" ] && [ "$never_clean" = "no" ]; then
Alex Lightbfac14a2014-07-30 09:41:21 -0700871 cd "$oldwd"
872 rm -rf "$tmp_dir"
873 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
874 adb shell rm -rf $DEX_LOCATION
875 fi
876 if [ "$good" = "yes" ]; then
877 exit 0
878 fi
879fi
880
881
882(
883 if [ "$always_clean" = "yes" ]; then
884 echo "${TEST_NAME} files deleted from host "
885 if [ "$target_mode" == "yes" ]; then
886 echo "and from target"
887 fi
888 else
889 echo "${TEST_NAME} files left in ${tmp_dir} on host"
890 if [ "$target_mode" == "yes" ]; then
891 echo "and in ${DEX_LOCATION} on target"
892 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700893 fi
894
Alex Light91de25f2015-10-28 17:00:06 -0700895) 2>&${real_stderr} 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700896
897exit 1