tests_in_valgrind.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/sh
  2. ###########################################
  3. # This script runs all tests in valgrind. Configure and compile bind the way
  4. # you want it to be tested (you should use --with-gtest, however, or you get
  5. # no tests). Then run this script from the top build directory.
  6. #
  7. # Note that the test isn't what you would call "production quality" (it is
  8. # expected to be used by the bind10 developers, not end user) and might break,
  9. # some ways of breaking it are known.
  10. #
  11. # There are two variables that modify it's behaviour.
  12. # * VALGRIND_FLAGS are the flag passed to valgrind. There are some, hopefully
  13. # reasonable defaults which you can overwrite. Note that the variable is
  14. # used unmodified inside a sed pattern with # as a modifier, which can
  15. # easily break it. There was no motivation to fix this.
  16. # * VALGRIND_FILE is the file to store the output into. Default is valgrind.log
  17. ###########################################
  18. # First, make sure the tests are up to date
  19. make
  20. if [ $? = 2 ] ; then
  21. echo "Did you run configure? Or maybe you're running the script from the tools directory? (you need to run it from the top bind10 build directory)"
  22. exit 1
  23. fi
  24. set -e
  25. # Some configuration
  26. # TODO Escape for sed, this might break
  27. LOGFILE="${VALGRIND_FILE:-`pwd`/valgrind.log}"
  28. FLAGS="${VALGRIND_FLAGS:---leak-check=full --track-fds=yes}"
  29. FLAGS="$FLAGS --log-file=$LOGFILE.%p"
  30. FOUND_ANY=false
  31. FAILED=
  32. # Find all the tests (yes, doing it by a name is a nasty hack)
  33. # Since the while runs in a subprocess, we need to get the assignments out, done by the eval
  34. eval $(find . -type f -name *_unittests -print | grep -v '\.libs/' | while read testname ; do
  35. sed -e 's#exec "#exec valgrind '"$FLAGS"' "#' "$testname" > "$testname.valgrind"
  36. chmod +x "$testname.valgrind"
  37. echo "$testname" >>"$LOGFILE"
  38. echo "===============" >>"$LOGFILE"
  39. OLDDIR="`pwd`"
  40. cd $(dirname "$testname")
  41. ./$(basename $testname).valgrind >&2 &
  42. PID="$!"
  43. set +e
  44. wait "$PID"
  45. CODE="$?"
  46. set -e
  47. cd "$OLDDIR"
  48. if [ "$CODE" != 0 ] ; then
  49. echo 'FAILED="$FAILED
  50. '"$testname"'"'
  51. fi
  52. NAME="$LOGFILE.$PID"
  53. rm "$testname.valgrind"
  54. # Remove the ones from death tests
  55. if [ -e $NAME ]; then
  56. grep "==$PID==" "$NAME" >>"$LOGFILE"
  57. rm "$NAME"
  58. fi
  59. echo 'FOUND_ANY=true'
  60. done)
  61. if test -n "$FAILED"; then
  62. echo "These tests failed:" >&2
  63. echo "$FAILED" >&2
  64. fi
  65. if ! $FOUND_ANY ; then
  66. echo "No test was found. It is possible you configured without --with-gtest or you run it from wrong directory" >&2
  67. exit 1
  68. fi