blob: f7a5827fca3038cc9305da98e3194d4195119a40 [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"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -070058build_only="no"
jeffhao5d1ac922011-09-29 17:41:15 -070059
60while true; do
61 if [ "x$1" = "x--host" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070062 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070063 RUN="${progdir}/etc/host-run-test-jar"
Elliott Hughese7fb2a62012-04-23 12:39:12 -070064 IMAGE=${ANDROID_HOST_OUT}/framework/core.art
TDYa127b92bcab2012-04-08 00:09:51 -070065 DEX_LOCATION=$tmp_dir
jeffhao5d1ac922011-09-29 17:41:15 -070066 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080067 elif [ "x$1" = "x--jvm" ]; then
Brian Carlstrom2613de42012-06-15 17:37:16 -070068 target_mode="no"
jeffhao5d1ac922011-09-29 17:41:15 -070069 RUN="${progdir}/etc/reference-run-test-classes"
Elliott Hughesc717eef2012-06-15 16:01:26 -070070 NEED_DEX="false"
jeffhao5d1ac922011-09-29 17:41:15 -070071 shift
Elliott Hughes58bcc402012-02-14 14:10:10 -080072 elif [ "x$1" = "x-O" ]; then
73 run_args="${run_args} -O"
Elliott Hughes7c046102011-10-19 18:16:03 -070074 shift
jeffhao5d1ac922011-09-29 17:41:15 -070075 elif [ "x$1" = "x--debug" ]; then
76 run_args="${run_args} --debug"
77 shift
78 elif [ "x$1" = "x--gdb" ]; then
79 run_args="${run_args} --gdb"
80 dev_mode="yes"
81 shift
82 elif [ "x$1" = "x--zygote" ]; then
83 run_args="${run_args} --zygote"
84 shift
85 elif [ "x$1" = "x--no-verify" ]; then
86 run_args="${run_args} --no-verify"
87 shift
88 elif [ "x$1" = "x--no-optimize" ]; then
89 run_args="${run_args} --no-optimize"
90 shift
91 elif [ "x$1" = "x--no-precise" ]; then
92 run_args="${run_args} --no-precise"
93 shift
Elliott Hughes7c046102011-10-19 18:16:03 -070094 elif [ "x$1" = "x--invoke-with" ]; then
95 shift
96 what="$1"
97 run_args="${run_args} --invoke-with \"${what}\""
jeffhao5d1ac922011-09-29 17:41:15 -070098 shift
99 elif [ "x$1" = "x--dev" ]; then
100 run_args="${run_args} --dev"
101 dev_mode="yes"
102 shift
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700103 elif [ "x$1" = "x--build-only" ]; then
104 build_only="yes"
105 shift
106 elif [ "x$1" = "x--output-path" ]; then
107 shift
108 tmp_dir=$1
109 shift
jeffhao5d1ac922011-09-29 17:41:15 -0700110 elif [ "x$1" = "x--update" ]; then
111 update_mode="yes"
112 shift
113 elif [ "x$1" = "x--help" ]; then
114 usage="yes"
115 shift
116 elif expr "x$1" : "x--" >/dev/null 2>&1; then
Elliott Hughes7c046102011-10-19 18:16:03 -0700117 echo "unknown $0 option: $1" 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700118 usage="yes"
119 break
120 else
121 break
122 fi
123done
124
125if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then
126 echo "--dev and --update are mutually exclusive" 1>&2
127 usage="yes"
128fi
129
130if [ "$usage" = "no" ]; then
131 if [ "x$1" = "x" -o "x$1" = "x-" ]; then
132 test_dir=`basename "$oldwd"`
133 else
134 test_dir="$1"
135 fi
136
137 if [ '!' -d "$test_dir" ]; then
138 td2=`echo ${test_dir}-*`
139 if [ '!' -d "$td2" ]; then
140 echo "${test_dir}: no such test directory" 1>&2
141 usage="yes"
142 fi
143 test_dir="$td2"
144 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700145 # Shift to get rid of the test name argument. The rest of the arguments
146 # will get passed to the test run.
147 shift
148fi
149
150if [ "$usage" = "yes" ]; then
151 prog=`basename $prog`
152 (
153 echo "usage:"
154 echo " $prog --help Print this message."
155 echo " $prog [options] [test-name] Run test normally."
156 echo " $prog --dev [options] [test-name] Development mode" \
157 "(dumps to stdout)."
158 echo " $prog --update [options] [test-name] Update mode" \
159 "(replaces expected.txt)."
160 echo ' Omitting the test name or specifying "-" will use the' \
161 "current directory."
162 echo " Runtime Options:"
Elliott Hughes58bcc402012-02-14 14:10:10 -0800163 echo " -O Run oatexec rather than oatexecd (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700164 echo " --debug Wait for a debugger to attach."
165 #echo " --gdb Run under gdb; incompatible with some tests."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700166 echo " --build-only Build test files only (off by default)."
jeffhao5d1ac922011-09-29 17:41:15 -0700167 echo " --no-verify Turn off verification (on by default)."
168 echo " --no-optimize Turn off optimization (on by default)."
169 echo " --no-precise Turn off precise GC (on by default)."
170 echo " --zygote Spawn the process from the Zygote." \
171 "If used, then the"
172 echo " other runtime options are ignored."
173 echo " --host Use the host-mode virtual machine."
174 echo " --valgrind Use valgrind when running locally."
Elliott Hughes58bcc402012-02-14 14:10:10 -0800175 echo " --jvm Use a host-local RI virtual machine."
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700176 echo " --output-path [path] Location where to store the build" \
177 "files."
jeffhao5d1ac922011-09-29 17:41:15 -0700178 ) 1>&2
179 exit 1
180fi
181
182cd "$test_dir"
183test_dir=`pwd`
184
185td_info="${test_dir}/${info}"
186td_expected="${test_dir}/${expected}"
187
jeffhao5d1ac922011-09-29 17:41:15 -0700188if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then
189 echo "${test_dir}: missing files" 1>&2
190 exit 1
191fi
192
193# copy the test to a temp dir and run it
194
Elliott Hughes510c8782011-10-06 10:57:34 -0700195echo "${test_dir}: building..." 1>&2
jeffhao5d1ac922011-09-29 17:41:15 -0700196
197rm -rf "$tmp_dir"
198cp -Rp "$test_dir" "$tmp_dir"
199cd "$tmp_dir"
200
201if [ '!' -r "$build" ]; then
202 cp "${progdir}/etc/default-build" build
203fi
204
Elliott Hughes510c8782011-10-06 10:57:34 -0700205echo "${test_dir}: running..." 1>&2
206
jeffhao5d1ac922011-09-29 17:41:15 -0700207if [ '!' -r "$run" ]; then
208 cp "${progdir}/etc/default-run" run
209fi
210
211chmod 755 "$build"
212chmod 755 "$run"
213
Elliott Hughes8cbc8bc2011-10-04 11:19:45 -0700214export TEST_NAME=`basename ${test_dir}`
215
jeffhao5d1ac922011-09-29 17:41:15 -0700216good="no"
217if [ "$dev_mode" = "yes" ]; then
218 "./${build}" 2>&1
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700219 build_exit="$?"
220 echo "build exit status: $build_exit" 1>&2
221 if [ "$build_exit" = '0' ]; then
222 "./${run}" $run_args "$@" 2>&1
223 echo "run exit status: $?" 1>&2
224 good="yes"
225 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700226elif [ "$update_mode" = "yes" ]; then
227 "./${build}" >"$build_output" 2>&1
228 build_exit="$?"
229 if [ "$build_exit" = '0' ]; then
230 "./${run}" $run_args "$@" >"$output" 2>&1
231 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}"
232 good="yes"
233 else
234 cat "$build_output" 1>&2
235 echo "build exit status: $build_exit" 1>&2
236 fi
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700237elif [ "$build_only" = "yes" ]; then
238 good="yes"
239 "./${build}" >"$build_output" 2>&1
240 build_exit="$?"
241 if [ "$build_exit" '!=' '0' ]; then
242 cp "$build_output" "$output"
243 echo "build exit status: $build_exit" >>"$output"
244 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
245 if [ "$?" '!=' "0" ]; then
246 good="no"
247 echo "BUILD FAILED For ${TEST_NAME}"
248 fi
249 fi
250 exit 0
jeffhao5d1ac922011-09-29 17:41:15 -0700251else
252 "./${build}" >"$build_output" 2>&1
253 build_exit="$?"
254 if [ "$build_exit" = '0' ]; then
255 "./${run}" $run_args "$@" >"$output" 2>&1
256 else
257 cp "$build_output" "$output"
258 echo "build exit status: $build_exit" >>"$output"
259 fi
260 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null
261 if [ "$?" = "0" ]; then
262 # output == expected
263 good="yes"
264 echo "${test_dir}: succeeded!" 1>&2
265 fi
266fi
267
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700268# Clean up test files.
269if [ "$good" == "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700270 cd "$oldwd"
271 rm -rf "$tmp_dir"
Elliott Hughes7ab3a2a2012-06-18 16:34:20 -0700272 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700273 adb shell rm -r $DEX_LOCATION
274 fi
jeffhao5d1ac922011-09-29 17:41:15 -0700275 exit 0
276fi
277
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700278
jeffhao5d1ac922011-09-29 17:41:15 -0700279(
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700280 if [ "$update_mode" != "yes" ]; then
jeffhao5d1ac922011-09-29 17:41:15 -0700281 echo "${test_dir}: FAILED!"
282 echo ' '
283 echo '#################### info'
284 cat "${td_info}" | sed 's/^/# /g'
285 echo '#################### diffs'
286 diff --strip-trailing-cr -u "$expected" "$output"
287 echo '####################'
288 echo ' '
289 fi
Brian Carlstrom105215d2012-06-14 12:50:44 -0700290 echo "${TEST_NAME} files left in ${tmp_dir} on host"
Tsu Chiang Chuang011fade2012-07-09 18:34:47 -0700291 if [ "$target_mode" == "yes" ]; then
Brian Carlstrom105215d2012-06-14 12:50:44 -0700292 echo "and in ${DEX_LOCATION} on target"
293 fi
294
jeffhao5d1ac922011-09-29 17:41:15 -0700295) 1>&2
296
297exit 1