jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1 | #!/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. |
| 19 | prog="$0" |
| 20 | while [ -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 |
| 29 | done |
| 30 | oldwd=`pwd` |
| 31 | progdir=`dirname "${prog}"` |
| 32 | cd "${progdir}" |
| 33 | progdir=`pwd` |
| 34 | prog="${progdir}"/`basename "${prog}"` |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 35 | test_dir="test-$$" |
| 36 | tmp_dir="/tmp/${test_dir}" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 37 | |
| 38 | export JAVA="java" |
Elliott Hughes | 4b0d1ee | 2011-11-30 14:11:39 -0800 | [diff] [blame] | 39 | export JAVAC="javac -g -target 1.5" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 40 | export RUN="${progdir}/etc/push-and-run-test-jar" |
TDYa127 | b92bcab | 2012-04-08 00:09:51 -0700 | [diff] [blame] | 41 | export IMAGE=${ANDROID_PRODUCT_OUT}/data/art-test/core.art |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 42 | export DEX_LOCATION=/data/run-test/${test_dir} |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 43 | export NEED_DEX="true" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 44 | |
| 45 | info="info.txt" |
| 46 | build="build" |
| 47 | run="run" |
| 48 | expected="expected.txt" |
| 49 | output="output.txt" |
| 50 | build_output="build-output.txt" |
| 51 | run_args="--quiet" |
| 52 | |
Brian Carlstrom | 2613de4 | 2012-06-15 17:37:16 -0700 | [diff] [blame^] | 53 | target_mode="yes" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 54 | dev_mode="no" |
| 55 | update_mode="no" |
| 56 | debug_mode="no" |
| 57 | usage="no" |
| 58 | |
| 59 | while true; do |
| 60 | if [ "x$1" = "x--host" ]; then |
Brian Carlstrom | 2613de4 | 2012-06-15 17:37:16 -0700 | [diff] [blame^] | 61 | target_mode="no" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 62 | RUN="${progdir}/etc/host-run-test-jar" |
Elliott Hughes | e7fb2a6 | 2012-04-23 12:39:12 -0700 | [diff] [blame] | 63 | IMAGE=${ANDROID_HOST_OUT}/framework/core.art |
TDYa127 | b92bcab | 2012-04-08 00:09:51 -0700 | [diff] [blame] | 64 | DEX_LOCATION=$tmp_dir |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 65 | shift |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 66 | elif [ "x$1" = "x--jvm" ]; then |
Brian Carlstrom | 2613de4 | 2012-06-15 17:37:16 -0700 | [diff] [blame^] | 67 | target_mode="no" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 68 | RUN="${progdir}/etc/reference-run-test-classes" |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 69 | NEED_DEX="false" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 70 | shift |
Elliott Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 71 | elif [ "x$1" = "x-O" ]; then |
| 72 | run_args="${run_args} -O" |
Elliott Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 73 | shift |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 74 | 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 Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 93 | elif [ "x$1" = "x--invoke-with" ]; then |
| 94 | shift |
| 95 | what="$1" |
| 96 | run_args="${run_args} --invoke-with \"${what}\"" |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 97 | 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 Hughes | 7c04610 | 2011-10-19 18:16:03 -0700 | [diff] [blame] | 109 | echo "unknown $0 option: $1" 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 110 | usage="yes" |
| 111 | break |
| 112 | else |
| 113 | break |
| 114 | fi |
| 115 | done |
| 116 | |
| 117 | if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then |
| 118 | echo "--dev and --update are mutually exclusive" 1>&2 |
| 119 | usage="yes" |
| 120 | fi |
| 121 | |
| 122 | if [ "$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 |
| 141 | fi |
| 142 | |
| 143 | if [ "$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 Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 156 | echo " -O Run oatexec rather than oatexecd (off by default)." |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 157 | 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 Hughes | 58bcc40 | 2012-02-14 14:10:10 -0800 | [diff] [blame] | 167 | echo " --jvm Use a host-local RI virtual machine." |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 168 | ) 1>&2 |
| 169 | exit 1 |
| 170 | fi |
| 171 | |
| 172 | cd "$test_dir" |
| 173 | test_dir=`pwd` |
| 174 | |
| 175 | td_info="${test_dir}/${info}" |
| 176 | td_expected="${test_dir}/${expected}" |
| 177 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 178 | if [ '!' '(' -r "$td_info" -a -r "$td_expected" ')' ]; then |
| 179 | echo "${test_dir}: missing files" 1>&2 |
| 180 | exit 1 |
| 181 | fi |
| 182 | |
| 183 | # copy the test to a temp dir and run it |
| 184 | |
Elliott Hughes | 510c878 | 2011-10-06 10:57:34 -0700 | [diff] [blame] | 185 | echo "${test_dir}: building..." 1>&2 |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 186 | |
| 187 | rm -rf "$tmp_dir" |
| 188 | cp -Rp "$test_dir" "$tmp_dir" |
| 189 | cd "$tmp_dir" |
| 190 | |
| 191 | if [ '!' -r "$build" ]; then |
| 192 | cp "${progdir}/etc/default-build" build |
| 193 | fi |
| 194 | |
Elliott Hughes | 510c878 | 2011-10-06 10:57:34 -0700 | [diff] [blame] | 195 | echo "${test_dir}: running..." 1>&2 |
| 196 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 197 | if [ '!' -r "$run" ]; then |
| 198 | cp "${progdir}/etc/default-run" run |
| 199 | fi |
| 200 | |
| 201 | chmod 755 "$build" |
| 202 | chmod 755 "$run" |
| 203 | |
Elliott Hughes | 8cbc8bc | 2011-10-04 11:19:45 -0700 | [diff] [blame] | 204 | export TEST_NAME=`basename ${test_dir}` |
| 205 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 206 | good="no" |
| 207 | if [ "$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" |
| 213 | elif [ "$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 |
| 224 | else |
| 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 |
| 239 | fi |
| 240 | |
| 241 | if [ "$good" = "yes" ]; then |
| 242 | cd "$oldwd" |
| 243 | rm -rf "$tmp_dir" |
Brian Carlstrom | 2613de4 | 2012-06-15 17:37:16 -0700 | [diff] [blame^] | 244 | if [ "$target_mode" = "yes" ]; then |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 245 | adb shell rm -r $DEX_LOCATION |
| 246 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 247 | exit 0 |
| 248 | fi |
| 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 Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 261 | echo "${TEST_NAME} files left in ${tmp_dir} on host" |
Brian Carlstrom | 2613de4 | 2012-06-15 17:37:16 -0700 | [diff] [blame^] | 262 | if [ "$target_mode" = "yes" ]; then |
Brian Carlstrom | 105215d | 2012-06-14 12:50:44 -0700 | [diff] [blame] | 263 | echo "and in ${DEX_LOCATION} on target" |
| 264 | fi |
| 265 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 266 | ) 1>&2 |
| 267 | |
| 268 | exit 1 |