2026-11-10 18:03:10 -06:00
|
|
|
#!/usr/bin/env bash
|
2026-11-25 15:36:55 -06:00
|
|
|
# Runs the headless suites in a few parallel Godot processes, inside a fixed time budget.
|
|
|
|
|
#
|
|
|
|
|
# The budget is a hard limit on the whole run. At the deadline, running suites
|
|
|
|
|
# are stopped and the rest don't start; those are listed as NOT RUN. Only the
|
|
|
|
|
# user changes BUDGET_SECS. Suites run longest first (by their last time), which
|
|
|
|
|
# fills the workers best; one that was never timed runs first.
|
|
|
|
|
#
|
|
|
|
|
# A suite fails on a failed check, a SCRIPT ERROR or a Godot crash.
|
|
|
|
|
#
|
2026-11-10 18:03:10 -06:00
|
|
|
# Usage: tools/run_tests.sh [name-filter] e.g. tools/run_tests.sh inspector
|
2026-11-25 15:36:55 -06:00
|
|
|
# Exit codes: 0 all passed, 1 a suite failed, 2 over budget, nothing failed.
|
2026-11-10 18:20:46 -06:00
|
|
|
# Failing suites print their first 8 error lines; passing output is discarded.
|
2026-11-10 18:03:10 -06:00
|
|
|
set -u
|
2026-11-25 15:36:55 -06:00
|
|
|
readonly BUDGET_SECS=15
|
|
|
|
|
cd "$(dirname "$0")/.." || exit 1
|
2026-11-10 18:03:10 -06:00
|
|
|
GODOT="${GODOT:-$HOME/apps/Godot_v4.7.2-stable_linux.x86_64}"
|
2026-11-25 15:36:55 -06:00
|
|
|
TIMES=.godot/test_times # git-ignored: "<milliseconds> <suite>"
|
|
|
|
|
CLASSES=.godot/global_script_class_cache.cfg
|
|
|
|
|
start_ms=$(date +%s%3N)
|
|
|
|
|
now_ms() { echo $(( $(date +%s%3N) - start_ms )); }
|
|
|
|
|
# 1 s is kept back for stopping suites and printing the report.
|
|
|
|
|
left_ms() { echo $(( BUDGET_SECS * 1000 - 1000 - $(now_ms) )); }
|
|
|
|
|
# Runs a command at low priority; it is killed at the deadline.
|
|
|
|
|
in_budget() {
|
|
|
|
|
local left; left=$(left_ms)
|
|
|
|
|
(( left < 100 )) && return 124
|
|
|
|
|
nice -n 10 timeout -s KILL "$(( left / 1000 )).$(printf %03d $(( left % 1000 )))" "$@"
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-10 18:03:10 -06:00
|
|
|
OUT="$(mktemp -d)"
|
|
|
|
|
trap 'rm -rf "$OUT"' EXIT
|
2026-11-25 15:36:55 -06:00
|
|
|
|
|
|
|
|
# Register class_name scripts, only when a script was added or changed its list.
|
|
|
|
|
# Compares names, not dates, so ordinary edits don't cost an import.
|
|
|
|
|
declared="$(grep -rhoE --include='*.gd' --exclude-dir=.godot --exclude-dir=.claude '^class_name +[A-Za-z0-9_]+' . | awk '{print $2}' | sort)"
|
|
|
|
|
known="$(grep -oE '"class": &"[^"]+"' "$CLASSES" 2>/dev/null | cut -d'"' -f4 | sort)"
|
|
|
|
|
if [[ "$declared" != "$known" ]]; then
|
|
|
|
|
in_budget "$GODOT" --headless --path . --import >/dev/null 2>&1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
shopt -s nullglob
|
|
|
|
|
declare -A last_ms
|
|
|
|
|
while read -r ms n; do last_ms[$n]=$ms; done < <(cat "$TIMES" 2>/dev/null)
|
|
|
|
|
mapfile -t suites < <(for t in tests/test_*"${1:-}"*.gd; do
|
|
|
|
|
n="$(basename "$t" .gd)"; echo "${last_ms[$n]:-99999} $n"
|
|
|
|
|
done | sort -rn | cut -d' ' -f2)
|
|
|
|
|
(( ${#suites[@]} )) || { echo "No suite matches '${1:-}'"; exit 1; }
|
|
|
|
|
|
|
|
|
|
# A few Godot workers share the list (tests/run_suites.gd). --fixed-fps makes
|
|
|
|
|
# timers and animations use simulated time, not real waiting.
|
|
|
|
|
mkdir "$OUT/claims"
|
|
|
|
|
SUITES="$(IFS=,; echo "${suites[*]}")"
|
|
|
|
|
export SUITES CLAIMS="$OUT/claims"
|
|
|
|
|
jobs_wanted=${JOBS:-6}
|
|
|
|
|
(( jobs_wanted > ${#suites[@]} )) && jobs_wanted=${#suites[@]}
|
|
|
|
|
for (( w = 0; w < jobs_wanted; w++ )); do
|
|
|
|
|
in_budget "$GODOT" --headless --fixed-fps 60 --path . -s res://tests/run_suites.gd -- --sample >"$OUT/worker$w" 2>&1 &
|
2026-11-10 18:03:10 -06:00
|
|
|
done
|
|
|
|
|
wait
|
2026-11-25 15:36:55 -06:00
|
|
|
# Cut the workers' output into one log per suite; "DONE" gives its time.
|
|
|
|
|
awk -v out="$OUT" '
|
|
|
|
|
/^SUITE test_/ { suite = $2; log_file = out "/" suite ".log"; printf "" >log_file; next }
|
|
|
|
|
/^DONE test_/ { print $3 >(out "/" $2 ".ms"); print $4 >(out "/" $2 ".failures"); suite = ""; next }
|
|
|
|
|
suite != "" { print >log_file }
|
|
|
|
|
' "$OUT"/worker*
|
|
|
|
|
|
2026-11-10 18:03:10 -06:00
|
|
|
fail=0
|
2026-11-25 15:36:55 -06:00
|
|
|
not_run=()
|
|
|
|
|
stopped=()
|
2026-11-10 19:17:27 -06:00
|
|
|
declare -A first_err
|
2026-11-25 15:36:55 -06:00
|
|
|
for n in "${suites[@]}"; do
|
2026-11-10 18:03:10 -06:00
|
|
|
log="$OUT/$n.log"
|
2026-11-25 15:36:55 -06:00
|
|
|
crashed=0
|
|
|
|
|
if [[ -e "$OUT/$n.ms" ]]; then
|
|
|
|
|
last_ms[$n]=$(<"$OUT/$n.ms")
|
|
|
|
|
if [[ $(<"$OUT/$n.failures") == 0 ]] && ! grep -q "SCRIPT ERROR" "$log"; then
|
|
|
|
|
echo "ok $n"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
elif [[ -e "$log" ]] && grep -q "handle_crash" "$log"; then
|
|
|
|
|
crashed=1
|
|
|
|
|
else
|
|
|
|
|
not_run+=("$n")
|
|
|
|
|
# Started but stopped at the deadline: it may be what ate the budget.
|
|
|
|
|
[[ -e "$log" ]] && stopped+=("$n")
|
2026-11-10 19:17:27 -06:00
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
fail=1
|
|
|
|
|
e="$(grep -m1 -E "SCRIPT ERROR|^ *FAIL [^:]" "$log")"
|
|
|
|
|
# A shared compile error fails many suites the same way: report it once.
|
2026-11-25 15:36:55 -06:00
|
|
|
if (( ! crashed )) && [[ "$e" == *"SCRIPT ERROR"* ]]; then
|
2026-11-10 19:17:27 -06:00
|
|
|
first_err["$e"]+="$n "
|
2026-11-10 18:03:10 -06:00
|
|
|
else
|
|
|
|
|
echo "FAIL $n"
|
2026-11-25 15:36:55 -06:00
|
|
|
(( crashed )) && echo " Godot crashed"
|
|
|
|
|
grep -E "FAIL|SCRIPT ERROR|ERROR|^ +\[[0-9]+\] .*res://" "$log" | head -8
|
2026-11-10 18:03:10 -06:00
|
|
|
fi
|
|
|
|
|
done
|
2026-11-10 19:17:27 -06:00
|
|
|
for e in "${!first_err[@]}"; do
|
|
|
|
|
echo "FAIL ${first_err[$e]}"
|
|
|
|
|
echo " $e"
|
|
|
|
|
done
|
2026-11-25 15:36:55 -06:00
|
|
|
for n in "${!last_ms[@]}"; do
|
|
|
|
|
[[ -e "tests/$n.gd" ]] && echo "${last_ms[$n]} $n"
|
|
|
|
|
done | sort -n >"$TIMES"
|
|
|
|
|
|
|
|
|
|
took="$(awk -v ms="$(now_ms)" 'BEGIN { printf "%.1f", ms / 1000 }')s of ${BUDGET_SECS}s"
|
|
|
|
|
if (( ${#not_run[@]} )); then
|
|
|
|
|
echo "NOT RUN (${#not_run[@]}): ${not_run[*]}"
|
|
|
|
|
(( ${#stopped[@]} )) && echo "Stopped while running: ${stopped[*]}"
|
|
|
|
|
echo "Slowest: $(sort -rn "$TIMES" | head -5 | awk '{ printf "%s %.1fs ", $2, $1 / 1000 }')"
|
|
|
|
|
fi
|
|
|
|
|
if (( fail )); then echo "SOME SUITES FAILED ($took)"; exit 1; fi
|
|
|
|
|
if (( ${#not_run[@]} )); then
|
|
|
|
|
echo "OVER BUDGET: $(( ${#suites[@]} - ${#not_run[@]} )) of ${#suites[@]} suites passed ($took)"; exit 2
|
|
|
|
|
fi
|
|
|
|
|
echo "ALL ${#suites[@]} SUITES PASSED ($took)"
|