From d6d9440fb0940a308a82ae71636cc4c94bd867d3 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Sat, 14 Nov 2026 10:35:55 +0100 Subject: [PATCH] ci(test): fix the slowest-suites table on uutils sort; print CPU and SHA support The "8 slowest suites" summary in scripts/run-tests-parallel.sh sorted with `sort -t= -k6 -rn`. uutils sort (Rust coreutils, shipped as sort on newer runner images) reads the attached form -t= as -t with an inline "=value", an empty separator, and exits with "separator must be exactly one character long: ''", leaving the table empty. Pass the separator as its own argument, which GNU, BSD and uutils sort all parse alike. Informational only: the script has no set -e and its exit status is unchanged. scripts/test.sh's environment line now also names the CPU and whether it has SHA-256 instructions (x86 sha_ni / ARMv8 sha2), the signal src/foundation/sha256.c uses to choose its hardware or portable backend. A sanitized runner fingerprints its own large image on that path, so which CPU a hosted job drew decides how long those fingerprints take. The helper lives in scripts/env.sh (cpu_summary, opted into via print_env --cpu, so build.sh, lint.sh and repro.sh print exactly what they did); it reads /proc/cpuinfo or lscpu on Linux/MSYS2 and sysctl on macOS, reports "unknown" for anything unreadable, and never fails the caller. Signed-off-by: Martin Vogel --- scripts/env.sh | 59 ++++++++++++++++++++++++++++++++++- scripts/run-tests-parallel.sh | 6 +++- scripts/test.sh | 2 +- 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/scripts/env.sh b/scripts/env.sh index 13ece00b52..7aa768a5df 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -138,8 +138,65 @@ if [[ "${CBM_NO_CCACHE:-0}" != "1" ]] && command -v ccache >/dev/null 2>&1; then export CCACHE_COMPILERCHECK=content fi +# ── CPU summary (model + SHA-256 instructions) ───────────────── +# src/foundation/sha256.c hashes on x86 SHA-NI / ARMv8 SHA2 when the CPU has +# them and on its portable transform otherwise. A sanitized test runner +# fingerprints its own ~800 MB image that way, so on a runner without those +# instructions every fingerprint is many times slower; this makes the CPU a +# hosted job drew visible in its log. Best effort and never fatal: anything +# unreadable prints "unknown". +cpu_summary() { + local model="" flags="" key="sha_ni" has="unknown" + if [[ "$HW_ARCH" == "arm64" || "${MSYSTEM:-}" == "CLANGARM64" ]]; then + key="sha2" + fi + if [[ "$OS" == "darwin" ]]; then + model="$(sysctl -n machdep.cpu.brand_string 2>/dev/null || true)" + if [[ "$key" == "sha2" ]]; then + flags="$(sysctl -n hw.optional.arm.FEAT_SHA256 2>/dev/null || true)" + case "$flags" in + 1) has="yes" ;; + 0) has="no" ;; + esac + else + flags="$(sysctl -n machdep.cpu.leaf7_features 2>/dev/null || true)" + if [[ -n "$flags" ]]; then + case " $flags " in + *" SHA "*) has="yes" ;; + *) has="no" ;; + esac + fi + fi + elif [[ -r /proc/cpuinfo ]]; then + model="$(awk -F': *' '/^model name/ {print $2; exit}' /proc/cpuinfo 2>/dev/null || true)" + # MSYS2's own runtime is x86-64 even on Windows ARM64, so there its + # /proc/cpuinfo flags describe the emulated CPU, not the real one. + if [[ "${MSYSTEM:-}" != "CLANGARM64" ]]; then + flags="$(awk '/^(flags|Features)[[:space:]]*:/ {print; exit}' /proc/cpuinfo 2>/dev/null || true)" + fi + if [[ -n "$flags" ]]; then + case " $flags " in + *" $key "*) has="yes" ;; + *) has="no" ;; + esac + fi + fi + if [[ -z "$model" ]] && command -v lscpu >/dev/null 2>&1; then + model="$(lscpu 2>/dev/null | awk -F': *' '/^Model name/ {print $2; exit}' || true)" + fi + if [[ "$model" == "-" ]]; then + model="" # lscpu's placeholder for a CPU part it has no name for + fi + printf 'cpu="%s" %s=%s' "${model:-unknown}" "$key" "$has" +} + # ── Print environment summary ────────────────────────────────── +# print_env CONTEXT [--cpu]: --cpu appends cpu_summary to the same line. print_env() { local context="$1" - echo "=== $context: os=$OS arch=$ARCH cores=$NPROC cc=${CC:-default} cxx=${CXX:-default} make=$MAKE ===" + local cpu="" + if [[ "${2:-}" == "--cpu" ]]; then + cpu=" $(cpu_summary)" + fi + echo "=== $context: os=$OS arch=$ARCH cores=$NPROC cc=${CC:-default} cxx=${CXX:-default} make=$MAKE$cpu ===" } diff --git a/scripts/run-tests-parallel.sh b/scripts/run-tests-parallel.sh index 087864cfcc..1dc5e33969 100644 --- a/scripts/run-tests-parallel.sh +++ b/scripts/run-tests-parallel.sh @@ -399,7 +399,11 @@ TOTAL_SKIP=$(awk -F'skip=' '{split($2,a," "); s+=a[1]} END{print s+0}' "$RESULTS BAD_RC=$(grep -cv ' rc=0 ' "$RESULTS_FILE" || true) echo "── 8 slowest suites ──" -sort -t= -k6 -rn "$RESULTS_FILE" | head -8 +# Field 6 of "name rc=N pass=N fail=N skip=N secs=N" split on '=' is secs. +# The separator is its own argument: uutils sort (Rust coreutils, on newer +# runner images) reads the attached form -t= as an inline "=value" with an +# empty value and rejects it, which left this table empty. +sort -t '=' -k6,6 -rn "$RESULTS_FILE" | head -8 grep -v ' rc=0 ' "$RESULTS_FILE" || true for f in $(grep -v ' rc=0 ' "$RESULTS_FILE" | awk '{print $1}'); do suite_failure_summary "$f" "$LOGDIR/$f.log" diff --git a/scripts/test.sh b/scripts/test.sh index 2b0e28774d..a2bb59aead 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -243,7 +243,7 @@ assert_test_runner_build_config() { fi } -print_env "test.sh" +print_env "test.sh" --cpu # ── TSan mode (--tsan): the data-race gate ── # One entry for every venue: CI's tsan jobs and the compose test-tsan service