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
38PROGDIR=$(dirname "$0")
39PROGNAME=$(basename "$0")
40. $PROGDIR/common-functions.sh
41
42# Extract test program name first.
43TEST_PROGRAM=$1
44shift
45
46if [ -z "$TEST_PROGRAM" ]; then
47  panic "No test program/script name on the command-line!"
48fi
49
50if [ ! -f "$TEST_PROGRAM" ]; then
51  panic "Can't find test program/script: $TEST_PROGRAM"
52fi
53
54# Create test directory on the device
55TEST_DIR=/data/local/tmp/test-google-breakpad-$$
56adb_shell mkdir "$TEST_DIR" ||
57    panic "Can't create test directory on device: $TEST_DIR"
58
59# Ensure that it is always removed when the script exits.
60clean_test_dir () {
61  # Don't care about success/failure, use '$ADB shell' directly.
62  adb_shell rm -r "$TEST_DIR"
63}
64
65atexit clean_test_dir
66
67TEST_PROGRAM_NAME=$(basename "$TEST_PROGRAM")
68TEST_PROGRAM_DIR=$(dirname "$TEST_PROGRAM")
69
70# Handle special case(s) here.
71DATA_FILES=
72case $TEST_PROGRAM_NAME in
73  linux_client_unittest)
74    # linux_client_unittest will call another executable at runtime, ensure
75    # it is installed too.
76    adb_install "$TEST_PROGRAM_DIR/linux_dumper_unittest_helper" "$TEST_DIR"
77    # linux_client_unittest loads a shared library at runtime, ensure it is
78    # installed too.
79    adb_install "$TEST_PROGRAM_DIR/linux_client_unittest_shlib" "$TEST_DIR"
80    ;;
81  basic_source_line_resolver_unittest)
82    DATA_FILES="module1.out \
83                module2.out \
84                module3_bad.out \
85                module4_bad.out"
86    ;;
87  exploitability_unittest)
88    DATA_FILES="scii_read_av.dmp \
89                ascii_read_av_block_write.dmp \
90                ascii_read_av_clobber_write.dmp \
91                ascii_read_av_conditional.dmp \
92                ascii_read_av_non_null.dmp \
93                ascii_read_av_then_jmp.dmp \
94                ascii_read_av_xchg_write.dmp \
95                ascii_write_av.dmp \
96                ascii_write_av_arg_to_call.dmp \
97                exec_av_on_stack.dmp \
98                null_read_av.dmp \
99                null_write_av.dmp \
100                read_av.dmp \
101                null_read_av.dmp \
102                write_av_non_null.dmp"
103    ;;
104  fast_source_line_resolver_unittest)
105    DATA_FILES="module0.out \
106                module1.out \
107                module2.out \
108                module3_bad.out \
109                module4_bad.out"
110    ;;
111  minidump_processor_unittest|minidump_unittest)
112    DATA_FILES="src/processor/testdata/minidump2.dmp"
113    ;;
114esac
115
116# Install the data files, their path is relative to the environment
117# variable 'srcdir'
118for FILE in $DATA_FILES; do
119  FILEDIR=src/processor/testdata/$(dirname "$FILE")
120  adb_shell mkdir -p "$TEST_DIR/$FILEDIR"
121  adb_install "${srcdir:-.}/$FILE" "$TEST_DIR"/"$FILE"
122done
123
124# Copy test program to device
125adb_install "$TEST_PROGRAM" "$TEST_DIR"
126
127# Run it
128adb_shell "cd $TEST_DIR && LD_LIBRARY_PATH=. ./$TEST_PROGRAM_NAME $@"
129
130# Note: exiting here will call cleanup_exit which will remove the temporary
131#       files from the device.
132