2 # Copyright 2008 Google, Inc. All Rights Reserved.
3 # Author: Satoru Takabayashi
5 # Unit tests for signalhandler.cc.
13 LIBGLOG="$BINDIR/libglog.so"
15 BINARY="$BINDIR/signalhandler_unittest"
16 LOG_INFO="./signalhandler_unittest.INFO"
18 # Remove temporary files.
19 rm -f signalhandler.out*
21 if test -e "$BINARY"; then
22 # We need shared object.
23 export LD_LIBRARY_PATH=$BINDIR
24 export DYLD_LIBRARY_PATH=$BINDIR
27 BINARY="./signalhandler_unittest.exe"
28 if ! test -e "$BINARY"; then
29 echo "We coundn't find demangle_unittest binary."
34 if [ x`$BINARY` != 'xOK' ]; then
35 echo "PASS (No stacktrace support. We don't run this test.)"
39 # The PC cannot be obtained in signal handlers on PowerPC correctly.
40 # We just skip the test for PowerPC.
41 if [ x`uname -p` = x"powerpc" ]; then
42 echo "PASS (We don't test the signal handler on PowerPC.)"
46 # Test for a case the program kills itself by SIGSEGV.
47 GOOGLE_LOG_DIR=. $BINARY segv 2> signalhandler.out1
48 for pattern in SIGSEGV 0xdead main "Aborted at [0-9]"; do
49 if ! grep --quiet "$pattern" signalhandler.out1; then
50 die "'$pattern' should appear in the output"
53 if ! grep --quiet "a message before segv" $LOG_INFO; then
54 die "'a message before segv' should appear in the INFO log"
58 # Test for a case the program is killed by this shell script.
59 # $! = the process id of the last command run in the background.
60 # $$ = the process id of this shell.
61 $BINARY loop 2> signalhandler.out2 &
62 # Wait until "looping" is written in the file. This indicates the program
63 # is ready to accept signals.
65 if grep --quiet looping signalhandler.out2; then
73 # Only linux has the process ID of the signal sender.
74 if [ x`uname` = "xLinux" ]; then
75 from_pid="from PID $$"
77 for pattern in SIGTERM "by PID $!" "$from_pid" main "Aborted at [0-9]"; do
78 if ! grep --quiet "$pattern" signalhandler.out2; then
79 die "'$pattern' should appear in the output"
83 # Test for a case the program dies in a non-main thread.
84 $BINARY die_in_thread 2> signalhandler.out3
85 EXPECTED_TID="`sed 's/ .*//' signalhandler.out3`"
87 for pattern in SIGFPE DieInThread "TID $EXPECTED_TID" "Aborted at [0-9]"; do
88 if ! grep --quiet "$pattern" signalhandler.out3; then
89 die "'$pattern' should appear in the output"
93 # Test for a case the program installs a custom failure writer that writes
94 # stuff to stdout instead of stderr.
95 $BINARY dump_to_stdout 1> signalhandler.out4
96 for pattern in SIGABRT main "Aborted at [0-9]"; do
97 if ! grep --quiet "$pattern" signalhandler.out4; then
98 die "'$pattern' should appear in the output"