#!/usr/bin/env bash # Boots the headless server, runs a full-size match for 1,000 ticks, prints the timing # statistics, and checks that the server: # - exits 0 and logs start, stats and stop lines that all carry the seed, # - produces the same state hash when run again with the same seed, # - exits non-zero when a script error happens (a deliberate --fault), # - exits non-zero on a bad command line, # - listens on a UDP port when asked to. # # tools/smoke.sh unthrottled, so it finishes in seconds # SMOKE_REALTIME=1 tools/smoke.sh at the real 30 Hz tick rate (about 34 seconds) set -uo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." seed="${SMOKE_SEED:-20261109}" ticks="${SMOKE_TICKS:-1000}" pace="--unthrottled" [[ "${SMOKE_REALTIME:-0}" == "1" ]] && pace="" status=0 code=0 # run : runs the server, sets $output (JSON lines only) and $code. run() { local raw raw="$(timeout --signal=KILL 300 tools/godot.sh -- --server "$@" 2>&1)" code=$? output="$(grep '^{' <<<"$raw")" stderr_tail="$(grep -v '^{' <<<"$raw" | tail -n 15)" } # field : prints a value from the first log line of that event. field() { grep -m1 "\"event\":\"$1\"" <<<"$output" | sed -E "s/.*\"$2\":(\"[^\"]*\"|[^,}]*).*/\1/" | tr -d '"' } fail() { echo "smoke FAIL: $*" status=1 } run --seed="$seed" --bots=24 --ticks="$ticks" --log-every=250 $pace if [[ "$code" -ne 0 ]]; then fail "server exited $code" echo "$output" echo "$stderr_tail" fi for event in start stats stop; do grep -q "\"event\":\"$event\"" <<<"$output" || fail "no '$event' log line" done lines="$(wc -l <<<"$output")" seeded="$(grep -c "\"seed\":$seed[,}]" <<<"$output")" [[ "$lines" -eq "$seeded" ]] || fail "only $seeded of $lines log lines carry the seed" [[ "$(field stats ticks)" == "$ticks" ]] || fail "ran $(field stats ticks) ticks, expected $ticks" hash="$(field stats state_hash)" echo "smoke: $ticks ticks, 24 bots, seed $seed" echo "smoke: tick us min $(field stats min_us) mean $(field stats mean_us) p50 $(field stats p50_us)" \ "p95 $(field stats p95_us) p99 $(field stats p99_us) max $(field stats max_us)," \ "$(field stats over_budget) over the $(field stats budget_us) us budget" echo "smoke: state hash $hash" run --seed="$seed" --bots=24 --ticks="$ticks" --unthrottled [[ "$code" -eq 0 && "$(field stats state_hash)" == "$hash" ]] \ || fail "a second run with the same seed gave a different state hash" run --seed="$seed" --bots=2 --ticks=50 --unthrottled --fault=script-error [[ "$code" -eq 1 ]] || fail "a script error exited $code, expected 1" [[ "$(field stop errors)" -ge 1 ]] || fail "a script error wasn't counted in the stop line" run --bots=99 --nonsense [[ "$code" -eq 2 ]] || fail "a bad command line exited $code, expected 2" grep -q '"event":"config_error"' <<<"$output" || fail "a bad command line logged no config_error" # A listening server opens its port, waits in the lobby with nobody there, and stops cleanly. port=$((20000 + RANDOM % 20000)) run --listen --port="$port" --seed="$seed" --bots=4 --ticks=120 --unthrottled [[ "$code" -eq 0 ]] || fail "a listening server exited $code" [[ "$(field start listening)" == "true" ]] || fail "a listening server didn't say it was listening" [[ "$(field start match_phase)" == "lobby" ]] || fail "a listening server didn't start in the lobby" if [[ "$status" -eq 0 ]]; then echo "smoke: ok (clean run, reproducible hash, script error exits 1, bad config exits 2, listens)" fi exit "$status"