]> granicus.if.org Git - check/commitdiff
test_mem_leak.sh: add convenience script for running valgrind
authorbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Wed, 18 Dec 2013 21:37:11 +0000 (21:37 +0000)
committerbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Wed, 18 Dec 2013 21:37:11 +0000 (21:37 +0000)
This script will run valgrind against check_mem_leaks, and
determine if there are any memory leaks.

This is not run as part of "make check", as valgrind really only works
on GNU/Linux. (It is available on OSX, but does not really work).

We will need to run this ourselves (or from our continuous integration
server) to periodically check for leaks.

git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@902 64e312b2-a51f-0410-8e61-82d0ca0eb02a

tests/test_mem_leaks.sh [new file with mode: 0755]

diff --git a/tests/test_mem_leaks.sh b/tests/test_mem_leaks.sh
new file mode 100755 (executable)
index 0000000..081f744
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+UNIT_TEST=./check_mem_leaks
+VALGRIND_LOG_FILE=${UNIT_TEST}.valgrind
+LEAK_MESSAGE="are definitely lost"
+
+# This test runs valgrind against the check_mem_leaks unit test
+# program, looking for memory leaks. If any are found, "exit 1"
+# is invoked, and one must look through the resulting valgrind log
+# file for details on the leak.
+
+rm -f ${VALGRIND_LOG_FILE}
+valgrind --leak-check=full ${UNIT_TEST} 2>&1 | tee ${VALGRIND_LOG_FILE}
+
+NUM_LEAKS=$(grep "${LEAK_MESSAGE}" ${VALGRIND_LOG_FILE} | wc -l)
+
+if test ${NUM_LEAKS} -gt 0; then
+    echo "ERROR: ${NUM_LEAKS} memory leaks were detected by valgrind."
+    echo "       Look through ${VALGRIND_LOG_FILE} for details,"
+    echo "       searching for \"${LEAK_MESSAGE}\"."
+    exit 1
+else
+    echo "No memory leaks found"
+    exit 0
+fi