debugallocation_test.sh 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. # Copyright (c) 2009, 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. # ---
  32. # Author: Craig Silverstein
  33. BINDIR="${BINDIR:-.}"
  34. # We expect PPROF_PATH to be set in the environment.
  35. # If not, we set it to some reasonable value
  36. export PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}"
  37. if [ "x$1" = "x-h" -o "x$1" = "x--help" ]; then
  38. echo "USAGE: $0 [unittest dir]"
  39. echo " By default, unittest_dir=$BINDIR"
  40. exit 1
  41. fi
  42. DEBUGALLOCATION_TEST="${1:-$BINDIR/debugallocation_test}"
  43. num_failures=0
  44. # Run the i-th death test and make sure the test has the expected
  45. # regexp. We can depend on the first line of the output being
  46. # Expected regex:<regex>
  47. # Evaluates to "done" if we are not actually a death-test (so $1 is
  48. # too big a number, and we can stop). Evaluates to "" otherwise.
  49. # Increments num_failures if the death test does not succeed.
  50. OneDeathTest() {
  51. "$DEBUGALLOCATION_TEST" "$1" 2>&1 | {
  52. regex_line='dummy'
  53. # Normally the regex_line is the first line of output, but not
  54. # always (if tcmalloc itself does any logging to stderr).
  55. while test -n "$regex_line"; do
  56. read regex_line
  57. regex=`expr "$regex_line" : "Expected regex:\(.*\)"`
  58. test -n "$regex" && break # found the regex line
  59. done
  60. test -z "$regex" && echo "done" || grep "$regex" 2>&1
  61. }
  62. }
  63. death_test_num=0 # which death test to run
  64. while :; do # same as 'while true', but more portable
  65. echo -n "Running death test $death_test_num..."
  66. output="`OneDeathTest $death_test_num`"
  67. case $output in
  68. # Empty string means grep didn't find anything.
  69. "") echo "FAILED"; num_failures=`expr $num_failures + 1`;;
  70. "done"*) echo "done with death tests"; break;;
  71. # Any other string means grep found something, like it ought to.
  72. *) echo "OK";;
  73. esac
  74. death_test_num=`expr $death_test_num + 1`
  75. done
  76. # Test the non-death parts of the test too
  77. echo -n "Running non-death tests..."
  78. if "$DEBUGALLOCATION_TEST"; then
  79. echo "OK"
  80. else
  81. echo "FAILED"
  82. num_failures=`expr $num_failures + 1`
  83. fi
  84. if [ "$num_failures" = 0 ]; then
  85. echo "PASS"
  86. else
  87. echo "Failed with $num_failures failures"
  88. fi
  89. exit $num_failures