heap-checker_unittest.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. # Copyright (c) 2005, Google Inc.
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are
  7. # met:
  8. #
  9. # * Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. # * Neither the name of Google Inc. nor the names of its
  16. # contributors may be used to endorse or promote products derived from
  17. # this software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. # ---
  31. # Author: Craig Silverstein
  32. #
  33. # Runs the heap-checker unittest with various environment variables.
  34. # This is necessary because we turn on features like the heap profiler
  35. # and heap checker via environment variables. This test makes sure
  36. # they all play well together.
  37. # We expect BINDIR and PPROF_PATH to be set in the environment.
  38. # If not, we set them to some reasonable values
  39. BINDIR="${BINDIR:-.}"
  40. PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}"
  41. if [ "x$1" = "x-h" -o "$1" = "x--help" ]; then
  42. echo "USAGE: $0 [unittest dir] [path to pprof]"
  43. echo " By default, unittest_dir=$BINDIR, pprof_path=$PPROF_PATH"
  44. exit 1
  45. fi
  46. HEAP_CHECKER="${1:-$BINDIR/heap-checker_unittest}"
  47. PPROF_PATH="${2:-$PPROF_PATH}"
  48. TMPDIR=/tmp/heap_check_info
  49. rm -rf $TMPDIR || exit 2
  50. mkdir $TMPDIR || exit 3
  51. # $1: value of heap-check env. var.
  52. run_check() {
  53. export PPROF_PATH="$PPROF_PATH"
  54. [ -n "$1" ] && export HEAPCHECK="$1" || unset HEAPPROFILE
  55. echo -n "Testing $HEAP_CHECKER with HEAPCHECK=$1 ... "
  56. if $HEAP_CHECKER > $TMPDIR/output 2>&1; then
  57. echo "OK"
  58. else
  59. echo "FAILED"
  60. echo "Output from the failed run:"
  61. echo "----"
  62. cat $TMPDIR/output
  63. echo "----"
  64. exit 4
  65. fi
  66. # If we set HEAPPROFILE, then we expect it to actually have emitted
  67. # a profile. Check that it did.
  68. if [ -n "$HEAPPROFILE" ]; then
  69. [ -e "$HEAPPROFILE.0001.heap" ] || exit 5
  70. fi
  71. }
  72. run_check ""
  73. run_check "local"
  74. run_check "normal"
  75. run_check "strict"
  76. rm -rf $TMPDIR # clean up
  77. echo "PASS"