blob: 38f8f83dbd7819b5562cee720b5c74b6d519a50b [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}
jeffhao5d1ac922011-09-29 17:41:15 -070043
44info="info.txt"
45build="build"
46run="run"
47expected="expected.txt"
48output="output.txt"
49build_output="build-output.txt"
50run_args="--quiet"
51
Brian Carlstrom105215d2012-06-14 12:50:44 -070052host_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070053dev_mode="no"
54update_mode="no"
55debug_mode="no"
56usage="no"
57
58while true; do
59 if [ "x$1" = "x--host" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -070060 host_mode="yes"
jeffhao5d1ac922011-09-29 17:41:15 -070061 RUN="${progdir}/etc/host-run-test-jar"
Elliott Hughese7fb2a62012-04-23 12:39:12 -070062 IMAGE=${ANDROID_HOST_OUT}/framework/core.art
TDYa127b92bcab2012-04-08 00:09:51 -070063 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070064 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080065 elif [ "x$1" = "x--jvm" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -070066 RUN="${progdir}/etc/reference-run-test-classes"
67 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080068 elif [ "x$1" = "x-O" ]; then
69 run_args="${run_args} -O"
Elliott Hughes7c046102011-10-19 18:16:03 -070070 shift
jeffhao5d1ac922011-09-29 17:41:15 -070071 elif [ "x$1" = "x--debug" ]; then
72 run_args="${run_args} --debug"
73 shift
74 elif [ "x$1" = "x--gdb" ]; then
75 run_args="${run_args} --gdb"
76 dev_mode="yes"
77 shift
78 elif [ "x$1" = "x--zygote" ]; then
79 run_args="${run_args} --zygote"
80 shift
81 elif [ "x$1" = "x--no-verify" ]; then
82 run_args="${run_args} --no-verify"
83 shift
84 elif [ "x$1" = "x--no-optimize" ]; then
85 run_args="${run_args} --no-optimize"
86 shift
87 elif [ "x$1" = "x--no-precise" ]; then
88 run_args="${run_args} --no-precise"
89 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070090 elif [ "x$1" = "x--invoke-with" ]; then
91 shift
92 what="$1"
93 run_args="${run_args} --invoke-with \"${what}\""
jeffhao5d1ac922011-09-29 17:41:15 -070094 shift
95 elif [ "x$1" = "x--dev" ]; then
96 run_args="${run_args} --dev"
97 dev_mode="yes"
98 shift
99 elif [ "x$1" = "x--update" ]; then
100 update_mode="yes"
101 shift
102 elif [ "x$1" = "x--help" ]; then
103 usage="yes"
104 shift
105 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700106 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700107 usage="yes"
108 break
109 else
110 break
111 fi
112done
113
114if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
115 echo "--dev and --update are mutually exclusive" 1>&2
116 usage="yes"
117fi
118
119if [ "$usage" = "no" ]; then
120 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
121 test_dir=`basename "$oldwd"`
122 else
123 test_dir="$1"
124 fi
125
126 if [ '!' -d "$test_dir" ]; then
127 td2=`echo ${test_dir}-*`
128 if [ '!' -d "$td2" ]; then
129 echo "${test_dir}: no such test directory" 1>&2
130 usage="yes"
131 fi
132 test_dir="$td2"
133 fi
134
135 # Shift to get rid of the test name argument. The rest of the arguments
136 # will get passed to the test run.
137 shift
138fi
139
140if [ "$usage" = "yes" ]; then
141 prog=`basename $prog`
142 (
143 echo "usage:"
144 echo " $prog --help Print this message."
145 echo " $prog [options] [test-name] Run test normally."
146 echo " $prog --dev [options] [test-name] Development mode" \
147 "(dumps to stdout)."
148 echo " $prog --update [options] [test-name] Update mode" \
149 "(replaces expected.txt)."
150 echo ' Omitting the test name or specifying "-" will use the' \
151 "current directory."
152 echo " Runtime Options:"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800153 echo " -O Run oatexec rather than oatexecd (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700154 echo " --debug Wait for a debugger to attach."
155 #echo " --gdb Run under gdb; incompatible with some tests."
156 echo " --no-verify Turn off verification (on by default)."
157 echo " --no-optimize Turn off optimization (on by default)."
158 echo " --no-precise Turn off precise GC (on by default)."
159 echo " --zygote Spawn the process from the Zygote." \
160 "If used, then the"
161 echo " other runtime options are ignored."
162 echo " --host Use the host-mode virtual machine."
163 echo " --valgrind Use valgrind when running locally."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800164 echo " --jvm Use a host-local RI virtual machine."
jeffhao5d1ac922011-09-29 17:41:15 -0700165 ) 1>&2
166 exit 1
167fi
168
169cd "$test_dir"
170test_dir=`pwd`
171
172td_info="${test_dir}/${info}"
173td_expected="${test_dir}/${expected}"
174
jeffhao5d1ac922011-09-29 17:41:15 -0700175if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then
176 echo "${test_dir}: missing files" 1>&2
177 exit 1
178fi
179
180# copy the test to a temp dir and run it
181
Elliott Hughes510c8782011-10-06 10:57:34 -0700182echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700183
184rm -rf "$tmp_dir"
185cp -Rp "$test_dir" "$tmp_dir"
186cd "$tmp_dir"
187
188if [ '!' -r "$build" ]; then
189 cp "${progdir}/etc/default-build" build
190fi
191
Elliott Hughes510c8782011-10-06 10:57:34 -0700192echo "${test_dir}: running..." 1>&2
193
jeffhao5d1ac922011-09-29 17:41:15 -0700194if [ '!' -r "$run" ]; then
195 cp "${progdir}/etc/default-run" run
196fi
197
198chmod 755 "$build"
199chmod 755 "$run"
200
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700201export TEST_NAME=`basename ${test_dir}`
202
jeffhao5d1ac922011-09-29 17:41:15 -0700203good="no"
204if [ "$dev_mode" = "yes" ]; then
205 "./${build}" 2>&1
206 echo "build exit status: $?" 1>&2
207 "./${run}" $run_args "$@" 2>&1
208 echo "run exit status: $?" 1>&2
209 good="yes"
210elif [ "$update_mode" = "yes" ]; then
211 "./${build}" >"$build_output" 2>&1
212 build_exit="$?"
213 if [ "$build_exit" = '0' ]; then
214 "./${run}" $run_args "$@" >"$output" 2>&1
215 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
216 good="yes"
217 else
218 cat "$build_output" 1>&2
219 echo "build exit status: $build_exit" 1>&2
220 fi
221else
222 "./${build}" >"$build_output" 2>&1
223 build_exit="$?"
224 if [ "$build_exit" = '0' ]; then
225 "./${run}" $run_args "$@" >"$output" 2>&1
226 else
227 cp "$build_output" "$output"
228 echo "build exit status: $build_exit" >>"$output"
229 fi
230 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
231 if [ "$?" = "0" ]; then
232 # output == expected
233 good="yes"
234 echo "${test_dir}: succeeded!" 1>&2
235 fi
236fi
237
238if [ "$good" = "yes" ]; then
239 cd "$oldwd"
240 rm -rf "$tmp_dir"
Brian Carlstrom105215d2012-06-14 12:50:44 -0700241 if [ "$host_mode" = "no" ]; then
242 adb shell rm -r $DEX_LOCATION
243 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700244 exit 0
245fi
246
247(
248 if [ "$update_mode" '!=' "yes" ]; then
249 echo "${test_dir}: FAILED!"
250 echo ' '
251 echo '#################### info'
252 cat "${td_info}" | sed 's/^/# /g'
253 echo '#################### diffs'
254 diff --strip-trailing-cr -u "$expected" "$output"
255 echo '####################'
256 echo ' '
257 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700258 echo "${TEST_NAME} files left in ${tmp_dir} on host"
259 if [ "$host_mode" = "yes" ]; then
260 echo "and in ${DEX_LOCATION} on target"
261 fi
262
jeffhao5d1ac922011-09-29 17:41:15 -0700263) 1>&2
264
265exit 1