tests_in_valgrind.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 run_unittests -print | grep -v '\.libs/run_unittests$' | 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. ./run_unittests.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. grep "==$PID==" "$NAME" >>"$LOGFILE"
  56. rm "$NAME"
  57. echo 'FOUND_ANY=true'
  58. done)
  59. if test -n "$FAILED"; then
  60. echo "These tests failed:" >&2
  61. echo "$FAILED" >&2
  62. fi
  63. if ! $FOUND_ANY ; then
  64. echo "No test was found. It is possible you configured without --with-gtest or you run it from wrong directory" >&2
  65. exit 1
  66. fi