From 939b71ee73de7d867ce6f592d583c63f00e6806c Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Apr 14 2015 17:02:55 +0000 Subject: Wire valgrind in to self-tests Run tests under valgrind if $VALGRIND is set. --- diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 9b91ea1..a0f7c2d 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -58,15 +58,19 @@ for testid in "$@" $subdirs ; do continue fi fi + RUNVALGRIND=${VALGRIND:+valgrind --log-file="$builddir"/"$testid"/valgrind/%p.log --trace-children=yes --track-origins=yes} + if test -n "$RUNVALGRIND" ; then + rm -fr "$builddir"/"$testid"/valgrind + mkdir -p "$builddir"/"$testid"/valgrind + fi if test -x "$srcdir"/"$testid"/run.sh ; then - mkdir -p "$builddir"/"$testid" pushd "$srcdir"/"$testid" > /dev/null rm -fr "$tmpdir"/* mkdir -m 500 "$tmpdir"/rosubdir mkdir -m 700 "$tmpdir"/rwsubdir if test -r ./expected.out ; then echo -n "Running test "$testid"... " - ./run.sh "$tmpdir" > "$tmpfile" 2> "$tmpdir"/errors + $RUNVALGRIND ./run.sh "$tmpdir" > "$tmpfile" 2> "$tmpdir"/errors sed -i "s|${TMPDIR:-/tmp}/runtests....../|\${tmpdir}/|g" "$tmpfile" "$tmpdir/errors" stat=1 for i in expected.out* ; do @@ -89,9 +93,15 @@ for testid in "$@" $subdirs ; do fi else echo "Running test "$testid"." - ./run.sh "$tmpdir" + $RUNVALGRIND ./run.sh "$tmpdir" stat=$? fi + if test -n "$RUNVALGRIND" ; then + echo > $tmpfile + if grep "ERROR SUMMARY" "$builddir"/"$testid"/valgrind/*.log | grep -v '0 errors' | cut -f1 -d: | xargs grep Command: $tmpfile | grep -qv "Command: /usr" ; then + echo valgrind detected errors + fi + fi for i in "$tmpdir"/core* ; do if test -s "$i"; then cp "$i" .