From: brarcher Date: Wed, 18 Dec 2013 21:37:11 +0000 (+0000) Subject: test_mem_leak.sh: add convenience script for running valgrind X-Git-Tag: 0.10.0~314 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=225afe50cc02a42cd281a90a01fb504804a260c1;p=check test_mem_leak.sh: add convenience script for running valgrind 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 --- diff --git a/tests/test_mem_leaks.sh b/tests/test_mem_leaks.sh new file mode 100755 index 0000000..081f744 --- /dev/null +++ b/tests/test_mem_leaks.sh @@ -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