OLD | NEW |
(Empty) | |
| 1 #!/bin/sh |
| 2 # |
| 3 # Copyright (c) 2012 Google Inc. |
| 4 # All rights reserved. |
| 5 # |
| 6 # Redistribution and use in source and binary forms, with or without |
| 7 # modification, are permitted provided that the following conditions are |
| 8 # met: |
| 9 # |
| 10 # * Redistributions of source code must retain the above copyright |
| 11 # notice, this list of conditions and the following disclaimer. |
| 12 # * Redistributions in binary form must reproduce the above |
| 13 # copyright notice, this list of conditions and the following disclaimer |
| 14 # in the documentation and/or other materials provided with the |
| 15 # distribution. |
| 16 # * Neither the name of Google Inc. nor the names of its |
| 17 # contributors may be used to endorse or promote products derived from |
| 18 # this software without specific prior written permission. |
| 19 # |
| 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
| 32 # A special shell wrapper that can be used to run the Google Breakpad unit |
| 33 # tests on a connected Android device. |
| 34 # |
| 35 # This is designed to be called from the Makefile during 'make check' |
| 36 # |
| 37 |
| 38 # Utility function to panic easily. |
| 39 panic () { |
| 40 echo "ERROR: $@" |
| 41 exit 1 |
| 42 } |
| 43 |
| 44 # Ensure proper cleanup on program exit. |
| 45 ALL_CLEANUPS= |
| 46 |
| 47 add_cleanup () { |
| 48 ALL_CLEANUPS="$1 $ALL_CLEANUPS" |
| 49 } |
| 50 |
| 51 clean_exit () { |
| 52 local CLEANUPS="$ALL_CLEANUPS" |
| 53 ALL_CLEANUPS= |
| 54 for CLEANUP in $CLEANUPS; do |
| 55 $CLEANUP |
| 56 done |
| 57 exit "$@" |
| 58 } |
| 59 |
| 60 trap "clean_exit \$?" EXIT |
| 61 trap "clean_exit 1" INT HUP TERM QUIT |
| 62 |
| 63 # Utility function to copy a program to the device, and fail on error. |
| 64 install_file () { |
| 65 "$ADB" push "$1" "$2" 2>/dev/null |
| 66 if [ $? != 0 ]; then |
| 67 panic "Can't push '$1' to device at '$2'" |
| 68 fi |
| 69 } |
| 70 |
| 71 # Extract test program name first. |
| 72 TEST_PROGRAM=$1 |
| 73 shift |
| 74 |
| 75 if [ -z "$TEST_PROGRAM" ]; then |
| 76 panic "No test program/script name on the command-line!" |
| 77 fi |
| 78 |
| 79 if [ ! -f "$TEST_PROGRAM" ]; then |
| 80 panic "Can't find test program/script: $TEST_PROGRAM" |
| 81 fi |
| 82 |
| 83 # Get ADB program path |
| 84 if [ -z "$ADB" ]; then |
| 85 ADB=$(which adb 2>/dev/null) |
| 86 if [ -z "$ADB" ]; then |
| 87 panic "Please have the 'adb' program in your path, or set ADB in your enviro
nment." |
| 88 fi |
| 89 elif [ ! -f "$ADB" ]; then |
| 90 panic "ADB points to a missing file: $ADB" |
| 91 else |
| 92 # Basic check |
| 93 ADB_VERSION=$("$ADB" version) |
| 94 case $ADB_VERSION in |
| 95 "Android Debug Bridge"*) # pass |
| 96 ;; |
| 97 *) # fail |
| 98 panic "ADB points to a program that is not Android adb ($ADB_VERSION)" |
| 99 esac |
| 100 fi |
| 101 |
| 102 # Count number of connected devices |
| 103 ADB_COUNT=$("$ADB" devices 2>/dev/null | awk '$2 == "device" { print $1; }' | wc
-l) |
| 104 case $ADB_COUNT in |
| 105 0) |
| 106 panic "No Android device connected to this computer!" |
| 107 ;; |
| 108 1) # All right. |
| 109 ;; |
| 110 *) |
| 111 if [ -z "$ANDROID_SERIAL" ]; then |
| 112 panic "More than one Android device connected. Please set ANDROID_SERIAL!" |
| 113 fi |
| 114 ;; |
| 115 esac |
| 116 |
| 117 # Call 'adb shell' return correct exit status |
| 118 # $1+: shell command |
| 119 adb_shell () { |
| 120 local RET ADB_LOG |
| 121 ADB_LOG=$(mktemp "${TMPDIR:-/tmp}/adb-XXXXXXXX") |
| 122 "$ADB" shell "$@" ";" echo \$? > "$ADB_LOG" 2>&1 |
| 123 sed -i -e 's![[:cntrl:]]!!g' "$ADB_LOG" # Remove \r. |
| 124 RET=$(sed -e '$!d' "$ADB_LOG") # Last line contains status code. |
| 125 sed -e '$d' "$ADB_LOG" # Print everything except last line. |
| 126 rm -f "$ADB_LOG" |
| 127 return $RET |
| 128 } |
| 129 |
| 130 # Create test directory on the device |
| 131 TEST_DIR=/data/local/tmp/test-google-breakpad |
| 132 adb_shell mkdir "$TEST_DIR" || panic "Can't create test directory on device" |
| 133 |
| 134 # Ensure that it is always removed when the script exits. |
| 135 clean_test_dir () { |
| 136 # Don't care about success/failure, use '$ADB shell' directly. |
| 137 "$ADB" shell rm -r "$TEST_DIR" |
| 138 } |
| 139 |
| 140 add_cleanup clean_test_dir |
| 141 |
| 142 TEST_PROGRAM_NAME=$(basename "$TEST_PROGRAM") |
| 143 TEST_PROGRAM_DIR=$(dirname "$TEST_PROGRAM") |
| 144 |
| 145 # Handle special case(s) here. |
| 146 DATA_FILES= |
| 147 case $TEST_PROGRAM_NAME in |
| 148 linux_client_unittest) |
| 149 # linux_client_unittest will call another executable at runtime, ensure |
| 150 # it is installed too. |
| 151 install_file "$TEST_PROGRAM_DIR/linux_dumper_unittest_helper" "$TEST_DIR" |
| 152 ;; |
| 153 basic_source_line_resolver_unittest) |
| 154 DATA_FILES="module1.out \ |
| 155 module2.out \ |
| 156 module3_bad.out \ |
| 157 module4_bad.out" |
| 158 ;; |
| 159 exploitability_unittest) |
| 160 DATA_FILES="scii_read_av.dmp \ |
| 161 ascii_read_av_block_write.dmp \ |
| 162 ascii_read_av_clobber_write.dmp \ |
| 163 ascii_read_av_conditional.dmp \ |
| 164 ascii_read_av_non_null.dmp \ |
| 165 ascii_read_av_then_jmp.dmp \ |
| 166 ascii_read_av_xchg_write.dmp \ |
| 167 ascii_write_av.dmp \ |
| 168 ascii_write_av_arg_to_call.dmp \ |
| 169 exec_av_on_stack.dmp \ |
| 170 null_read_av.dmp \ |
| 171 null_write_av.dmp \ |
| 172 read_av.dmp \ |
| 173 null_read_av.dmp \ |
| 174 write_av_non_null.dmp" |
| 175 ;; |
| 176 fast_source_line_resolver_unittest) |
| 177 DATA_FILES="module0.out \ |
| 178 module1.out \ |
| 179 module2.out \ |
| 180 module3_bad.out \ |
| 181 module4_bad.out" |
| 182 ;; |
| 183 minidump_processor_unittest|minidump_unittest) |
| 184 DATA_FILES="src/processor/testdata/minidump2.dmp" |
| 185 ;; |
| 186 esac |
| 187 |
| 188 # Install the data files, their path is relative to the environment |
| 189 # variable 'srcdir' |
| 190 for FILE in $DATA_FILES; do |
| 191 FILEDIR=src/processor/testdata/$(dirname "$FILE") |
| 192 adb_shell mkdir -p "$TEST_DIR/$FILEDIR" |
| 193 install_file "${srcdir:-.}/$FILE" "$TEST_DIR"/"$FILE" |
| 194 done |
| 195 |
| 196 # Copy test program to device |
| 197 install_file "$TEST_PROGRAM" "$TEST_DIR" |
| 198 |
| 199 # Run it |
| 200 adb_shell "cd $TEST_DIR && ./$TEST_PROGRAM_NAME $@" |
| 201 |
| 202 # Note: exiting here will call cleanup_exit which will remove the temporary |
| 203 # files from the device. |
OLD | NEW |