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"
17 # Remove temporary files.
18 rm -f signalhandler.out*
20 if test -e "$BINARY"; then
21 # We need shared object.
22 export LD_LIBRARY_PATH=$BINDIR
23 export DYLD_LIBRARY_PATH=$BINDIR
26 BINARY="./signalhandler_unittest.exe"
27 if ! test -e "$BINARY"; then
28 echo "We coundn't find demangle_unittest binary."
33 if [ x`$BINARY` != 'xOK' ]; then
34 echo "PASS (No stacktrace support. We don't run this test.)"
38 # Test for a case the program kills itself by SIGSEGV.
39 $BINARY segv 2> signalhandler.out1
40 for pattern in SIGSEGV 0xdead main "Aborted at [0-9]"; do
41 if ! grep --quiet "$pattern" signalhandler.out1; then
42 die "'$pattern' should appear in the output"
46 # Test for a case the program is killed by this shell script.
47 # $! = the process id of the last command run in the background.
48 # $$ = the process id of this shell.
49 $BINARY loop 2> signalhandler.out2 &
50 # Wait until "looping" is written in the file. This indicates the program
51 # is ready to accept signals.
53 if grep --quiet looping signalhandler.out2; then
61 # Only linux has the process ID of the signal sender.
62 if [ x`uname` = "xLinux" ]; then
63 from_pid="from PID $$"
65 for pattern in SIGTERM "by PID $!" "$from_pid" main "Aborted at [0-9]"; do
66 if ! grep --quiet "$pattern" signalhandler.out2; then
67 die "'$pattern' should appear in the output"
71 # Test for a case the program dies in a non-main thread.
72 $BINARY die_in_thread 2> signalhandler.out3
73 EXPECTED_TID="`sed 's/ .*//' signalhandler.out3`"
75 for pattern in SIGFPE DieInThread "TID $EXPECTED_TID" "Aborted at [0-9]"; do
76 if ! grep --quiet "$pattern" signalhandler.out3; then
77 die "'$pattern' should appear in the output"
81 # Test for a case the program installs a custom failure writer that writes
82 # stuff to stdout instead of stderr.
83 $BINARY dump_to_stdout 1> signalhandler.out4
84 for pattern in SIGABRT main "Aborted at [0-9]"; do
85 if ! grep --quiet "$pattern" signalhandler.out4; then
86 die "'$pattern' should appear in the output"