aboutsummaryrefslogtreecommitdiff
path: root/android/test-shell.sh
blob: 526e926aebd2baafbf7c7d6c9915fb35c26dbb5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
#
# Copyright (c) 2012 Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
#     * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
#     * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# A special shell wrapper that can be used to run the Google Breakpad unit
# tests on a connected Android device.
#
# This is designed to be called from the Makefile during 'make check'
#

PROGDIR=$(dirname "$0")
PROGNAME=$(basename "$0")
. $PROGDIR/common-functions.sh

# Extract test program name first.
TEST_PROGRAM=$1
shift

if [ -z "$TEST_PROGRAM" ]; then
  panic "No test program/script name on the command-line!"
fi

if [ ! -f "$TEST_PROGRAM" ]; then
  panic "Can't find test program/script: $TEST_PROGRAM"
fi

# Create test directory on the device
TEST_DIR=/data/local/tmp/test-google-breakpad
adb_shell mkdir "$TEST_DIR" || panic "Can't create test directory on device"

# Ensure that it is always removed when the script exits.
clean_test_dir () {
  # Don't care about success/failure, use '$ADB shell' directly.
  adb_shell rm -r "$TEST_DIR"
}

atexit clean_test_dir

TEST_PROGRAM_NAME=$(basename "$TEST_PROGRAM")
TEST_PROGRAM_DIR=$(dirname "$TEST_PROGRAM")

# Handle special case(s) here.
DATA_FILES=
case $TEST_PROGRAM_NAME in
  linux_client_unittest)
    # linux_client_unittest will call another executable at runtime, ensure
    # it is installed too.
    adb_install "$TEST_PROGRAM_DIR/linux_dumper_unittest_helper" "$TEST_DIR"
    # linux_client_unittest loads a shared library at runtime, ensure it is
    # installed too.
    adb_install "$TEST_PROGRAM_DIR/linux_client_unittest_shlib" "$TEST_DIR"
    ;;
  basic_source_line_resolver_unittest)
    DATA_FILES="module1.out \
                module2.out \
                module3_bad.out \
                module4_bad.out"
    ;;
  exploitability_unittest)
    DATA_FILES="scii_read_av.dmp \
                ascii_read_av_block_write.dmp \
                ascii_read_av_clobber_write.dmp \
                ascii_read_av_conditional.dmp \
                ascii_read_av_non_null.dmp \
                ascii_read_av_then_jmp.dmp \
                ascii_read_av_xchg_write.dmp \
                ascii_write_av.dmp \
                ascii_write_av_arg_to_call.dmp \
                exec_av_on_stack.dmp \
                null_read_av.dmp \
                null_write_av.dmp \
                read_av.dmp \
                null_read_av.dmp \
                write_av_non_null.dmp"
    ;;
  fast_source_line_resolver_unittest)
    DATA_FILES="module0.out \
                module1.out \
                module2.out \
                module3_bad.out \
                module4_bad.out"
    ;;
  minidump_processor_unittest|minidump_unittest)
    DATA_FILES="src/processor/testdata/minidump2.dmp"
    ;;
esac

# Install the data files, their path is relative to the environment
# variable 'srcdir'
for FILE in $DATA_FILES; do
  FILEDIR=src/processor/testdata/$(dirname "$FILE")
  adb_shell mkdir -p "$TEST_DIR/$FILEDIR"
  adb_install "${srcdir:-.}/$FILE" "$TEST_DIR"/"$FILE"
done

# Copy test program to device
adb_install "$TEST_PROGRAM" "$TEST_DIR"

# Run it
adb_shell "cd $TEST_DIR && LD_LIBRARY_PATH=. ./$TEST_PROGRAM_NAME $@"

# Note: exiting here will call cleanup_exit which will remove the temporary
#       files from the device.