Run memleak tests in parallel where possible

This commit is contained in:
Mano 2022-12-01 01:15:23 +00:00
parent 230dd7e643
commit 4f4082e817

View File

@ -35,11 +35,11 @@ function _test_thread_free_multi { #threads
frees=$(extract_num "[0-9]* frees" "$heap_usage") frees=$(extract_num "[0-9]* frees" "$heap_usage")
if (( "$allocs" == 0 )); then if (( "$allocs" == 0 )); then
err "Allocated 0 times. Something is wrong.." "$output" err "Allocated 0 times. Something is wrong.." "$output"
exit 1 return 1
fi fi
if (( "$allocs" != "$frees" )); then if (( "$allocs" != "$frees" )); then
err "Allocated $allocs times but freed only $frees" "$output" err "Allocated $allocs times but freed only $frees" "$output"
exit 1 return 1
fi fi
#echo "Allocs: $allocs Frees: $frees" #echo "Allocs: $allocs Frees: $frees"
} }
@ -49,9 +49,26 @@ function _test_thread_free_multi { #threads
function test_thread_free_multi { #threads #times function test_thread_free_multi { #threads #times
echo "Testing multiple threads creation and destruction in pool(threads=$1 times=$2)" echo "Testing multiple threads creation and destruction in pool(threads=$1 times=$2)"
compile src/no_work.c compile src/no_work.c
for ((i = 1; i <= $2; i++)); do pids=()
# Run tests in p
for (( i = 1; i <= "$2"; i++ )); do
# Run test in background
python -c "import sys; sys.stdout.write('$i/$2\r')" python -c "import sys; sys.stdout.write('$i/$2\r')"
_test_thread_free_multi $1 _test_thread_free_multi "$1" &
pids+=($!)
# Wait for 10 background jobs to finish
if (( "$i" % 10 == 0 )); then
for pid in ${pids[@]}; do
wait $pid
if (( $? != 0 )); then
err "Test failed" "Test failed"
fi
done
pids=()
fi
done done
echo echo
} }