blob: 8f0d85bd2332b48e0e224fd5f38ea39476ea8c93 [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-$$"
36tmp_dir="/tmp/${test_dir}"
jeffhao5d1ac922011-09-29 17:41:15 -070037
38export JAVA="java"
Elliott Hughes4b0d1ee2011-11-30 14:11:39 -080039export JAVAC="javac -g -target 1.5"
jeffhao5d1ac922011-09-29 17:41:15 -070040export RUN="${progdir}/etc/push-and-run-test-jar"
TDYa127b92bcab2012-04-08 00:09:51 -070041export IMAGE=${ANDROID_PRODUCT_OUT}/data/art-test/core.art
Brian Carlstrom105215d2012-06-14 12:50:44 -070042export DEX_LOCATION=/data/run-test/${test_dir}
Elliott Hughesc717eef2012-06-15 16:01:26 -070043export NEED_DEX="true"
jeffhao5d1ac922011-09-29 17:41:15 -070044
45info="info.txt"
46build="build"
47run="run"
48expected="expected.txt"
49output="output.txt"
50build_output="build-output.txt"
51run_args="--quiet"
52
Brian Carlstrom105215d2012-06-14 12:50:44 -070053host_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070054dev_mode="no"
55update_mode="no"
56debug_mode="no"
57usage="no"
58
59while true; do
60 if [ "x$1" = "x--host" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -070061 host_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070062 RUN="${progdir}/etc/host-run-test-jar"
Elliott Hughese7fb2a62012-04-23 12:39:12 -070063 IMAGE=${ANDROID_HOST_OUT}/framework/core.art
TDYa127b92bcab2012-04-08 00:09:51 -070064 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070065 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080066 elif [ "x$1" = "x--jvm" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -070067 RUN="${progdir}/etc/reference-run-test-classes"
Elliott Hughesc717eef2012-06-15 16:01:26 -070068 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070069 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080070 elif [ "x$1" = "x-O" ]; then
71 run_args="${run_args} -O"
Elliott Hughes7c046102011-10-19 18:16:03 -070072 shift
jeffhao5d1ac922011-09-29 17:41:15 -070073 elif [ "x$1" = "x--debug" ]; then
74 run_args="${run_args} --debug"
75 shift
76 elif [ "x$1" = "x--gdb" ]; then
77 run_args="${run_args} --gdb"
78 dev_mode="yes"
79 shift
80 elif [ "x$1" = "x--zygote" ]; then
81 run_args="${run_args} --zygote"
82 shift
83 elif [ "x$1" = "x--no-verify" ]; then
84 run_args="${run_args} --no-verify"
85 shift
86 elif [ "x$1" = "x--no-optimize" ]; then
87 run_args="${run_args} --no-optimize"
88 shift
89 elif [ "x$1" = "x--no-precise" ]; then
90 run_args="${run_args} --no-precise"
91 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070092 elif [ "x$1" = "x--invoke-with" ]; then
93 shift
94 what="$1"
95 run_args="${run_args} --invoke-with \"${what}\""
jeffhao5d1ac922011-09-29 17:41:15 -070096 shift
97 elif [ "x$1" = "x--dev" ]; then
98 run_args="${run_args} --dev"
99 dev_mode="yes"
100 shift
101 elif [ "x$1" = "x--update" ]; then
102 update_mode="yes"
103 shift
104 elif [ "x$1" = "x--help" ]; then
105 usage="yes"
106 shift
107 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700108 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700109 usage="yes"
110 break
111 else
112 break
113 fi
114done
115
116if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
117 echo "--dev and --update are mutually exclusive" 1>&2
118 usage="yes"
119fi
120
121if [ "$usage" = "no" ]; then
122 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
123 test_dir=`basename "$oldwd"`
124 else
125 test_dir="$1"
126 fi
127
128 if [ '!' -d "$test_dir" ]; then
129 td2=`echo ${test_dir}-*`
130 if [ '!' -d "$td2" ]; then
131 echo "${test_dir}: no such test directory" 1>&2
132 usage="yes"
133 fi
134 test_dir="$td2"
135 fi
136
137 # Shift to get rid of the test name argument. The rest of the arguments
138 # will get passed to the test run.
139 shift
140fi
141
142if [ "$usage" = "yes" ]; then
143 prog=`basename $prog`
144 (
145 echo "usage:"
146 echo " $prog --help Print this message."
147 echo " $prog [options] [test-name] Run test normally."
148 echo " $prog --dev [options] [test-name] Development mode" \
149 "(dumps to stdout)."
150 echo " $prog --update [options] [test-name] Update mode" \
151 "(replaces expected.txt)."
152 echo ' Omitting the test name or specifying "-" will use the' \
153 "current directory."
154 echo " Runtime Options:"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800155 echo " -O Run oatexec rather than oatexecd (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700156 echo " --debug Wait for a debugger to attach."
157 #echo " --gdb Run under gdb; incompatible with some tests."
158 echo " --no-verify Turn off verification (on by default)."
159 echo " --no-optimize Turn off optimization (on by default)."
160 echo " --no-precise Turn off precise GC (on by default)."
161 echo " --zygote Spawn the process from the Zygote." \
162 "If used, then the"
163 echo " other runtime options are ignored."
164 echo " --host Use the host-mode virtual machine."
165 echo " --valgrind Use valgrind when running locally."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800166 echo " --jvm Use a host-local RI virtual machine."
jeffhao5d1ac922011-09-29 17:41:15 -0700167 ) 1>&2
168 exit 1
169fi
170
171cd "$test_dir"
172test_dir=`pwd`
173
174td_info="${test_dir}/${info}"
175td_expected="${test_dir}/${expected}"
176
jeffhao5d1ac922011-09-29 17:41:15 -0700177if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then
178 echo "${test_dir}: missing files" 1>&2
179 exit 1
180fi
181
182# copy the test to a temp dir and run it
183
Elliott Hughes510c8782011-10-06 10:57:34 -0700184echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700185
186rm -rf "$tmp_dir"
187cp -Rp "$test_dir" "$tmp_dir"
188cd "$tmp_dir"
189
190if [ '!' -r "$build" ]; then
191 cp "${progdir}/etc/default-build" build
192fi
193
Elliott Hughes510c8782011-10-06 10:57:34 -0700194echo "${test_dir}: running..." 1>&2
195
jeffhao5d1ac922011-09-29 17:41:15 -0700196if [ '!' -r "$run" ]; then
197 cp "${progdir}/etc/default-run" run
198fi
199
200chmod 755 "$build"
201chmod 755 "$run"
202
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700203export TEST_NAME=`basename ${test_dir}`
204
jeffhao5d1ac922011-09-29 17:41:15 -0700205good="no"
206if [ "$dev_mode" = "yes" ]; then
207 "./${build}" 2>&1
208 echo "build exit status: $?" 1>&2
209 "./${run}" $run_args "$@" 2>&1
210 echo "run exit status: $?" 1>&2
211 good="yes"
212elif [ "$update_mode" = "yes" ]; then
213 "./${build}" >"$build_output" 2>&1
214 build_exit="$?"
215 if [ "$build_exit" = '0' ]; then
216 "./${run}" $run_args "$@" >"$output" 2>&1
217 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
218 good="yes"
219 else
220 cat "$build_output" 1>&2
221 echo "build exit status: $build_exit" 1>&2
222 fi
223else
224 "./${build}" >"$build_output" 2>&1
225 build_exit="$?"
226 if [ "$build_exit" = '0' ]; then
227 "./${run}" $run_args "$@" >"$output" 2>&1
228 else
229 cp "$build_output" "$output"
230 echo "build exit status: $build_exit" >>"$output"
231 fi
232 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
233 if [ "$?" = "0" ]; then
234 # output == expected
235 good="yes"
236 echo "${test_dir}: succeeded!" 1>&2
237 fi
238fi
239
240if [ "$good" = "yes" ]; then
241 cd "$oldwd"
242 rm -rf "$tmp_dir"
Brian Carlstrom105215d2012-06-14 12:50:44 -0700243 if [ "$host_mode" = "no" ]; then
244 adb shell rm -r $DEX_LOCATION
245 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700246 exit 0
247fi
248
249(
250 if [ "$update_mode" '!=' "yes" ]; then
251 echo "${test_dir}: FAILED!"
252 echo ' '
253 echo '#################### info'
254 cat "${td_info}" | sed 's/^/# /g'
255 echo '#################### diffs'
256 diff --strip-trailing-cr -u "$expected" "$output"
257 echo '####################'
258 echo ' '
259 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700260 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Brian Carlstrom6e9c5a52012-06-14 15:06:22 -0700261 if [ "$host_mode" = "no" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700262 echo "and in ${DEX_LOCATION} on target"
263 fi
264
jeffhao5d1ac922011-09-29 17:41:15 -0700265) 1>&2
266
267exit 1