blob: eed28a56bec02f945cfb51555f5684552b05f370 [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"
Elliott Hughesc717eef2012-06-15 16:01:26 -070096 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070097 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080098 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -070099 lib="libart.so"
100 shift
101 elif [ "x$1" = "x--dalvik" ]; then
102 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -0800103 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700104 shift
Alex Light03a112d2014-08-25 13:25:56 -0700105 elif [ "x$1" = "x--no-dex2oat" ]; then
106 have_dex2oat="no"
107 shift
108 elif [ "x$1" = "x--no-patchoat" ]; then
109 have_patchoat="no"
110 shift
111 elif [ "x$1" = "x--no-image" ]; then
112 have_image="no"
113 shift
Alex Lighta59dd802014-07-02 16:28:08 -0700114 elif [ "x$1" = "x--relocate" ]; then
115 relocate="yes"
116 shift
117 elif [ "x$1" = "x--no-relocate" ]; then
118 relocate="no"
119 shift
120 elif [ "x$1" = "x--prebuild" ]; then
121 prebuild_mode="yes"
122 shift;
123 elif [ "x$1" = "x--no-prebuild" ]; then
124 prebuild_mode="no"
125 shift;
Alex Lighte7873ec2014-08-12 09:53:50 -0700126 elif [ "x$1" = "x--gcverify" ]; then
127 basic_verify="true"
128 gc_verify="true"
129 shift
130 elif [ "x$1" = "x--gcstress" ]; then
131 basic_verify="true"
132 gc_stress="true"
133 shift
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700134 elif [ "x$1" = "x--image" ]; then
135 shift
136 image="$1"
137 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -0700138 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000139 elif [ "x$1" = "x-Xcompiler-option" ]; then
140 shift
141 option="$1"
142 run_args="${run_args} -Xcompiler-option $option"
143 shift
Mathieu Chartier769a5ad2014-05-18 15:30:10 -0700144 elif [ "x$1" = "x--runtime-option" ]; then
145 shift
146 option="$1"
147 run_args="${run_args} --runtime-option $option"
148 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700149 elif [ "x$1" = "x--debug" ]; then
150 run_args="${run_args} --debug"
151 shift
152 elif [ "x$1" = "x--gdb" ]; then
153 run_args="${run_args} --gdb"
154 dev_mode="yes"
155 shift
156 elif [ "x$1" = "x--zygote" ]; then
157 run_args="${run_args} --zygote"
158 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800159 elif [ "x$1" = "x--interpreter" ]; then
160 run_args="${run_args} --interpreter"
161 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700162 elif [ "x$1" = "x--no-verify" ]; then
163 run_args="${run_args} --no-verify"
164 shift
165 elif [ "x$1" = "x--no-optimize" ]; then
166 run_args="${run_args} --no-optimize"
167 shift
168 elif [ "x$1" = "x--no-precise" ]; then
169 run_args="${run_args} --no-precise"
170 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700171 elif [ "x$1" = "x--invoke-with" ]; then
172 shift
173 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700174 if [ "x$what" = "x" ]; then
175 echo "$0 missing argument to --invoke-with" 1>&2
176 usage="yes"
177 break
178 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700179 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700180 shift
181 elif [ "x$1" = "x--dev" ]; then
182 run_args="${run_args} --dev"
183 dev_mode="yes"
184 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700185 elif [ "x$1" = "x--build-only" ]; then
186 build_only="yes"
187 shift
188 elif [ "x$1" = "x--output-path" ]; then
189 shift
190 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700191 if [ "x$tmp_dir" = "x" ]; then
192 echo "$0 missing argument to --output-path" 1>&2
193 usage="yes"
194 break
195 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700196 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700197 elif [ "x$1" = "x--update" ]; then
198 update_mode="yes"
199 shift
200 elif [ "x$1" = "x--help" ]; then
201 usage="yes"
202 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700203 elif [ "x$1" = "x--64" ]; then
204 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700205 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700206 shift
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200207 elif [ "x$1" = "x--trace" ]; then
Jeff Hao85139a32014-07-23 11:52:52 -0700208 trace="true"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200209 shift
Alex Lightbfac14a2014-07-30 09:41:21 -0700210 elif [ "x$1" = "x--always-clean" ]; then
211 always_clean="yes"
212 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700213 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700214 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700215 usage="yes"
216 break
217 else
218 break
219 fi
220done
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700221
222# tmp_dir may be relative, resolve.
223#
224# Cannot use realpath, as it does not exist on Mac.
225# Cannot us a simple "cd", as the path might not be created yet.
226# Use -m option of readlink: canonicalizes, but allows non-existing components.
Andreas Gampe907b6992014-08-18 22:26:49 -0700227noncanonical_tmp_dir=$tmp_dir
Andreas Gampe3a12cfe2014-08-13 15:40:22 -0700228tmp_dir="`cd $oldwd ; readlink -m $tmp_dir`"
229
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700230mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700231
Alex Lighte7873ec2014-08-12 09:53:50 -0700232if [ "$basic_verify" = "true" ]; then
233 run_args="${run_args} --runtime-option -Xgc:preverify --runtime-option -Xgc:postverify"
234fi
235if [ "$gc_verify" = "true" ]; then
236 run_args="${run_args} --runtime-option -Xgc:preverify_rosalloc --runtime-option -Xgc:postverify_rosalloc"
237fi
238if [ "$gc_stress" = "true" ]; then
239 run_args="${run_args} --runtime-option -Xgc:SS --runtime-option -Xms2m --runtime-option -Xmx2m"
240fi
Jeff Hao85139a32014-07-23 11:52:52 -0700241if [ "$trace" = "true" ]; then
242 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000"
243fi
244
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700245# Most interesting target architecture variables are Makefile variables, not environment variables.
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100246# 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 -0700247function guess_arch_name() {
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100248 grep32bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm|x86|mips)$'`
249 grep64bit=`ls ${ANDROID_PRODUCT_OUT}/data/art-test | grep -E '^(arm64|x86_64)$'`
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700250 if [ "x${suffix64}" = "x64" ]; then
251 target_arch_name=${grep64bit}
252 else
253 target_arch_name=${grep32bit}
254 fi
255}
256
Alex Lighta59dd802014-07-02 16:28:08 -0700257if [ "$target_mode" = "no" ]; then
258 if [ "$runtime" = "jvm" ]; then
259 RUN="${progdir}/etc/reference-run-test-classes"
260 if [ "$prebuild_mode" = "yes" ]; then
261 echo "--prebuild with --jvm is unsupported";
262 exit 1;
263 fi
264 else
265 RUN="${progdir}/etc/host-run-test-jar"
266 if [ "$prebuild_mode" = "yes" ]; then
267 run_args="${run_args} --prebuild"
268 fi
269 fi
270else
271 if [ "$prebuild_mode" = "yes" ]; then
272 RUN="${progdir}/etc/push-and-run-prebuilt-test-jar"
273 fi
274fi
275
Alex Light03a112d2014-08-25 13:25:56 -0700276if [ "$have_patchoat" = "no" ]; then
277 run_args="${run_args} --no-patchoat"
278fi
279
280if [ "$have_dex2oat" = "no" ]; then
281 run_args="${run_args} --no-dex2oat"
282fi
283
Jeff Hao201803f2013-11-20 18:11:39 -0800284if [ ! "$runtime" = "jvm" ]; then
285 run_args="${run_args} --lib $lib"
286fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700287
Jeff Hao201803f2013-11-20 18:11:39 -0800288if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700289 if [ "$target_mode" = "no" ]; then
Nicolas Geoffray6fbcc122014-07-24 00:36:48 +0100290 framework="${ANDROID_PRODUCT_OUT}/system/framework"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700291 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
292 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
293 else
294 true # defaults to using target BOOTCLASSPATH
295 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800296elif [ "$runtime" = "art" ]; then
297 if [ "$target_mode" = "no" ]; then
Brian Carlstrom43534862014-02-19 01:13:52 -0800298 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
299 if [ -z "$ANDROID_BUILD_TOP" ]; then
300 export ANDROID_BUILD_TOP=$oldwd
301 fi
302 if [ -z "$ANDROID_HOST_OUT" ]; then
303 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
304 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800305 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700306 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}"
Jeff Hao201803f2013-11-20 18:11:39 -0800307 else
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700308 guess_arch_name
309 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}"
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700310 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800311 fi
Alex Lighta59dd802014-07-02 16:28:08 -0700312 if [ "$relocate" = "yes" ]; then
313 run_args="${run_args} --relocate"
314 else
315 run_args="${run_args} --no-relocate"
316 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700317fi
318
Alex Light03a112d2014-08-25 13:25:56 -0700319if [ "$have_image" = "no" ]; then
Alex Light1ef4ce82014-08-27 11:13:47 -0700320 if [ "$runtime" != "art" ]; then
321 echo "--no-image is only supported on the art runtime"
322 exit 1
323 fi
324 if [ "$target_mode" = "no" ]; then
325 framework="${ANDROID_HOST_OUT}/framework"
326 bpath_suffix="-hostdex"
327 else
328 framework="/system/framework"
329 bpath_suffix=""
330 fi
331 # TODO If the target was compiled WITH_DEXPREOPT=true then these tests will
332 # fail since these jar files will be stripped.
333 bpath="${framework}/core-libart${bpath_suffix}.jar"
334 bpath="${bpath}:${framework}/conscrypt${bpath_suffix}.jar"
335 bpath="${bpath}:${framework}/okhttp${bpath_suffix}.jar"
336 bpath="${bpath}:${framework}/core-junit${bpath_suffix}.jar"
337 bpath="${bpath}:${framework}/bouncycastle${bpath_suffix}.jar"
338 # Pass down the bootclasspath
339 run_args="${run_args} --runtime-option -Xbootclasspath:${bpath}"
Alex Light03a112d2014-08-25 13:25:56 -0700340 run_args="${run_args} --no-image"
341fi
342
jeffhao5d1ac922011-09-29 17:41:15 -0700343if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
344 echo "--dev and --update are mutually exclusive" 1>&2
345 usage="yes"
346fi
347
348if [ "$usage" = "no" ]; then
349 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
350 test_dir=`basename "$oldwd"`
351 else
352 test_dir="$1"
353 fi
354
355 if [ '!' -d "$test_dir" ]; then
356 td2=`echo ${test_dir}-*`
357 if [ '!' -d "$td2" ]; then
358 echo "${test_dir}: no such test directory" 1>&2
359 usage="yes"
360 fi
361 test_dir="$td2"
362 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700363 # Shift to get rid of the test name argument. The rest of the arguments
364 # will get passed to the test run.
365 shift
366fi
367
368if [ "$usage" = "yes" ]; then
369 prog=`basename $prog`
370 (
371 echo "usage:"
372 echo " $prog --help Print this message."
373 echo " $prog [options] [test-name] Run test normally."
374 echo " $prog --dev [options] [test-name] Development mode" \
375 "(dumps to stdout)."
376 echo " $prog --update [options] [test-name] Update mode" \
377 "(replaces expected.txt)."
378 echo ' Omitting the test name or specifying "-" will use the' \
379 "current directory."
380 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000381 echo " -O Run non-debug rather than debug build (off by default)."
382 echo " -Xcompiler-option Pass an option to the compiler."
Ian Rogers701aa642014-07-18 11:38:13 -0700383 echo " --runtime-option Pass an option to the runtime."
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000384 echo " --debug Wait for a debugger to attach."
385 echo " --gdb Run under gdb; incompatible with some tests."
386 echo " --build-only Build test files only (off by default)."
387 echo " --interpreter Enable interpreter only mode (off by default)."
388 echo " --no-verify Turn off verification (on by default)."
389 echo " --no-optimize Turn off optimization (on by default)."
390 echo " --no-precise Turn off precise GC (on by default)."
391 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700392 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000393 echo " other runtime options are ignored."
Alex Light03a112d2014-08-25 13:25:56 -0700394 echo " --no-dex2oat Run as though dex2oat was failing."
395 echo " --no-patchoat Run as though patchoat was failing."
Alex Light9d722532014-07-22 18:07:12 -0700396 echo " --prebuild Run dex2oat on the files before starting test. (default)"
Alex Lighta59dd802014-07-02 16:28:08 -0700397 echo " --no-prebuild Do not run dex2oat on the files before starting"
Alex Light9d722532014-07-22 18:07:12 -0700398 echo " the test."
Alex Lighta59dd802014-07-02 16:28:08 -0700399 echo " --relocate Force the use of relocating in the test, making"
400 echo " the image and oat files be relocated to a random"
401 echo " address before running. (default)"
402 echo " --no-relocate Force the use of no relocating in the test"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000403 echo " --host Use the host-mode virtual machine."
404 echo " --invoke-with Pass --invoke-with option to runtime."
405 echo " --dalvik Use Dalvik (off by default)."
406 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700407 echo " --output-path [path] Location where to store the build" \
408 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700409 echo " --64 Run the test in 64-bit mode"
Sebastien Hertz07aaac82014-07-09 15:59:05 +0200410 echo " --trace Run with method tracing"
Alex Lighte7873ec2014-08-12 09:53:50 -0700411 echo " --gcstress Run with gc stress testing"
412 echo " --gcverify Run with gc verification"
Alex Lightbfac14a2014-07-30 09:41:21 -0700413 echo " --always-clean Delete the test files even if the test fails."
jeffhao5d1ac922011-09-29 17:41:15 -0700414 ) 1>&2
415 exit 1
416fi
417
418cd "$test_dir"
419test_dir=`pwd`
420
421td_info="${test_dir}/${info}"
422td_expected="${test_dir}/${expected}"
423
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700424if [ ! -r $td_info ]; then
425 echo "${test_dir}: missing file $td_info" 1>&2
426 exit 1
427fi
428
429if [ ! -r $td_expected ]; then
430 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700431 exit 1
432fi
433
434# copy the test to a temp dir and run it
435
Elliott Hughes510c8782011-10-06 10:57:34 -0700436echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700437
438rm -rf "$tmp_dir"
439cp -Rp "$test_dir" "$tmp_dir"
440cd "$tmp_dir"
441
442if [ '!' -r "$build" ]; then
443 cp "${progdir}/etc/default-build" build
444fi
445
446if [ '!' -r "$run" ]; then
447 cp "${progdir}/etc/default-run" run
448fi
449
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700450if [ '!' -r "$check_cmd" ]; then
451 cp "${progdir}/etc/default-check" check
452fi
453
jeffhao5d1ac922011-09-29 17:41:15 -0700454chmod 755 "$build"
455chmod 755 "$run"
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700456chmod 755 "$check_cmd"
jeffhao5d1ac922011-09-29 17:41:15 -0700457
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700458export TEST_NAME=`basename ${test_dir}`
459
Ian Rogers997f0f92014-06-21 22:58:05 -0700460# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB.
461file_size_limit=2048
462if echo "$test_dir" | grep 089; then
463 file_size_limit=5120
464elif echo "$test_dir" | grep 083; then
465 file_size_limit=5120
Andreas Gampe855564b2014-07-25 02:32:19 -0700466elif echo "$test_dir" | grep 115; then
467# Native bridge test copies libarttest.so into its directory, which needs 2MB already.
468 file_size_limit=5120
Ian Rogers997f0f92014-06-21 22:58:05 -0700469fi
Alex Lighta59dd802014-07-02 16:28:08 -0700470if ! ulimit -S "$file_size_limit"; then
Ian Rogers997f0f92014-06-21 22:58:05 -0700471 echo "ulimit file size setting failed"
472fi
473
jeffhao5d1ac922011-09-29 17:41:15 -0700474good="no"
475if [ "$dev_mode" = "yes" ]; then
476 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700477 build_exit="$?"
478 echo "build exit status: $build_exit" 1>&2
479 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800480 echo "${test_dir}: running..." 1>&2
481 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700482 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800483 echo "run exit status: $run_exit" 1>&2
484 if [ "$run_exit" = "0" ]; then
485 good="yes"
486 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700487 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700488elif [ "$update_mode" = "yes" ]; then
489 "./${build}" >"$build_output" 2>&1
490 build_exit="$?"
491 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800492 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700493 "./${run}" $run_args "$@" >"$output" 2>&1
494 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
495 good="yes"
496 else
497 cat "$build_output" 1>&2
498 echo "build exit status: $build_exit" 1>&2
499 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700500elif [ "$build_only" = "yes" ]; then
501 good="yes"
502 "./${build}" >"$build_output" 2>&1
503 build_exit="$?"
504 if [ "$build_exit" '!=' '0' ]; then
505 cp "$build_output" "$output"
506 echo "build exit status: $build_exit" >>"$output"
507 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
508 if [ "$?" '!=' "0" ]; then
509 good="no"
510 echo "BUILD FAILED For ${TEST_NAME}"
511 fi
512 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700513 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700514 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700515 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700516else
517 "./${build}" >"$build_output" 2>&1
518 build_exit="$?"
519 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800520 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700521 "./${run}" $run_args "$@" >"$output" 2>&1
522 else
523 cp "$build_output" "$output"
Andreas Gampe907b6992014-08-18 22:26:49 -0700524 echo "Failed to build in tmpdir=${tmp_dir} from oldwd=${oldwd} and cwd=`pwd`"
525 echo "Non-canonical tmpdir was ${noncanonical_tmp_dir}"
jeffhao5d1ac922011-09-29 17:41:15 -0700526 echo "build exit status: $build_exit" >>"$output"
527 fi
Andreas Gampe1c83cbc2014-07-22 18:52:29 -0700528 ./$check_cmd "$expected" "$output"
jeffhao5d1ac922011-09-29 17:41:15 -0700529 if [ "$?" = "0" ]; then
530 # output == expected
531 good="yes"
532 echo "${test_dir}: succeeded!" 1>&2
533 fi
534fi
535
jeffhao5d1ac922011-09-29 17:41:15 -0700536(
Alex Lightbfac14a2014-07-30 09:41:21 -0700537 if [ "$good" != "yes" -a "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700538 echo "${test_dir}: FAILED!"
539 echo ' '
540 echo '#################### info'
541 cat "${td_info}" | sed 's/^/# /g'
542 echo '#################### diffs'
Ian Rogers997f0f92014-06-21 22:58:05 -0700543 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500
jeffhao5d1ac922011-09-29 17:41:15 -0700544 echo '####################'
545 echo ' '
546 fi
Alex Lightbfac14a2014-07-30 09:41:21 -0700547
548) 1>&2
549
550# Clean up test files.
551if [ "$always_clean" = "yes" -o "$good" = "yes" ]; then
552 cd "$oldwd"
553 rm -rf "$tmp_dir"
554 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
555 adb shell rm -rf $DEX_LOCATION
556 fi
557 if [ "$good" = "yes" ]; then
558 exit 0
559 fi
560fi
561
562
563(
564 if [ "$always_clean" = "yes" ]; then
565 echo "${TEST_NAME} files deleted from host "
566 if [ "$target_mode" == "yes" ]; then
567 echo "and from target"
568 fi
569 else
570 echo "${TEST_NAME} files left in ${tmp_dir} on host"
571 if [ "$target_mode" == "yes" ]; then
572 echo "and in ${DEX_LOCATION} on target"
573 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700574 fi
575
jeffhao5d1ac922011-09-29 17:41:15 -0700576) 1>&2
577
578exit 1