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