From 5da295673c530a23e5f1bcaa25111a74cba271f9 Mon Sep 17 00:00:00 2001 From: djonker Date: Mon, 6 Mar 2023 09:08:01 +0100 Subject: [PATCH] valgrind --- test.sh | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 2df349a..d0f1f68 100755 --- a/test.sh +++ b/test.sh @@ -6,7 +6,7 @@ # By: houtworm // \ \ __| | | \ \/ / # # (| | )|_| |_| |> < # # Created: 2023/02/20 12:46:46 by houtworm /'\_ _/`\__|\__,_/_/\_\ # -# Updated: 2023/02/25 03:51:43 by houtworm \___)=(___/ # +# Updated: 2023/03/06 09:04:17 by houtworm \___)=(___/ # # # # **************************************************************************** # @@ -17,6 +17,14 @@ PNAME=get_next_line.a SLEEP=1 FAULTS=0 +VALGRIND=0 +which valgrind > /dev/null +if [ $? -eq 0 ] +then + VALGRIND=1 +else + printf "\n\e[1;31mInstall Valgrind for extra Memory Checking\e[0;00m\n" +fi HEADLOC=$(find ./ -name '*line.h' | grep -v tests) mkdir -p tests/tmp cp $HEADLOC tests/tmp/get_next_line.h @@ -60,7 +68,7 @@ getnextline() cat tests/tmp/memorycheck | grep "leaked" > /dev/null if [ $? -eq 1 ] then - printf "\e[1;32mLeaks OK\e[0;00m\n" + printf "\e[1;32mNo Leaks Fsanitize\e[0;00m\n" else printf "\n\e[1;31mKO found Leaks \e[0;00m\n" cat tests/tmp/memorycheck @@ -71,6 +79,29 @@ getnextline() cat tests/tmp/memorycheck FAULTS=$(($FAULTS+1)) fi + if [ $VALGRIND -eq 1 ] + then + gcc -o tests/tmp/binary ${SRCPATH}$2 get_next_line.a 2> /dev/null + valgrind --leak-check=full ./tests/tmp/binary 2> tests/tmp/memorycheck > /dev/null + cat tests/tmp/memorycheck | grep indirectly | grep "[123456789] bytes" > /dev/null + if [ $? -eq 0 ] + then + printf "\n\e[1;31mLeaks Valgrind $1 $2\e[0;00m\n" + cat tests/tmp/memorycheck + FAULTS=$(($FAULTS+1)) + CURFUNERR=1 + else + printf "\e[1;32mNo Leaks Valgrind\e[0;00m\n" + fi + cat tests/tmp/memorycheck | grep definitely | grep "[123456789] bytes" > /dev/null + if [ $? -eq 0 ] + then + printf "\n\e[1;31mLeaks Valgrind $1 $2\e[0;00m\n" + cat tests/tmp/memorycheck + FAULTS=$(($FAULTS+1)) + CURFUNERR=1 + fi + fi } checkfile()