$(UNIT_CHECKS): check-%: $(BIN)/tests/%
$<
+JOBS := $(filter -j%,$(MAKEFLAGS))
+ifndef JOBS
+ JOBS := -j1
+endif
+
$(STRATEGY_CHECKS): check-%: $(BIN)/bfs $(TEST_UTILS)
- ./tests/tests.sh --bfs="$(BIN)/bfs -S $*" $(TEST_FLAGS)
+ ./tests/tests.sh $(JOBS) --bfs="$(BIN)/bfs -S $*" $(TEST_FLAGS)
# Custom test flags for distcheck
DISTCHECK_FLAGS := -s TEST_FLAGS="--sudo --verbose=skipped"
# Parse the command line
parse_args() {
+ JOBS=0
PATTERNS=()
SUDO=()
STOP=0
for arg; do
case "$arg" in
+ -j*)
+ JOBS="${arg#-j}"
+ ;;
--bfs=*)
BFS="${arg#*=}"
;;
esac
done
+ if ((JOBS == 0)); then
+ if command -v nproc &>/dev/null; then
+ JOBS=$(nproc)
+ else
+ JOBS=1
+ fi
+ fi
+
# Try to resolve the path to $BFS before we cd, while also supporting
# --bfs="./bin/bfs -S ids"
read -a BFS <<<"${BFS:-$BIN/bfs}"
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
TEST_FMT="."
fi
+ BG=0
+
# Turn off set -e (but turn it back on in run_test)
set +e
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}"