tests_in_valgrind.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # Yes, really bash, there are some bashisms
  3. ###########################################
  4. # This script runs all tests in valgrind. Configure and compile bind the way
  5. # you want it to be tested (you should use --with-gtest, however, or you get
  6. # no tests). Then run this script from the top build directory.
  7. #
  8. # Note that the test isn't what you would call "production quality" (it is
  9. # expected to be used by the bind10 developers, not end user) and might break,
  10. # some ways of breaking it are known.
  11. #
  12. # There are two variables that modify it's behaviour.
  13. # * VALGRIND_FLAGS are the flag passed to valgrind. There are some, hopefully
  14. # reasonable defaults which you can overwrite. Note that the variable is
  15. # used unmodified inside a sed pattern with # as a modifier, which can
  16. # easily break it. There was no motivation to fix this.
  17. # * VALGRIND_FILE is the file to store the output into. Default is valgrind.log
  18. ###########################################
  19. # First, make sure the tests are up to date
  20. make
  21. if [ $? = 2 ] ; then
  22. echo "Did you run configure? Do you call me from the top bind10 directory?" >&2
  23. exit 1
  24. fi
  25. set -e
  26. # Some configuration
  27. # TODO Escape for sed, this might break
  28. LOGFILE="${VALGRIND_FILE:-`pwd`/valgrind.log}"
  29. FLAGS="${VALGRIND_FLAGS:---read-var-info=yes --leak-check=full --track-fds=yes}"
  30. FLAGS="$FLAGS --log-file=$LOGFILE.%p"
  31. FOUND_ANY=false
  32. FAILED=
  33. # Find all the tests (yes, doing it by a name is a nasty hack)
  34. # Since the while runs in a subprocess, we need to get the assignments out, done by the eval
  35. eval $(find . -type f -executable -name run_unittests -print | grep -v '\.libs/run_unittests$' | while read testname ; do
  36. sed -e 's#exec "#exec valgrind '"$FLAGS"' "#' "$testname" > "$testname.valgrind"
  37. chmod +x "$testname.valgrind"
  38. echo "$testname" >>"$LOGFILE"
  39. echo "===============" >>"$LOGFILE"
  40. pushd $(dirname "$testname") >/dev/null
  41. "./run_unittests.valgrind" >&2 &
  42. PID="$!"
  43. set +e
  44. wait "$PID"
  45. CODE="$?"
  46. set -e
  47. popd >/dev/null
  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 [ -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 witouth --with-gtest or you run it from wrong directory" >&2
  65. exit 1
  66. fi