run-test revision 1c83cbc4a817acbd7f9abb5b29a2d418a958e6a1
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. 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}"` 35test_dir="test-$$" 36tmp_dir="/tmp/$USER/${test_dir}" 37 38export JAVA="java" 39export JAVAC="javac -g" 40export RUN="${progdir}/etc/push-and-run-test-jar" 41export DEX_LOCATION=/data/run-test/${test_dir} 42export NEED_DEX="true" 43 44# If dx was not set by the environment variable, assume it is in the path. 45if [ -z "$DX" ]; then 46 export DX="dx" 47fi 48 49# If jasmin was not set by the environment variable, assume it is in the path. 50if [ -z "$JASMIN" ]; then 51 export JASMIN="jasmin" 52fi 53 54 55info="info.txt" 56build="build" 57run="run" 58expected="expected.txt" 59check_cmd="check" 60output="output.txt" 61build_output="build-output.txt" 62lib="libartd.so" 63run_args="--quiet" 64 65prebuild_mode="yes" 66target_mode="yes" 67dev_mode="no" 68update_mode="no" 69debug_mode="no" 70relocate="yes" 71runtime="art" 72usage="no" 73build_only="no" 74suffix64="" 75 76while true; do 77 if [ "x$1" = "x--host" ]; then 78 target_mode="no" 79 DEX_LOCATION=$tmp_dir 80 shift 81 elif [ "x$1" = "x--jvm" ]; then 82 target_mode="no" 83 runtime="jvm" 84 NEED_DEX="false" 85 shift 86 elif [ "x$1" = "x-O" ]; then 87 lib="libart.so" 88 shift 89 elif [ "x$1" = "x--dalvik" ]; then 90 lib="libdvm.so" 91 runtime="dalvik" 92 shift 93 elif [ "x$1" = "x--relocate" ]; then 94 relocate="yes" 95 shift 96 elif [ "x$1" = "x--no-relocate" ]; then 97 relocate="no" 98 shift 99 elif [ "x$1" = "x--prebuild" ]; then 100 prebuild_mode="yes" 101 shift; 102 elif [ "x$1" = "x--no-prebuild" ]; then 103 prebuild_mode="no" 104 shift; 105 elif [ "x$1" = "x--image" ]; then 106 shift 107 image="$1" 108 run_args="${run_args} --image $image" 109 shift 110 elif [ "x$1" = "x-Xcompiler-option" ]; then 111 shift 112 option="$1" 113 run_args="${run_args} -Xcompiler-option $option" 114 shift 115 elif [ "x$1" = "x--runtime-option" ]; then 116 shift 117 option="$1" 118 run_args="${run_args} --runtime-option $option" 119 shift 120 elif [ "x$1" = "x--debug" ]; then 121 run_args="${run_args} --debug" 122 shift 123 elif [ "x$1" = "x--gdb" ]; then 124 run_args="${run_args} --gdb" 125 dev_mode="yes" 126 shift 127 elif [ "x$1" = "x--zygote" ]; then 128 run_args="${run_args} --zygote" 129 shift 130 elif [ "x$1" = "x--interpreter" ]; then 131 run_args="${run_args} --interpreter" 132 shift 133 elif [ "x$1" = "x--no-verify" ]; then 134 run_args="${run_args} --no-verify" 135 shift 136 elif [ "x$1" = "x--no-optimize" ]; then 137 run_args="${run_args} --no-optimize" 138 shift 139 elif [ "x$1" = "x--no-precise" ]; then 140 run_args="${run_args} --no-precise" 141 shift 142 elif [ "x$1" = "x--invoke-with" ]; then 143 shift 144 what="$1" 145 if [ "x$what" = "x" ]; then 146 echo "$0 missing argument to --invoke-with" 1>&2 147 usage="yes" 148 break 149 fi 150 run_args="${run_args} --invoke-with ${what}" 151 shift 152 elif [ "x$1" = "x--dev" ]; then 153 run_args="${run_args} --dev" 154 dev_mode="yes" 155 shift 156 elif [ "x$1" = "x--build-only" ]; then 157 build_only="yes" 158 shift 159 elif [ "x$1" = "x--output-path" ]; then 160 shift 161 tmp_dir=$1 162 if [ "x$tmp_dir" = "x" ]; then 163 echo "$0 missing argument to --output-path" 1>&2 164 usage="yes" 165 break 166 fi 167 shift 168 elif [ "x$1" = "x--update" ]; then 169 update_mode="yes" 170 shift 171 elif [ "x$1" = "x--help" ]; then 172 usage="yes" 173 shift 174 elif [ "x$1" = "x--64" ]; then 175 run_args="${run_args} --64" 176 suffix64="64" 177 shift 178 elif [ "x$1" = "x--trace" ]; then 179 run_args="${run_args} --runtime-option -Xmethod-trace --runtime-option -Xmethod-trace-file:${DEX_LOCATION}/trace.bin --runtime-option -Xmethod-trace-file-size:2000000" 180 shift 181 elif expr "x$1" : "x--" >/dev/null 2>&1; then 182 echo "unknown $0 option: $1" 1>&2 183 usage="yes" 184 break 185 else 186 break 187 fi 188done 189mkdir -p $tmp_dir 190 191# Most interesting target architecture variables are Makefile variables, not environment variables. 192# Try to map the suffix64 flag and what we find in ${OUT}/data/art-test to an architecture name. 193function guess_arch_name() { 194 grep32bit=`ls ${OUT}/data/art-test | grep -E '^(arm|x86|mips)$'` 195 grep64bit=`ls ${OUT}/data/art-test | grep -E '^(arm64|x86_64)$'` 196 if [ "x${suffix64}" = "x64" ]; then 197 target_arch_name=${grep64bit} 198 else 199 target_arch_name=${grep32bit} 200 fi 201} 202 203if [ "$target_mode" = "no" ]; then 204 if [ "$runtime" = "jvm" ]; then 205 RUN="${progdir}/etc/reference-run-test-classes" 206 if [ "$prebuild_mode" = "yes" ]; then 207 echo "--prebuild with --jvm is unsupported"; 208 exit 1; 209 fi 210 else 211 RUN="${progdir}/etc/host-run-test-jar" 212 if [ "$prebuild_mode" = "yes" ]; then 213 run_args="${run_args} --prebuild" 214 fi 215 fi 216else 217 if [ "$prebuild_mode" = "yes" ]; then 218 RUN="${progdir}/etc/push-and-run-prebuilt-test-jar" 219 fi 220fi 221 222if [ ! "$runtime" = "jvm" ]; then 223 run_args="${run_args} --lib $lib" 224fi 225 226if [ "$runtime" = "dalvik" ]; then 227 if [ "$target_mode" = "no" ]; then 228 framework="${OUT}/system/framework" 229 bpath="${framework}/core.jar:${framework}/conscrypt.jar:${framework}/okhttp.jar:${framework}/core-junit.jar:${framework}/bouncycastle.jar:${framework}/ext.jar" 230 run_args="${run_args} --boot -Xbootclasspath:${bpath}" 231 else 232 true # defaults to using target BOOTCLASSPATH 233 fi 234elif [ "$runtime" = "art" ]; then 235 if [ "$target_mode" = "no" ]; then 236 # ANDROID_BUILD_TOP and ANDROID_HOST_OUT are not set in a build environment. 237 if [ -z "$ANDROID_BUILD_TOP" ]; then 238 export ANDROID_BUILD_TOP=$oldwd 239 fi 240 if [ -z "$ANDROID_HOST_OUT" ]; then 241 export ANDROID_HOST_OUT=$ANDROID_BUILD_TOP/out/host/linux-x86 242 fi 243 run_args="${run_args} --boot -Ximage:${ANDROID_HOST_OUT}/framework/core.art" 244 run_args="${run_args} --runtime-option -Djava.library.path=${ANDROID_HOST_OUT}/lib${suffix64}" 245 else 246 guess_arch_name 247 run_args="${run_args} --runtime-option -Djava.library.path=/data/art-test/${target_arch_name}" 248 run_args="${run_args} --boot -Ximage:/data/art-test/core.art" 249 fi 250 if [ "$relocate" = "yes" ]; then 251 run_args="${run_args} --relocate" 252 else 253 run_args="${run_args} --no-relocate" 254 fi 255fi 256 257if [ "$dev_mode" = "yes" -a "$update_mode" = "yes" ]; then 258 echo "--dev and --update are mutually exclusive" 1>&2 259 usage="yes" 260fi 261 262if [ "$usage" = "no" ]; then 263 if [ "x$1" = "x" -o "x$1" = "x-" ]; then 264 test_dir=`basename "$oldwd"` 265 else 266 test_dir="$1" 267 fi 268 269 if [ '!' -d "$test_dir" ]; then 270 td2=`echo ${test_dir}-*` 271 if [ '!' -d "$td2" ]; then 272 echo "${test_dir}: no such test directory" 1>&2 273 usage="yes" 274 fi 275 test_dir="$td2" 276 fi 277 # Shift to get rid of the test name argument. The rest of the arguments 278 # will get passed to the test run. 279 shift 280fi 281 282if [ "$usage" = "yes" ]; then 283 prog=`basename $prog` 284 ( 285 echo "usage:" 286 echo " $prog --help Print this message." 287 echo " $prog [options] [test-name] Run test normally." 288 echo " $prog --dev [options] [test-name] Development mode" \ 289 "(dumps to stdout)." 290 echo " $prog --update [options] [test-name] Update mode" \ 291 "(replaces expected.txt)." 292 echo ' Omitting the test name or specifying "-" will use the' \ 293 "current directory." 294 echo " Runtime Options:" 295 echo " -O Run non-debug rather than debug build (off by default)." 296 echo " -Xcompiler-option Pass an option to the compiler." 297 echo " --runtime-option Pass an option to the runtime." 298 echo " --debug Wait for a debugger to attach." 299 echo " --gdb Run under gdb; incompatible with some tests." 300 echo " --build-only Build test files only (off by default)." 301 echo " --interpreter Enable interpreter only mode (off by default)." 302 echo " --no-verify Turn off verification (on by default)." 303 echo " --no-optimize Turn off optimization (on by default)." 304 echo " --no-precise Turn off precise GC (on by default)." 305 echo " --zygote Spawn the process from the Zygote." \ 306 "If used, then the" 307 echo " other runtime options are ignored." 308 echo " --prebuild Run dex2oat on the files before starting test. (default)" 309 echo " --no-prebuild Do not run dex2oat on the files before starting" 310 echo " the test." 311 echo " --relocate Force the use of relocating in the test, making" 312 echo " the image and oat files be relocated to a random" 313 echo " address before running. (default)" 314 echo " --no-relocate Force the use of no relocating in the test" 315 echo " --host Use the host-mode virtual machine." 316 echo " --invoke-with Pass --invoke-with option to runtime." 317 echo " --dalvik Use Dalvik (off by default)." 318 echo " --jvm Use a host-local RI virtual machine." 319 echo " --output-path [path] Location where to store the build" \ 320 "files." 321 echo " --64 Run the test in 64-bit mode" 322 echo " --trace Run with method tracing" 323 ) 1>&2 324 exit 1 325fi 326 327cd "$test_dir" 328test_dir=`pwd` 329 330td_info="${test_dir}/${info}" 331td_expected="${test_dir}/${expected}" 332 333if [ ! -r $td_info ]; then 334 echo "${test_dir}: missing file $td_info" 1>&2 335 exit 1 336fi 337 338if [ ! -r $td_expected ]; then 339 echo "${test_dir}: missing file $td_expected" 1>&2 340 exit 1 341fi 342 343# copy the test to a temp dir and run it 344 345echo "${test_dir}: building..." 1>&2 346 347rm -rf "$tmp_dir" 348cp -Rp "$test_dir" "$tmp_dir" 349cd "$tmp_dir" 350 351if [ '!' -r "$build" ]; then 352 cp "${progdir}/etc/default-build" build 353fi 354 355if [ '!' -r "$run" ]; then 356 cp "${progdir}/etc/default-run" run 357fi 358 359if [ '!' -r "$check_cmd" ]; then 360 cp "${progdir}/etc/default-check" check 361fi 362 363chmod 755 "$build" 364chmod 755 "$run" 365chmod 755 "$check_cmd" 366 367export TEST_NAME=`basename ${test_dir}` 368 369# To cause tests to fail fast, limit the file sizes created by dx, dex2oat and ART output to 2MB. 370file_size_limit=2048 371if echo "$test_dir" | grep 089; then 372 file_size_limit=5120 373elif echo "$test_dir" | grep 083; then 374 file_size_limit=5120 375fi 376if ! ulimit -S "$file_size_limit"; then 377 echo "ulimit file size setting failed" 378fi 379 380good="no" 381if [ "$dev_mode" = "yes" ]; then 382 "./${build}" 2>&1 383 build_exit="$?" 384 echo "build exit status: $build_exit" 1>&2 385 if [ "$build_exit" = '0' ]; then 386 echo "${test_dir}: running..." 1>&2 387 "./${run}" $run_args "$@" 2>&1 388 run_exit="$?" 389 echo "run exit status: $run_exit" 1>&2 390 if [ "$run_exit" = "0" ]; then 391 good="yes" 392 fi 393 fi 394elif [ "$update_mode" = "yes" ]; then 395 "./${build}" >"$build_output" 2>&1 396 build_exit="$?" 397 if [ "$build_exit" = '0' ]; then 398 echo "${test_dir}: running..." 1>&2 399 "./${run}" $run_args "$@" >"$output" 2>&1 400 sed -e 's/[[:cntrl:]]$//g' < "$output" >"${td_expected}" 401 good="yes" 402 else 403 cat "$build_output" 1>&2 404 echo "build exit status: $build_exit" 1>&2 405 fi 406elif [ "$build_only" = "yes" ]; then 407 good="yes" 408 "./${build}" >"$build_output" 2>&1 409 build_exit="$?" 410 if [ "$build_exit" '!=' '0' ]; then 411 cp "$build_output" "$output" 412 echo "build exit status: $build_exit" >>"$output" 413 diff --strip-trailing-cr -q "$expected" "$output" >/dev/null 414 if [ "$?" '!=' "0" ]; then 415 good="no" 416 echo "BUILD FAILED For ${TEST_NAME}" 417 fi 418 fi 419 # Clean up extraneous files that are not used by tests. 420 find $tmp_dir -mindepth 1 ! -regex ".*/\(.*jar\|$output\|$expected\)" | xargs rm -rf 421 exit 0 422else 423 "./${build}" >"$build_output" 2>&1 424 build_exit="$?" 425 if [ "$build_exit" = '0' ]; then 426 echo "${test_dir}: running..." 1>&2 427 "./${run}" $run_args "$@" >"$output" 2>&1 428 else 429 cp "$build_output" "$output" 430 echo "build exit status: $build_exit" >>"$output" 431 fi 432 ./$check_cmd "$expected" "$output" 433 if [ "$?" = "0" ]; then 434 # output == expected 435 good="yes" 436 echo "${test_dir}: succeeded!" 1>&2 437 fi 438fi 439 440# Clean up test files. 441if [ "$good" == "yes" ]; then 442 cd "$oldwd" 443 rm -rf "$tmp_dir" 444 if [ "$target_mode" = "yes" -a "$build_exit" = "0" ]; then 445 adb shell rm -rf $DEX_LOCATION 446 fi 447 exit 0 448fi 449 450 451( 452 if [ "$update_mode" != "yes" ]; then 453 echo "${test_dir}: FAILED!" 454 echo ' ' 455 echo '#################### info' 456 cat "${td_info}" | sed 's/^/# /g' 457 echo '#################### diffs' 458 diff --strip-trailing-cr -u "$expected" "$output" | tail -n 500 459 echo '####################' 460 echo ' ' 461 fi 462 echo "${TEST_NAME} files left in ${tmp_dir} on host" 463 if [ "$target_mode" == "yes" ]; then 464 echo "and in ${DEX_LOCATION} on target" 465 fi 466 467) 1>&2 468 469exit 1 470