test_mem_leaks.sh 944 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env sh
  2. SCRIPT_PATH="$(dirname "$(readlink -f "$0")")"
  3. if test -z "${1}"; then
  4. UNIT_TEST="${SCRIPT_PATH}/check_mem_leaks"
  5. else
  6. UNIT_TEST="${1}"
  7. fi
  8. VALGRIND_LOG_FILE=${UNIT_TEST}.valgrind
  9. LEAK_MESSAGE="are definitely lost"
  10. # This test runs valgrind against the check_mem_leaks unit test
  11. # program, looking for memory leaks. If any are found, "exit 1"
  12. # is invoked, and one must look through the resulting valgrind log
  13. # file for details on the leak.
  14. rm -f ${VALGRIND_LOG_FILE}
  15. libtool --mode=execute valgrind --leak-check=full ${UNIT_TEST} 2>&1 | tee ${VALGRIND_LOG_FILE}
  16. NUM_LEAKS=$(grep "${LEAK_MESSAGE}" ${VALGRIND_LOG_FILE} | wc -l)
  17. if test ${NUM_LEAKS} -gt 0; then
  18. echo "ERROR: ${NUM_LEAKS} memory leaks were detected by valgrind."
  19. echo " Look through ${VALGRIND_LOG_FILE} for details,"
  20. echo " searching for \"${LEAK_MESSAGE}\"."
  21. exit 1
  22. else
  23. echo "No memory leaks found"
  24. exit 0
  25. fi