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

http://github.com/tomahawk-player/tomahawk · Shell · 95 lines · 50 code · 7 blank · 38 comment · 4 complexity · 620a6b1d03b52b2d0cc635465ebe299b MD5 · raw file

  1. #! /bin/sh
  2. #
  3. # Copyright (c) 2006, 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 demangle.c with a real binary.
  35. set -e
  36. die () {
  37. echo $1
  38. exit 1
  39. }
  40. BINDIR=".libs"
  41. LIBGLOG="$BINDIR/libglog.so"
  42. DEMANGLER="$BINDIR/demangle_unittest"
  43. if test -e "$DEMANGLER"; then
  44. # We need shared object.
  45. export LD_LIBRARY_PATH=$BINDIR
  46. export DYLD_LIBRARY_PATH=$BINDIR
  47. else
  48. # For windows
  49. DEMANGLER="./demangle_unittest.exe"
  50. if ! test -e "$DEMANGLER"; then
  51. echo "We coundn't find demangle_unittest binary."
  52. exit 1
  53. fi
  54. fi
  55. # Extract C++ mangled symbols from libbase.so.
  56. NM_OUTPUT="demangle.nm"
  57. nm "$LIBGLOG" | perl -nle 'print $1 if /\s(_Z\S+$)/' > "$NM_OUTPUT"
  58. # Check if mangled symbols exist. If there are none, we quit.
  59. # The binary is more likely compiled with GCC 2.95 or something old.
  60. if ! grep --quiet '^_Z' "$NM_OUTPUT"; then
  61. echo "PASS"
  62. exit 0
  63. fi
  64. # Demangle the symbols using our demangler.
  65. DM_OUTPUT="demangle.dm"
  66. GLOG_demangle_filter=1 "$DEMANGLER" --demangle_filter < "$NM_OUTPUT" > "$DM_OUTPUT"
  67. # Calculate the numbers of lines.
  68. NM_LINES=`wc -l "$NM_OUTPUT" | awk '{ print $1 }'`
  69. DM_LINES=`wc -l "$DM_OUTPUT" | awk '{ print $1 }'`
  70. # Compare the numbers of lines. They must be the same.
  71. if test "$NM_LINES" != "$DM_LINES"; then
  72. die "$NM_OUTPUT and $DM_OUTPUT don't have the same numbers of lines"
  73. fi
  74. # Check if mangled symbols exist. They must not exist.
  75. if grep --quiet '^_Z' "$DM_OUTPUT"; then
  76. MANGLED=`grep '^_Z' "$DM_OUTPUT" | wc -l | awk '{ print \$1 }'`
  77. echo "Mangled symbols ($MANGLED out of $NM_LINES) found in $DM_OUTPUT:"
  78. grep '^_Z' "$DM_OUTPUT"
  79. die "Mangled symbols ($MANGLED out of $NM_LINES) found in $DM_OUTPUT"
  80. fi
  81. # All C++ symbols are demangled successfully.
  82. echo "PASS"
  83. exit 0