Files

57 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# run_all.sh — build all C/C++ utilities, then run every utility's smoke test.
# Usage: tests/run_all.sh
# Runs each utility's --help and --selftest (60 s timeout each), in parallel
# batches of up to min(8, nproc) jobs using bash & + wait. Exits 0 only if
# the build and every smoke test pass.
set -u
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT" || exit 1
JOBS="$(nproc 2>/dev/null || echo 4)"
[ "$JOBS" -gt 8 ] && JOBS=8
[ "$JOBS" -lt 1 ] && JOBS=1
echo "== build (make -j$JOBS) =="
if ! make -j"$JOBS" > /tmp/fileutils-build.log 2>&1; then
echo "BUILD FAILED — see /tmp/fileutils-build.log"
tail -20 /tmp/fileutils-build.log
exit 1
fi
echo "build OK"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
PASS=0; FAIL=0; FAILED=""
run_one() {
name="$1"
if timeout 60 "./bin/$name" --help >/dev/null 2>&1 && timeout 60 "./bin/$name" --selftest >"$TMP/$name.log" 2>&1; then
echo "PASS $name" > "$TMP/$name.result"
else
echo "FAIL $name" > "$TMP/$name.result"
fi
}
i=0
for f in bin/*; do
[ -x "$f" ] || continue
run_one "$(basename "$f")" &
i=$((i+1))
if [ "$i" -ge "$JOBS" ]; then wait; i=0; fi
done
wait
for r in "$TMP"/*.result; do
[ -e "$r" ] || continue
line="$(cat "$r")"
case "$line" in
PASS*) PASS=$((PASS+1));;
FAIL*) FAIL=$((FAIL+1)); FAILED="$FAILED ${line#FAIL }";;
esac
done
echo "== results: $PASS passed, $FAIL failed =="
if [ -n "$FAILED" ]; then
echo "failed:$FAILED"
for n in $FAILED; do echo "--- $n ---"; tail -15 "$TMP/$n.log" 2>/dev/null; done
exit 1
fi
echo "ALL PASS"
exit 0