1#!/bin/sh 2# 3# Copyright 2012 Google LLC 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: 8# 9# * Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# * Redistributions in binary form must reproduce the above 12# copyright notice, this list of conditions and the following disclaimer 13# in the documentation and/or other materials provided with the 14# distribution. 15# * Neither the name of Google LLC nor the names of its 16# contributors may be used to endorse or promote products derived from 17# this software without specific prior written permission. 18# 19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31# A special shell wrapper that can be used to run the Google Breakpad unit 32# tests on a connected Android device. 33# 34# This is designed to be called from the Makefile during 'make check' 35# 36 37PROGDIR=$(dirname "$0") 38PROGNAME=$(basename "$0") 39. $PROGDIR/common-functions.sh 40 41# Extract test program name first. 42TEST_PROGRAM=$1 43shift 44 45if [ -z "$TEST_PROGRAM" ]; then 46 panic "No test program/script name on the command-line!" 47fi 48 49if [ ! -f "$TEST_PROGRAM" ]; then 50 panic "Can't find test program/script: $TEST_PROGRAM" 51fi 52 53# Create test directory on the device 54TEST_DIR=/data/local/tmp/test-google-breakpad-$$ 55adb_shell mkdir "$TEST_DIR" || 56 panic "Can't create test directory on device: $TEST_DIR" 57 58# Ensure that it is always removed when the script exits. 59clean_test_dir () { 60 # Don't care about success/failure, use '$ADB shell' directly. 61 adb_shell rm -r "$TEST_DIR" 62} 63 64atexit clean_test_dir 65 66TEST_PROGRAM_NAME=$(basename "$TEST_PROGRAM") 67TEST_PROGRAM_DIR=$(dirname "$TEST_PROGRAM") 68 69# Handle special case(s) here. 70DATA_FILES= 71case $TEST_PROGRAM_NAME in 72 linux_client_unittest) 73 # linux_client_unittest will call another executable at runtime, ensure 74 # it is installed too. 75 adb_install "$TEST_PROGRAM_DIR/linux_dumper_unittest_helper" "$TEST_DIR" 76 # linux_client_unittest loads a shared library at runtime, ensure it is 77 # installed too. 78 adb_install "$TEST_PROGRAM_DIR/linux_client_unittest_shlib" "$TEST_DIR" 79 ;; 80 basic_source_line_resolver_unittest) 81 DATA_FILES="module1.out \ 82 module2.out \ 83 module3_bad.out \ 84 module4_bad.out" 85 ;; 86 exploitability_unittest) 87 DATA_FILES="scii_read_av.dmp \ 88 ascii_read_av_block_write.dmp \ 89 ascii_read_av_clobber_write.dmp \ 90 ascii_read_av_conditional.dmp \ 91 ascii_read_av_non_null.dmp \ 92 ascii_read_av_then_jmp.dmp \ 93 ascii_read_av_xchg_write.dmp \ 94 ascii_write_av.dmp \ 95 ascii_write_av_arg_to_call.dmp \ 96 exec_av_on_stack.dmp \ 97 null_read_av.dmp \ 98 null_write_av.dmp \ 99 read_av.dmp \ 100 null_read_av.dmp \ 101 write_av_non_null.dmp" 102 ;; 103 fast_source_line_resolver_unittest) 104 DATA_FILES="module0.out \ 105 module1.out \ 106 module2.out \ 107 module3_bad.out \ 108 module4_bad.out" 109 ;; 110 minidump_processor_unittest|minidump_unittest) 111 DATA_FILES="src/processor/testdata/minidump2.dmp" 112 ;; 113esac 114 115# Install the data files, their path is relative to the environment 116# variable 'srcdir' 117for FILE in $DATA_FILES; do 118 FILEDIR=src/processor/testdata/$(dirname "$FILE") 119 adb_shell mkdir -p "$TEST_DIR/$FILEDIR" 120 adb_install "${srcdir:-.}/$FILE" "$TEST_DIR"/"$FILE" 121done 122 123# Copy test program to device 124adb_install "$TEST_PROGRAM" "$TEST_DIR" 125 126# Run it 127adb_shell "cd $TEST_DIR && LD_LIBRARY_PATH=. ./$TEST_PROGRAM_NAME $@" 128 129# Note: exiting here will call cleanup_exit which will remove the temporary 130# files from the device. 131