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 # The PC cannot be obtained in signal handlers on PowerPC correctly.
39 # We just skip the test for PowerPC.
40 if [ x`uname -p` = x"powerpc" ]; then
41 echo "PASS (We don't test the signal handler on PowerPC.)"
45 # Test for a case the program kills itself by SIGSEGV.
46 $BINARY segv 2> signalhandler.out1
47 for pattern in SIGSEGV 0xdead main "Aborted at [0-9]"; do
48 if ! grep --quiet "$pattern" signalhandler.out1; then
49 die "'$pattern' should appear in the output"
53 # Test for a case the program is killed by this shell script.
54 # $! = the process id of the last command run in the background.
55 # $$ = the process id of this shell.
56 $BINARY loop 2> signalhandler.out2 &
57 # Wait until "looping" is written in the file. This indicates the program
58 # is ready to accept signals.
60 if grep --quiet looping signalhandler.out2; then
68 # Only linux has the process ID of the signal sender.
69 if [ x`uname` = "xLinux" ]; then
70 from_pid="from PID $$"
72 for pattern in SIGTERM "by PID $!" "$from_pid" main "Aborted at [0-9]"; do
73 if ! grep --quiet "$pattern" signalhandler.out2; then
74 die "'$pattern' should appear in the output"
78 # Test for a case the program dies in a non-main thread.
79 $BINARY die_in_thread 2> signalhandler.out3
80 EXPECTED_TID="`sed 's/ .*//' signalhandler.out3`"
82 for pattern in SIGFPE DieInThread "TID $EXPECTED_TID" "Aborted at [0-9]"; do
83 if ! grep --quiet "$pattern" signalhandler.out3; then
84 die "'$pattern' should appear in the output"
88 # Test for a case the program installs a custom failure writer that writes
89 # stuff to stdout instead of stderr.
90 $BINARY dump_to_stdout 1> signalhandler.out4
91 for pattern in SIGABRT main "Aborted at [0-9]"; do
92 if ! grep --quiet "$pattern" signalhandler.out4; then
93 die "'$pattern' should appear in the output"