diff --git a/tests/memleaks.sh b/tests/memleaks.sh index 397d500..95fc3e7 100755 --- a/tests/memleaks.sh +++ b/tests/memleaks.sh @@ -28,25 +28,30 @@ function test_thread_free { #threads } +function _test_thread_free_multi { #threads + output=$(valgrind --leak-check=full --track-origins=yes ./test "$1" 2>&1 > /dev/null) + heap_usage=$(echo "$output" | grep "total heap usage") + allocs=$(extract_num "[0-9]* allocs" "$heap_usage") + frees=$(extract_num "[0-9]* frees" "$heap_usage") + if (( "$allocs" == 0 )); then + err "Allocated 0 times. Something is wrong.." "$output" + exit 1 + fi + if (( "$allocs" != "$frees" )); then + err "Allocated $allocs times but freed only $frees" "$output" + exit 1 + fi + #echo "Allocs: $allocs Frees: $frees" +} + + # This is the same with test_many_thread_allocs but multiplied function test_thread_free_multi { #threads #times echo "Testing multiple threads creation and destruction in pool(threads=$1 times=$2)" compile src/no_work.c for ((i = 1; i <= $2; i++)); do python -c "import sys; sys.stdout.write('$i/$2\r')" - output=$(valgrind --leak-check=full --track-origins=yes ./test "$1" 2>&1 > /dev/null) - heap_usage=$(echo "$output" | grep "total heap usage") - allocs=$(extract_num "[0-9]* allocs" "$heap_usage") - frees=$(extract_num "[0-9]* frees" "$heap_usage") - if (( "$allocs" == 0 )); then - err "Allocated 0 times. Something is wrong.." "$output" - exit 1 - fi - if (( "$allocs" != "$frees" )); then - err "Allocated $allocs times but freed only $frees" "$output" - exit 1 - fi - #echo "Allocs: $allocs Frees: $frees" + _test_thread_free_multi $1 done echo }