blob: 75aeeffe7a58170441999a1d350aa5de4b1a775f [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}"`
TDYa127b92bcab2012-04-08 00:09:51 -070035tmp_dir="/tmp/test-$$"
jeffhao5d1ac922011-09-29 17:41:15 -070036
37export JAVA="java"
Elliott Hughes4b0d1ee2011-11-30 14:11:39 -080038export JAVAC="javac -g -target 1.5"
jeffhao5d1ac922011-09-29 17:41:15 -070039export RUN="${progdir}/etc/push-and-run-test-jar"
TDYa127b92bcab2012-04-08 00:09:51 -070040export IMAGE=${ANDROID_PRODUCT_OUT}/data/art-test/core.art
41export DEX_LOCATION=/data/run-test
jeffhao5d1ac922011-09-29 17:41:15 -070042
43info="info.txt"
44build="build"
45run="run"
46expected="expected.txt"
47output="output.txt"
48build_output="build-output.txt"
49run_args="--quiet"
50
51dev_mode="no"
52update_mode="no"
53debug_mode="no"
54usage="no"
55
56while true; do
57 if [ "x$1" = "x--host" ]; then
58 RUN="${progdir}/etc/host-run-test-jar"
Elliott Hughese7fb2a62012-04-23 12:39:12 -070059 IMAGE=${ANDROID_HOST_OUT}/framework/core.art
TDYa127b92bcab2012-04-08 00:09:51 -070060 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070061 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080062 elif [ "x$1" = "x--jvm" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -070063 RUN="${progdir}/etc/reference-run-test-classes"
64 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080065 elif [ "x$1" = "x-O" ]; then
66 run_args="${run_args} -O"
Elliott Hughes7c046102011-10-19 18:16:03 -070067 shift
jeffhao5d1ac922011-09-29 17:41:15 -070068 elif [ "x$1" = "x--debug" ]; then
69 run_args="${run_args} --debug"
70 shift
71 elif [ "x$1" = "x--gdb" ]; then
72 run_args="${run_args} --gdb"
73 dev_mode="yes"
74 shift
75 elif [ "x$1" = "x--zygote" ]; then
76 run_args="${run_args} --zygote"
77 shift
78 elif [ "x$1" = "x--no-verify" ]; then
79 run_args="${run_args} --no-verify"
80 shift
81 elif [ "x$1" = "x--no-optimize" ]; then
82 run_args="${run_args} --no-optimize"
83 shift
84 elif [ "x$1" = "x--no-precise" ]; then
85 run_args="${run_args} --no-precise"
86 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070087 elif [ "x$1" = "x--invoke-with" ]; then
88 shift
89 what="$1"
90 run_args="${run_args} --invoke-with \"${what}\""
jeffhao5d1ac922011-09-29 17:41:15 -070091 shift
92 elif [ "x$1" = "x--dev" ]; then
93 run_args="${run_args} --dev"
94 dev_mode="yes"
95 shift
96 elif [ "x$1" = "x--update" ]; then
97 update_mode="yes"
98 shift
99 elif [ "x$1" = "x--help" ]; then
100 usage="yes"
101 shift
102 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700103 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700104 usage="yes"
105 break
106 else
107 break
108 fi
109done
110
111if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
112 echo "--dev and --update are mutually exclusive" 1>&2
113 usage="yes"
114fi
115
116if [ "$usage" = "no" ]; then
117 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
118 test_dir=`basename "$oldwd"`
119 else
120 test_dir="$1"
121 fi
122
123 if [ '!' -d "$test_dir" ]; then
124 td2=`echo ${test_dir}-*`
125 if [ '!' -d "$td2" ]; then
126 echo "${test_dir}: no such test directory" 1>&2
127 usage="yes"
128 fi
129 test_dir="$td2"
130 fi
131
132 # Shift to get rid of the test name argument. The rest of the arguments
133 # will get passed to the test run.
134 shift
135fi
136
137if [ "$usage" = "yes" ]; then
138 prog=`basename $prog`
139 (
140 echo "usage:"
141 echo " $prog --help Print this message."
142 echo " $prog [options] [test-name] Run test normally."
143 echo " $prog --dev [options] [test-name] Development mode" \
144 "(dumps to stdout)."
145 echo " $prog --update [options] [test-name] Update mode" \
146 "(replaces expected.txt)."
147 echo ' Omitting the test name or specifying "-" will use the' \
148 "current directory."
149 echo " Runtime Options:"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800150 echo " -O Run oatexec rather than oatexecd (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700151 echo " --debug Wait for a debugger to attach."
152 #echo " --gdb Run under gdb; incompatible with some tests."
153 echo " --no-verify Turn off verification (on by default)."
154 echo " --no-optimize Turn off optimization (on by default)."
155 echo " --no-precise Turn off precise GC (on by default)."
156 echo " --zygote Spawn the process from the Zygote." \
157 "If used, then the"
158 echo " other runtime options are ignored."
159 echo " --host Use the host-mode virtual machine."
160 echo " --valgrind Use valgrind when running locally."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800161 echo " --jvm Use a host-local RI virtual machine."
jeffhao5d1ac922011-09-29 17:41:15 -0700162 ) 1>&2
163 exit 1
164fi
165
166cd "$test_dir"
167test_dir=`pwd`
168
169td_info="${test_dir}/${info}"
170td_expected="${test_dir}/${expected}"
171
jeffhao5d1ac922011-09-29 17:41:15 -0700172if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then
173 echo "${test_dir}: missing files" 1>&2
174 exit 1
175fi
176
177# copy the test to a temp dir and run it
178
Elliott Hughes510c8782011-10-06 10:57:34 -0700179echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700180
181rm -rf "$tmp_dir"
182cp -Rp "$test_dir" "$tmp_dir"
183cd "$tmp_dir"
184
185if [ '!' -r "$build" ]; then
186 cp "${progdir}/etc/default-build" build
187fi
188
Elliott Hughes510c8782011-10-06 10:57:34 -0700189echo "${test_dir}: running..." 1>&2
190
jeffhao5d1ac922011-09-29 17:41:15 -0700191if [ '!' -r "$run" ]; then
192 cp "${progdir}/etc/default-run" run
193fi
194
195chmod 755 "$build"
196chmod 755 "$run"
197
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700198export TEST_NAME=`basename ${test_dir}`
199
jeffhao5d1ac922011-09-29 17:41:15 -0700200good="no"
201if [ "$dev_mode" = "yes" ]; then
202 "./${build}" 2>&1
203 echo "build exit status: $?" 1>&2
204 "./${run}" $run_args "$@" 2>&1
205 echo "run exit status: $?" 1>&2
206 good="yes"
207elif [ "$update_mode" = "yes" ]; then
208 "./${build}" >"$build_output" 2>&1
209 build_exit="$?"
210 if [ "$build_exit" = '0' ]; then
211 "./${run}" $run_args "$@" >"$output" 2>&1
212 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
213 good="yes"
214 else
215 cat "$build_output" 1>&2
216 echo "build exit status: $build_exit" 1>&2
217 fi
218else
219 "./${build}" >"$build_output" 2>&1
220 build_exit="$?"
221 if [ "$build_exit" = '0' ]; then
222 "./${run}" $run_args "$@" >"$output" 2>&1
223 else
224 cp "$build_output" "$output"
225 echo "build exit status: $build_exit" >>"$output"
226 fi
227 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
228 if [ "$?" = "0" ]; then
229 # output == expected
230 good="yes"
231 echo "${test_dir}: succeeded!" 1>&2
232 fi
233fi
234
235if [ "$good" = "yes" ]; then
236 cd "$oldwd"
237 rm -rf "$tmp_dir"
238 exit 0
239fi
240
241(
242 if [ "$update_mode" '!=' "yes" ]; then
243 echo "${test_dir}: FAILED!"
244 echo ' '
245 echo '#################### info'
246 cat "${td_info}" | sed 's/^/# /g'
247 echo '#################### diffs'
248 diff --strip-trailing-cr -u "$expected" "$output"
249 echo '####################'
250 echo ' '
251 fi
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700252 echo "${TEST_NAME} files left in ${tmp_dir}"
jeffhao5d1ac922011-09-29 17:41:15 -0700253) 1>&2
254
255exit 1