blob: f11580e9fbf9dd8f1f61b28d86b36914ef618ace [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"
20while [ -h "${prog}" ]; do
21 newProg=`/bin/ls -ld "${prog}"`
22 newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
23 if expr "x${newProg}" : 'x/' >/dev/null; then
24 prog="${newProg}"
25 else
26 progdir=`dirname "${prog}"`
27 prog="${progdir}/${newProg}"
28 fi
29done
30oldwd=`pwd`
31progdir=`dirname "${prog}"`
32cd "${progdir}"
33progdir=`pwd`
34prog="${progdir}"/`basename "${prog}"`
Brian Carlstrom105215d2012-06-14 12:50:44 -070035test_dir="test-$$"
Andreas Gampe5a79fde2014-08-06 13:12:26 -070036if [ -z "$TMPDIR" ]; then
37 tmp_dir="/tmp/$USER/${test_dir}"
38else
39 tmp_dir="${TMPDIR}/$USER/${test_dir}"
40fi
jeffhao5d1ac922011-09-29 17:41:15 -070041
42export JAVA="java"
Brian Carlstrom5103ce62014-03-30 16:17:42 -070043export JAVAC="javac -g"
jeffhao5d1ac922011-09-29 17:41:15 -070044export RUN="${progdir}/etc/push-and-run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070045export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070046export NEED_DEX="true"
jeffhao5d1ac922011-09-29 17:41:15 -070047
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070048# If dx was not set by the environment variable, assume it is in the path.
49if [ -z "$DX" ]; then
50 export DX="dx"
51fi
52
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080053# If jasmin was not set by the environment variable, assume it is in the path.
54if [ -z "$JASMIN" ]; then
55 export JASMIN="jasmin"
56fi
57
58
jeffhao5d1ac922011-09-29 17:41:15 -070059info="info.txt"
60build="build"
61run="run"
62expected="expected.txt"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -070063check_cmd="check"
jeffhao5d1ac922011-09-29 17:41:15 -070064output="output.txt"
65build_output="build-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070066lib="libartd.so"
jeffhao5d1ac922011-09-29 17:41:15 -070067run_args="--quiet"
68
Alex Light9d722532014-07-22 18:07:12 -070069prebuild_mode="yes"
Brian Carlstrom2613de42012-06-15 17:37:16 -070070target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070071dev_mode="no"
72update_mode="no"
Alex Lighta59dd802014-07-02 16:28:08 -070073debug_mode="no"
74relocate="yes"
Jeff Hao201803f2013-11-20 18:11:39 -080075runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070076usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070077build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070078suffix64=""
Jeff Hao85139a32014-07-23 11:52:52 -070079trace="false"
Alex Lighte7873ec2014-08-12 09:53:50 -070080basic_verify="false"
81gc_verify="false"
82gc_stress="false"
Alex Lightbfac14a2014-07-30 09:41:21 -070083always_clean="no"
Alex Light03a112d2014-08-25 13:25:56 -070084have_dex2oat="yes"
85have_patchoat="yes"
86have_image="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070087
88while true; do
89 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070090 target_mode="no"
TDYa127b92bcab2012-04-08 00:09:51 -070091 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070092 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080093 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070094 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -080095 runtime="jvm"
Brian Carlstrom01afdba2014-10-03 10:28:47 -070096 prebuild_mode="no"
Elliott Hughesc717eef2012-06-15 16:01:26 -070097 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070098 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080099 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700100 lib="libart.so"
101 shift
102 elif [ "x$1" = "x--dalvik" ]; then
103 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800104 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700105 shift
Alex Light03a112d2014-08-25 13:25:56 -0700106 elif [ "x$1" = "x--no-dex2oat" ]; then
107 have_dex2oat="no"
108 shift
109 elif [ "x$1" = "x--no-patchoat" ]; then
110 have_patchoat="no"
111 shift
112 elif [ "x$1" = "x--no-image" ]; then
113 have_image="no"
114 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700115 elif [ "x$1" = "x--relocate" ]; then
116 relocate="yes"
117 shift
118 elif [ "x$1" = "x--no-relocate" ]; then
119 relocate="no"
120 shift
121 elif [ "x$1" = "x--prebuild" ]; then
122 prebuild_mode="yes"
123 shift;
124 elif [ "x$1" = "x--no-prebuild" ]; then
125 prebuild_mode="no"
126 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700127 elif [ "x$1" = "x--gcverify" ]; then
128 basic_verify="true"
129 gc_verify="true"
130 shift
131 elif [ "x$1" = "x--gcstress" ]; then
132 basic_verify="true"
133 gc_stress="true"
134 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700135 elif [ "x$1" = "x--image" ]; then
136 shift
137 image="$1"
138 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700139 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000140 elif [ "x$1" = "x-Xcompiler-option" ]; then
141 shift
142 option="$1"
143 run_args="${run_args} -Xcompiler-option $option"
144 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700145 elif [ "x$1" = "x--runtime-option" ]; then
146 shift
147 option="$1"
148 run_args="${run_args} --runtime-option $option"
149 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700150 elif [ "x$1" = "x--debug" ]; then
151 run_args="${run_args} --debug"
152 shift
153 elif [ "x$1" = "x--gdb" ]; then
154 run_args="${run_args} --gdb"
155 dev_mode="yes"
156 shift
157 elif [ "x$1" = "x--zygote" ]; then
158 run_args="${run_args} --zygote"
159 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800160 elif [ "x$1" = "x--interpreter" ]; then
161 run_args="${run_args} --interpreter"
162 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700163 elif [ "x$1" = "x--no-verify" ]; then
164 run_args="${run_args} --no-verify"
165 shift
166 elif [ "x$1" = "x--no-optimize" ]; then
167 run_args="${run_args} --no-optimize"
168 shift
169 elif [ "x$1" = "x--no-precise" ]; then
170 run_args="${run_args} --no-precise"
171 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700172 elif [ "x$1" = "x--invoke-with" ]; then
173 shift
174 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700175 if [ "x$what" = "x" ]; then
176 echo "$0 missing argument to --invoke-with" 1>&2
177 usage="yes"
178 break
179 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700180 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700181 shift
182 elif [ "x$1" = "x--dev" ]; then
183 run_args="${run_args} --dev"
184 dev_mode="yes"
185 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700186 elif [ "x$1" = "x--build-only" ]; then
187 build_only="yes"
188 shift
189 elif [ "x$1" = "x--output-path" ]; then
190 shift
191 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700192 if [ "x$tmp_dir" = "x" ]; then
193 echo "$0 missing argument to --output-path" 1>&2
194 usage="yes"
195 break
196 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700197 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700198 elif [ "x$1" = "x--update" ]; then
199 update_mode="yes"
200 shift
201 elif [ "x$1" = "x--help" ]; then
202 usage="yes"
203 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700204 elif [ "x$1" = "x--64" ]; then
205 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700206 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700207 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200208 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700209 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200210 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700211 elif [ "x$1" = "x--always-clean" ]; then
212 always_clean="yes"
213 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700214 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700215 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700216 usage="yes"
217 break
218 else
219 break
220 fi
221done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700222
223# tmp_dir may be relative, resolve.
224#
225# Cannot use realpath, as it does not exist on Mac.
226# Cannot us a simple "cd", as the path might not be created yet.
Brian Carlstromc580e042014-09-08 21:37:39 -0700227# Cannot use readlink -m, as it does not exist on Mac.
228# Fallback to nuclear option:
Andreas Gampe907b6992014-08-18 22:26:49 -0700229noncanonical_tmp_dir=$tmp_dir
Brian Carlstromc580e042014-09-08 21:37:39 -0700230tmp_dir="`cd $oldwd ; python -c "import os; print os.path.realpath('$tmp_dir')"`"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700231mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700232
Alex Lighte7873ec2014-08-12 09:53:50 -0700233if [ "$basic_verify" = "true" ]; then
234 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify"
235fi
236if [ "$gc_verify" = "true" ]; then
237 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
238fi
239if [ "$gc_stress" = "true" ]; then
240 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
241fi
Jeff Hao85139a32014-07-23 11:52:52 -0700242if [ "$trace" = "true" ]; then
243 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
244fi
245
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700246# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100247# Try to map the suffix64 flag and what we find in ${ANDROID_PRODUCT_OUT}/data/art-test to an architecture name.
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700248function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100249 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
250 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700251 if [ "x${suffix64}" = "x64" ]; then
252 target_arch_name=${grep64bit}
253 else
254 target_arch_name=${grep32bit}
255 fi
256}
257
Alex Lighta59dd802014-07-02 16:28:08 -0700258if [ "$target_mode" = "no" ]; then
259 if [ "$runtime" = "jvm" ]; then
260 RUN="${progdir}/etc/reference-run-test-classes"
261 if [ "$prebuild_mode" = "yes" ]; then
262 echo "--prebuild with --jvm is unsupported";
263 exit 1;
264 fi
265 else
266 RUN="${progdir}/etc/host-run-test-jar"
267 if [ "$prebuild_mode" = "yes" ]; then
268 run_args="${run_args} --prebuild"
269 fi
270 fi
271else
272 if [ "$prebuild_mode" = "yes" ]; then
273 RUN="${progdir}/etc/push-and-run-prebuilt-test-jar"
274 fi
275fi
276
Alex Light03a112d2014-08-25 13:25:56 -0700277if [ "$have_patchoat" = "no" ]; then
278 run_args="${run_args} --no-patchoat"
279fi
280
281if [ "$have_dex2oat" = "no" ]; then
282 run_args="${run_args} --no-dex2oat"
283fi
284
Jeff Hao201803f2013-11-20 18:11:39 -0800285if [ ! "$runtime" = "jvm" ]; then
286 run_args="${run_args} --lib $lib"
287fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700288
Jeff Hao201803f2013-11-20 18:11:39 -0800289if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700290 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100291 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700292 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
293 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
294 else
295 true # defaults to using target BOOTCLASSPATH
296 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800297elif [ "$runtime" = "art" ]; then
298 if [ "$target_mode" = "no" ]; then
Brian Carlstrom43534862014-02-19 01:13:52 -0800299 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
300 if [ -z "$ANDROID_BUILD_TOP" ]; then
301 export ANDROID_BUILD_TOP=$oldwd
302 fi
303 if [ -z "$ANDROID_HOST_OUT" ]; then
304 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
305 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800306 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700307 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800308 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700309 guess_arch_name
310 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700311 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800312 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700313 if [ "$relocate" = "yes" ]; then
314 run_args="${run_args} --relocate"
315 else
316 run_args="${run_args} --no-relocate"
317 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700318fi
319
Alex Light03a112d2014-08-25 13:25:56 -0700320if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700321 if [ "$runtime" != "art" ]; then
322 echo "--no-image is only supported on the art runtime"
323 exit 1
324 fi
325 if [ "$target_mode" = "no" ]; then
326 framework="${ANDROID_HOST_OUT}/framework"
327 bpath_suffix="-hostdex"
328 else
329 framework="/system/framework"
330 bpath_suffix=""
331 fi
332 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
333 # fail since these jar files will be stripped.
334 bpath="${framework}/core-libart${bpath_suffix}.jar"
335 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
336 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
337 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
338 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
339 # Pass down the bootclasspath
340 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700341 run_args="${run_args} --no-image"
342fi
343
jeffhao5d1ac922011-09-29 17:41:15 -0700344if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
345 echo "--dev and --update are mutually exclusive" 1>&2
346 usage="yes"
347fi
348
349if [ "$usage" = "no" ]; then
350 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
351 test_dir=`basename "$oldwd"`
352 else
353 test_dir="$1"
354 fi
355
356 if [ '!' -d "$test_dir" ]; then
357 td2=`echo ${test_dir}-*`
358 if [ '!' -d "$td2" ]; then
359 echo "${test_dir}: no such test directory" 1>&2
360 usage="yes"
361 fi
362 test_dir="$td2"
363 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700364 # Shift to get rid of the test name argument. The rest of the arguments
365 # will get passed to the test run.
366 shift
367fi
368
369if [ "$usage" = "yes" ]; then
370 prog=`basename $prog`
371 (
372 echo "usage:"
373 echo " $prog --help Print this message."
374 echo " $prog [options] [test-name] Run test normally."
375 echo " $prog --dev [options] [test-name] Development mode" \
376 "(dumps to stdout)."
377 echo " $prog --update [options] [test-name] Update mode" \
378 "(replaces expected.txt)."
379 echo ' Omitting the test name or specifying "-" will use the' \
380 "current directory."
381 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000382 echo " -O Run non-debug rather than debug build (off by default)."
383 echo " -Xcompiler-option Pass an option to the compiler."
Ian Rogers701aa642014-07-18 11:38:13 -0700384 echo " --runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000385 echo " --debug Wait for a debugger to attach."
386 echo " --gdb Run under gdb; incompatible with some tests."
387 echo " --build-only Build test files only (off by default)."
388 echo " --interpreter Enable interpreter only mode (off by default)."
389 echo " --no-verify Turn off verification (on by default)."
390 echo " --no-optimize Turn off optimization (on by default)."
391 echo " --no-precise Turn off precise GC (on by default)."
392 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700393 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000394 echo " other runtime options are ignored."
Alex Light03a112d2014-08-25 13:25:56 -0700395 echo " --no-dex2oat Run as though dex2oat was failing."
396 echo " --no-patchoat Run as though patchoat was failing."
Alex Light9d722532014-07-22 18:07:12 -0700397 echo " --prebuild Run dex2oat on the files before starting test. (default)"
Alex Lighta59dd802014-07-02 16:28:08 -0700398 echo " --no-prebuild Do not run dex2oat on the files before starting"
Alex Light9d722532014-07-22 18:07:12 -0700399 echo " the test."
Alex Lighta59dd802014-07-02 16:28:08 -0700400 echo " --relocate Force the use of relocating in the test, making"
401 echo " the image and oat files be relocated to a random"
402 echo " address before running. (default)"
403 echo " --no-relocate Force the use of no relocating in the test"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000404 echo " --host Use the host-mode virtual machine."
405 echo " --invoke-with Pass --invoke-with option to runtime."
406 echo " --dalvik Use Dalvik (off by default)."
407 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700408 echo " --output-path [path] Location where to store the build" \
409 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700410 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200411 echo " --trace Run with method tracing"
Alex Lighte7873ec2014-08-12 09:53:50 -0700412 echo " --gcstress Run with gc stress testing"
413 echo " --gcverify Run with gc verification"
Alex Lightbfac14a2014-07-30 09:41:21 -0700414 echo " --always-clean Delete the test files even if the test fails."
jeffhao5d1ac922011-09-29 17:41:15 -0700415 ) 1>&2
416 exit 1
417fi
418
419cd "$test_dir"
420test_dir=`pwd`
421
422td_info="${test_dir}/${info}"
423td_expected="${test_dir}/${expected}"
424
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700425if [ ! -r $td_info ]; then
426 echo "${test_dir}: missing file $td_info" 1>&2
427 exit 1
428fi
429
430if [ ! -r $td_expected ]; then
431 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700432 exit 1
433fi
434
435# copy the test to a temp dir and run it
436
Elliott Hughes510c8782011-10-06 10:57:34 -0700437echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700438
439rm -rf "$tmp_dir"
440cp -Rp "$test_dir" "$tmp_dir"
441cd "$tmp_dir"
442
443if [ '!' -r "$build" ]; then
444 cp "${progdir}/etc/default-build" build
445fi
446
447if [ '!' -r "$run" ]; then
448 cp "${progdir}/etc/default-run" run
449fi
450
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700451if [ '!' -r "$check_cmd" ]; then
452 cp "${progdir}/etc/default-check" check
453fi
454
jeffhao5d1ac922011-09-29 17:41:15 -0700455chmod 755 "$build"
456chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700457chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700458
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700459export TEST_NAME=`basename ${test_dir}`
460
Ian Rogers997f0f92014-06-21 22:58:05 -0700461# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
462file_size_limit=2048
463if echo "$test_dir" | grep 089; then
464 file_size_limit=5120
465elif echo "$test_dir" | grep 083; then
466 file_size_limit=5120
Andreas Gampe855564b2014-07-25 02:32:19 -0700467elif echo "$test_dir" | grep 115; then
468# Native bridge test copies libarttest.so into its directory, which needs 2MB already.
469 file_size_limit=5120
Ian Rogers997f0f92014-06-21 22:58:05 -0700470fi
Alex Lighta59dd802014-07-02 16:28:08 -0700471if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700472 echo "ulimit file size setting failed"
473fi
474
jeffhao5d1ac922011-09-29 17:41:15 -0700475good="no"
476if [ "$dev_mode" = "yes" ]; then
477 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700478 build_exit="$?"
479 echo "build exit status: $build_exit" 1>&2
480 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800481 echo "${test_dir}: running..." 1>&2
482 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700483 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800484 echo "run exit status: $run_exit" 1>&2
485 if [ "$run_exit" = "0" ]; then
486 good="yes"
487 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700488 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700489elif [ "$update_mode" = "yes" ]; then
490 "./${build}" >"$build_output" 2>&1
491 build_exit="$?"
492 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800493 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700494 "./${run}" $run_args "$@" >"$output" 2>&1
495 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
496 good="yes"
497 else
498 cat "$build_output" 1>&2
499 echo "build exit status: $build_exit" 1>&2
500 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700501elif [ "$build_only" = "yes" ]; then
502 good="yes"
503 "./${build}" >"$build_output" 2>&1
504 build_exit="$?"
505 if [ "$build_exit" '!=' '0' ]; then
506 cp "$build_output" "$output"
507 echo "build exit status: $build_exit" >>"$output"
508 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
509 if [ "$?" '!=' "0" ]; then
510 good="no"
511 echo "BUILD FAILED For ${TEST_NAME}"
512 fi
513 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700514 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700515 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700516 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700517else
518 "./${build}" >"$build_output" 2>&1
519 build_exit="$?"
520 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800521 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700522 "./${run}" $run_args "$@" >"$output" 2>&1
523 else
524 cp "$build_output" "$output"
Andreas Gampe907b6992014-08-18 22:26:49 -0700525 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`"
526 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}"
jeffhao5d1ac922011-09-29 17:41:15 -0700527 echo "build exit status: $build_exit" >>"$output"
528 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700529 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700530 if [ "$?" = "0" ]; then
531 # output == expected
532 good="yes"
533 echo "${test_dir}: succeeded!" 1>&2
534 fi
535fi
536
jeffhao5d1ac922011-09-29 17:41:15 -0700537(
Alex Lightbfac14a2014-07-30 09:41:21 -0700538 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700539 echo "${test_dir}: FAILED!"
540 echo ' '
541 echo '#################### info'
542 cat "${td_info}" | sed 's/^/# /g'
543 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700544 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700545 echo '####################'
546 echo ' '
547 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700548
549) 1>&2
550
551# Clean up test files.
552if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
553 cd "$oldwd"
554 rm -rf "$tmp_dir"
555 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
556 adb shell rm -rf $DEX_LOCATION
557 fi
558 if [ "$good" = "yes" ]; then
559 exit 0
560 fi
561fi
562
563
564(
565 if [ "$always_clean" = "yes" ]; then
566 echo "${TEST_NAME} files deleted from host "
567 if [ "$target_mode" == "yes" ]; then
568 echo "and from target"
569 fi
570 else
571 echo "${TEST_NAME} files left in ${tmp_dir} on host"
572 if [ "$target_mode" == "yes" ]; then
573 echo "and in ${DEX_LOCATION} on target"
574 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700575 fi
576
jeffhao5d1ac922011-09-29 17:41:15 -0700577) 1>&2
578
579exit 1