blob: 8d7198ffba9f1f48b66566435b5b89b0ed33a34e [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 Carlstrom2613de42012-06-15 17:37:16 -070053target_mode="yes"
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 Carlstrom2613de42012-06-15 17:37:16 -070061 target_mode="no"
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
Brian Carlstrom2613de42012-06-15 17:37:16 -070067 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070068 RUN="${progdir}/etc/reference-run-test-classes"
Elliott Hughesc717eef2012-06-15 16:01:26 -070069 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070070 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080071 elif [ "x$1" = "x-O" ]; then
72 run_args="${run_args} -O"
Elliott Hughes7c046102011-10-19 18:16:03 -070073 shift
jeffhao5d1ac922011-09-29 17:41:15 -070074 elif [ "x$1" = "x--debug" ]; then
75 run_args="${run_args} --debug"
76 shift
77 elif [ "x$1" = "x--gdb" ]; then
78 run_args="${run_args} --gdb"
79 dev_mode="yes"
80 shift
81 elif [ "x$1" = "x--zygote" ]; then
82 run_args="${run_args} --zygote"
83 shift
84 elif [ "x$1" = "x--no-verify" ]; then
85 run_args="${run_args} --no-verify"
86 shift
87 elif [ "x$1" = "x--no-optimize" ]; then
88 run_args="${run_args} --no-optimize"
89 shift
90 elif [ "x$1" = "x--no-precise" ]; then
91 run_args="${run_args} --no-precise"
92 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070093 elif [ "x$1" = "x--invoke-with" ]; then
94 shift
95 what="$1"
96 run_args="${run_args} --invoke-with \"${what}\""
jeffhao5d1ac922011-09-29 17:41:15 -070097 shift
98 elif [ "x$1" = "x--dev" ]; then
99 run_args="${run_args} --dev"
100 dev_mode="yes"
101 shift
102 elif [ "x$1" = "x--update" ]; then
103 update_mode="yes"
104 shift
105 elif [ "x$1" = "x--help" ]; then
106 usage="yes"
107 shift
108 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700109 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700110 usage="yes"
111 break
112 else
113 break
114 fi
115done
116
117if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
118 echo "--dev and --update are mutually exclusive" 1>&2
119 usage="yes"
120fi
121
122if [ "$usage" = "no" ]; then
123 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
124 test_dir=`basename "$oldwd"`
125 else
126 test_dir="$1"
127 fi
128
129 if [ '!' -d "$test_dir" ]; then
130 td2=`echo ${test_dir}-*`
131 if [ '!' -d "$td2" ]; then
132 echo "${test_dir}: no such test directory" 1>&2
133 usage="yes"
134 fi
135 test_dir="$td2"
136 fi
137
138 # Shift to get rid of the test name argument. The rest of the arguments
139 # will get passed to the test run.
140 shift
141fi
142
143if [ "$usage" = "yes" ]; then
144 prog=`basename $prog`
145 (
146 echo "usage:"
147 echo " $prog --help Print this message."
148 echo " $prog [options] [test-name] Run test normally."
149 echo " $prog --dev [options] [test-name] Development mode" \
150 "(dumps to stdout)."
151 echo " $prog --update [options] [test-name] Update mode" \
152 "(replaces expected.txt)."
153 echo ' Omitting the test name or specifying "-" will use the' \
154 "current directory."
155 echo " Runtime Options:"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800156 echo " -O Run oatexec rather than oatexecd (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700157 echo " --debug Wait for a debugger to attach."
158 #echo " --gdb Run under gdb; incompatible with some tests."
159 echo " --no-verify Turn off verification (on by default)."
160 echo " --no-optimize Turn off optimization (on by default)."
161 echo " --no-precise Turn off precise GC (on by default)."
162 echo " --zygote Spawn the process from the Zygote." \
163 "If used, then the"
164 echo " other runtime options are ignored."
165 echo " --host Use the host-mode virtual machine."
166 echo " --valgrind Use valgrind when running locally."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800167 echo " --jvm Use a host-local RI virtual machine."
jeffhao5d1ac922011-09-29 17:41:15 -0700168 ) 1>&2
169 exit 1
170fi
171
172cd "$test_dir"
173test_dir=`pwd`
174
175td_info="${test_dir}/${info}"
176td_expected="${test_dir}/${expected}"
177
jeffhao5d1ac922011-09-29 17:41:15 -0700178if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then
179 echo "${test_dir}: missing files" 1>&2
180 exit 1
181fi
182
183# copy the test to a temp dir and run it
184
Elliott Hughes510c8782011-10-06 10:57:34 -0700185echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700186
187rm -rf "$tmp_dir"
188cp -Rp "$test_dir" "$tmp_dir"
189cd "$tmp_dir"
190
191if [ '!' -r "$build" ]; then
192 cp "${progdir}/etc/default-build" build
193fi
194
Elliott Hughes510c8782011-10-06 10:57:34 -0700195echo "${test_dir}: running..." 1>&2
196
jeffhao5d1ac922011-09-29 17:41:15 -0700197if [ '!' -r "$run" ]; then
198 cp "${progdir}/etc/default-run" run
199fi
200
201chmod 755 "$build"
202chmod 755 "$run"
203
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700204export TEST_NAME=`basename ${test_dir}`
205
jeffhao5d1ac922011-09-29 17:41:15 -0700206good="no"
207if [ "$dev_mode" = "yes" ]; then
208 "./${build}" 2>&1
209 echo "build exit status: $?" 1>&2
210 "./${run}" $run_args "$@" 2>&1
211 echo "run exit status: $?" 1>&2
212 good="yes"
213elif [ "$update_mode" = "yes" ]; then
214 "./${build}" >"$build_output" 2>&1
215 build_exit="$?"
216 if [ "$build_exit" = '0' ]; then
217 "./${run}" $run_args "$@" >"$output" 2>&1
218 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
219 good="yes"
220 else
221 cat "$build_output" 1>&2
222 echo "build exit status: $build_exit" 1>&2
223 fi
224else
225 "./${build}" >"$build_output" 2>&1
226 build_exit="$?"
227 if [ "$build_exit" = '0' ]; then
228 "./${run}" $run_args "$@" >"$output" 2>&1
229 else
230 cp "$build_output" "$output"
231 echo "build exit status: $build_exit" >>"$output"
232 fi
233 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
234 if [ "$?" = "0" ]; then
235 # output == expected
236 good="yes"
237 echo "${test_dir}: succeeded!" 1>&2
238 fi
239fi
240
241if [ "$good" = "yes" ]; then
242 cd "$oldwd"
243 rm -rf "$tmp_dir"
Brian Carlstrom2613de42012-06-15 17:37:16 -0700244 if [ "$target_mode" = "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700245 adb shell rm -r $DEX_LOCATION
246 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700247 exit 0
248fi
249
250(
251 if [ "$update_mode" '!=' "yes" ]; then
252 echo "${test_dir}: FAILED!"
253 echo ' '
254 echo '#################### info'
255 cat "${td_info}" | sed 's/^/# /g'
256 echo '#################### diffs'
257 diff --strip-trailing-cr -u "$expected" "$output"
258 echo '####################'
259 echo ' '
260 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700261 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Brian Carlstrom2613de42012-06-15 17:37:16 -0700262 if [ "$target_mode" = "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700263 echo "and in ${DEX_LOCATION} on target"
264 fi
265
jeffhao5d1ac922011-09-29 17:41:15 -0700266) 1>&2
267
268exit 1