/thirdparty/breakpad/third_party/glog/src/signalhandler_unittest.sh
Shell | 131 lines | 86 code | 6 blank | 39 comment | 3 complexity | 90c1df46d724147770fef73d24d52a5c MD5 | raw file
1#! /bin/sh 2# 3# Copyright (c) 2008, 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# Author: Satoru Takabayashi 33# 34# Unit tests for signalhandler.cc. 35 36die () { 37 echo $1 38 exit 1 39} 40 41BINDIR=".libs" 42LIBGLOG="$BINDIR/libglog.so" 43 44BINARY="$BINDIR/signalhandler_unittest" 45LOG_INFO="./signalhandler_unittest.INFO" 46 47# Remove temporary files. 48rm -f signalhandler.out* 49 50if test -e "$BINARY"; then 51 # We need shared object. 52 export LD_LIBRARY_PATH=$BINDIR 53 export DYLD_LIBRARY_PATH=$BINDIR 54else 55 # For windows 56 BINARY="./signalhandler_unittest.exe" 57 if ! test -e "$BINARY"; then 58 echo "We coundn't find demangle_unittest binary." 59 exit 1 60 fi 61fi 62 63if [ x`$BINARY` != 'xOK' ]; then 64 echo "PASS (No stacktrace support. We don't run this test.)" 65 exit 0 66fi 67 68# The PC cannot be obtained in signal handlers on PowerPC correctly. 69# We just skip the test for PowerPC. 70if [ x`uname -p` = x"powerpc" ]; then 71 echo "PASS (We don't test the signal handler on PowerPC.)" 72 exit 0 73fi 74 75# Test for a case the program kills itself by SIGSEGV. 76GOOGLE_LOG_DIR=. $BINARY segv 2> signalhandler.out1 77for 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" 80 fi 81done 82if ! grep --quiet "a message before segv" $LOG_INFO; then 83 die "'a message before segv' should appear in the INFO log" 84fi 85rm -f $LOG_INFO 86 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. 93while true; do 94 if grep --quiet looping signalhandler.out2; then 95 break 96 fi 97done 98kill -TERM $! 99wait $! 100 101from_pid='' 102# Only linux has the process ID of the signal sender. 103if [ x`uname` = "xLinux" ]; then 104 from_pid="from PID $$" 105fi 106for 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" 109 fi 110done 111 112# Test for a case the program dies in a non-main thread. 113$BINARY die_in_thread 2> signalhandler.out3 114EXPECTED_TID="`sed 's/ .*//' signalhandler.out3`" 115 116for 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" 119 fi 120done 121 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 125for 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" 128 fi 129done 130 131echo PASS