diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-10-23 10:12:25 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-10-23 10:12:25 -0400 |
commit | 4c7a49a83e082a7bfff85a9305882f0912655123 (patch) | |
tree | 140355e5e30ec2d0414c977441a55a2f5b7100fa /tests/run.sh | |
parent | a2af2746c4686201e2e0796fbdfa115d08727b86 (diff) | |
download | bfs-4c7a49a83e082a7bfff85a9305882f0912655123.tar.xz |
tests: Run test cases in parallel
Diffstat (limited to 'tests/run.sh')
-rw-r--r-- | tests/run.sh | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/tests/run.sh b/tests/run.sh index 28801f4..b46fde6 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -42,6 +42,42 @@ run_test() ( source "$@" ) +# Run a test in the background +bg_test() { + if ((VERBOSE_ERRORS)); then + run_test "$1" + else + run_test "$1" 2>"$TMP/TEST.err" + fi + ret=$? + + if ((ret != 0 && ret != EX_SKIP)); then + ((VERBOSE_ERRORS)) || cat "$TMP/$TEST.err" >&2 + color printf "${BOL}${RED}%s failed!${RST}\n" "$TEST" + fi + + return $ret +} + +# Reap a background job +reap() { + wait -n + ret=$? + ((BG--)) + + case $ret in + 0) + ((++passed)) + ;; + $EX_SKIP) + ((++skipped)) + ;; + *) + ((++failed)) + ;; + esac +} + # Run all the tests run_tests() { if ((VERBOSE_TESTS)); then @@ -70,6 +106,8 @@ run_tests() { TEST_FMT="." fi + BG=0 + # Turn off set -e (but turn it back on in run_test) set +e @@ -79,23 +117,16 @@ run_tests() { mkdir -p "$TMP/$TEST" OUT="$TMP/$TEST.out" - if ((VERBOSE_ERRORS)); then - run_test "$TESTS/$TEST.sh" - else - run_test "$TESTS/$TEST.sh" 2>"$TMP/$TEST.err" + if ((BG >= JOBS)); then + reap fi - status=$? + ((++BG)) - if ((status == 0)); then - ((++passed)) - elif ((status == EX_SKIP)); then - ((++skipped)) - else - ((++failed)) - ((VERBOSE_ERRORS)) || cat "$TMP/$TEST.err" >&2 - color printf "${BOL}${RED}%s failed!${RST}\n" "$TEST" - ((STOP)) && break - fi + bg_test "$TESTS/$TEST.sh" & + done + + while ((BG > 0)); do + reap done printf "${BOL}" |