| index 2906f7e11..32c40df28 100755 |
| --- a/.amadan/test-gate.sh |
| +++ b/.amadan/test-gate.sh |
| @@ -31,10 +31,36 @@ |
| # Shards are separate processes, so tests that leaned on running in the |
| # same process as some other test (package state one test leaves for the |
| # next) can surface here. That is a bug in the test, not in the split. |
| +# |
| +# THE TIMEOUT. Every go test here runs with -timeout 15m, half CI's |
| +# 30-minute step limit. A hung test then fails its own job with Go's |
| +# goroutine dump (go test kills the binary a minute after that if it |
| +# still will not stop) and the gate prints it. At -timeout 30m the step |
| +# limit fired first and the log was empty (main 6c2c167a, 2026-11-10). |
| +# |
| +# WEIGHTS. GATE_WEIGHTS=1 runs the split packages' shards with -json |
| +# and, instead of their logs, prints a fresh test-weights.tsv measured on |
| +# whatever machine ran it. Set it in .amadan/ci.d/10-gate for one push to |
| +# measure on CI itself, copy the printed file in, and unset it again. The |
| +# shards' own logs are not printed in that mode, so it is a measurement |
| +# run, not a gate. |
| +# |
| +# The last thing the gate prints is how much CPU its jobs used against |
| +# how long it took, so a slow run says whether it was short of cores. |
| set -eu |
| |
| -: "${TEST_SPLIT=./internal/console=8 ./internal/host=4 .=5}" |
| +# Heaviest first: discovery compiles each package's tests in turn, so the |
| +# packages that dominate the wall clock get their shards started earliest. |
| +: "${TEST_SPLIT=./internal/console=8 ./internal/edge=4 ./internal/activator=4 ./internal/host=4 .=5 ./internal/grouproll=2}" |
| weights=$(pwd)/.amadan/test-weights.tsv |
| +gate_t0=$(date +%s) |
| +# Busy and total jiffies for the whole machine, from /proc/stat's cpu |
| +# line (user nice system idle iowait irq softirq steal), or nothing where |
| +# there is no /proc/stat (a maintainer's Mac). |
| +machine_cpu() { |
| + awk '$1 == "cpu" { print $2 + $3 + $4 + $7 + $8 + $9, $2 + $3 + $4 + $5 + $6 + $7 + $8 + $9; exit }' /proc/stat 2>/dev/null || true |
| +} |
| +machine_t0=$(machine_cpu) |
| |
| # A shard count that is not a whole number of at least 1 would take a |
| # package out of the ordinary run and then launch none of its shards: a |
| @@ -117,6 +143,7 @@ start() { |
| ( |
| set +e |
| t0=$(date +%s) |
| + echo $((t0 - gate_t0)) >"$out/$start_name.at" |
| "$@" >"$out/$start_name.log" 2>&1 |
| echo $? >"$out/$start_name.rc" |
| echo $(($(date +%s) - t0)) >"$out/$start_name.secs" |
| @@ -166,13 +193,19 @@ done |
| # With no packages left, go test would test the current directory instead. |
| if [ -n "$rest" ]; then |
| # shellcheck disable=SC2086 # one word per package, on purpose |
| - start rest go test -count=1 -timeout 30m $rest |
| + start rest go test -count=1 -timeout 15m $rest |
| fi |
| # The fleet-run cutover witnesses (rootfs apps Plan 6 Task 16): the real CLI |
| # against a fleet run queued across a lifetimes cutover. They and the console |
| # controls they need are built only with this tag, which no other job and no |
| # production build sets. |
| -start cutover-witness go test -count=1 -timeout 30m -tags carlos_cutover_witness -run '^TestQueuedFleetRunAtACutoverExpires' . |
| +start cutover-witness go test -count=1 -timeout 15m -tags carlos_cutover_witness -run '^TestQueuedFleetRunAtACutoverExpires' . |
| + |
| +# The split shards' -json, in weights mode only (see WEIGHTS above). |
| +shard_json="" |
| +if [ "${GATE_WEIGHTS:-}" = 1 ]; then |
| + shard_json=-json |
| +fi |
| |
| for spec in $TEST_SPLIT; do |
| dir=${spec%=*} |
| @@ -222,7 +255,7 @@ for spec in $TEST_SPLIT; do |
| while [ "$i" -lt "$shards" ]; do |
| pattern=$(awk -v i="$i" -F '\t' '$1 == i { printf "%s%s", sep, $2; sep = "|" }' "$out/deal-$tag") |
| if [ -n "$pattern" ]; then |
| - start "$tag@$i" go test -count=1 -timeout 30m -run "^($pattern)\$" "$dir" |
| + start "$tag@$i" go test $shard_json -count=1 -timeout 15m -run "^($pattern)\$" "$dir" |
| launched=$((launched + $(awk -v i="$i" -F '\t' '$1 == i' "$out/deal-$tag" | wc -l))) |
| fi |
| i=$((i + 1)) |
| @@ -239,8 +272,11 @@ failed="" |
| for name in $names; do |
| # A job with no status file was killed before it could write one. |
| rc=$(cat "$out/$name.rc" 2>/dev/null || echo 1) |
| - echo "=== $name ($(cat "$out/$name.secs" 2>/dev/null || echo '?') s)" |
| - cat "$out/$name.log" 2>/dev/null || true |
| + echo "=== $name ($(cat "$out/$name.secs" 2>/dev/null || echo '?') s, from +$(cat "$out/$name.at" 2>/dev/null || echo '?') s)" |
| + case $shard_json:$name in |
| + -json:*@*) grep '"Action":"fail"' "$out/$name.log" 2>/dev/null | head -20 || true ;; |
| + *) cat "$out/$name.log" 2>/dev/null || true ;; |
| + esac |
| case $name in |
| *@*) |
| if grep -q 'no tests to run' "$out/$name.log"; then |
| @@ -252,6 +288,37 @@ for name in $names; do |
| [ "$rc" -eq 0 ] || failed="$failed $name" |
| done |
| |
| +# CPU used against wall clock. The shell's `times` covers every job it |
| +# has waited for, and each job waited for its go test and the test |
| +# binaries under it, so this is the whole gate's CPU. Busy cores well |
| +# under the machine's count mean the run was waiting, not computing; the |
| +# machine's own figure includes whatever else was running on it. |
| +wall=$(($(date +%s) - gate_t0)) |
| +cores=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo '?') |
| +# `times` writes to a file, not a pipe: in a pipeline it would run in a |
| +# subshell, which has waited for nothing. |
| +times >"$out/times" |
| +awk -v wall="$wall" -v cores="$cores" -v m0="$machine_t0" -v m1="$(machine_cpu)" ' |
| + NR == 2 { |
| + gsub(/[ms]/, " ") |
| + cpu = $1 * 60 + $2 + $3 * 60 + $4 |
| + line = sprintf("=== cpu: the gate used %d cpu-seconds in %d s, about %.1f of %s cores", cpu, wall, (wall > 0 ? cpu / wall : 0), cores) |
| + split(m0, a, " "); split(m1, b, " ") |
| + if (b[2] > a[2]) line = line sprintf("; the machine as a whole was %d%% busy", 100 * (b[1] - a[1]) / (b[2] - a[2])) |
| + print line |
| + } |
| +' "$out/times" |
| + |
| +if [ -n "$shard_json" ]; then |
| + # shellcheck disable=SC2046 # one file per split shard, on purpose |
| + .amadan/test-weights.sh $(for name in $names; do |
| + case $name in *@*) echo "$out/$name.log" ;; esac |
| + done) |
| + echo "=== test-weights.tsv measured on this run" |
| + cat .amadan/test-weights.tsv |
| + echo "=== end test-weights.tsv" |
| +fi |
| + |
| if [ -n "$failed" ]; then |
| # The logs above can run to megabytes, and CI keeps only the tail, so |
| # a failing test's name used to scroll out of sight (main bcae2a72, |