blob: 323f84665edb991ac775ca0830c44370ba213a70 [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-$$"
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +070036tmp_dir="/tmp/$USER/${test_dir}"
jeffhao5d1ac922011-09-29 17:41:15 -070037
38export JAVA="java"
Brian Carlstrom5103ce62014-03-30 16:17:42 -070039export JAVAC="javac -g"
jeffhao5d1ac922011-09-29 17:41:15 -070040export RUN="${progdir}/etc/push-and-run-test-jar"
Brian Carlstrom105215d2012-06-14 12:50:44 -070041export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070042export NEED_DEX="true"
jeffhao5d1ac922011-09-29 17:41:15 -070043
Tsu Chiang Chuang4407e612012-07-19 16:13:43 -070044# If dx was not set by the environment variable, assume it is in the path.
45if [ -z "$DX" ]; then
46 export DX="dx"
47fi
48
Tsu Chiang Chuang6674f8a2013-01-16 15:41:21 -080049# If jasmin was not set by the environment variable, assume it is in the path.
50if [ -z "$JASMIN" ]; then
51 export JASMIN="jasmin"
52fi
53
54
jeffhao5d1ac922011-09-29 17:41:15 -070055info="info.txt"
56build="build"
57run="run"
58expected="expected.txt"
59output="output.txt"
60build_output="build-output.txt"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070061lib="libartd.so"
jeffhao5d1ac922011-09-29 17:41:15 -070062run_args="--quiet"
63
Brian Carlstrom2613de42012-06-15 17:37:16 -070064target_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070065dev_mode="no"
66update_mode="no"
67debug_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -080068runtime="art"
jeffhao5d1ac922011-09-29 17:41:15 -070069usage="no"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070070build_only="no"
Andreas Gampe2fe07922014-04-21 07:50:39 -070071suffix64=""
jeffhao5d1ac922011-09-29 17:41:15 -070072
73while true; do
74 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070075 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070076 RUN="${progdir}/etc/host-run-test-jar"
TDYa127b92bcab2012-04-08 00:09:51 -070077 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070078 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080079 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070080 target_mode="no"
Jeff Hao201803f2013-11-20 18:11:39 -080081 runtime="jvm"
jeffhao5d1ac922011-09-29 17:41:15 -070082 RUN="${progdir}/etc/reference-run-test-classes"
Elliott Hughesc717eef2012-06-15 16:01:26 -070083 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070084 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080085 elif [ "x$1" = "x-O" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -070086 lib="libart.so"
87 shift
88 elif [ "x$1" = "x--dalvik" ]; then
89 lib="libdvm.so"
Jeff Hao201803f2013-11-20 18:11:39 -080090 runtime="dalvik"
Brian Carlstromdc959ea2013-10-28 00:44:49 -070091 shift
92 elif [ "x$1" = "x--image" ]; then
93 shift
94 image="$1"
95 run_args="${run_args} --image $image"
Elliott Hughes7c046102011-10-19 18:16:03 -070096 shift
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +000097 elif [ "x$1" = "x-Xcompiler-option" ]; then
98 shift
99 option="$1"
100 run_args="${run_args} -Xcompiler-option $option"
101 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700102 elif [ "x$1" = "x--debug" ]; then
103 run_args="${run_args} --debug"
104 shift
105 elif [ "x$1" = "x--gdb" ]; then
106 run_args="${run_args} --gdb"
107 dev_mode="yes"
108 shift
109 elif [ "x$1" = "x--zygote" ]; then
110 run_args="${run_args} --zygote"
111 shift
jeffhao0dff3f42012-11-20 15:13:43 -0800112 elif [ "x$1" = "x--interpreter" ]; then
113 run_args="${run_args} --interpreter"
114 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700115 elif [ "x$1" = "x--no-verify" ]; then
116 run_args="${run_args} --no-verify"
117 shift
118 elif [ "x$1" = "x--no-optimize" ]; then
119 run_args="${run_args} --no-optimize"
120 shift
121 elif [ "x$1" = "x--no-precise" ]; then
122 run_args="${run_args} --no-precise"
123 shift
Elliott Hughes7c046102011-10-19 18:16:03 -0700124 elif [ "x$1" = "x--invoke-with" ]; then
125 shift
126 what="$1"
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700127 if [ "x$what" = "x" ]; then
128 echo "$0 missing argument to --invoke-with" 1>&2
129 usage="yes"
130 break
131 fi
Ian Rogers0e033672013-04-19 10:22:46 -0700132 run_args="${run_args} --invoke-with ${what}"
jeffhao5d1ac922011-09-29 17:41:15 -0700133 shift
134 elif [ "x$1" = "x--dev" ]; then
135 run_args="${run_args} --dev"
136 dev_mode="yes"
137 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700138 elif [ "x$1" = "x--build-only" ]; then
139 build_only="yes"
140 shift
141 elif [ "x$1" = "x--output-path" ]; then
142 shift
143 tmp_dir=$1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700144 if [ "x$tmp_dir" = "x" ]; then
145 echo "$0 missing argument to --output-path" 1>&2
146 usage="yes"
147 break
148 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700149 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700150 elif [ "x$1" = "x--update" ]; then
151 update_mode="yes"
152 shift
153 elif [ "x$1" = "x--help" ]; then
154 usage="yes"
155 shift
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700156 elif [ "x$1" = "x--64" ]; then
157 run_args="${run_args} --64"
Andreas Gampe2fe07922014-04-21 07:50:39 -0700158 suffix64="64"
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700159 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700160 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700161 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700162 usage="yes"
163 break
164 else
165 break
166 fi
167done
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700168mkdir -p $tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -0700169
Jeff Hao201803f2013-11-20 18:11:39 -0800170if [ ! "$runtime" = "jvm" ]; then
171 run_args="${run_args} --lib $lib"
172fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700173
Jeff Hao201803f2013-11-20 18:11:39 -0800174if [ "$runtime" = "dalvik" ]; then
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700175 if [ "$target_mode" = "no" ]; then
176 framework="${OUT}/system/framework"
177 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar"
178 run_args="${run_args} --boot -Xbootclasspath:${bpath}"
179 else
180 true # defaults to using target BOOTCLASSPATH
181 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800182elif [ "$runtime" = "art" ]; then
183 if [ "$target_mode" = "no" ]; then
Brian Carlstrom43534862014-02-19 01:13:52 -0800184 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment.
185 if [ -z "$ANDROID_BUILD_TOP" ]; then
186 export ANDROID_BUILD_TOP=$oldwd
187 fi
188 if [ -z "$ANDROID_HOST_OUT" ]; then
189 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86
190 fi
Jeff Hao201803f2013-11-20 18:11:39 -0800191 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art"
192 else
Brian Carlstrom0e12bdc2014-05-14 17:44:28 -0700193 run_args="${run_args} --boot -Ximage:/data/art-test/core.art"
Jeff Hao201803f2013-11-20 18:11:39 -0800194 fi
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700195fi
196
jeffhao5d1ac922011-09-29 17:41:15 -0700197if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
198 echo "--dev and --update are mutually exclusive" 1>&2
199 usage="yes"
200fi
201
202if [ "$usage" = "no" ]; then
203 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
204 test_dir=`basename "$oldwd"`
205 else
206 test_dir="$1"
207 fi
208
209 if [ '!' -d "$test_dir" ]; then
210 td2=`echo ${test_dir}-*`
211 if [ '!' -d "$td2" ]; then
212 echo "${test_dir}: no such test directory" 1>&2
213 usage="yes"
214 fi
215 test_dir="$td2"
216 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700217 # Shift to get rid of the test name argument. The rest of the arguments
218 # will get passed to the test run.
219 shift
220fi
221
222if [ "$usage" = "yes" ]; then
223 prog=`basename $prog`
224 (
225 echo "usage:"
226 echo " $prog --help Print this message."
227 echo " $prog [options] [test-name] Run test normally."
228 echo " $prog --dev [options] [test-name] Development mode" \
229 "(dumps to stdout)."
230 echo " $prog --update [options] [test-name] Update mode" \
231 "(replaces expected.txt)."
232 echo ' Omitting the test name or specifying "-" will use the' \
233 "current directory."
234 echo " Runtime Options:"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000235 echo " -O Run non-debug rather than debug build (off by default)."
236 echo " -Xcompiler-option Pass an option to the compiler."
237 echo " --debug Wait for a debugger to attach."
238 echo " --gdb Run under gdb; incompatible with some tests."
239 echo " --build-only Build test files only (off by default)."
240 echo " --interpreter Enable interpreter only mode (off by default)."
241 echo " --no-verify Turn off verification (on by default)."
242 echo " --no-optimize Turn off optimization (on by default)."
243 echo " --no-precise Turn off precise GC (on by default)."
244 echo " --zygote Spawn the process from the Zygote." \
jeffhao5d1ac922011-09-29 17:41:15 -0700245 "If used, then the"
Nicolas Geoffray92cf83e2014-03-18 17:59:20 +0000246 echo " other runtime options are ignored."
247 echo " --host Use the host-mode virtual machine."
248 echo " --invoke-with Pass --invoke-with option to runtime."
249 echo " --dalvik Use Dalvik (off by default)."
250 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700251 echo " --output-path [path] Location where to store the build" \
252 "files."
Andreas Gampeafbaa1a2014-03-25 18:09:32 -0700253 echo " --64 Run the test in 64-bit mode"
jeffhao5d1ac922011-09-29 17:41:15 -0700254 ) 1>&2
255 exit 1
256fi
257
258cd "$test_dir"
259test_dir=`pwd`
260
261td_info="${test_dir}/${info}"
262td_expected="${test_dir}/${expected}"
263
Brian Carlstrom22469aa2012-09-07 10:34:57 -0700264if [ ! -r $td_info ]; then
265 echo "${test_dir}: missing file $td_info" 1>&2
266 exit 1
267fi
268
269if [ ! -r $td_expected ]; then
270 echo "${test_dir}: missing file $td_expected" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700271 exit 1
272fi
273
274# copy the test to a temp dir and run it
275
Elliott Hughes510c8782011-10-06 10:57:34 -0700276echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700277
278rm -rf "$tmp_dir"
279cp -Rp "$test_dir" "$tmp_dir"
280cd "$tmp_dir"
281
282if [ '!' -r "$build" ]; then
283 cp "${progdir}/etc/default-build" build
284fi
285
286if [ '!' -r "$run" ]; then
287 cp "${progdir}/etc/default-run" run
288fi
289
290chmod 755 "$build"
291chmod 755 "$run"
292
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700293export TEST_NAME=`basename ${test_dir}`
294
jeffhao5d1ac922011-09-29 17:41:15 -0700295good="no"
296if [ "$dev_mode" = "yes" ]; then
297 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700298 build_exit="$?"
299 echo "build exit status: $build_exit" 1>&2
300 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800301 echo "${test_dir}: running..." 1>&2
302 "./${run}" $run_args "$@" 2>&1
Brian Carlstromdc959ea2013-10-28 00:44:49 -0700303 run_exit="$?"
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800304 echo "run exit status: $run_exit" 1>&2
305 if [ "$run_exit" = "0" ]; then
306 good="yes"
307 fi
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700308 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700309elif [ "$update_mode" = "yes" ]; then
310 "./${build}" >"$build_output" 2>&1
311 build_exit="$?"
312 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800313 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700314 "./${run}" $run_args "$@" >"$output" 2>&1
315 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
316 good="yes"
317 else
318 cat "$build_output" 1>&2
319 echo "build exit status: $build_exit" 1>&2
320 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700321elif [ "$build_only" = "yes" ]; then
322 good="yes"
323 "./${build}" >"$build_output" 2>&1
324 build_exit="$?"
325 if [ "$build_exit" '!=' '0' ]; then
326 cp "$build_output" "$output"
327 echo "build exit status: $build_exit" >>"$output"
328 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
329 if [ "$?" '!=' "0" ]; then
330 good="no"
331 echo "BUILD FAILED For ${TEST_NAME}"
332 fi
333 fi
Tsu Chiang Chuang379e2f52013-08-20 12:24:52 -0700334 # Clean up extraneous files that are not used by tests.
Tsu Chiang Chuang0160d992013-09-13 14:17:42 -0700335 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700336 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700337else
338 "./${build}" >"$build_output" 2>&1
339 build_exit="$?"
340 if [ "$build_exit" = '0' ]; then
Elliott Hughes2bfc6732012-11-27 20:40:51 -0800341 echo "${test_dir}: running..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700342 "./${run}" $run_args "$@" >"$output" 2>&1
343 else
344 cp "$build_output" "$output"
345 echo "build exit status: $build_exit" >>"$output"
346 fi
347 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
348 if [ "$?" = "0" ]; then
349 # output == expected
350 good="yes"
351 echo "${test_dir}: succeeded!" 1>&2
352 fi
353fi
354
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700355# Clean up test files.
356if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700357 cd "$oldwd"
358 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700359 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Dmitry Petrochenko81c56e72014-03-05 15:05:46 +0700360 adb shell rm -rf $DEX_LOCATION
Brian Carlstrom105215d2012-06-14 12:50:44 -0700361 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700362 exit 0
363fi
364
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700365
jeffhao5d1ac922011-09-29 17:41:15 -0700366(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700367 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700368 echo "${test_dir}: FAILED!"
369 echo ' '
370 echo '#################### info'
371 cat "${td_info}" | sed 's/^/# /g'
372 echo '#################### diffs'
373 diff --strip-trailing-cr -u "$expected" "$output"
374 echo '####################'
375 echo ' '
376 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700377 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700378 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700379 echo "and in ${DEX_LOCATION} on target"
380 fi
381
jeffhao5d1ac922011-09-29 17:41:15 -0700382) 1>&2
383
384exit 1