From c407e6599254746cbc1f6508127ab2616e9ff3aa Mon Sep 17 00:00:00 2001 From: Houtworm Date: Tue, 7 Mar 2023 07:26:11 +0100 Subject: [PATCH] sumstuff --- test.sh | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 203 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 45d7846..1f79500 100755 --- a/test.sh +++ b/test.sh @@ -1,12 +1,12 @@ # **************************************************************************** # # # # .--. _ # -# test.sh |o_o || | # +# test.sh :+: :+: :+: # # |:_/ || |_ _ ___ __ # # By: houtworm // \ \ __| | | \ \/ / # # (| | )|_| |_| |> < # # Created: 2023/02/20 12:46:17 by houtworm /'\_ _/`\__|\__,_/_/\_\ # -# Updated: 2023/03/07 05:33:23 by houtworm \___)=(___/ # +# Updated: 2023/03/07 07:19:30 by houtworm ### ########.fr # # # # **************************************************************************** # @@ -126,6 +126,35 @@ pushswap() fi } +pushswapvalgrind() +{ + CURFUNERR=0 + valgrind --leak-check=full ./push_swap $1 2> tmp/memorycheck > /dev/null + cat tmp/memorycheck | grep indirectly | grep "[123456789] bytes" > /dev/null + if [ $? -eq 0 ] + then + printf "\e[1;31mLeaks Valgrind $1\e[0;00m\n" + cat tmp/memorycheck + FAULTS=$(($FAULTS+1)) + CURFUNERR=1 + fi + if [ $CURFUNERR -eq 0 ] + then + cat tmp/memorycheck | grep definitely | grep "[123456789] bytes" > /dev/null + if [ $? -eq 0 ] + then + printf "\e[1;31mLeaks Valgrind $1\e[0;00m\n" + cat tmp/memorycheck + FAULTS=$(($FAULTS+1)) + CURFUNERR=1 + fi + fi + if [ $CURFUNERR -eq 0 ] + then + printf "\e[1;32mValgrind OK\e[0;00m\n" + fi +} + checker() { ./push_swap $2 | $CHECKER $2 > tmp/output 2>&1 @@ -150,6 +179,35 @@ onlychecker() fi } +onlycheckervalgrind() +{ + CURFUNERR=0 + valgrind --leak-check=full $CHECKER $1 2> tmp/memorycheck > /dev/null + cat tmp/memorycheck | grep indirectly | grep "[123456789] bytes" > /dev/null + if [ $? -eq 0 ] + then + printf "\e[1;31mLeaks Valgrind $1\e[0;00m\n" + cat tmp/memorycheck + FAULTS=$(($FAULTS+1)) + CURFUNERR=1 + fi + if [ $CURFUNERR -eq 0 ] + then + cat tmp/memorycheck | grep definitely | grep "[123456789] bytes" > /dev/null + if [ $? -eq 0 ] + then + printf "\e[1;31mLeaks Valgrind $1\e[0;00m\n" + cat tmp/memorycheck + FAULTS=$(($FAULTS+1)) + CURFUNERR=1 + fi + fi + if [ $CURFUNERR -eq 0 ] + then + printf "\e[1;32mValgrind OK\e[0;00m\n" + fi +} + checkersilent() { ./push_swap $2 | $CHECKER $2 > tmp/output 2>&1 @@ -261,6 +319,14 @@ COUNT4=0 SLEEP=1 FAULTS=0 CHECKF=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 mkdir -p tmp touch tmp/empty echo "Error" > tmp/error @@ -346,66 +412,110 @@ sleep $SLEEP printf "\e[1;36mTest 4 Running push_swap with non numeric value\e[0;00m\n" pushswap 1 "a" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind 1 "a" +fi sleep $SLEEP # Test 5 printf "\e[1;36mTest 5 Running push_swap with hidden non numeric value begin\e[0;00m\n" pushswap 1 "a1234" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "a1234" +fi sleep $SLEEP # Test 6 printf "\e[1;36mTest 6 Running push_swap with hidden non numeric value middle\e[0;00m\n" pushswap 1 "12/34" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "12/34" +fi sleep $SLEEP # Test 7 printf "\e[1;36mTest 7 Running push_swap with hidden non numeric value end\e[0;00m\n" pushswap 1 "1234-" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "1234-" +fi sleep $SLEEP # Test 8 printf "\e[1;36mTest 8 Running push_swap with duplicate number\e[0;00m\n" pushswap 1 "1 2 3 4 5 6 7 1" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "1 2 3 4 5 6 7 1" +fi sleep $SLEEP # Test 9 printf "\e[1;36mTest 9 Running push_swap with max int + 1\e[0;00m\n" pushswap 1 "1 2 3 4 5 6 7 8 9 2147483648" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "1 2 3 4 5 6 7 8 9 2147483648" +fi sleep $SLEEP # Test 10 printf "\e[1;36mTest 10 Running push_swap with min int - 1\e[0;00m\n" pushswap 1 "-2147483649 1 2 3 4 5 6 7 8 9" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "-2147483649 1 2 3 4 5 6 7 8 9" +fi sleep $SLEEP # Test 11 printf "\e[1;36mTest 11 Running push_swap without arguments\e[0;00m\n" pushswap 0 checkoutput tmp/empty +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind +fi sleep $SLEEP # Test 12 printf "\e[1;36mTest 12 Running push_swap with one number\e[0;00m\n" pushswap 0 "42" checkoutput tmp/empty +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "42" +fi sleep $SLEEP # Test 13 printf "\e[1;36mTest 13 Running push_swap with numbers in order\e[0;00m\n" pushswap 0 "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20" checkoutput tmp/empty +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20" +fi sleep $SLEEP # Test 14 printf "\e[1;36mTest 14 Running push_swap against checker with 2 1 0\e[0;00m\n" checker 0 "2 1 0" checkoutput tmp/ok +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "2 1 0" +fi count 2 3 3 3 3 "2 1 0" sleep $SLEEP @@ -413,6 +523,10 @@ sleep $SLEEP printf "\e[1;36mTest 15 Running push_swap against checker with 1 5 2 4 3\e[0;00m\n" checker 0 "1 5 2 4 3" checkoutput tmp/ok +if [ $VALGRIND -eq 1 ] +then + pushswapvalgrind "1 5 2 4 3" +fi count 7 8 9 10 12 "1 5 2 4 3" sleep $SLEEP @@ -475,48 +589,80 @@ sleep $SLEEP printf "\e[1;36mTest 21 Running checker with non numeric value\e[0;00m\n" onlychecker 1 "a" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + onlycheckervalgrind "a" +fi sleep $SLEEP # Test 22 printf "\e[1;36mTest 22 Running checker with hidden non numeric value begin\e[0;00m\n" onlychecker 1 "a1234" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + onlycheckervalgrind "a1234" +fi sleep $SLEEP # Test 23 printf "\e[1;36mTest 23 Running checker with hidden non numeric value middle\e[0;00m\n" onlychecker 1 "12/34" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + onlycheckervalgrind "12/34" +fi sleep $SLEEP # Test 24 printf "\e[1;36mTest 24 Running checker with hidden non numeric value end\e[0;00m\n" onlychecker 1 "1234-" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + onlycheckervalgrind "1324-" +fi sleep $SLEEP # Test 25 printf "\e[1;36mTest 25 Running checker with duplicate number\e[0;00m\n" onlychecker 1 "1 2 3 4 5 6 7 1" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + onlycheckervalgrind "1 2 3 4 5 6 7 1" +fi sleep $SLEEP # Test 26 printf "\e[1;36mTest 26 Running checker with max int + 1\e[0;00m\n" onlychecker 1 "1 2 3 4 5 6 7 8 9 2147483648" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + onlycheckervalgrind "1 2 3 4 5 6 7 8 9 2147483648" +fi sleep $SLEEP # Test 27 printf "\e[1;36mTest 27 Running checker with min int - 1\e[0;00m\n" onlychecker 1 "-2147483649 1 2 3 4 5 6 7 8 9" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + onlycheckervalgrind "-2147483649 1 2 3 4 5 6 7 8 9" +fi sleep $SLEEP # Test 28 printf "\e[1;36mTest 28 Running checker without arguments\e[0;00m\n" onlychecker 0 checkoutput tmp/empty +if [ $VALGRIND -eq 1 ] +then + onlycheckervalgrind +fi sleep $SLEEP # Test 29 @@ -524,6 +670,11 @@ printf "\e[1;36mTest 29 Running checker with no stdin\e[0;00m\n" printf "Please press CTRL+D (maybe twice)\n" onlychecker 0 "42" checkoutput tmp/ok +if [ $VALGRIND -eq 1 ] +then + printf "Please press CTRL+D (maybe twice)\n" + onlycheckervalgrind "42" +fi sleep $SLEEP # Test 30 @@ -531,6 +682,11 @@ printf "\e[1;36mTest 30 Running checker with all possible moves\e[0;00m\n" printf "Please type pb, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr, pa and hit CTRL+D (maybe twice)\n" onlychecker 0 "42 21 420 210" checkoutput tmp/ko +if [ $VALGRIND -eq 1 ] +then + printf "Please type pb, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr, pa and hit CTRL+D (maybe twice)\n" + onlycheckervalgrind "42" +fi sleep $SLEEP # Test 31 @@ -538,6 +694,11 @@ printf "\e[1;36mTest 31 Running checker with some impossible moves\e[0;00m\n" printf "Please type pa, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr and hit CTRL+D (maybe twice)\n" onlychecker 0 "42" checkoutput tmp/ok +if [ $VALGRIND -eq 1 ] +then + printf "Please type pa, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr and hit CTRL+D (maybe twice)\n" + onlycheckervalgrind "42" +fi sleep $SLEEP # Test 32 @@ -545,6 +706,11 @@ printf "\e[1;36mTest 32 Running checker invalid stdin\e[0;00m\n" printf "Please type br and press enter Do Not hit CTRL+D\n" onlychecker 1 "42" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + printf "Please type br and press enter Do Not hit CTRL+D\n" + onlycheckervalgrind "42" +fi sleep $SLEEP # Test 33 @@ -552,6 +718,11 @@ printf "\e[1;36mTest 33 Running checker invalid stdin space before\e[0;00m\n" printf "Please type ' sa' and press enter Do Not hit CTRL+D\n" onlychecker 1 "42" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + printf "Please type ' sa' and press enter Do Not hit CTRL+D\n" + onlycheckervalgrind "42" +fi sleep $SLEEP # Test 34 @@ -559,6 +730,11 @@ printf "\e[1;36mTest 34 Running checker invalid stdin space after\e[0;00m\n" printf "Please type 'sa ' and press enter Do Not hit CTRL+D\n" onlychecker 1 "42" checkoutput tmp/error +if [ $VALGRIND -eq 1 ] +then + printf "Please type 'sa ' and press enter Do Not hit CTRL+D\n" + onlycheckervalgrind "42" +fi sleep $SLEEP # Test 35 @@ -566,6 +742,11 @@ printf "\e[1;36mTest 35 Running checker with wrong stdin 0 9 1 8 2 7 3 6 4 5\e[0 printf "Please type sa, pb, rrr and hit CTRL+D (maybe twice)\n" onlychecker 0 "0 9 1 8 2 7 3 6 4 5" checkoutput tmp/ko +if [ $VALGRIND -eq 1 ] +then + printf "Please type sa, pb, rrr and hit CTRL+D (maybe twice)\n" + onlycheckervalgrind "0 9 1 8 2 7 3 6 4 5" +fi sleep $SLEEP # Test 36 @@ -573,6 +754,11 @@ printf "\e[1;36mTest 36 Running checker with wrong stdin 32 -65 12 83 55 23 54 5 printf "Please type sa, ra, rra and hit CTRL+D (maybe twice)\n" onlychecker 0 "32 -65 12 83 55 23 54 53 16" checkoutput tmp/ko +if [ $VALGRIND -eq 1 ] +then + printf "Please type sa, ra, rra and hit CTRL+D (maybe twice)\n" + onlycheckervalgrind "32 -65 12 83 55 23 54 53 16" +fi sleep $SLEEP # Test 37 @@ -580,6 +766,11 @@ printf "\e[1;36mTest 37 Running checker with numbers 1 - 20 in order\e[0;00m\n" printf "Please hit CTRL+D (maybe twice)\n" onlychecker 0 "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20" checkoutput tmp/ok +if [ $VALGRIND -eq 1 ] +then + printf "Please hit CTRL+D (maybe twice)\n" + onlycheckervalgrind "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20" +fi sleep $SLEEP # Test 38 @@ -587,6 +778,11 @@ printf "\e[1;36mTest 38 Running checker with valid input 0 9 1 8 2\e[0;00m\n" printf "Please type pb, ra, pb, ra, sa, ra, pa, pa and hit CTRL+D (maybe twice)\n" onlychecker 0 "0 9 1 8 2" checkoutput tmp/ok +if [ $VALGRIND -eq 1 ] +then + printf "Please type pb, ra, pb, ra, sa, ra, pa, pa and hit CTRL+D (maybe twice)\n" + onlycheckervalgrind "0 9 1 8 2" +fi sleep $SLEEP # Test 39 @@ -594,6 +790,11 @@ printf "\e[1;36mTest 39 Running checker with valid input a little harder\e[0;00m printf "Please type rra, rra and hit CTRL+D (maybe twice)\n" onlychecker 0 "12345 23456 34567 45678 56789 67890 -98765 -87654" checkoutput tmp/ok +if [ $VALGRIND -eq 1 ] +then + printf "Please type rra, rra and hit CTRL+D (maybe twice)\n" + onlycheckervalgrind "12345 23456 34567 45678 56789 67890 -98765 -87654" +fi sleep $SLEEP # Test 40