tests_in_valgrind.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. ###########################################
  3. # This script runs all tests in valgrind. Configure and compile kea the way
  4. # you want it to be tested (you should use --with-gtest or --with-gtest-source,
  5. # however, or you get no tests). Then run this script from the top build
  6. # directory.
  7. #
  8. # Note that the test isn't what you would call "production quality" (it is
  9. # expected to be used by the kea 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? Or maybe you're running the script from the tools directory? (you need to run it from the top kea build directory)"
  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:---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 -name *_unittests -print | grep -v '\.libs/' | 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. OLDDIR="`pwd`"
  41. cd $(dirname "$testname")
  42. ./$(basename $testname).valgrind >&2 &
  43. PID="$!"
  44. set +e
  45. wait "$PID"
  46. CODE="$?"
  47. set -e
  48. cd "$OLDDIR"
  49. if [ "$CODE" != 0 ] ; then
  50. echo 'FAILED="$FAILED
  51. '"$testname"'"'
  52. fi
  53. NAME="$LOGFILE.$PID"
  54. rm "$testname.valgrind"
  55. # Remove the ones from death tests
  56. if [ -e $NAME ]; then
  57. grep "==$PID==" "$NAME" >>"$LOGFILE"
  58. rm "$NAME"
  59. fi
  60. echo 'FOUND_ANY=true'
  61. done)
  62. if test -n "$FAILED"; then
  63. echo "These tests failed:" >&2
  64. echo "$FAILED" >&2
  65. fi
  66. if ! $FOUND_ANY ; then
  67. echo "No test was found. It is possible you configured without --with-gtest or you run it from wrong directory" >&2
  68. exit 1
  69. fi