From 4f4082e817b1c727516e368d60493aeb7d3cd099 Mon Sep 17 00:00:00 2001 From: Mano Date: Thu, 1 Dec 2022 01:15:23 +0000 Subject: [PATCH] Run memleak tests in parallel where possible --- tests/memleaks.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/memleaks.sh b/tests/memleaks.sh index 95fc3e7..08c0c11 100755 --- a/tests/memleaks.sh +++ b/tests/memleaks.sh @@ -35,11 +35,11 @@ function _test_thread_free_multi { #threads frees=$(extract_num "[0-9]* frees" "$heap_usage") if (( "$allocs" == 0 )); then err "Allocated 0 times. Something is wrong.." "$output" - exit 1 + return 1 fi if (( "$allocs" != "$frees" )); then err "Allocated $allocs times but freed only $frees" "$output" - exit 1 + return 1 fi #echo "Allocs: $allocs Frees: $frees" } @@ -49,9 +49,26 @@ function _test_thread_free_multi { #threads 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 + 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')" - _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 echo }