3
# Copyright (c) 2008, Google Inc.
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are
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
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.
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.
32
# Author: Satoru Takabayashi
34
# Unit tests for signalhandler.cc.
42
LIBGLOG="$BINDIR/libglog.so"
44
BINARY="$BINDIR/signalhandler_unittest"
45
LOG_INFO="./signalhandler_unittest.INFO"
47
# Remove temporary files.
48
rm -f signalhandler.out*
50
if test -e "$BINARY"; then
51
# We need shared object.
52
export LD_LIBRARY_PATH=$BINDIR
53
export DYLD_LIBRARY_PATH=$BINDIR
56
BINARY="./signalhandler_unittest.exe"
57
if ! test -e "$BINARY"; then
58
echo "We coundn't find demangle_unittest binary."
63
if [ x`$BINARY` != 'xOK' ]; then
64
echo "PASS (No stacktrace support. We don't run this test.)"
68
# The PC cannot be obtained in signal handlers on PowerPC correctly.
69
# We just skip the test for PowerPC.
70
if [ x`uname -p` = x"powerpc" ]; then
71
echo "PASS (We don't test the signal handler on PowerPC.)"
75
# Test for a case the program kills itself by SIGSEGV.
76
GOOGLE_LOG_DIR=. $BINARY segv 2> signalhandler.out1
77
for pattern in SIGSEGV 0xdead main "Aborted at [0-9]"; do
78
if ! grep --quiet "$pattern" signalhandler.out1; then
79
die "'$pattern' should appear in the output"
82
if ! grep --quiet "a message before segv" $LOG_INFO; then
83
die "'a message before segv' should appear in the INFO log"
87
# Test for a case the program is killed by this shell script.
88
# $! = the process id of the last command run in the background.
89
# $$ = the process id of this shell.
90
$BINARY loop 2> signalhandler.out2 &
91
# Wait until "looping" is written in the file. This indicates the program
92
# is ready to accept signals.
94
if grep --quiet looping signalhandler.out2; then
102
# Only linux has the process ID of the signal sender.
103
if [ x`uname` = "xLinux" ]; then
104
from_pid="from PID $$"
106
for pattern in SIGTERM "by PID $!" "$from_pid" main "Aborted at [0-9]"; do
107
if ! grep --quiet "$pattern" signalhandler.out2; then
108
die "'$pattern' should appear in the output"
112
# Test for a case the program dies in a non-main thread.
113
$BINARY die_in_thread 2> signalhandler.out3
114
EXPECTED_TID="`sed 's/ .*//' signalhandler.out3`"
116
for pattern in SIGFPE DieInThread "TID $EXPECTED_TID" "Aborted at [0-9]"; do
117
if ! grep --quiet "$pattern" signalhandler.out3; then
118
die "'$pattern' should appear in the output"
122
# Test for a case the program installs a custom failure writer that writes
123
# stuff to stdout instead of stderr.
124
$BINARY dump_to_stdout 1> signalhandler.out4
125
for pattern in SIGABRT main "Aborted at [0-9]"; do
126
if ! grep --quiet "$pattern" signalhandler.out4; then
127
die "'$pattern' should appear in the output"