tests_in_valgrind.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. # Yes, really bash, there are some bashisms
  3. # First, make sure the tests are up to date
  4. make
  5. if [ $? = 2 ] ; then
  6. echo "Did you run configure? Do you call me from the top bind10 directory?" >&2
  7. exit 1
  8. fi
  9. set -e
  10. # Some configuration
  11. # TODO Escape for sed, this might break
  12. LOGFILE="${VALGRIND_FILE:-`pwd`/valgrind.log}"
  13. FLAGS="${VALGRIND_FLAGS:---read-var-info=yes --leak-check=full}"
  14. FLAGS="$FLAGS --log-file=$LOGFILE.%p"
  15. FOUND_ANY=false
  16. FAILED=
  17. # Find all the tests (yes, doing it by a name is a nasty hack)
  18. # Since the while runs in a subprocess, we need to get the assignments out, done by the eval
  19. eval $(find . -type f -executable -name run_unittests -print | grep -v '\.libs/run_unittests$' | while read testname ; do
  20. sed -e 's#exec "#exec valgrind '"$FLAGS"' "#' "$testname" > "$testname.valgrind"
  21. chmod +x "$testname.valgrind"
  22. echo "$testname" >>"$LOGFILE"
  23. echo "===============" >>"$LOGFILE"
  24. pushd $(dirname "$testname") >/dev/null
  25. "./run_unittests.valgrind" >&2 &
  26. PID="$!"
  27. set +e
  28. wait "$PID"
  29. CODE="$?"
  30. set -e
  31. popd >/dev/null
  32. if [ "$CODE" != 0 ] ; then
  33. echo 'FAILED="$FAILED
  34. '"$testname"'"'
  35. fi
  36. NAME="$LOGFILE.$PID"
  37. rm "$testname.valgrind"
  38. # Remove the ones from death tests
  39. grep "==$PID==" "$NAME" >>"$LOGFILE"
  40. rm "$NAME"
  41. echo 'FOUND_ANY=true'
  42. done)
  43. if [ -n "$FAILED" ] ; then
  44. echo "These tests failed:" >&2
  45. echo "$FAILED" >&2
  46. fi
  47. if ! $FOUND_ANY ; then
  48. echo "No test was found. It is possible you configured witouth --with-gtest or you run it from wrong directory" >&2
  49. exit 1
  50. fi