/thirdparty/breakpad/third_party/glog/src/signalhandler_unittest.sh

http://github.com/tomahawk-player/tomahawk · 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. die () {
  36. echo $1
  37. exit 1
  38. }
  39. BINDIR=".libs"
  40. LIBGLOG="$BINDIR/libglog.so"
  41. BINARY="$BINDIR/signalhandler_unittest"
  42. LOG_INFO="./signalhandler_unittest.INFO"
  43. # Remove temporary files.
  44. rm -f signalhandler.out*
  45. if test -e "$BINARY"; then
  46. # We need shared object.
  47. export LD_LIBRARY_PATH=$BINDIR
  48. export DYLD_LIBRARY_PATH=$BINDIR
  49. else
  50. # For windows
  51. BINARY="./signalhandler_unittest.exe"
  52. if ! test -e "$BINARY"; then
  53. echo "We coundn't find demangle_unittest binary."
  54. exit 1
  55. fi
  56. fi
  57. if [ x`$BINARY` != 'xOK' ]; then
  58. echo "PASS (No stacktrace support. We don't run this test.)"
  59. exit 0
  60. fi
  61. # The PC cannot be obtained in signal handlers on PowerPC correctly.
  62. # We just skip the test for PowerPC.
  63. if [ x`uname -p` = x"powerpc" ]; then
  64. echo "PASS (We don't test the signal handler on PowerPC.)"
  65. exit 0
  66. fi
  67. # Test for a case the program kills itself by SIGSEGV.
  68. GOOGLE_LOG_DIR=. $BINARY segv 2> signalhandler.out1
  69. for pattern in SIGSEGV 0xdead main "Aborted at [0-9]"; do
  70. if ! grep --quiet "$pattern" signalhandler.out1; then
  71. die "'$pattern' should appear in the output"
  72. fi
  73. done
  74. if ! grep --quiet "a message before segv" $LOG_INFO; then
  75. die "'a message before segv' should appear in the INFO log"
  76. fi
  77. rm -f $LOG_INFO
  78. # Test for a case the program is killed by this shell script.
  79. # $! = the process id of the last command run in the background.
  80. # $$ = the process id of this shell.
  81. $BINARY loop 2> signalhandler.out2 &
  82. # Wait until "looping" is written in the file. This indicates the program
  83. # is ready to accept signals.
  84. while true; do
  85. if grep --quiet looping signalhandler.out2; then
  86. break
  87. fi
  88. done
  89. kill -TERM $!
  90. wait $!
  91. from_pid=''
  92. # Only linux has the process ID of the signal sender.
  93. if [ x`uname` = "xLinux" ]; then
  94. from_pid="from PID $$"
  95. fi
  96. for pattern in SIGTERM "by PID $!" "$from_pid" main "Aborted at [0-9]"; do
  97. if ! grep --quiet "$pattern" signalhandler.out2; then
  98. die "'$pattern' should appear in the output"
  99. fi
  100. done
  101. # Test for a case the program dies in a non-main thread.
  102. $BINARY die_in_thread 2> signalhandler.out3
  103. EXPECTED_TID="`sed 's/ .*//' signalhandler.out3`"
  104. for pattern in SIGFPE DieInThread "TID $EXPECTED_TID" "Aborted at [0-9]"; do
  105. if ! grep --quiet "$pattern" signalhandler.out3; then
  106. die "'$pattern' should appear in the output"
  107. fi
  108. done
  109. # Test for a case the program installs a custom failure writer that writes
  110. # stuff to stdout instead of stderr.
  111. $BINARY dump_to_stdout 1> signalhandler.out4
  112. for pattern in SIGABRT main "Aborted at [0-9]"; do
  113. if ! grep --quiet "$pattern" signalhandler.out4; then
  114. die "'$pattern' should appear in the output"
  115. fi
  116. done
  117. echo PASS