From cf849370ead263189264049fab72f86c62d326a3 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:25:07 -0600 Subject: [PATCH 01/11] tests: profile run.sh sections and inventory every suite call (part of #875) Co-Authored-By: Claude Sonnet 5.5 --- Makefile | 6 +- docs/dev/suite-inventory.tsv | 286 ++++++++++++++++++++++++++++++++++ docs/dev/suite-profile.md | 131 ++++++++++++++++ tests/README.md | 2 + tests/suite-inventory.py | 237 ++++++++++++++++++++++++++++ tests/suite-profile.py | 57 +++++++ tests/test-suite-inventory.sh | 70 +++++++++ tests/test-suite-profile.sh | 47 ++++++ 8 files changed, 834 insertions(+), 2 deletions(-) create mode 100644 docs/dev/suite-inventory.tsv create mode 100644 docs/dev/suite-profile.md create mode 100755 tests/suite-inventory.py create mode 100755 tests/suite-profile.py create mode 100755 tests/test-suite-inventory.sh create mode 100755 tests/test-suite-profile.sh diff --git a/Makefile b/Makefile index 36955bd2..ba13e4cc 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,8 @@ help: ## List the available targets test: lint test-suite ## Lint + the dependency-free suite (runs on macOS or Linux, no Docker) -test-suite: ## rigforge test suite: unit + black-box, every CPU/OS profile simulated - bash tests/run.sh +test-suite: ## rigforge test suite: unit + black-box, every CPU/OS profile simulated (RIGFORGE_SUITE_PROFILE=1 prints per-section seconds to stderr) + $(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )bash tests/run.sh bash tests/test-doctor-json.sh bash tests/test-contract-credentials.sh bash tests/test-access-token-readiness.sh @@ -49,6 +49,8 @@ test-suite: ## rigforge test suite: unit + black-box, every CPU/OS profile simul bash tests/test-env-override-gate.sh python3 tests/test-server-deadline.py bash tests/test-build-deb.sh + bash tests/test-suite-inventory.sh + bash tests/test-suite-profile.sh test-e2e: ## Full end-to-end run in disposable Linux containers (needs Docker) bash tests/e2e/linux.sh diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv new file mode 100644 index 00000000..099ae239 --- /dev/null +++ b/docs/dev/suite-inventory.tsv @@ -0,0 +1,286 @@ +# Generated by tests/suite-inventory.py --generate . Columns: kind, unit, caller, call site (the run.sh section header above the call, or the make target), stream passes, standalone passes. +# kind: section = a run.sh '== ... ==' header; sourced = a suite sourced into run.sh; chained = a suite run as a subprocess by run.sh; make = a suite run by 'make test-suite' after run.sh. +# stream passes: tick lines run.sh prints under the unit (sections and sourced suites partition them); '-' = folded into the enclosing section. standalone passes: the suite's own count when run alone; '-' = it needs run.sh's fixtures or failed on the generating host. See docs/dev/suite-profile.md. +section (preamble) run.sh (preamble) 58 - +chained tests/test-thread-profile.py run.sh (preamble) - 18 +chained tests/test-suite-liveness.sh run.sh (preamble) - 8 +chained tests/test-xmrig-overlay.sh run.sh (preamble) - 81 +chained tests/test-thread-placement.sh run.sh (preamble) - 78 +chained tests/test-xmrig-logging.sh run.sh (preamble) - 11 +chained tests/test-config-ownership.sh run.sh (preamble) - 22 +chained tests/test-feed-identity.sh run.sh (preamble) - 35 +chained tests/test-grub-edit.sh run.sh (preamble) - 18 +chained tests/test-token-error-text.sh run.sh (preamble) - 0 +chained tests/test-worker-root-owned.sh run.sh (preamble) - 0 +chained tests/test-config-apply-state.sh run.sh (preamble) - 1 +chained tests/test-hugepages-ceiling.sh run.sh (preamble) - 19 +chained tests/test-benchmark-verification.sh run.sh (preamble) - 50 +chained tests/test-benchmark-support.sh run.sh (preamble) - 1 +chained tests/test-stress.sh run.sh (preamble) - 22 +chained tests/test-perf-submission.sh run.sh (preamble) - - +chained tests/test-e2e-selftest.sh run.sh (preamble) - 1 +chained tests/test-root-guard.sh run.sh (preamble) - 46 +chained tests/test-control-hardening.sh run.sh (preamble) - 0 +chained tests/test-upgrade-throttle-security.sh run.sh (preamble) - 1 +chained tests/test-appliance-pools.sh run.sh (preamble) - 2 +section unit: parse_config — pool url used verbatim (#15) run.sh unit: parse_config — pool url used verbatim (#15) 3 - +section unit: pool url validation (#8) run.sh unit: pool url validation (#8) 9 - +section unit: native pools array + defaults (#21, #42) run.sh unit: native pools array + defaults (#21, #42) 65 - +chained tests/test-pool-fields.sh run.sh unit: native pools array + defaults (#21, #42) - - +section unit: config field sanitization run.sh unit: config field sanitization 42 - +chained tests/test-host-port-message.sh run.sh unit: config field sanitization - 0 +section unit: parse_config — workspace + token run.sh unit: parse_config — workspace + token 4 - +section unit: rig label = pool user; API token off by default (#22) run.sh unit: rig label = pool user; API token off by default (#22) 4 - +section unit: parse_config — error paths run.sh unit: parse_config — error paths 2 - +section unit: ensure_config_exists interactive first-run run.sh unit: ensure_config_exists interactive first-run 19 - +chained tests/test-config-atomic.sh run.sh unit: ensure_config_exists interactive first-run - 0 +chained tests/test-shared-host.sh run.sh unit: ensure_config_exists interactive first-run - 1 +chained tests/test-shared-host-lifecycle.sh run.sh unit: ensure_config_exists interactive first-run - - +chained tests/test-donation.sh run.sh unit: ensure_config_exists interactive first-run - 8 +section unit: DONATION validation (new) run.sh unit: DONATION validation (new) 9 - +section unit: append_once idempotency run.sh unit: append_once idempotency 3 - +section unit: remove_line (#12) run.sh unit: remove_line (#12) 2 - +section config-gen: generic Linux (default profile) run.sh config-gen: generic Linux (default profile) 23 - +section config-gen: open API by default (no ACCESS_TOKEN) run.sh config-gen: open API by default (no ACCESS_TOKEN) 2 - +section config-gen: AMD EPYC (server) run.sh config-gen: AMD EPYC (server) 7 - +section config-gen: AMD Ryzen X3D — auto, not hand-pinned (#44) run.sh config-gen: AMD Ryzen X3D — auto, not hand-pinned (#44) 5 - +section config-gen: macOS overrides run.sh config-gen: macOS overrides 9 - +section config-gen: multi-pool passthrough (#21, #42) run.sh config-gen: multi-pool passthrough (#21, #42) 6 - +section config-gen: explicit pool user / rig label (#22) run.sh config-gen: explicit pool user / rig label (#22) 1 - +section config-gen: tls-fingerprint passthrough (#115) run.sh config-gen: tls-fingerprint passthrough (#115) 1 - +section config-gen: socks5 passthrough (#400) run.sh config-gen: socks5 passthrough (#400) 2 - +section config-gen: miner_user disables in-process MSR writes (#140) run.sh config-gen: miner_user disables in-process MSR writes (#140) 2 - +section config-gen: IPv6 host / single-pool TLS / empty-token round-trip run.sh config-gen: IPv6 host / single-pool TLS / empty-token round-trip 3 - +section config-gen: idempotent (same inputs -> identical output) run.sh config-gen: idempotent (same inputs -> identical output) 1 - +section unit: util/proposed-grub.sh hardware math run.sh unit: util/proposed-grub.sh hardware math 17 - +section unit: proposed-grub.sh co-resident headroom + thread cap (#305) run.sh unit: proposed-grub.sh co-resident headroom + thread cap (#305) 8 - +section unit: _cmdline_reserved_2mb (#305) run.sh unit: _cmdline_reserved_2mb (#305) 5 - +section fixture: the lscpu stub stays silent when its reader closes early (#419) run.sh fixture: the lscpu stub stays silent when its reader closes early (#419) 5 - +section unit: proposed-grub.sh honours the declared pool ceiling (#410) run.sh unit: proposed-grub.sh honours the declared pool ceiling (#410) 19 - +section unit: _grub_proposed passes the declared ceiling to proposed-grub (#410) run.sh unit: _grub_proposed passes the declared ceiling to proposed-grub (#410) 5 - +section unit: parse_config hugepages_reserve_extra_mb + threads (#305) run.sh unit: parse_config hugepages_reserve_extra_mb + threads (#305) 6 - +section unit: parse_config hugepages_pool_ceiling_mb (#398) run.sh unit: parse_config hugepages_pool_ceiling_mb (#398) 4 - +section unit: parse_config rejects a bash-inevaluable value in every numeric key (#412) run.sh unit: parse_config rejects a bash-inevaluable value in every numeric key (#412) 29 - +section config-gen: threads cap clamps cpu.rx (#305) run.sh config-gen: threads cap clamps cpu.rx (#305) 3 - +section unit: _grub_proposed co-resident keep-existing guard (#305) run.sh unit: _grub_proposed co-resident keep-existing guard (#305) 4 - +section unit: grub_merge_cmdline preserves other kernel params (#19) run.sh unit: grub_merge_cmdline preserves other kernel params (#19) 8 - +section unit: grub_strip_managed (#12) run.sh unit: grub_strip_managed (#12) 2 - +section unit: _sed_escape_replacement protects the GRUB rewrites (#134) run.sh unit: _sed_escape_replacement protects the GRUB rewrites (#134) 6 - +section unit: compile_xmrig pinned-commit verification (#18) run.sh unit: compile_xmrig pinned-commit verification (#18) 5 - +section unit: compute_build_jobs caps -j by RAM (#9) run.sh unit: compute_build_jobs caps -j by RAM (#9) 6 - +section unit: on_err reports the failing step (#9) run.sh unit: on_err reports the failing step (#9) 2 - +section black-box: on_err names the running verb, not the stale setup default (#353) run.sh black-box: on_err names the running verb, not the stale setup default (#353) 2 - +section unit: staged rebuild swaps in and prunes old build archives (#4, #612) run.sh unit: staged rebuild swaps in and prunes old build archives (#4, #612) 6 - +chained tests/test-root-input-hardening.sh run.sh unit: staged rebuild swaps in and prunes old build archives (#4, #612) - 0 +section unit: xmrig_already_built detection (#4) run.sh unit: xmrig_already_built detection (#4) 6 - +section unit: compile_xmrig honours XMRIG_REBUILD (#4) run.sh unit: compile_xmrig honours XMRIG_REBUILD (#4) 3 - +section black-box: upgrade / help / unknown command (#4) run.sh black-box: upgrade / help / unknown command (#4) 13 - +section black-box: upgrade leaves a stopped miner stopped (#413) run.sh black-box: upgrade leaves a stopped miner stopped (#413) 7 - +section black-box: upgrade / help / unknown command (#4), rebuild path run.sh black-box: upgrade / help / unknown command (#4), rebuild path 12 - +section unit: upgrade --check (#148) run.sh unit: upgrade --check (#148) 24 - +section black-box: consistency sweep — flags, prompts, templates (#149) run.sh black-box: consistency sweep — flags, prompts, templates (#149) 27 - +section black-box: command surface (#11) run.sh black-box: command surface (#11) 30 - +section black-box: apply / bench (#11) run.sh black-box: apply / bench (#11) 10 - +section black-box: apply reports the miner's pool connection (#343) run.sh black-box: apply reports the miner's pool connection (#343) 7 - +section unit: _miner_deliberately_stopped — the predicate the #396 decision turns on run.sh unit: _miner_deliberately_stopped — the predicate the #396 decision turns on 5 - +section unit: _apply_runtime preserve-run-state — the held rig stays stopped, tune's bare call does not (#396) run.sh unit: _apply_runtime preserve-run-state — the held rig stays stopped, tune's bare call does not (#396) 8 - +section black-box: apply on a deliberately stopped rig regenerates and holds (#396) run.sh black-box: apply on a deliberately stopped rig regenerates and holds (#396) 10 - +section unit: apply reports the autotune target (#95) run.sh unit: apply reports the autotune target (#95) 4 - +section black-box: apply reconciles the autotune timer to config (#95) run.sh black-box: apply reconciles the autotune timer to config (#95) 2 - +section black-box: apply reconciles the sister API to config (#99) run.sh black-box: apply reconciles the sister API to config (#99) 4 - +section black-box: apply reconciles the writable control path to config (#236) run.sh black-box: apply reconciles the writable control path to config (#236) 15 - +section unit: _worker_root_from_config validates HOME_DIR run.sh unit: _worker_root_from_config validates HOME_DIR 3 - +section black-box: install_autotune timer enable/disable (#95 tri-state) run.sh black-box: install_autotune timer enable/disable (#95 tri-state) 10 - +section black-box: install_watchdog timer enable/disable (#139) run.sh black-box: install_watchdog timer enable/disable (#139) 10 - +section unit: install_watchdog returns non-zero when it could not render (#395) run.sh unit: install_watchdog returns non-zero when it could not render (#395) 7 - +section unit: parse_config — watchdog keys (#139) run.sh unit: parse_config — watchdog keys (#139) 16 - +chained tests/test-watchdog-thermal-retry.sh run.sh unit: parse_config — watchdog keys (#139) - 1 +chained tests/test-watchdog-shared-host-guard.sh run.sh unit: parse_config — watchdog keys (#139) - 1 +chained tests/test-watchdog-fail-safe.sh run.sh unit: parse_config — watchdog keys (#139) - 0 +section unit: watchdog health check (#139) run.sh unit: watchdog health check (#139) 39 - +section unit: parse_config — autotune tri-state (#95) run.sh unit: parse_config — autotune tri-state (#95) 9 - +section black-box: autotune ranks by target (#95) run.sh black-box: autotune ranks by target (#95) 10 - +chained tests/test-autotune-noise.sh run.sh black-box: autotune ranks by target (#95) - 0 +section black-box: upgrade re-tunes the new build (#95) run.sh black-box: upgrade re-tunes the new build (#95) 7 - +section unit: _wait_miner_live (#95) run.sh unit: _wait_miner_live (#95) 2 - +section unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) 6 - +chained tests/test-config-mode-token-scope.sh run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) - 0 +section black-box: support-bundle collects + redacts (#147) run.sh black-box: support-bundle collects + redacts (#147) 21 - +section black-box: setup --dry-run plan + no-mutation guard (#146) run.sh black-box: setup --dry-run plan + no-mutation guard (#146) 67 - +section black-box: completion script + verb-list drift guard (#145) run.sh black-box: completion script + verb-list drift guard (#145) 13 - +section unit: the API readers never let a curl failure escape (#353/#364) run.sh unit: the API readers never let a curl failure escape (#353/#364) 4 - +section unit: status live summary (#143) run.sh unit: status live summary (#143) 8 - +section black-box: unreachable worker API is quiet, not an abort (#364) run.sh black-box: unreachable worker API is quiet, not an abort (#364) 4 - +section black-box: an unreachable API never aborts a tune sampling read (#364) run.sh black-box: an unreachable API never aborts a tune sampling read (#364) 5 - +section unit: status hugepages shapes (#341) run.sh unit: status hugepages shapes (#341) 7 - +section unit: _parse_hashrate (#11) run.sh unit: _parse_hashrate (#11) 1 - +section unit: install_dependencies non-interactive auto-install (#74) run.sh unit: install_dependencies non-interactive auto-install (#74) 3 - +section unit: install_dependencies adds versioned linux-tools when apt-cache has it (#74) run.sh unit: install_dependencies adds versioned linux-tools when apt-cache has it (#74) 3 - +section unit: apt cpupower package probe — Debian / neither exists (#327) run.sh unit: apt cpupower package probe — Debian / neither exists (#327) 7 - +section unit: check_prerequisites installs jq per package manager run.sh unit: check_prerequisites installs jq per package manager 10 - +section unit: install_dependencies dnf / pacman / no-manager branches run.sh unit: install_dependencies dnf / pacman / no-manager branches 6 - +section unit: finish_deployment points at 'start' run.sh unit: finish_deployment points at 'start' 2 - +section black-box: macOS process control (start/status/stop) run.sh black-box: macOS process control (start/status/stop) 11 - +section black-box: macOS login agent (enable/disable via launchd) run.sh black-box: macOS login agent (enable/disable via launchd) 13 - +section unit: install_service reboot-gates the start (#audit A2) run.sh unit: install_service reboot-gates the start (#audit A2) 10 - +section unit: install_service with miner_user (#140) run.sh unit: install_service with miner_user (#140) 4 - +section unit: msr-apply preset detection + masked RMW (#140) run.sh unit: msr-apply preset detection + masked RMW (#140) 17 - +section unit: _reown_worker hands config+log back to the miner user (#140) run.sh unit: _reown_worker hands config+log back to the miner user (#140) 2 - +section unit: apply re-renders the installed unit to the configured miner_user (#140) run.sh unit: apply re-renders the installed unit to the configured miner_user (#140) 4 - +section unit: install_service honors SERVICE_NAME override (#133) run.sh unit: install_service honors SERVICE_NAME override (#133) 36 - +section black-box: full deployment run (stubbed, native $HOST_OS path) run.sh black-box: full deployment run (stubbed, native $HOST_OS path) - - +section black-box: re-run is idempotent (#5) run.sh black-box: re-run is idempotent (#5) 8 - +section black-box: setup installs the CLI only when add_to_path is enabled (#cli) run.sh black-box: setup installs the CLI only when add_to_path is enabled (#cli) 1 - +section black-box: no ANSI escapes off-terminal (#144) run.sh black-box: no ANSI escapes off-terminal (#144) 2 - +section unit: doctor health checks (#45) run.sh unit: doctor health checks (#45) 15 - +section unit: doctor checks http.restricted in the live config (#135) run.sh unit: doctor checks http.restricted in the live config (#135) 3 - +section unit: doctor's sister-feed check follows control's api implication (#507) run.sh unit: doctor's sister-feed check follows control's api implication (#507) 6 - +section unit: doctor hashrate-capping hardware (#67) run.sh unit: doctor hashrate-capping hardware (#67) 18 - +section unit: doctor BIOS/firmware advisory (#78) run.sh unit: doctor BIOS/firmware advisory (#78) 12 - +section unit: doctor kernel-lockdown detection (#333) run.sh unit: doctor kernel-lockdown detection (#333) 29 - +section unit: CPU ISA preflight — AES-NI / AVX2 surfaced (#338) run.sh unit: CPU ISA preflight — AES-NI / AVX2 surfaced (#338) 17 - +section unit: doctor control receiver health (#278) run.sh unit: doctor control receiver health (#278) 11 - +section unit: doctor pool connection (#343) run.sh unit: doctor pool connection (#343) 13 - +sourced tests/onion-proxy.sh run.sh unit: doctor pool connection (#343) 62 0 +section unit: EPYC NPS detection (#201) run.sh unit: EPYC NPS detection (#201) 12 - +section unit: guided BIOS flow (#80) run.sh unit: guided BIOS flow (#80) 57 - +section unit: doctor service-inactive branch (#audit) run.sh unit: doctor service-inactive branch (#audit) 3 - +section unit: _reown_worker reconciles file ownership (#audit) run.sh unit: _reown_worker reconciles file ownership (#audit) 5 - +section unit: _script_dir resolves through symlinks (#cli) run.sh unit: _script_dir resolves through symlinks (#cli) 3 - +section unit: link_cli installs + guards the rigforge command (#cli) run.sh unit: link_cli installs + guards the rigforge command (#cli) 8 - +section unit: doctor MSR mod verification (#66) run.sh unit: doctor MSR mod verification (#66) 14 - +section unit: doctor MSR unverifiable — guard-input failures named (#367) run.sh unit: doctor MSR unverifiable — guard-input failures named (#367) 6 - +section unit: doctor miner_user + root-side MSR preset (#140) run.sh unit: doctor miner_user + root-side MSR preset (#140) 5 - +section unit: doctor exposure posture advisory (#sec) run.sh unit: doctor exposure posture advisory (#sec) 6 - +section unit: MSR preset table values (#66) run.sh unit: MSR preset table values (#66) 12 - +section black-box: uninstall reverts system changes (#12) run.sh black-box: uninstall reverts system changes (#12) 28 - +chained tests/test-uninstall-state.sh run.sh black-box: uninstall reverts system changes (#12) - 1 +section black-box: uninstall without --yes aborts on 'n' (reverts nothing) run.sh black-box: uninstall without --yes aborts on 'n' (reverts nothing) 3 - +section black-box: appliance uninstall disables with --runtime too (#353) run.sh black-box: appliance uninstall disables with --runtime too (#353) 2 - +section black-box: tune (iterative hill-climb, multi-knob) (#54) run.sh black-box: tune (iterative hill-climb, multi-knob) (#54) 28 - +section black-box: zero-hashrate bench iteration stays quiet (#277) run.sh black-box: zero-hashrate bench iteration stays quiet (#277) 4 - +section black-box: tune restarts the service after a mid-run bench crash (#276) run.sh black-box: tune restarts the service after a mid-run bench crash (#276) 2 - +section black-box: tune target follows autotune config + is announced (#tunefix) run.sh black-box: tune target follows autotune config + is announced (#tunefix) 20 - +chained tests/test-sudo-env-forward.sh run.sh black-box: tune target follows autotune config + is announced (#tunefix) - 0 +section black-box: tune --history surfaces periodic auto-tune (Linux) (#hist) run.sh black-box: tune --history surfaces periodic auto-tune (Linux) (#hist) 7 - +section black-box: tune median-of-N noise handling (#54) run.sh black-box: tune median-of-N noise handling (#54) 4 - +section black-box: tune min-delta gate (#54) run.sh black-box: tune min-delta gate (#54) 3 - +section black-box: tune variance-aware acceptance gate (#63) run.sh black-box: tune variance-aware acceptance gate (#63) 3 - +section black-box: tune 1gb-pages knob when reserved (#54) run.sh black-box: tune 1gb-pages knob when reserved (#54) 3 - +section black-box: tune power/temp recording (#54) run.sh black-box: tune power/temp recording (#54) 5 - +section unit: _read_temp hwmon fallback (#208) run.sh unit: _read_temp hwmon fallback (#208) 4 - +section unit: power measurement helpers (#81) run.sh unit: power measurement helpers (#81) 11 - +section black-box: tune samples power under load, not idle (#81) run.sh black-box: tune samples power under load, not idle (#81) 3 - +section black-box: tune built-in RAPL power path (#81) run.sh black-box: tune built-in RAPL power path (#81) 2 - +section unit: efficiency-target acceptance gate (#79) run.sh unit: efficiency-target acceptance gate (#79) 3 - +section unit: _autotune_score efficiency needs watts, else raw H/s (#95) run.sh unit: _autotune_score efficiency needs watts, else raw H/s (#95) 4 - +section black-box: efficiency winner differs from perf winner (#79) run.sh black-box: efficiency winner differs from perf winner (#79) 4 - +section black-box: tune --efficiency falls back without a power source (#79) run.sh black-box: tune --efficiency falls back without a power source (#79) 3 - +section black-box: tune --live (API-measured) (#54) run.sh black-box: tune --live (API-measured) (#54) 11 - +section black-box: aborted tune --live restores the pre-sweep overrides (#347) run.sh black-box: aborted tune --live restores the pre-sweep overrides (#347) 5 - +section black-box: tune --confirm live A/B (#64) run.sh black-box: tune --confirm live A/B (#64) 5 - +section unit: tune bench freq writer floors a sci-notation median to whole kHz (#266) run.sh unit: tune bench freq writer floors a sci-notation median to whole kHz (#266) 2 - +section black-box: tune thermal-throttle rejection (#62) run.sh black-box: tune thermal-throttle rejection (#62) 4 - +section unit: tune seeds keep explicit false (#265) run.sh unit: tune seeds keep explicit false (#265) 4 - +section black-box: tune wrmsr knob (#66) run.sh black-box: tune wrmsr knob (#66) 8 - +chained tests/test-tune-pins.sh run.sh black-box: tune wrmsr knob (#66) - 35 +section black-box: tune reservation-aware threads (#65) run.sh black-box: tune reservation-aware threads (#65) 6 - +section black-box: setup sizes the reservation for the tuned threads (#65) run.sh black-box: setup sizes the reservation for the tuned threads (#65) 6 - +section black-box: runtime HugePages reservation is grow-only (#328) run.sh black-box: runtime HugePages reservation is grow-only (#328) 7 - +section unit: hugepages pool ceiling bounds the grow-only write (#398) run.sh unit: hugepages pool ceiling bounds the grow-only write (#398) 13 - +section black-box: appliance mode (pithead#797 R1) run.sh black-box: appliance mode (pithead#797 R1) 99 - +sourced tests/test-donation-tor.sh run.sh black-box: appliance mode (pithead#797 R1) - - +section black-box: autotune live trial + merge (#46) run.sh black-box: autotune live trial + merge (#46) 12 - +section black-box: aborted autotune restores the pre-sweep prefetch mode (#347) run.sh black-box: aborted autotune restores the pre-sweep prefetch mode (#347) 7 - +section black-box: tune grid search (#6) run.sh black-box: tune grid search (#6) 5 - +section black-box: tune huge-pages-jit knob (#7) run.sh black-box: tune huge-pages-jit knob (#7) 3 - +section unit: _thread_candidates is SMT-aware (#4) run.sh unit: _thread_candidates is SMT-aware (#4) 5 - +section black-box: backup / restore round-trip run.sh black-box: backup / restore round-trip 24 - +chained tests/test-config-write-safety.sh run.sh black-box: backup / restore round-trip - 0 +section black-box: backup leaks no staging tempdir on a set -e abort (#353) run.sh black-box: backup leaks no staging tempdir on a set -e abort (#353) 2 - +section black-box: restore leaks no staging tempdir on a set -e abort (#353) run.sh black-box: restore leaks no staging tempdir on a set -e abort (#353) 2 - +section black-box: support-bundle leaks no staging tempdir on a set -e abort (#353) run.sh black-box: support-bundle leaks no staging tempdir on a set -e abort (#353) 2 - +section unit: VERSION is SemVer (#3) run.sh unit: VERSION is SemVer (#3) 1 - +section unit: config.reference.json (#23) run.sh unit: config.reference.json (#23) 5 - +section unit: config.minimal.json (starter) run.sh unit: config.minimal.json (starter) 3 - +section unit: sister API config keys (#99) run.sh unit: sister API config keys (#99) 42 - +chained tests/test-sister-reconcile.sh run.sh unit: sister API config keys (#99) - - +section black-box: install_api_firewall renders + tears down the nft table (#142) run.sh black-box: install_api_firewall renders + tears down the nft table (#142) 16 - +chained tests/test-api-firewall-path.sh run.sh black-box: install_api_firewall renders + tears down the nft table (#142) - 0 +section black-box: install_api server/timer enable/disable (#99/#164) run.sh black-box: install_api server/timer enable/disable (#99/#164) 26 - +section unit: api-refresh produces the response files (#99/#164) run.sh unit: api-refresh produces the response files (#99/#164) 43 - +sourced tests/test-api-refresh-liveness.sh run.sh unit: api-refresh produces the response files (#99/#164) 32 - +chained tests/test-api-refresh-spawns.sh run.sh unit: api-refresh produces the response files (#99/#164) - 110 +chained tests/test-tune-files-regular.sh run.sh unit: api-refresh produces the response files (#99/#164) - 0 +section black-box: the persistent api server (#164, the xmrig model) run.sh black-box: the persistent api server (#164, the xmrig model) 26 - +section black-box: api-server IPv6 dual-stack bind (#243) run.sh black-box: api-server IPv6 dual-stack bind (#243) 3 - +section unit: parse_config — control keys + fail-closed dual auth (#236) run.sh unit: parse_config — control keys + fail-closed dual auth (#236) 25 - +section black-box: install_control units enable/disable (#236) run.sh black-box: install_control units enable/disable (#236) 31 - +chained tests/test-control-firewall.sh run.sh black-box: install_control units enable/disable (#236) - - +section unit: _control_commit — validate, backup, merge, atomic (#236) run.sh unit: _control_commit — validate, backup, merge, atomic (#236) 41 - +chained tests/test-control-status-write.sh run.sh unit: _control_commit — validate, backup, merge, atomic (#236) - 1 +section unit: _api_config_json — effective writable config, secrets masked (#253) run.sh unit: _api_config_json — effective writable config, secrets masked (#253) 18 - +chained tests/test-jq-config-input.sh run.sh unit: _api_config_json — effective writable config, secrets masked (#253) - 0 +section unit: config_meta — revision + last-change provenance (#254) run.sh unit: config_meta — revision + last-change provenance (#254) 23 - +section unit: _control_commit — masked pool secrets survive a pools edit (#415) run.sh unit: _control_commit — masked pool secrets survive a pools edit (#415) 55 - +section unit: _control_fast_path_eligible — closed allowlist classification (#381) run.sh unit: _control_fast_path_eligible — closed allowlist classification (#381) 13 - +section unit: _control_do_apply_fast — reuses install_watchdog, skips apply()/xmrig restart (#381) run.sh unit: _control_do_apply_fast — reuses install_watchdog, skips apply()/xmrig restart (#381) 7 - +section unit: control_apply + REAL _control_do_apply_fast — run-state criterion, not is-active alone (#381 security review) run.sh unit: control_apply + REAL _control_do_apply_fast — run-state criterion, not is-active alone (#381 security review) 16 - +section unit: control_apply FULL path — a deliberately stopped rig is not rolled back (#396) run.sh unit: control_apply FULL path — a deliberately stopped rig is not rolled back (#396) 14 - +section unit: apply() and _control_do_apply propagate a watchdog render failure (#395) run.sh unit: apply() and _control_do_apply propagate a watchdog render failure (#395) 7 - +section unit: control_apply orchestration + rollback (#236) run.sh unit: control_apply orchestration + rollback (#236) 77 - +sourced tests/test-control-upgrade.sh run.sh unit: control_apply orchestration + rollback (#236) 68 - +sourced tests/test-fetch-proxy.sh run.sh unit: control_apply orchestration + rollback (#236) 101 - +sourced tests/test-package-mode.sh run.sh unit: control_apply orchestration + rollback (#236) 30 0 +section unit: e2e-real git calls survive a nested sudo (#401) run.sh unit: e2e-real git calls survive a nested sudo (#401) 3 - +section unit: control writable-keys drift guard — bash vs python (#236) run.sh unit: control writable-keys drift guard — bash vs python (#236) 1 - +section black-box: the control server (#236) run.sh black-box: the control server (#236) 75 - +chained tests/test-control-revocation.sh run.sh black-box: the control server (#236) - 1 +chained tests/test-control-spool-cap.py run.sh black-box: the control server (#236) - 0 +section unit: e2e-real perf record gate (#214/#267) run.sh unit: e2e-real perf record gate (#214/#267) 14 - +section unit: require_traversable_checkout — DynamicUser traversal pre-flight (#362) run.sh unit: require_traversable_checkout — DynamicUser traversal pre-flight (#362) 5 - +sourced tests/test-e2e-apt-prereqs.sh run.sh unit: require_traversable_checkout — DynamicUser traversal pre-flight (#362) 10 - +section unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) run.sh unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) 34 - +sourced tests/test-e2e-gate-fail-closed.sh run.sh unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) 152 - +sourced tests/test-e2e-hammer.sh run.sh unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) 16 - +section unit: rig_lock — the shared-rig flock (#183) run.sh unit: rig_lock — the shared-rig flock (#183) 24 - +section contract guard: wire-shape fixtures (#351) run.sh contract guard: wire-shape fixtures (#351) 9 - +sourced tests/test-randomx-mode.sh run.sh contract guard: wire-shape fixtures (#351) - 1 +sourced tests/daemon-pools.sh run.sh contract guard: wire-shape fixtures (#351) 142 - +chained tests/test-l3-units.sh run.sh contract guard: wire-shape fixtures (#351) - 10 +section tree hygiene: the suite writes nothing into the tracked tree (#418) run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) 2 - +chained tests/docs-replay-commands.sh run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) - - +make tests/suite-profile.py Makefile test-suite - - +make tests/test-doctor-json.sh Makefile test-suite - 51 +make tests/test-contract-credentials.sh Makefile test-suite - 1 +make tests/test-access-token-readiness.sh Makefile test-suite - 9 +make tests/test-docs-clone-pin.sh Makefile test-suite - 11 +make tests/test-staged-rebuild.sh Makefile test-suite - 1 +make tests/test-package-upgrade.sh Makefile test-suite - 0 +make tests/test-dependabot-coverage.sh Makefile test-suite - 1 +make tests/test-security-backlog-expiry.sh Makefile test-suite - 1 +make tests/test-codeql-workflow.sh Makefile test-suite - 0 +make tests/test-tool-pin-watch.sh Makefile test-suite - 8 +make tests/test-xmrig-bump.sh Makefile test-suite - 1 +make tests/test-osv-file-issue.sh Makefile test-suite - 5 +make tests/test-file-security-issue.sh Makefile test-suite - 3 +make tests/test-workflow-contract.sh Makefile test-suite - 0 +make tests/test-docs-replay.py Makefile test-suite - 18 +make tests/test-api-allowlist-probe.sh Makefile test-suite - 0 +make tests/test-e2e-docs-guest.sh Makefile test-suite - 22 +make tests/test-control-readiness.py Makefile test-suite - 3 +make tests/test-worker-proof.py Makefile test-suite - 24 +make tests/test-serve-poll.py Makefile test-suite - 3 +make tests/test-worker-proof.sh Makefile test-suite - 22 +make tests/test-coverage-cache.sh Makefile test-suite - 1 +make tests/test-revision-key.sh Makefile test-suite - 0 +make tests/test-state-lib.sh Makefile test-suite - 0 +make tests/test-homebrew-formula.sh Makefile test-suite - 6 +make tests/test-e2e-gate.sh Makefile test-suite - 44 +make tests/manifest-selftest.sh Makefile test-suite - - +make tests/test-release-bundle.sh Makefile test-suite - - +make tests/test-env-override-gate.sh Makefile test-suite - 0 +make tests/test-server-deadline.py Makefile test-suite - 0 +make tests/test-build-deb.sh Makefile test-suite - 0 +make tests/test-suite-inventory.sh Makefile test-suite - - +make tests/test-suite-profile.sh Makefile test-suite - 5 diff --git a/docs/dev/suite-profile.md b/docs/dev/suite-profile.md new file mode 100644 index 00000000..18ee7688 --- /dev/null +++ b/docs/dev/suite-profile.md @@ -0,0 +1,131 @@ +# Suite profile and inventory + +`make test-suite` runs `tests/run.sh` (one process, thousands of assertions) +followed by a list of standalone suites. Nothing records where the time goes or +which suites run from where, so an isolation or caching change (#624) could drop +or double-run assertions without anyone noticing. This page is the measured +"before" and the rule for keeping the suite inventory true. + +## Profiling a run + +```sh +RIGFORGE_SUITE_PROFILE=1 make test-suite +``` + +With the variable set, the Makefile runs `tests/run.sh` through +`tests/suite-profile.py`. Without it, the recipe is the same `bash tests/run.sh` +as before. The wrapper passes the suite's stdout through unchanged and writes one +`suite-profile:` line per `== ... ==` section to stderr (seconds, tick lines +printed under it, section name), then the whole-suite total. `tests/run.sh` is not +touched; its line count is pinned by `docs/dev/file-budget.tsv`. +`tests/test-suite-profile.sh` proves the output is byte-identical, the exit status +is preserved and the report carries the elapsed seconds. + +A section's time is the time from its header line to the next header line, as seen +on the pipe, so it includes the standalone suites that run inside it. Sections that +a sourced suite prints for itself (for example `tests/test-control-upgrade.sh`) are +rows of their own. + +## Baseline + +Three consecutive runs of `bash tests/run.sh` under the wrapper, with +`RIGFORGE_TEST_OVERRIDES=1` as the Makefile sets it, on a Linux x86_64 host +(Ubuntu 26.04, 8 cores). This is the same OS family as the `ubuntu-24.04` CI runner +but not the runner itself; CI reports a whole-job median of 8.1 minutes (p90 18.7) +on its own hardware. All three runs ended with `2858 passed, 0 failed` and the same +239 runtime sections. + +| Run | Whole-suite seconds | +|---|---| +| 1 | 568.2 | +| 2 | 575.7 | +| 3 | 589.6 | + +Whole-suite median 575.7 s, p90 589.6 s (nearest rank over three runs). The standalone +suites the Makefile runs after `run.sh` took about 4.5 minutes in sequence when +measured one by one for the inventory; that figure includes starting each one cold +and is not a CI number. + +Per-section median and p90 over the three runs, the 15 slowest of 239. 180 sections +take under a second. The top five take 64.6% of the section time. + +| Section | Median s | p90 s | +|---|---|---| +| black-box: appliance mode (pithead#797 R1) | 264.4 | 264.7 | +| black box: the msr-apply pre-start step still runs to the end as root | 52.9 | 53.3 | +| unit: e2e-real watchdog cleanup restores prior service state (#462) | 34.3 | 41.0 | +| unit: doctor's sister-feed check follows control's api implication (#507) | 9.9 | 10.4 | +| pool schema fields (#527) | 7.3 | 7.4 | +| unit: ensure_config_exists interactive first-run | 6.1 | 7.0 | +| unit: _control_commit — validate, backup, merge, atomic (#236) | 5.9 | 6.0 | +| unit: sister API config keys (#99) | 5.8 | 6.8 | +| unit: staged rebuild swaps in and prunes old build archives (#4, #612) | 5.5 | 5.8 | +| config ownership and setup service transitions (#529) | 4.8 | 4.8 | +| black-box: tune (iterative hill-climb, multi-knob) (#54) | 4.7 | 5.1 | +| (preamble) | 4.6 | 5.1 | +| unit: root-guard refuses root-run units on a tree a non-root user can write (#783) | 4.5 | 4.9 | +| black-box: tune variance-aware acceptance gate (#63) | 4.5 | 4.7 | +| unit: _control_commit — masked pool secrets survive a pools edit (#415) | 4.4 | 4.5 | + +The full per-section rows come from the same command; re-measure rather than copy +this table when comparing. + +### The parse hotspot + +`parse_and_print` and `parse_rc` (`tests/run.sh`) run `source "$SCRIPT"` in a +subshell for every fixture, so `rigforge.sh` is re-read and re-parsed each time. +`tests/run.sh` has 223 `source "$SCRIPT"` sites. One bare `source rigforge.sh` in a +fresh `bash` costs 25 ms here (20 starts in 0.50 s). The dynamic number of sources +per run was not counted. The profile shows that the parse cost alone cannot explain +the run time: the three slowest sections, none of them parse loops, are 61% of the +total, and the rest of the unit sections are mostly under a second. Any parse-reuse +change should be measured against the per-section rows above, not assumed. + +## Inventory + +`docs/dev/suite-inventory.tsv` lists every unit of the suite, one per line, in call +order: + +- `section`: a `== ... ==` header in `tests/run.sh`, plus `(preamble)` for what runs + before the first header (190 rows). +- `sourced`: a suite sourced into `tests/run.sh`, sharing its pass counter (11). +- `chained`: a suite `tests/run.sh` runs as a subprocess, including the ones run by + loops and the Python ones (48). +- `make`: a suite `make test-suite` runs after `tests/run.sh` (34). + +Columns: kind, unit, caller, call site (the run.sh section header above the call, or +the make target), stream passes, standalone passes. + +Stream passes are the tick lines `tests/run.sh` printed under the unit in the profiled +run. Sections and sourced suites partition the stream: the stream carries 2904 ticks, +the 2858 of `tests/run.sh`'s own counter plus 46 printed by chained suites that use the +same tick. A sourced suite that prints its own `== ... ==` header gets its own count; +one that prints none (`tests/test-donation-tor.sh`, `tests/test-randomx-mode.sh`) is +folded into the section above it and shows `-`. Chained and make rows show `-` in this +column. + +Standalone passes are the suite's own count when run alone, from its `N passed`, +`passed=N` or `Ran N tests` line, or else its count of `PASS`, `ok` and tick lines. `-` +means it needs fixtures `tests/run.sh` builds (PATH stubs, exported functions) or it +failed on the host that generated the file; `tests/test-release-bundle.sh` needs `zip`. +The standalone count of a chained suite is not added to the stream count of the section +it runs in. + +Disjoint means no suite file is called twice. `tests/suite-inventory.py --check` +fails when a suite appears at two call sites, or in both `tests/run.sh` and the +Makefile `test-suite` recipe. Suites that those suites call in turn (for example +`tests/test-donation.sh` running `tests/test-e2e-donation.sh`) are not listed. + +### Keeping it true + +`tests/test-suite-inventory.sh` runs in `make test-suite`. It fails when +`tests/run.sh` or the Makefile gains or loses a section header or a suite call that +`docs/dev/suite-inventory.tsv` does not list, and its cases show each of those +mutations red. After an intended change, regenerate with: + +```sh +RIGFORGE_SUITE_PROFILE=1 make test-suite 2>profile.err >/dev/null +python3 tests/suite-inventory.py --generate profile.err +``` + +The generator runs every standalone suite once, which takes a few minutes. diff --git a/tests/README.md b/tests/README.md index 521f15b8..596e0ee6 100644 --- a/tests/README.md +++ b/tests/README.md @@ -17,6 +17,8 @@ GitHub Test suite job, including argument inspection, password rotation and EXIT The offline `test-coverage-cache.sh` regression also runs in `make test-suite`. Coverage caches only the pinned jq download, keyed by release, Linux architecture and SHA256. + +The suite inventory (`docs/dev/suite-inventory.tsv`) lists every `run.sh` section and every standalone suite `run.sh` or `make test-suite` runs. `test-suite-inventory.sh` fails when a section header or suite call is missing from it, and `test-suite-profile.sh` covers `RIGFORGE_SUITE_PROFILE=1 make test-suite`, which prints per-section seconds to stderr. See [docs/dev/suite-profile.md](../docs/dev/suite-profile.md). Every invocation copies it into private disposable storage and verifies the checksum before use; the container mounts that verified copy read-only. A corrupt entry fails before coverage runs; remove the invalid entry from `.coverage-cache` and retry. Downloads publish atomically only after diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py new file mode 100755 index 00000000..d6a4cd75 --- /dev/null +++ b/tests/suite-inventory.py @@ -0,0 +1,237 @@ +#!/usr/bin/env python3 +import os +import re +import shlex +import subprocess +import sys + +ROOT = os.environ.get("SUITE_INVENTORY_ROOT") or os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +INVENTORY = os.path.join(ROOT, "docs", "dev", "suite-inventory.tsv") +HEADER = re.compile(r'^\s*echo "== (.*) =="\s*$') +FOR_LOOP = re.compile(r"^\s*for (\w+) in (.*?); do\b") +REFERENCE = re.compile(r"(?:bash|python3|source)\s+\"?\$ROOT/tests/(?:([A-Za-z0-9_.-]+\.(?:sh|py))|test-(\$\w+)\.sh)") +PASS_SUMMARIES = ( + re.compile(r"(\d+) passed"), + re.compile(r"passed=(\d+)"), + re.compile(r"Ran (\d+) tests?"), +) +PASS_LINE = re.compile(r"✓|PASS|^ok ", re.M) +LOOP_ALIAS = {"_f": "_sh"} + + +def read(path): + with open(os.path.join(ROOT, path), encoding="utf-8") as handle: + return handle.read().splitlines() + + +def loop_values(items): + out = [] + for item in shlex.split(items.replace("$PATH", "").replace("$STUBS", "")): + out.append(item.split()[0] if item.split() else item) + return out + + +def run_sh_units(): + site = "(preamble)" + units = [("section", site, "run.sh", site)] + loops = {} + for line in read("tests/run.sh"): + header = HEADER.match(line) + if header: + site = header.group(1) + units.append(("section", site, "run.sh", site)) + continue + loop = FOR_LOOP.match(line) + if loop: + loops[loop.group(1)] = loop_values(loop.group(2)) + for match in REFERENCE.finditer(line): + names = [] + if match.group(1): + names = [match.group(1)] + else: + var = match.group(2).lstrip("$") + names = ["test-%s.sh" % value for value in loops.get(LOOP_ALIAS.get(var, var), [])] + if not names: + raise SystemExit("suite-inventory: unresolved loop variable $%s in tests/run.sh" % var) + for name in names: + if not name.startswith("tests/"): + name = "tests/" + name + if name == "tests/run.sh": + continue + kind = "sourced" if re.search(r"(?:source|\.)\s+\"?\$ROOT/" + re.escape(name), line) else "chained" + row = (kind, name, "run.sh", site) + if row not in units: + units.append(row) + return units + + +def make_units(): + units = [] + in_target = False + for line in read("Makefile"): + if line.startswith("test-suite:"): + in_target = True + continue + if in_target: + if not line.startswith("\t"): + break + match = re.search(r"tests/([A-Za-z0-9_.-]+\.(?:sh|py))", line) + if match and match.group(1) != "run.sh": + units.append(("make", "tests/" + match.group(1), "Makefile", "test-suite")) + return units + + +def scan(): + return run_sh_units() + make_units() + + +def suite_headers(): + found = {} + for name in sorted(os.listdir(os.path.join(ROOT, "tests"))): + if name.endswith(".sh"): + for line in read("tests/" + name): + match = HEADER.match(line) + if match: + found.setdefault(match.group(1), "tests/" + name) + return found + + +def count_passes(text): + for pattern in PASS_SUMMARIES: + match = pattern.search(text) + if match: + return int(match.group(1)) + return len(PASS_LINE.findall(text)) + + +def parse_profile(path): + rows = [] + with open(path, encoding="utf-8", errors="replace") as handle: + for line in handle: + parts = line.rstrip("\n").split("\t") + if line.startswith("suite-profile: ") and len(parts) == 3 and parts[0] != "suite-profile: seconds": + rows.append((parts[2], int(parts[1]))) + return rows + + +def attribute(units, profile_rows): + run_headers = {u[1] for u in units if u[0] == "section"} + owner_of = suite_headers() + totals = {} + current = None + for header, passes in profile_rows: + if header in run_headers: + current = ("section", header) + elif header in owner_of and ("sourced", owner_of[header]) in {(u[0], u[1]) for u in units}: + current = ("sourced", owner_of[header]) + if current is not None: + totals[current] = totals.get(current, 0) + passes + return totals + + +def measure_standalone(units): + counts = {} + for kind, name, _, _ in units: + if kind == "section" or name in counts: + continue + if name.endswith(".py"): + cmd = ["python3", name] + if name == "tests/test-control-spool-cap.py": + cmd.append("util/control-server.py") + else: + cmd = ["bash", name] + if kind != "make": + cmd.append(os.path.join(ROOT, "rigforge.sh")) + env = dict(os.environ, RIGFORGE_TEST_OVERRIDES="1", PYTHONDONTWRITEBYTECODE="1") + try: + result = subprocess.run(cmd, cwd=ROOT, env=env, capture_output=True, text=True, timeout=120, stdin=subprocess.DEVNULL) + except subprocess.TimeoutExpired: + continue + if result.returncode == 0: + counts[name] = count_passes(result.stdout + result.stderr) + else: + sys.stderr.write("suite-inventory: %s exited %d standalone; its standalone count stays '-'\n" % (name, result.returncode)) + return counts + + +def render(units, stream=None, standalone=None): + lines = [] + for kind, name, caller, site in units: + if stream is None or kind in ("chained", "make"): + mid = "-" + else: + mid = str(stream.get((kind, name), "-")) + last = "-" if standalone is None or kind == "section" else str(standalone.get(name, "-")) + lines.append("\t".join((kind, name, caller, site, mid, last))) + return lines + + +def stripped(lines): + return [line.rsplit("\t", 2)[0] for line in lines if line and not line.startswith("#")] + + +def committed(): + with open(INVENTORY, encoding="utf-8") as handle: + return handle.read().splitlines() + + +def check(): + units = scan() + problems = [] + run_files = {u[1] for u in units if u[0] in ("sourced", "chained")} + make_files = {u[1] for u in units if u[0] == "make"} + for name in sorted(run_files & make_files): + problems.append("%s runs from both tests/run.sh and make test-suite" % name) + names = [u[1] for u in units if u[0] != "section"] + for name in sorted({n for n in names if names.count(n) > 1}): + problems.append("%s is called %d times; a suite must run once" % (name, names.count(name))) + for name in sorted(run_files | make_files): + if not os.path.exists(os.path.join(ROOT, name)): + problems.append("%s is called but does not exist" % name) + have = stripped(committed()) + want = stripped(render(units)) + for line in want: + if line not in have: + problems.append("missing from docs/dev/suite-inventory.tsv: %s" % line.replace("\t", " | ")) + for line in have: + if line not in want: + problems.append("stale in docs/dev/suite-inventory.tsv: %s" % line.replace("\t", " | ")) + if have != want and not problems: + problems.append("docs/dev/suite-inventory.tsv is in a different order than the suite calls") + for line in committed(): + if line and not line.startswith("#") and not all(re.fullmatch(r"-|\d+", f) for f in line.split("\t")[-2:]): + problems.append("bad pass count in docs/dev/suite-inventory.tsv: %s" % line.replace("\t", " | ")) + return problems + + +def generate(profile_path): + units = scan() + stream = attribute(units, parse_profile(profile_path)) + standalone = measure_standalone(units) + head = [ + "# Generated by tests/suite-inventory.py --generate . Columns: kind, unit, caller, call site (the run.sh section header above the call, or the make target), stream passes, standalone passes.", + "# kind: section = a run.sh '== ... ==' header; sourced = a suite sourced into run.sh; chained = a suite run as a subprocess by run.sh; make = a suite run by 'make test-suite' after run.sh.", + "# stream passes: tick lines run.sh prints under the unit (sections and sourced suites partition them); '-' = folded into the enclosing section. standalone passes: the suite's own count when run alone; '-' = it needs run.sh's fixtures or failed on the generating host. See docs/dev/suite-profile.md.", + ] + return head + render(units, stream, standalone) + + +def main(argv): + if len(argv) == 2 and argv[1] == "--check": + problems = check() + for problem in problems: + sys.stderr.write("suite-inventory: %s\n" % problem) + if problems: + return 1 + print("suite-inventory: %d units match the run.sh and Makefile calls" % len(scan())) + return 0 + if len(argv) == 3 and argv[1] == "--generate": + with open(INVENTORY, "w", encoding="utf-8") as handle: + handle.write("\n".join(generate(argv[2])) + "\n") + return 0 + sys.stderr.write("usage: suite-inventory.py --check | --generate PROFILE_STDERR\n") + return 2 + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/tests/suite-profile.py b/tests/suite-profile.py new file mode 100755 index 00000000..2d5d1450 --- /dev/null +++ b/tests/suite-profile.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +import re +import subprocess +import sys +import time + +HEADER = re.compile(r"^== (.*) ==$") +PASS_LINE = re.compile(r"\x1b\[1;32m✓\x1b\[0m ") +SUMMARY = re.compile(r"rigforge tests: \x1b\[1;32m(\d+) passed") + + +def profile(stream, clock=time.monotonic): + sections = [] + start = clock() + current = ["(preamble)", start, 0] + total_pass = None + for raw in stream: + now = clock() + line = raw.decode("utf-8", "replace").rstrip("\n") + match = HEADER.match(line) + if match: + sections.append((current[0], now - current[1], current[2])) + current = [match.group(1), now, 0] + elif PASS_LINE.search(line): + current[2] += 1 + summary = SUMMARY.search(line) + if summary: + total_pass = int(summary.group(1)) + yield raw + end = clock() + sections.append((current[0], end - current[1], current[2])) + profile.result = (sections, end - start, total_pass) + + +def report(sections, total, total_pass): + lines = ["suite-profile: seconds\tpasses\tsection"] + for name, seconds, passes in sections: + lines.append("suite-profile: %.3f\t%d\t%s" % (seconds, passes, name)) + lines.append("suite-profile: total %.3f s, %d sections, %s passed" % (total, len(sections), total_pass)) + return "\n".join(lines) + "\n" + + +def main(argv): + if len(argv) < 2 or argv[1] != "--": + sys.stderr.write("usage: suite-profile.py -- command [args...]\n") + return 2 + child = subprocess.Popen(argv[2:], stdout=subprocess.PIPE) + for raw in profile(child.stdout): + sys.stdout.buffer.write(raw) + sys.stdout.buffer.flush() + rc = child.wait() + sys.stderr.write(report(*profile.result)) + return rc + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/tests/test-suite-inventory.sh b/tests/test-suite-inventory.sh new file mode 100755 index 00000000..42946647 --- /dev/null +++ b/tests/test-suite-inventory.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +set -euo pipefail +ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT +INV="$ROOT/tests/suite-inventory.py" +fail() { + printf 'FAIL: %s\n' "$1" >&2 + exit 1 +} + +fresh_tree() { + rm -rf "$WORK/tree" + mkdir -p "$WORK/tree/tests" "$WORK/tree/docs/dev" + for f in "$ROOT"/tests/*; do + [ -f "$f" ] && ln -s "$f" "$WORK/tree/tests/$(basename "$f")" + done + rm "$WORK/tree/tests/run.sh" + cp "$ROOT/tests/run.sh" "$WORK/tree/tests/run.sh" + cp "$ROOT/Makefile" "$WORK/tree/Makefile" + cp "$ROOT/docs/dev/suite-inventory.tsv" "$WORK/tree/docs/dev/suite-inventory.tsv" +} + +check_tree() { SUITE_INVENTORY_ROOT="$WORK/tree" python3 -I "$INV" --check 2>&1; } + +expect_red() { + local name="$1" want="$2" out rc=0 + out=$(check_tree) || rc=$? + [ "$rc" -ne 0 ] || fail "$name: the check passed" + case "$out" in *"$want"*) ;; *) fail "$name: the output does not mention [$want]: $out" ;; esac + printf 'PASS: %s\n' "$name" +} + +fresh_tree +check_tree >/dev/null || fail "the committed inventory does not match run.sh and the Makefile: $(check_tree)" +printf 'PASS: the committed inventory matches the run.sh and Makefile calls\n' + +fresh_tree +printf 'echo "== unit: a section nobody inventoried =="\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a new run.sh section header is refused' 'a section nobody inventoried' + +fresh_tree +header=$(grep -m1 '^echo "== unit: parse_config' "$WORK/tree/tests/run.sh") +grep -vxF -- "$header" "$WORK/tree/tests/run.sh" >"$WORK/run.sh.new" +cp "$WORK/run.sh.new" "$WORK/tree/tests/run.sh" +expect_red 'a removed run.sh section header is refused' 'stale in docs/dev/suite-inventory.tsv' + +fresh_tree +printf 'bash "$ROOT/tests/test-doctor-json.sh"\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a suite run by both run.sh and make test-suite is refused' 'test-doctor-json.sh runs from both' + +fresh_tree +printf 'bash "$ROOT/tests/test-not-inventoried.sh"\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a new chained suite call is refused' 'test-not-inventoried.sh' + +fresh_tree +printf 'source "$ROOT/tests/daemon-pools.sh"\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a suite called a second time is refused' 'daemon-pools.sh is called 2 times' + +fresh_tree +grep -vF 'bash tests/test-doctor-json.sh' "$WORK/tree/Makefile" >"$WORK/Makefile.new" +cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +expect_red 'a suite dropped from make test-suite is refused' 'stale in docs/dev/suite-inventory.tsv' + +fresh_tree +sed 's|^\tbash tests/test-doctor-json.sh$|&\n\tbash tests/test-new-make-suite.sh|' "$WORK/tree/Makefile" >"$WORK/Makefile.new" +cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +expect_red 'a suite added to make test-suite is refused' 'test-new-make-suite.sh' + +printf 'suite inventory selftest: all checks passed\n' diff --git a/tests/test-suite-profile.sh b/tests/test-suite-profile.sh new file mode 100755 index 00000000..ff51c342 --- /dev/null +++ b/tests/test-suite-profile.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -euo pipefail +ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT +fail() { + printf 'FAIL: %s\n' "$1" >&2 + exit 1 +} + +cat >"$WORK/fake.sh" <<'FAKE' +printf 'preamble line\n' +printf '== first section ==\n' +printf ' \033[1;32m✓\033[0m one\n' +sleep 1 +printf ' \033[1;32m✓\033[0m two\n' +printf '== second section ==\n' +printf ' \033[1;32m✓\033[0m three\n' +printf 'rigforge tests: \033[1;32m3 passed\033[0m, 0 failed\n' +exit "${FAKE_RC:-0}" +FAKE + +bash "$WORK/fake.sh" >"$WORK/direct.out" +python3 -I "$ROOT/tests/suite-profile.py" -- bash "$WORK/fake.sh" >"$WORK/profiled.out" 2>"$WORK/profile.err" +cmp -s "$WORK/direct.out" "$WORK/profiled.out" || fail "profiling changed the suite's output" +printf 'PASS: the profiled run prints exactly the unprofiled output\n' + +grep -q '^suite-profile: .* 2 first section$' "$WORK/profile.err" || fail "first section pass count missing: $(cat "$WORK/profile.err")" +grep -q '^suite-profile: .* 1 second section$' "$WORK/profile.err" || fail "second section pass count missing" +grep -q '^suite-profile: total .* 3 sections, 3 passed$' "$WORK/profile.err" || fail "total line missing" +printf 'PASS: every section and the total are reported on stderr\n' + +first=$(awk -F'\t' '/first section$/ {split($1, a, " "); print a[2]}' "$WORK/profile.err") +awk -v s="$first" 'BEGIN { exit !(s >= 0.9 && s < 5) }' || fail "first section took $first s, expected about 1" +printf 'PASS: the sleeping section carries the elapsed seconds\n' + +rc=0 +FAKE_RC=7 python3 -I "$ROOT/tests/suite-profile.py" -- bash "$WORK/fake.sh" >/dev/null 2>&1 || rc=$? +[ "$rc" = 7 ] || fail "exit status 7 became $rc" +printf 'PASS: the suite exit status is preserved\n' + +rc=0 +python3 -I "$ROOT/tests/suite-profile.py" bash "$WORK/fake.sh" >/dev/null 2>&1 || rc=$? +[ "$rc" = 2 ] || fail "a call without -- exited $rc, expected 2" +printf 'PASS: a call without the separator is a usage error\n' + +printf 'suite profile selftest: all checks passed\n' From f15bbeb4660cf0bb8251a542e4c44bba7c39a511 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:28:09 -0600 Subject: [PATCH 02/11] tests: widen the inventory scanner, drop the profiler false row, commit baseline rows (part of #875) Co-Authored-By: Claude Sonnet 5.5 --- docs/dev/suite-inventory.tsv | 1 - docs/dev/suite-profile-baseline.tsv | 240 ++++++++++++++++++++++++++++ docs/dev/suite-profile.md | 15 +- tests/suite-inventory.py | 18 ++- tests/test-suite-inventory.sh | 26 +++ 5 files changed, 287 insertions(+), 13 deletions(-) create mode 100644 docs/dev/suite-profile-baseline.tsv diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index 099ae239..0c9282cb 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -250,7 +250,6 @@ sourced tests/daemon-pools.sh run.sh contract guard: wire-shape fixtures (#351) chained tests/test-l3-units.sh run.sh contract guard: wire-shape fixtures (#351) - 10 section tree hygiene: the suite writes nothing into the tracked tree (#418) run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) 2 - chained tests/docs-replay-commands.sh run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) - - -make tests/suite-profile.py Makefile test-suite - - make tests/test-doctor-json.sh Makefile test-suite - 51 make tests/test-contract-credentials.sh Makefile test-suite - 1 make tests/test-access-token-readiness.sh Makefile test-suite - 9 diff --git a/docs/dev/suite-profile-baseline.tsv b/docs/dev/suite-profile-baseline.tsv new file mode 100644 index 00000000..48e8c8d6 --- /dev/null +++ b/docs/dev/suite-profile-baseline.tsv @@ -0,0 +1,240 @@ +# Per-section median and p90 seconds over three runs of tests/run.sh (see suite-profile.md). Columns: median, p90, section. +264.4 264.7 black-box: appliance mode (pithead#797 R1) +52.9 53.3 black box: the msr-apply pre-start step still runs to the end as root +34.3 41.0 unit: e2e-real watchdog cleanup restores prior service state (#462) +9.9 10.4 unit: doctor's sister-feed check follows control's api implication (#507) +7.3 7.4 pool schema fields (#527) +6.1 7.0 unit: ensure_config_exists interactive first-run +5.9 6.0 unit: _control_commit — validate, backup, merge, atomic (#236) +5.8 6.8 unit: sister API config keys (#99) +5.5 5.8 unit: staged rebuild swaps in and prunes old build archives (#4, #612) +4.8 4.8 config ownership and setup service transitions (#529) +4.7 5.1 black-box: tune (iterative hill-climb, multi-knob) (#54) +4.6 5.1 (preamble) +4.5 4.9 unit: root-guard refuses root-run units on a tree a non-root user can write (#783) +4.5 4.7 black-box: tune variance-aware acceptance gate (#63) +4.4 4.5 unit: _control_commit — masked pool secrets survive a pools edit (#415) +4.3 4.4 contract guard: wire-shape fixtures (#351) +4.3 4.8 black-box: efficiency winner differs from perf winner (#79) +4.0 4.0 black-box: the control server (#236) +4.0 4.2 unit: control_apply orchestration + rollback (#236) +3.9 3.9 unit: daemon pool parsing and validation (#528) +3.6 4.1 black-box: tune wrmsr knob (#66) +3.4 3.4 unit: native pools array + defaults (#21, #42) +3.3 4.3 black-box: tune target follows autotune config + is announced (#tunefix) +3.1 3.7 unit: config field sanitization +3.1 3.2 black-box: autotune ranks by target (#95) +3.1 3.1 unit: _wait_miner_live (#95) +2.9 3.6 unit: api-refresh produces the response files (#99/#164) +2.7 2.8 unit: daemon node health and miner summary (#528) +2.7 3.1 unit: config_meta — revision + last-change provenance (#254) +2.5 2.5 unit: rig_lock — the shared-rig flock (#183) +2.3 2.3 unit: api-impact hammer dies with the phase and never holds the rig-lock fd (#653) +2.3 2.4 black-box: tune --live (API-measured) (#54) +2.2 2.2 unit: tor_socks5 routes RigForge's own fetches through one SOCKS5 proxy (#668) +2.2 2.2 unit: parse_config — control keys + fail-closed dual auth (#236) +2.1 2.3 unit: parse_config rejects a bash-inevaluable value in every numeric key (#412) +2.1 2.1 unit: control_upgrade orchestration — whitelist, anti-rollback, throttle, rollback (#308) +2.1 2.1 black-box: setup --dry-run plan + no-mutation guard (#146) +2.0 2.2 unit: onion setup and SOCKS diagnostics (#520) +1.9 1.9 unit: appliance rigs default tor_socks5 to the local Tor client (#696) +1.8 1.8 black-box: tune --confirm live A/B (#64) +1.7 1.9 black-box: autotune live trial + merge (#46) +1.7 1.7 unit: package marker makes upgrade, link and dependency paths package-aware (#782) +1.6 1.7 unit: doctor MSR mod verification (#66) +1.6 1.6 unit: parse_config — watchdog keys (#139) +1.5 1.5 unit: control_upgrade fails cleanly before checkout and re-runs a pending install (#816) +1.5 1.8 unit: doctor hashrate-capping hardware (#67) +1.5 2.0 unit: doctor kernel-lockdown detection (#333) +1.4 1.4 xmrig overlay: apply validation +1.4 1.6 unit: guided BIOS flow (#80) +1.3 1.3 unit: _control_upgrade_do fetch + reachability + checkout (#308, stub git) +1.3 1.8 black-box: tune min-delta gate (#54) +1.2 1.2 unit: release e2e gates fail closed (#491) +1.2 1.4 thread placement: generated config and the cap +1.2 1.4 unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) +1.2 1.2 black-box: apply reconciles the writable control path to config (#236) +1.1 1.1 unit: _api_config_json — effective writable config, secrets masked (#253) +1.1 1.1 black-box: the persistent api server (#164, the xmrig model) +1.1 1.2 black-box: backup / restore round-trip +1.0 1.2 black-box: zero-hashrate bench iteration stays quiet (#277) +1.0 1.2 xmrig overlay: tuning pins +0.9 1.2 black-box: tune samples power under load, not idle (#81) +0.9 1.2 unit: doctor pool connection (#343) +0.9 1.1 black-box: upgrade / help / unknown command (#4) +0.9 1.2 unit: CPU ISA preflight — AES-NI / AVX2 surfaced (#338) +0.9 0.9 unit: parse_config — autotune tri-state (#95) +0.9 0.9 thread placement: overlay pin validation +0.9 0.9 unit: control_apply FULL path — a deliberately stopped rig is not rolled back (#396) +0.9 0.9 black-box: tune thermal-throttle rejection (#62) +0.8 1.2 black-box: apply reports the miner's pool connection (#343) +0.8 1.0 xmrig overlay: generation order and compatibility +0.8 0.8 black-box: support-bundle collects + redacts (#147) +0.8 1.4 unit: doctor control receiver health (#278) +0.7 0.9 unit: doctor exposure posture advisory (#sec) +0.7 0.8 unit: control_apply + REAL _control_do_apply_fast — run-state criterion, not is-active alone (#381 security review) +0.7 0.9 black-box: full deployment run (stubbed, native Linux path) +0.7 0.7 unit: pool url validation (#8) +0.7 0.8 black-box: setup installs the CLI only when add_to_path is enabled (#cli) +0.7 1.0 black-box: re-run is idempotent (#5) +0.7 0.7 unit: watchdog health check (#139) +0.7 0.8 unit: DONATION validation (new) +0.7 0.7 black-box: apply on a deliberately stopped rig regenerates and holds (#396) +0.7 0.7 xmrig overlay: parse validation +0.7 0.7 black-box: tune grid search (#6) +0.6 0.7 unit: doctor miner_user + root-side MSR preset (#140) +0.6 0.6 black-box: install_control units enable/disable (#236) +0.6 0.6 fixture: the lscpu stub stays silent when its reader closes early (#419) +0.6 0.7 black-box: aborted autotune restores the pre-sweep prefetch mode (#347) +0.6 0.6 black-box: aborted tune --live restores the pre-sweep overrides (#347) +0.6 0.6 black-box: install_api_firewall renders + tears down the nft table (#142) +0.6 0.8 black-box: tune reservation-aware threads (#65) +0.6 0.6 unit: EPYC NPS detection (#201) +0.6 0.6 black-box: apply / bench (#11) +0.6 0.6 black-box: upgrade / help / unknown command (#4), rebuild path +0.5 0.6 unit: doctor MSR unverifiable — guard-input failures named (#367) +0.5 0.6 black-box: tune restarts the service after a mid-run bench crash (#276) +0.5 0.6 unit: parse_config hugepages_reserve_extra_mb + threads (#305) +0.5 0.5 unit: daemon sister-feed mode (#528) +0.5 0.5 black-box: command surface (#11) +0.5 0.6 unit: doctor health checks (#45) +0.5 0.9 black-box: macOS process control (start/status/stop) +0.5 0.5 unit: install failure leaves marker, rollback cleans it (#816) +0.5 0.7 black-box: uninstall reverts system changes (#12) +0.5 0.5 black-box: upgrade leaves a stopped miner stopped (#413) +0.5 1.0 unit: doctor BIOS/firmware advisory (#78) +0.5 0.5 xmrig overlay: feed and remote boundary +0.5 0.5 unit: daemon pool rendering and scope boundary (#528) +0.5 0.5 unit: check_prerequisites installs jq per package manager +0.5 0.6 black-box: tune power/temp recording (#54) +0.5 0.5 unit: restore takes the worker folder back before copying tune files +0.5 0.6 black-box: tune median-of-N noise handling (#54) +0.4 0.4 xmrig overlay: logging keys (#530) +0.4 0.6 black-box: tune 1gb-pages knob when reserved (#54) +0.4 0.4 watchdog: a config that fails validation still gets the thermal stop +0.4 0.5 black-box: tune huge-pages-jit knob (#7) +0.4 0.4 unit: status hugepages shapes (#341) +0.4 0.5 thread placement: doctor and bundle evidence +0.4 0.6 unit: rig label = pool user; API token off by default (#22) +0.4 0.5 unit: msr-apply preset detection + masked RMW (#140) +0.4 0.4 unit: upgrade --check (#148) +0.4 0.4 unit: apply re-renders the installed unit to the configured miner_user (#140) +0.4 0.4 unit: install_watchdog returns non-zero when it could not render (#395) +0.4 0.5 unit: MSR preset table values (#66) +0.4 0.9 black-box: tune built-in RAPL power path (#81) +0.4 0.5 unit: link_cli installs + guards the rigforge command (#cli) +0.3 0.5 unit: power measurement helpers (#81) +0.3 0.3 black-box: api-server IPv6 dual-stack bind (#243) +0.3 0.3 unit: parse_config hugepages_pool_ceiling_mb (#398) +0.3 0.4 black-box: runtime HugePages reservation is grow-only (#328) +0.3 0.3 black-box: tune --efficiency falls back without a power source (#79) +0.3 0.4 unit: doctor checks http.restricted in the live config (#135) +0.3 0.3 unit: root takes the worker folder back and removes every link inside it +0.3 0.3 unit: tune bench freq writer floors a sci-notation median to whole kHz (#266) +0.3 0.3 unit: _control_fast_path_eligible — closed allowlist classification (#381) +0.3 0.3 unit: parse_config — pool url used verbatim (#15) +0.3 0.3 unit: parse_config — workspace + token +0.3 0.3 black-box: macOS login agent (enable/disable via launchd) +0.3 0.3 black-box: consistency sweep — flags, prompts, templates (#149) +0.3 0.3 unit: _control_upgrade_do reowns what the upgrade creates to the checkout owner (#798) +0.3 0.3 unit: prepare_workspace before a root build +0.3 0.3 unit: hugepages pool ceiling bounds the grow-only write (#398) +0.3 0.3 unit: config snapshots on a root-owned tree +0.2 0.3 black-box: install_api server/timer enable/disable (#99/#164) +0.2 0.2 unit: status live summary (#143) +0.2 0.2 thread placement: tune candidates +0.2 0.2 unit: _control_upgrade_throttle_ok (#308) +0.2 0.2 max_temp_c written with a leading zero is read as a decimal number +0.2 0.2 config-gen: threads cap clamps cpu.rx (#305) +0.2 0.2 black-box: support-bundle leaks no staging tempdir on a set -e abort (#353) +0.2 0.2 unit: xmrig_already_built detection (#4) +0.2 0.2 unit: e2e-real perf record gate (#214/#267) +0.2 0.2 black-box: setup sizes the reservation for the tuned threads (#65) +0.2 0.2 unit: compute_build_jobs caps -j by RAM (#9) +0.2 0.2 unit: _miner_deliberately_stopped — the predicate the #396 decision turns on +0.2 0.2 unit: _grub_proposed co-resident keep-existing guard (#305) +0.2 0.2 unit: _apply_runtime preserve-run-state — the held rig stays stopped, tune's bare call does not (#396) +0.2 0.2 unit: apply() and _control_do_apply propagate a watchdog render failure (#395) +0.1 0.2 unit: install_service reboot-gates the start (#audit A2) +0.1 0.1 unit: _reown_worker reconciles file ownership (#audit) +0.1 0.2 unit: util/proposed-grub.sh hardware math +0.1 0.2 black-box: tune --history surfaces periodic auto-tune (Linux) (#hist) +0.1 0.2 xmrig overlay: HugePages thread sizing +0.1 0.2 unit: e2e-real retries NEXT through timer activation (#458) +0.1 0.1 unit: _reown_worker on a root-owned tree +0.1 0.1 unit: a control change snapshots through the same path +0.1 0.2 unit: _cmdline_reserved_2mb (#305) +0.1 0.1 black-box: install_watchdog timer enable/disable (#139) +0.1 0.1 black-box: install_autotune timer enable/disable (#95 tri-state) +0.1 0.1 unit: compile_xmrig pinned-commit verification (#18) +0.1 0.1 black-box: apply reconciles the sister API to config (#99) +0.1 0.2 unit: _read_temp hwmon fallback (#208) +0.1 0.1 config-gen: IPv6 host / single-pool TLS / empty-token round-trip +0.1 0.1 unit: tune seeds keep explicit false (#265) +0.1 0.1 unit: proposed-grub.sh honours the declared pool ceiling (#410) +0.1 0.2 unit: install_dependencies dnf / pacman / no-manager branches +0.1 0.1 unit: _control_do_apply_fast — reuses install_watchdog, skips apply()/xmrig restart (#381) +0.1 0.1 unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) +0.1 0.1 unit: real-git control-upgrade as root keeps a user-owned checkout user-owned (#798) +0.1 0.1 config-gen: idempotent (same inputs -> identical output) +0.1 0.1 black-box: unreachable worker API is quiet, not an abort (#364) +0.1 0.1 unit: doctor service-inactive branch (#audit) +0.1 0.1 black-box: upgrade re-tunes the new build (#95) +0.1 0.3 unit: efficiency-target acceptance gate (#79) +0.1 0.1 config-gen: generic Linux (default profile) +0.1 0.1 unit: _grub_proposed passes the declared ceiling to proposed-grub (#410) +0.1 0.1 black-box: completion script + verb-list drift guard (#145) +0.1 0.3 unit: _autotune_score efficiency needs watts, else raw H/s (#95) +0.1 0.1 unit: apt cpupower package probe — Debian / neither exists (#327) +0.1 0.2 black-box: appliance uninstall disables with --runtime too (#353) +0.1 0.1 unit: apply reports the autotune target (#95) +0.1 0.1 unit: compile_xmrig honours XMRIG_REBUILD (#4) +0.1 0.1 watchdog: a miner started during a thermal hold is stopped again +0.1 0.1 unit: _worker_root_from_config validates HOME_DIR +0.1 0.1 unit: proposed-grub.sh co-resident headroom + thread cap (#305) +0.1 0.1 unit: _script_dir resolves through symlinks (#cli) +0.1 0.1 unit: _sed_escape_replacement protects the GRUB rewrites (#134) +0.1 0.1 unit: grub_merge_cmdline preserves other kernel params (#19) +0.1 0.1 config-gen: macOS overrides +0.1 0.1 black-box: an unreachable API never aborts a tune sampling read (#364) +0.1 0.1 config-gen: multi-pool passthrough (#21, #42) +0.1 0.1 config-gen: AMD EPYC (server) +0.1 0.1 config-gen: AMD Ryzen X3D — auto, not hand-pinned (#44) +0.1 0.1 unit: _thread_candidates is SMT-aware (#4) +0.1 0.1 unit: config.minimal.json (starter) +0.1 0.1 unit: install_dependencies non-interactive auto-install (#74) +0.1 0.1 tree hygiene: the suite writes nothing into the tracked tree (#418) +0.1 0.1 config-gen: open API by default (no ACCESS_TOKEN) +0.1 0.1 config-gen: miner_user disables in-process MSR writes (#140) +0.1 0.1 black-box: apply reconciles the autotune timer to config (#95) +0.1 0.1 config-gen: explicit pool user / rig label (#22) +0.1 0.1 config-gen: socks5 passthrough (#400) +0.1 0.1 config-gen: tls-fingerprint passthrough (#115) +0.1 0.1 black-box: no ANSI escapes off-terminal (#144) +0.1 0.1 unit: parse_config — error paths +0.1 0.1 tuning sweeps: a bare re-apply leaves a thermally held miner stopped +0.1 0.1 unit: install_service with miner_user (#140) +0.1 0.1 unit: invalid daemon apply fails before side effects (#528) +0.1 0.1 unit: install_service honors SERVICE_NAME override (#133) +0.1 0.1 black-box: backup leaks no staging tempdir on a set -e abort (#353) +0.1 0.1 unit: install_dependencies adds versioned linux-tools when apt-cache has it (#74) +0.1 0.1 unit: grub_strip_managed (#12) +0.1 0.1 unit: e2e apt prerequisites retry (#449) +0.0 0.1 unit: _reown_worker hands config+log back to the miner user (#140) +0.0 0.0 black-box: restore leaks no staging tempdir on a set -e abort (#353) +0.0 0.0 unit: append_once idempotency +0.0 0.0 unit: remove_line (#12) +0.0 0.0 unit: the backup sweep hands snapshots, not the folder +0.0 0.1 black-box: uninstall without --yes aborts on 'n' (reverts nothing) +0.0 0.0 black-box: on_err names the running verb, not the stale setup default (#353) +0.0 0.0 unit: _parse_hashrate (#11) +0.0 0.0 unit: the API readers never let a curl failure escape (#353/#364) +0.0 0.0 unit: the worker folder stays root-owned only on a root-owned tree +0.0 0.1 unit: finish_deployment points at 'start' +0.0 0.0 unit: on_err reports the failing step (#9) +0.0 0.0 unit: require_traversable_checkout — DynamicUser traversal pre-flight (#362) +0.0 0.0 unit: config.reference.json (#23) +0.0 0.0 unit: e2e-real git calls survive a nested sudo (#401) +0.0 0.0 unit: control writable-keys drift guard — bash vs python (#236) +0.0 0.0 unit: VERSION is SemVer (#3) +0.0 0.0 unit: control-upgrade git calls pin safe.directory (#308) diff --git a/docs/dev/suite-profile.md b/docs/dev/suite-profile.md index 18ee7688..67f296bd 100644 --- a/docs/dev/suite-profile.md +++ b/docs/dev/suite-profile.md @@ -12,7 +12,7 @@ or double-run assertions without anyone noticing. This page is the measured RIGFORGE_SUITE_PROFILE=1 make test-suite ``` -With the variable set, the Makefile runs `tests/run.sh` through +With the variable set to any non-empty value (leave it unset to turn it off), the Makefile runs `tests/run.sh` through `tests/suite-profile.py`. Without it, the recipe is the same `bash tests/run.sh` as before. The wrapper passes the suite's stdout through unchanged and writes one `suite-profile:` line per `== ... ==` section to stderr (seconds, tick lines @@ -31,8 +31,8 @@ rows of their own. Three consecutive runs of `bash tests/run.sh` under the wrapper, with `RIGFORGE_TEST_OVERRIDES=1` as the Makefile sets it, on a Linux x86_64 host (Ubuntu 26.04, 8 cores). This is the same OS family as the `ubuntu-24.04` CI runner -but not the runner itself; CI reports a whole-job median of 8.1 minutes (p90 18.7) -on its own hardware. All three runs ended with `2858 passed, 0 failed` and the same +but not the runner itself; the operator's review on rigforge#624 reports a CI whole-job median of +8.1 minutes (p90 18.7) on its own hardware. All three runs ended with `2858 passed, 0 failed` and the same 239 runtime sections. | Run | Whole-suite seconds | @@ -67,8 +67,8 @@ take under a second. The top five take 64.6% of the section time. | black-box: tune variance-aware acceptance gate (#63) | 4.5 | 4.7 | | unit: _control_commit — masked pool secrets survive a pools edit (#415) | 4.4 | 4.5 | -The full per-section rows come from the same command; re-measure rather than copy -this table when comparing. +All 239 rows are committed in +[`suite-profile-baseline.tsv`](suite-profile-baseline.tsv). ### The parse hotspot @@ -91,7 +91,7 @@ order: - `sourced`: a suite sourced into `tests/run.sh`, sharing its pass counter (11). - `chained`: a suite `tests/run.sh` runs as a subprocess, including the ones run by loops and the Python ones (48). -- `make`: a suite `make test-suite` runs after `tests/run.sh` (34). +- `make`: a suite `make test-suite` runs after `tests/run.sh` (33). Columns: kind, unit, caller, call site (the run.sh section header above the call, or the make target), stream passes, standalone passes. @@ -111,7 +111,8 @@ failed on the host that generated the file; `tests/test-release-bundle.sh` needs The standalone count of a chained suite is not added to the stream count of the section it runs in. -Disjoint means no suite file is called twice. `tests/suite-inventory.py --check` +Disjoint means no suite file is called twice, which is the check; assertions are +not compared one by one. `tests/suite-inventory.py --check` fails when a suite appears at two call sites, or in both `tests/run.sh` and the Makefile `test-suite` recipe. Suites that those suites call in turn (for example `tests/test-donation.sh` running `tests/test-e2e-donation.sh`) are not listed. diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index d6a4cd75..ed7d6e36 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -7,9 +7,13 @@ ROOT = os.environ.get("SUITE_INVENTORY_ROOT") or os.path.dirname(os.path.dirname(os.path.abspath(__file__))) INVENTORY = os.path.join(ROOT, "docs", "dev", "suite-inventory.tsv") -HEADER = re.compile(r'^\s*echo "== (.*) =="\s*$') +HEADER = re.compile(r"""^\s*(?:echo|printf)\s+(?:-\w+\s+)?["']== (.*) ==(?:\\n)?["'](?:\s*>.*)?$""") FOR_LOOP = re.compile(r"^\s*for (\w+) in (.*?); do\b") -REFERENCE = re.compile(r"(?:bash|python3|source)\s+\"?\$ROOT/tests/(?:([A-Za-z0-9_.-]+\.(?:sh|py))|test-(\$\w+)\.sh)") +INVOKE = r"(?:(?:^|[;&|(]|\s)(?:bash|sh|python3?|source|\.)(?:\s+-[\w-]+)*\s+|(?:^\s*|[;&|(]\s*))" +ROOT_DIR = r"\"?\$\{?ROOT\}?\"?/tests/" +REFERENCE = re.compile(INVOKE + ROOT_DIR + r"(?:([A-Za-z0-9_.-]+\.(?:sh|py))|test-(\$\w+)\.sh)") +PROFILE_PREFIX = "$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )" +MAKE_COMMAND = re.compile(r"^\t(?:\w+=\S+\s+)*(?:bash|python3)\s+(?:\S+\s+)*?tests/([A-Za-z0-9_.-]+\.(?:sh|py))\s*$") PASS_SUMMARIES = ( re.compile(r"(\d+) passed"), re.compile(r"passed=(\d+)"), @@ -36,6 +40,8 @@ def run_sh_units(): units = [("section", site, "run.sh", site)] loops = {} for line in read("tests/run.sh"): + if line.lstrip().startswith("#"): + continue header = HEADER.match(line) if header: site = header.group(1) @@ -58,7 +64,7 @@ def run_sh_units(): name = "tests/" + name if name == "tests/run.sh": continue - kind = "sourced" if re.search(r"(?:source|\.)\s+\"?\$ROOT/" + re.escape(name), line) else "chained" + kind = "sourced" if re.search(r"(?:source|\.)\s+" + ROOT_DIR + re.escape(name[len("tests/"):]), line) else "chained" row = (kind, name, "run.sh", site) if row not in units: units.append(row) @@ -75,8 +81,10 @@ def make_units(): if in_target: if not line.startswith("\t"): break - match = re.search(r"tests/([A-Za-z0-9_.-]+\.(?:sh|py))", line) - if match and match.group(1) != "run.sh": + match = MAKE_COMMAND.match(line.replace(PROFILE_PREFIX, "")) + if match is None: + raise SystemExit("suite-inventory: unrecognised test-suite recipe line: %s" % line.strip()) + if match.group(1) != "run.sh": units.append(("make", "tests/" + match.group(1), "Makefile", "test-suite")) return units diff --git a/tests/test-suite-inventory.sh b/tests/test-suite-inventory.sh index 42946647..2ba04c47 100755 --- a/tests/test-suite-inventory.sh +++ b/tests/test-suite-inventory.sh @@ -67,4 +67,30 @@ sed 's|^\tbash tests/test-doctor-json.sh$|&\n\tbash tests/test-new-make-suite.sh cp "$WORK/Makefile.new" "$WORK/tree/Makefile" expect_red 'a suite added to make test-suite is refused' 'test-new-make-suite.sh' +fresh_tree +printf '. "${ROOT}/tests/test-new-dot.sh"\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a dot-sourced suite with a braced ROOT is refused' 'test-new-dot.sh' + +fresh_tree +printf 'bash -x "$ROOT"/tests/test-new-flag.sh\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a suite run with a shell flag is refused' 'test-new-flag.sh' + +fresh_tree +printf '"$ROOT/tests/test-new-direct.sh"\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a suite executed directly is refused' 'test-new-direct.sh' + +fresh_tree +printf "printf '== a printed header ==\\\\n' >&2\n" >>"$WORK/tree/tests/run.sh" +expect_red 'a printf section header is refused' 'a printed header' + +fresh_tree +printf '# bash "$ROOT/tests/test-commented.sh"\n' >>"$WORK/tree/tests/run.sh" +check_tree >/dev/null || fail "a commented-out call was counted" +printf 'PASS: a commented-out call is ignored\n' + +fresh_tree +sed 's|^\tbash tests/test-doctor-json.sh$|&\n\t$(MAKE) other-target|' "$WORK/tree/Makefile" >"$WORK/Makefile.new" +cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +expect_red 'an unrecognised test-suite recipe line is refused' 'unrecognised test-suite recipe line' + printf 'suite inventory selftest: all checks passed\n' From 7d47f8609138f34a21f4bf7704d22b2bdeeb32c1 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:42:18 -0600 Subject: [PATCH 03/11] tests: register the profile and inventory suites in the manifest (part of #875) Co-Authored-By: Claude Sonnet 5.5 --- docs/dev/suite-inventory.tsv | 2 +- tests/manifest.json | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index 0c9282cb..b597079a 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -276,7 +276,7 @@ make tests/test-revision-key.sh Makefile test-suite - 0 make tests/test-state-lib.sh Makefile test-suite - 0 make tests/test-homebrew-formula.sh Makefile test-suite - 6 make tests/test-e2e-gate.sh Makefile test-suite - 44 -make tests/manifest-selftest.sh Makefile test-suite - - +make tests/manifest-selftest.sh Makefile test-suite - 8 make tests/test-release-bundle.sh Makefile test-suite - - make tests/test-env-override-gate.sh Makefile test-suite - 0 make tests/test-server-deadline.py Makefile test-suite - 0 diff --git a/tests/manifest.json b/tests/manifest.json index 85a6ac89..8597c883 100644 --- a/tests/manifest.json +++ b/tests/manifest.json @@ -644,6 +644,43 @@ "1": "fail" }, "needs": [] + }, + { + "name": "suite-inventory", + "file": "tests/test-suite-inventory.sh", + "phases": [], + "timeout_seconds": 120, + "inputs": [], + "exit_codes": { + "0": "pass", + "1": "fail" + }, + "needs": [] + }, + { + "name": "suite-profile", + "file": "tests/test-suite-profile.sh", + "phases": [], + "timeout_seconds": 60, + "inputs": [], + "exit_codes": { + "0": "pass", + "1": "fail" + }, + "needs": [] + }, + { + "name": "suite-profile-wrapper", + "file": "tests/suite-profile.py", + "phases": [], + "timeout_seconds": 3600, + "inputs": [], + "exit_codes": { + "0": "pass", + "1": "fail", + "2": "usage" + }, + "needs": [] } ] } From f989d685dc1a24ab296628a1339209cb47a1a6ed Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:23:00 -0600 Subject: [PATCH 04/11] tests: attribute passes to real unit boundaries, regenerate atomically, profile in CI (part of #875) Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ci.yml | 2 + Makefile | 1 + docs/dev/suite-inventory.tsv | 1 + tests/manifest.json | 12 + tests/suite-inventory.py | 291 ++++++++++++++++++------- tests/suite-profile.py | 60 ++++- tests/test-suite-inventory-generate.sh | 99 +++++++++ tests/test-suite-inventory.sh | 23 +- tests/test-suite-profile.sh | 40 ++++ 9 files changed, 448 insertions(+), 81 deletions(-) create mode 100755 tests/test-suite-inventory-generate.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 273eb73d..7a826228 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,6 +146,8 @@ jobs: persist-credentials: false # zizmor: artipacked - name: "assert: test suite (make test-suite)" id: assert_test_suite + env: + RIGFORGE_SUITE_PROFILE: "1" run: make test-suite - name: "assert: categorize outcome" id: assert_categorize diff --git a/Makefile b/Makefile index ba13e4cc..d3d433b1 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ test-suite: ## rigforge test suite: unit + black-box, every CPU/OS profile simul python3 tests/test-server-deadline.py bash tests/test-build-deb.sh bash tests/test-suite-inventory.sh + bash tests/test-suite-inventory-generate.sh bash tests/test-suite-profile.sh test-e2e: ## Full end-to-end run in disposable Linux containers (needs Docker) diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index b597079a..bec22521 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -282,4 +282,5 @@ make tests/test-env-override-gate.sh Makefile test-suite - 0 make tests/test-server-deadline.py Makefile test-suite - 0 make tests/test-build-deb.sh Makefile test-suite - 0 make tests/test-suite-inventory.sh Makefile test-suite - - +make tests/test-suite-inventory-generate.sh Makefile test-suite - - make tests/test-suite-profile.sh Makefile test-suite - 5 diff --git a/tests/manifest.json b/tests/manifest.json index 8597c883..8dd7f3a0 100644 --- a/tests/manifest.json +++ b/tests/manifest.json @@ -657,6 +657,18 @@ }, "needs": [] }, + { + "name": "suite-inventory-generate", + "file": "tests/test-suite-inventory-generate.sh", + "phases": [], + "timeout_seconds": 120, + "inputs": [], + "exit_codes": { + "0": "pass", + "1": "fail" + }, + "needs": [] + }, { "name": "suite-profile", "file": "tests/test-suite-profile.sh", diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index ed7d6e36..ee65571e 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -2,16 +2,23 @@ import os import re import shlex +import shutil import subprocess import sys +import tempfile ROOT = os.environ.get("SUITE_INVENTORY_ROOT") or os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -INVENTORY = os.path.join(ROOT, "docs", "dev", "suite-inventory.tsv") +INVENTORY = os.environ.get("SUITE_INVENTORY_FILE") or os.path.join(ROOT, "docs", "dev", "suite-inventory.tsv") +SELFTEST = "tests/test-suite-inventory.sh" HEADER = re.compile(r"""^\s*(?:echo|printf)\s+(?:-\w+\s+)?["']== (.*) ==(?:\\n)?["'](?:\s*>.*)?$""") FOR_LOOP = re.compile(r"^\s*for (\w+) in (.*?); do\b") -INVOKE = r"(?:(?:^|[;&|(]|\s)(?:bash|sh|python3?|source|\.)(?:\s+-[\w-]+)*\s+|(?:^\s*|[;&|(]\s*))" -ROOT_DIR = r"\"?\$\{?ROOT\}?\"?/tests/" -REFERENCE = re.compile(INVOKE + ROOT_DIR + r"(?:([A-Za-z0-9_.-]+\.(?:sh|py))|test-(\$\w+)\.sh)") +COMMAND = r"(?:bash|sh|python3?|source|\.)(?:\s+-[\w-]+)*\s+" +ROOT_PREFIX = r"(?:\"?\$\{?ROOT\}?\"?/|\./)" +NAME = r"(?:([A-Za-z0-9_.-]+\.(?:sh|py))|test-(\$\w+)\.sh)" +REFERENCE = re.compile( + r"(?:(?:^|[;&|(]|\s)" + COMMAND + ROOT_PREFIX + r"?tests/|(?:^\s*|[;&|(]\s*)" + ROOT_PREFIX + r"tests/)" + NAME +) +SOURCE_WORD = r"(?:source|\.)\s+" PROFILE_PREFIX = "$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )" MAKE_COMMAND = re.compile(r"^\t(?:\w+=\S+\s+)*(?:bash|python3)\s+(?:\S+\s+)*?tests/([A-Za-z0-9_.-]+\.(?:sh|py))\s*$") PASS_SUMMARIES = ( @@ -19,7 +26,11 @@ re.compile(r"passed=(\d+)"), re.compile(r"Ran (\d+) tests?"), ) -PASS_LINE = re.compile(r"✓|PASS|^ok ", re.M) +PASS_LINE = re.compile(r"✓|\bPASS\b|^\s*ok[ :]", re.M) +ANSI = re.compile(r"\x1b\[[0-9;]*m") +LOG_PREFIX = re.compile(r"^.*?\d{4}-\d\d-\d\dT[\d:.]+Z ") +MESSAGE_CALL = re.compile(r"""\b\w*(?:assert\w*|ok)\s+(["'])((?:\\.|(?!\1).)*)\1""") +EXPANSION = re.compile(r"\$\{[^}]*\}|\$\([^)]*\)|\$[A-Za-z_0-9@*#?]+") LOOP_ALIAS = {"_f": "_sh"} @@ -51,7 +62,6 @@ def run_sh_units(): if loop: loops[loop.group(1)] = loop_values(loop.group(2)) for match in REFERENCE.finditer(line): - names = [] if match.group(1): names = [match.group(1)] else: @@ -60,19 +70,17 @@ def run_sh_units(): if not names: raise SystemExit("suite-inventory: unresolved loop variable $%s in tests/run.sh" % var) for name in names: - if not name.startswith("tests/"): - name = "tests/" + name + name = "tests/" + name if name == "tests/run.sh": continue - kind = "sourced" if re.search(r"(?:source|\.)\s+" + ROOT_DIR + re.escape(name[len("tests/"):]), line) else "chained" - row = (kind, name, "run.sh", site) - if row not in units: - units.append(row) + sourced = re.search(SOURCE_WORD + ROOT_PREFIX + r"?" + re.escape(name), line) + units.append(("sourced" if sourced else "chained", name, "run.sh", site)) return units def make_units(): units = [] + runners = 0 in_target = False for line in read("Makefile"): if line.startswith("test-suite:"): @@ -84,26 +92,114 @@ def make_units(): match = MAKE_COMMAND.match(line.replace(PROFILE_PREFIX, "")) if match is None: raise SystemExit("suite-inventory: unrecognised test-suite recipe line: %s" % line.strip()) - if match.group(1) != "run.sh": + if match.group(1) == "run.sh": + runners += 1 + else: units.append(("make", "tests/" + match.group(1), "Makefile", "test-suite")) - return units + return units, runners def scan(): - return run_sh_units() + make_units() + return run_sh_units() + make_units()[0] + + +def skeleton(text): + text = re.sub(r"\\(.)", r"\1", text) + parts = EXPANSION.split(text) + if len("".join(parts).strip()) < 4: + return None + return re.compile(".*?".join(re.escape(part) for part in parts), re.S) + + +def file_headers(path): + return [m.group(1) for m in (HEADER.match(line) for line in read(path)) if m] -def suite_headers(): - found = {} - for name in sorted(os.listdir(os.path.join(ROOT, "tests"))): - if name.endswith(".sh"): - for line in read("tests/" + name): - match = HEADER.match(line) - if match: - found.setdefault(match.group(1), "tests/" + name) +def file_messages(path): + found = [] + for line in read(path): + if line.lstrip().startswith("#"): + continue + for match in MESSAGE_CALL.finditer(line): + pattern = skeleton(match.group(2)) + if pattern is not None: + found.append(pattern) return found +class Matcher: + def __init__(self, units): + self.run_headers = [(skeleton(h) or re.compile(re.escape(h)), h) for h in file_headers("tests/run.sh")] + self.run_messages = file_messages("tests/run.sh") + self.sourced = {} + self.site_of = {} + for kind, name, _, site in units: + if kind == "sourced": + self.sourced[name] = { + "headers": [skeleton(h) or re.compile(re.escape(h)) for h in file_headers(name)], + "messages": file_messages(name), + } + self.site_of[name] = site + + def run_header(self, text): + for pattern, literal in self.run_headers: + if pattern.fullmatch(text): + return literal + return None + + def sourced_header(self, text): + for name, info in self.sourced.items(): + if any(p.fullmatch(text) for p in info["headers"]): + return name + return None + + def run_message(self, text): + return any(p.fullmatch(text) for p in self.run_messages) + + def sourced_message(self, name, text): + return any(p.fullmatch(text) for p in self.sourced[name]["messages"]) + + +def attribute(units, stream_text): + matcher = Matcher(units) + totals = {} + section = "(preamble)" + active = None + for raw in stream_text.splitlines(): + line = ANSI.sub("", LOG_PREFIX.sub("", raw)).strip() + if re.match(r"rigforge tests: \d+ passed", line): + break + header = re.fullmatch(r"== (.*) ==", line) + if header: + literal = matcher.run_header(header.group(1)) + if literal is not None: + section, active = literal, None + continue + name = matcher.sourced_header(header.group(1)) + if name is not None: + active = name + continue + if not line.startswith("✓ "): + continue + message = line[2:].strip() + if active is not None: + if matcher.sourced_message(active, message) or not matcher.run_message(message): + key = ("sourced", active) + else: + active = None + key = ("section", section) + else: + key = ("section", section) + if not matcher.run_message(message): + for name, info in matcher.sourced.items(): + if matcher.site_of[name] == section and matcher.sourced_message(name, message): + active = name + key = ("sourced", name) + break + totals[key] = totals.get(key, 0) + 1 + return totals + + def count_passes(text): for pattern in PASS_SUMMARIES: match = pattern.search(text) @@ -112,47 +208,49 @@ def count_passes(text): return len(PASS_LINE.findall(text)) -def parse_profile(path): - rows = [] - with open(path, encoding="utf-8", errors="replace") as handle: - for line in handle: - parts = line.rstrip("\n").split("\t") - if line.startswith("suite-profile: ") and len(parts) == 3 and parts[0] != "suite-profile: seconds": - rows.append((parts[2], int(parts[1]))) - return rows +def standalone_command(kind, name, candidate): + if name.endswith(".py"): + cmd = ["python3", "-B", name] + if name == "tests/test-control-spool-cap.py": + cmd.append("util/control-server.py") + return cmd + cmd = ["bash", name] + if kind == "chained": + cmd.append(os.path.join(ROOT, "rigforge.sh")) + return cmd -def attribute(units, profile_rows): - run_headers = {u[1] for u in units if u[0] == "section"} - owner_of = suite_headers() - totals = {} - current = None - for header, passes in profile_rows: - if header in run_headers: - current = ("section", header) - elif header in owner_of and ("sourced", owner_of[header]) in {(u[0], u[1]) for u in units}: - current = ("sourced", owner_of[header]) - if current is not None: - totals[current] = totals.get(current, 0) + passes - return totals +def measure_standalone(units, candidate): + counts = {} + scratch = tempfile.mkdtemp(prefix="suite-inventory-") + try: + return measure_in(units, candidate, scratch, counts) + finally: + shutil.rmtree(scratch, ignore_errors=True) -def measure_standalone(units): - counts = {} +def measure_in(units, candidate, scratch, counts): for kind, name, _, _ in units: - if kind == "section" or name in counts: + if kind not in ("make", "chained") or name in counts or name == SELFTEST: continue - if name.endswith(".py"): - cmd = ["python3", name] - if name == "tests/test-control-spool-cap.py": - cmd.append("util/control-server.py") - else: - cmd = ["bash", name] - if kind != "make": - cmd.append(os.path.join(ROOT, "rigforge.sh")) - env = dict(os.environ, RIGFORGE_TEST_OVERRIDES="1", PYTHONDONTWRITEBYTECODE="1") + env = dict( + os.environ, + RIGFORGE_TEST_OVERRIDES="1", + PYTHONDONTWRITEBYTECODE="1", + HOME=scratch, + TMPDIR=scratch, + SUITE_INVENTORY_FILE=candidate, + ) try: - result = subprocess.run(cmd, cwd=ROOT, env=env, capture_output=True, text=True, timeout=120, stdin=subprocess.DEVNULL) + result = subprocess.run( + standalone_command(kind, name, candidate), + cwd=ROOT, + env=env, + capture_output=True, + text=True, + timeout=120, + stdin=subprocess.DEVNULL, + ) except subprocess.TimeoutExpired: continue if result.returncode == 0: @@ -168,8 +266,8 @@ def render(units, stream=None, standalone=None): if stream is None or kind in ("chained", "make"): mid = "-" else: - mid = str(stream.get((kind, name), "-")) - last = "-" if standalone is None or kind == "section" else str(standalone.get(name, "-")) + mid = str(stream.get((kind, name), 0 if kind == "section" else "-")) + last = "-" if standalone is None or kind in ("section", "sourced") else str(standalone.get(name, "-")) lines.append("\t".join((kind, name, caller, site, mid, last))) return lines @@ -178,14 +276,17 @@ def stripped(lines): return [line.rsplit("\t", 2)[0] for line in lines if line and not line.startswith("#")] -def committed(): - with open(INVENTORY, encoding="utf-8") as handle: +def committed(path=None): + with open(path or INVENTORY, encoding="utf-8") as handle: return handle.read().splitlines() -def check(): +def check(path=None): units = scan() problems = [] + runners = make_units()[1] + if runners != 1: + problems.append("the test-suite recipe runs tests/run.sh %d times; it must run once" % runners) run_files = {u[1] for u in units if u[0] in ("sourced", "chained")} make_files = {u[1] for u in units if u[0] == "make"} for name in sorted(run_files & make_files): @@ -196,32 +297,69 @@ def check(): for name in sorted(run_files | make_files): if not os.path.exists(os.path.join(ROOT, name)): problems.append("%s is called but does not exist" % name) - have = stripped(committed()) + lines = committed(path) + have = stripped(lines) want = stripped(render(units)) for line in want: - if line not in have: + if have.count(line) < want.count(line): problems.append("missing from docs/dev/suite-inventory.tsv: %s" % line.replace("\t", " | ")) for line in have: if line not in want: problems.append("stale in docs/dev/suite-inventory.tsv: %s" % line.replace("\t", " | ")) if have != want and not problems: problems.append("docs/dev/suite-inventory.tsv is in a different order than the suite calls") - for line in committed(): + for line in lines: if line and not line.startswith("#") and not all(re.fullmatch(r"-|\d+", f) for f in line.split("\t")[-2:]): problems.append("bad pass count in docs/dev/suite-inventory.tsv: %s" % line.replace("\t", " | ")) return problems -def generate(profile_path): +HEAD = [ + "# Generated by tests/suite-inventory.py --generate . Columns: kind, unit, caller, call site (the run.sh section header above the call, or the make target), stream passes, standalone passes.", + "# kind: section = a run.sh '== ... ==' header; sourced = a suite sourced into run.sh; chained = a suite run as a subprocess by run.sh; make = a suite run by 'make test-suite' after run.sh.", + "# stream passes: tick lines run.sh printed for the unit in one run (sections and sourced suites partition them; a sourced suite keeps the ticks of its own assertions only). standalone passes: a chained or make suite's own count when run alone; '-' = it needs run.sh's fixtures or failed on the generating host. See docs/dev/suite-profile.md.", +] + + +def generate(stream_path): + try: + with open(stream_path, encoding="utf-8", errors="replace") as handle: + stream_text = handle.read() + except OSError as error: + raise SystemExit("suite-inventory: cannot read the suite output: %s" % error) + if not re.search(r"^rigforge tests: \d+ passed", "\n".join(ANSI.sub("", LOG_PREFIX.sub("", row)) for row in stream_text.splitlines()), re.M): + raise SystemExit("suite-inventory: %s is not a finished tests/run.sh output" % stream_path) units = scan() - stream = attribute(units, parse_profile(profile_path)) - standalone = measure_standalone(units) - head = [ - "# Generated by tests/suite-inventory.py --generate . Columns: kind, unit, caller, call site (the run.sh section header above the call, or the make target), stream passes, standalone passes.", - "# kind: section = a run.sh '== ... ==' header; sourced = a suite sourced into run.sh; chained = a suite run as a subprocess by run.sh; make = a suite run by 'make test-suite' after run.sh.", - "# stream passes: tick lines run.sh prints under the unit (sections and sourced suites partition them); '-' = folded into the enclosing section. standalone passes: the suite's own count when run alone; '-' = it needs run.sh's fixtures or failed on the generating host. See docs/dev/suite-profile.md.", - ] - return head + render(units, stream, standalone) + stream = attribute(units, stream_text) + directory = os.path.dirname(INVENTORY) + handle, candidate = tempfile.mkstemp(prefix=".suite-inventory-", suffix=".tsv", dir=directory) + os.close(handle) + try: + standalone = measure_standalone(units, candidate) + + def write(extra): + with open(candidate, "w", encoding="utf-8") as out: + out.write("\n".join(HEAD + render(units, stream, dict(standalone, **extra))) + "\n") + + write({}) + selftest = subprocess.run( + ["bash", SELFTEST], + cwd=ROOT, + env=dict(os.environ, RIGFORGE_TEST_OVERRIDES="1", SUITE_INVENTORY_FILE=candidate), + capture_output=True, + text=True, + stdin=subprocess.DEVNULL, + ) + if selftest.returncode != 0: + raise SystemExit("suite-inventory: the selftest fails on the new inventory:\n%s%s" % (selftest.stdout, selftest.stderr)) + write({SELFTEST: count_passes(selftest.stdout + selftest.stderr)}) + problems = check(candidate) + if problems: + raise SystemExit("suite-inventory: the new inventory does not pass --check:\n" + "\n".join(problems)) + os.replace(candidate, INVENTORY) + finally: + if os.path.exists(candidate): + os.unlink(candidate) def main(argv): @@ -234,10 +372,9 @@ def main(argv): print("suite-inventory: %d units match the run.sh and Makefile calls" % len(scan())) return 0 if len(argv) == 3 and argv[1] == "--generate": - with open(INVENTORY, "w", encoding="utf-8") as handle: - handle.write("\n".join(generate(argv[2])) + "\n") + generate(argv[2]) return 0 - sys.stderr.write("usage: suite-inventory.py --check | --generate PROFILE_STDERR\n") + sys.stderr.write("usage: suite-inventory.py --check | --generate SUITE_STDOUT_FILE\n") return 2 diff --git a/tests/suite-profile.py b/tests/suite-profile.py index 2d5d1450..69d3fa9d 100755 --- a/tests/suite-profile.py +++ b/tests/suite-profile.py @@ -40,9 +40,65 @@ def report(sections, total, total_pass): return "\n".join(lines) + "\n" +ROW = re.compile(r"suite-profile: ([0-9.]+)\t(\d+)\t(.*?)\s*$") +TOTAL = re.compile(r"suite-profile: total ([0-9.]+) s, (\d+) sections, (\S+) passed") + + +def percentile(values, fraction): + ordered = sorted(values) + rank = -(-len(ordered) * fraction // 1) + return ordered[min(len(ordered) - 1, max(0, int(rank) - 1))] + + +def median(values): + ordered = sorted(values) + middle = len(ordered) // 2 + if len(ordered) % 2: + return ordered[middle] + return (ordered[middle - 1] + ordered[middle]) / 2 + + +def aggregate(paths): + runs = [] + totals = [] + for path in paths: + rows = {} + order = [] + total = None + with open(path, encoding="utf-8", errors="replace") as handle: + for line in handle: + match = ROW.search(line) + if match: + name = match.group(3) + if name not in rows: + order.append(name) + rows[name] = float(match.group(1)) + continue + match = TOTAL.search(line) + if match: + total = float(match.group(1)) + if total is None or not rows: + raise SystemExit("suite-profile: %s has no profile report" % path) + runs.append((rows, order)) + totals.append(total) + names = runs[0][1] + for rows, order in runs[1:]: + if order != names: + raise SystemExit("suite-profile: the runs do not have the same sections") + out = [(name, median([rows[name] for rows, _ in runs]), percentile([rows[name] for rows, _ in runs], 0.9)) for name in names] + return totals, sorted(out, key=lambda row: -row[1]) + + def main(argv): - if len(argv) < 2 or argv[1] != "--": - sys.stderr.write("usage: suite-profile.py -- command [args...]\n") + if len(argv) >= 3 and argv[1] == "--aggregate": + totals, rows = aggregate(argv[2:]) + print("# Per-section median and p90 seconds over %d runs of tests/run.sh (see suite-profile.md). Columns: median, p90, section." % len(totals)) + print("# whole-suite run.sh seconds per run: %s; median %.1f, p90 %.1f" % (", ".join("%.1f" % t for t in totals), median(totals), percentile(totals, 0.9))) + for name, mid, high in rows: + print("%.1f\t%.1f\t%s" % (mid, high, name)) + return 0 + if len(argv) < 3 or argv[1] != "--": + sys.stderr.write("usage: suite-profile.py -- command [args...] | --aggregate report...\n") return 2 child = subprocess.Popen(argv[2:], stdout=subprocess.PIPE) for raw in profile(child.stdout): diff --git a/tests/test-suite-inventory-generate.sh b/tests/test-suite-inventory-generate.sh new file mode 100755 index 00000000..e684f878 --- /dev/null +++ b/tests/test-suite-inventory-generate.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +set -euo pipefail +ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +WORK=$(mktemp -d) +trap 'rm -rf "$WORK"' EXIT +INV="$ROOT/tests/suite-inventory.py" +TREE="$WORK/tree" +fail() { + printf 'FAIL: %s\n' "$1" >&2 + exit 1 +} + +mkdir -p "$TREE/tests" "$TREE/docs/dev" +cat >"$TREE/Makefile" <<'MAKEFILE' +test-suite: + bash tests/run.sh + bash tests/test-a.sh + bash tests/test-suite-inventory.sh +MAKEFILE +cat >"$TREE/tests/run.sh" <<'RUNSH' +echo "== first section ==" +source "$ROOT/tests/frag-headed.sh" +ok "parent after headed return" +echo "== linux $HOST_OS deployment ==" +source "$ROOT/tests/frag-bare.sh" +ok "parent after bare return" +bash "$ROOT/tests/test-chained.sh" "$SCRIPT" +RUNSH +cat >"$TREE/tests/frag-headed.sh" <<'FRAG' +echo "== headed fragment ==" +touch "$FRAG_SENTINEL" +assert_eq "headed one" a a +assert_eq "headed two" a a +FRAG +cat >"$TREE/tests/frag-bare.sh" <<'FRAG' +touch "$FRAG_SENTINEL" +assert_eq "bare fragment check $n" a a +FRAG +cat >"$TREE/tests/test-a.sh" <<'SUITE' +printf ' ok one\n ok two\n' +SUITE +cat >"$TREE/tests/test-chained.sh" <<'SUITE' +printf 'chained: 2 passed\n' +SUITE +cat >"$TREE/tests/test-suite-inventory.sh" <<'SUITE' +[ -s "$SUITE_INVENTORY_FILE" ] || exit 1 +printf 'selftest: 5 passed\n' +SUITE +printf 'OLD\n' >"$TREE/docs/dev/suite-inventory.tsv" +tick=$'\033[1;32m✓\033[0m' +{ + printf '2026-01-01T00:00:00.1Z preamble line\n' + printf '2026-01-01T00:00:00.2Z == first section ==\n' + printf '2026-01-01T00:00:00.3Z %s headed one\n' "$tick" + printf '2026-01-01T00:00:00.4Z %s headed two\n' "$tick" + printf '2026-01-01T00:00:00.5Z %s parent after headed return\n' "$tick" + printf '2026-01-01T00:00:00.6Z == linux Debian deployment ==\n' + printf '2026-01-01T00:00:00.7Z %s bare fragment check 1\n' "$tick" + printf '2026-01-01T00:00:00.8Z %s bare fragment check 2\n' "$tick" + printf '2026-01-01T00:00:00.9Z %s parent after bare return\n' "$tick" + printf '2026-01-01T00:00:01.0Z rigforge tests: \033[1;32m5 passed\033[0m, 0 failed\n' + printf '2026-01-01T00:00:01.1Z %s a later suite tick\n' "$tick" +} >"$WORK/stream.txt" + +generate() { + FRAG_SENTINEL="$WORK/sentinel" SUITE_INVENTORY_ROOT="$TREE" python3 -I -B "$INV" --generate "$1" 2>&1 +} + +before=$(cksum <"$TREE/docs/dev/suite-inventory.tsv") +rc=0 +generate "$WORK/missing.txt" >"$WORK/out" || rc=$? +[ "$rc" -ne 0 ] || fail "a missing suite output was accepted" +[ "$(cksum <"$TREE/docs/dev/suite-inventory.tsv")" = "$before" ] || fail "a missing suite output changed the inventory" +printf 'unfinished\n' >"$WORK/unfinished.txt" +rc=0 +generate "$WORK/unfinished.txt" >"$WORK/out" || rc=$? +[ "$rc" -ne 0 ] || fail "an unfinished suite output was accepted" +[ "$(cksum <"$TREE/docs/dev/suite-inventory.tsv")" = "$before" ] || fail "an unfinished suite output changed the inventory" +printf 'PASS: a failed regeneration leaves the committed bytes alone\n' + +generate "$WORK/stream.txt" >"$WORK/out" || fail "regeneration failed: $(cat "$WORK/out")" +[ ! -e "$WORK/sentinel" ] || fail "regeneration launched a sourced fragment on its own" +printf 'PASS: regeneration never launches a sourced fragment by itself\n' +for leftover in "$TREE"/docs/dev/.suite-inventory-*; do + [ ! -e "$leftover" ] || fail "regeneration left a temporary file" +done + +row() { awk -F'\t' -v k="$1" -v u="$2" '$1 == k && $2 == u { print $5 "/" $6 }' "$TREE/docs/dev/suite-inventory.tsv"; } +want() { [ "$(row "$1" "$2")" = "$3" ] || fail "$1 $2: expected $3, got [$(row "$1" "$2")]"; } +want section 'first section' 1/- +want sourced tests/frag-headed.sh 2/- +want section 'linux $HOST_OS deployment' 1/- +want sourced tests/frag-bare.sh 2/- +want chained tests/test-chained.sh -/2 +want make tests/test-a.sh -/2 +want make tests/test-suite-inventory.sh -/5 +printf 'PASS: every unit carries its own count, across a source return, an expanded header, indented ok lines and a log prefix\n' + +printf 'suite inventory generation selftest: all checks passed\n' diff --git a/tests/test-suite-inventory.sh b/tests/test-suite-inventory.sh index 2ba04c47..9feb668d 100755 --- a/tests/test-suite-inventory.sh +++ b/tests/test-suite-inventory.sh @@ -18,10 +18,10 @@ fresh_tree() { rm "$WORK/tree/tests/run.sh" cp "$ROOT/tests/run.sh" "$WORK/tree/tests/run.sh" cp "$ROOT/Makefile" "$WORK/tree/Makefile" - cp "$ROOT/docs/dev/suite-inventory.tsv" "$WORK/tree/docs/dev/suite-inventory.tsv" + cp "${SUITE_INVENTORY_FILE:-$ROOT/docs/dev/suite-inventory.tsv}" "$WORK/tree/docs/dev/suite-inventory.tsv" } -check_tree() { SUITE_INVENTORY_ROOT="$WORK/tree" python3 -I "$INV" --check 2>&1; } +check_tree() { env -u SUITE_INVENTORY_FILE SUITE_INVENTORY_ROOT="$WORK/tree" python3 -I -B "$INV" --check 2>&1; } expect_red() { local name="$1" want="$2" out rc=0 @@ -93,4 +93,23 @@ sed 's|^\tbash tests/test-doctor-json.sh$|&\n\t$(MAKE) other-target|' "$WORK/tre cp "$WORK/Makefile.new" "$WORK/tree/Makefile" expect_red 'an unrecognised test-suite recipe line is refused' 'unrecognised test-suite recipe line' +fresh_tree +sed 's|^\(source "$ROOT/tests/daemon-pools.sh"\)$|\1\n\1|' "$WORK/tree/tests/run.sh" >"$WORK/run.sh.new" +cp "$WORK/run.sh.new" "$WORK/tree/tests/run.sh" +expect_red 'a repeated call in the same section is refused' 'daemon-pools.sh is called 2 times' + +fresh_tree +printf 'bash tests/test-doctor-json.sh\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a repository-relative call to a make suite is refused' 'test-doctor-json.sh runs from both' + +fresh_tree +grep -vxF $'\tbash tests/run.sh' "$WORK/tree/Makefile" | sed '/^\t\$(if \$(RIGFORGE_SUITE_PROFILE)/d' >"$WORK/Makefile.new" +cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +expect_red 'a test-suite recipe without tests/run.sh is refused' 'runs tests/run.sh 0 times' + +fresh_tree +sed 's|^\t\$(if \$(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )bash tests/run.sh$|&\n&|' "$WORK/tree/Makefile" >"$WORK/Makefile.new" +cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +expect_red 'a test-suite recipe that runs tests/run.sh twice is refused' 'runs tests/run.sh 2 times' + printf 'suite inventory selftest: all checks passed\n' diff --git a/tests/test-suite-profile.sh b/tests/test-suite-profile.sh index ff51c342..716b8a73 100755 --- a/tests/test-suite-profile.sh +++ b/tests/test-suite-profile.sh @@ -44,4 +44,44 @@ python3 -I "$ROOT/tests/suite-profile.py" bash "$WORK/fake.sh" >/dev/null 2>&1 | [ "$rc" = 2 ] || fail "a call without -- exited $rc, expected 2" printf 'PASS: a call without the separator is a usage error\n' +first_recipe() { env "$@" make --no-print-directory -n -C "$ROOT" test-suite | sed -n 1p; } +mkdir -p "$WORK/tree/tests" +ln -s "$ROOT/tests/suite-profile.py" "$WORK/tree/tests/suite-profile.py" +cp "$WORK/fake.sh" "$WORK/tree/tests/run.sh" +default_line=$(first_recipe -u RIGFORGE_SUITE_PROFILE) +profiled_line=$(first_recipe RIGFORGE_SUITE_PROFILE=1) +[ "$default_line" = 'bash tests/run.sh' ] || fail "the default recipe is [$default_line], not the plain suite run" +(cd "$WORK/tree" && bash -c "$default_line") >"$WORK/make-default.out" 2>"$WORK/make-default.err" +cmp -s "$WORK/direct.out" "$WORK/make-default.out" || fail "the default recipe changed the output" +grep -q 'suite-profile:' "$WORK/make-default.err" && fail "the default recipe printed a profile" +printf 'PASS: make test-suite runs the plain suite without the toggle\n' + +case "$profiled_line" in *'tests/suite-profile.py -- bash tests/run.sh') ;; *) fail "the toggled recipe is [$profiled_line]" ;; esac +(cd "$WORK/tree" && bash -c "$profiled_line") >"$WORK/make-profiled.out" 2>"$WORK/make-profiled.err" +cmp -s "$WORK/direct.out" "$WORK/make-profiled.out" || fail "the toggled recipe changed the output" +grep -q '^suite-profile: total .* 3 sections, 3 passed$' "$WORK/make-profiled.err" || fail "the toggled recipe printed no report" +rc=0 +(cd "$WORK/tree" && FAKE_RC=7 bash -c "$profiled_line") >/dev/null 2>&1 || rc=$? +[ "$rc" = 7 ] || fail "the toggled recipe turned exit status 7 into $rc" +printf 'PASS: RIGFORGE_SUITE_PROFILE=1 profiles through the make recipe with the same output and exit status\n' + +rc=0 +python3 -I "$ROOT/tests/suite-profile.py" -- >/dev/null 2>&1 || rc=$? +[ "$rc" = 2 ] || fail "a bare separator exited $rc, expected 2" +printf 'PASS: a bare separator is a usage error\n' + +for n in 1 2 3; do + { + printf '2026-01-01T00:00:0%d.0Z suite-profile: seconds\tpasses\tsection\n' "$n" + printf '2026-01-01T00:00:0%d.1Z suite-profile: %d.000\t2\tfast section\n' "$n" "$n" + printf '2026-01-01T00:00:0%d.2Z suite-profile: %d.500\t1\tslow section\n' "$n" "$((n * 10))" + printf '2026-01-01T00:00:0%d.3Z suite-profile: total %d.500 s, 2 sections, 3 passed\n' "$n" "$((n * 10 + n))" + } >"$WORK/run$n.log" +done +python3 -I "$ROOT/tests/suite-profile.py" --aggregate "$WORK/run1.log" "$WORK/run2.log" "$WORK/run3.log" >"$WORK/aggregate.tsv" +grep -qxF $'20.5\t30.5\tslow section' "$WORK/aggregate.tsv" || fail "slow section median/p90 wrong: $(cat "$WORK/aggregate.tsv")" +grep -qxF $'2.0\t3.0\tfast section' "$WORK/aggregate.tsv" || fail "fast section median/p90 wrong" +grep -q '^# whole-suite run.sh seconds per run: 11.5, 22.5, 33.5; median 22.5, p90 33.5$' "$WORK/aggregate.tsv" || fail "totals wrong: $(cat "$WORK/aggregate.tsv")" +printf 'PASS: --aggregate reads timestamped CI logs and reports per-section and whole-suite median and p90\n' + printf 'suite profile selftest: all checks passed\n' From 5302e4ca2cf52f7e7b40c4d3954508d392534c6c Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 15:09:46 -0600 Subject: [PATCH 05/11] tests: CI-runner baseline, per-unit counts from the CI log, review fixes (part of #875) Co-Authored-By: Claude Sonnet 5.5 --- docs/dev/suite-inventory.tsv | 78 ++--- docs/dev/suite-profile-baseline.tsv | 377 +++++++++++++------------ docs/dev/suite-profile.md | 178 +++++++----- tests/suite-inventory.py | 13 +- tests/test-suite-inventory-generate.sh | 2 +- 5 files changed, 345 insertions(+), 303 deletions(-) diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index bec22521..4e7a879c 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -1,6 +1,6 @@ -# Generated by tests/suite-inventory.py --generate . Columns: kind, unit, caller, call site (the run.sh section header above the call, or the make target), stream passes, standalone passes. +# Generated by tests/suite-inventory.py --generate . Columns: kind, unit, caller, call site (the run.sh section header above the call, or the make target), stream passes, standalone passes. # kind: section = a run.sh '== ... ==' header; sourced = a suite sourced into run.sh; chained = a suite run as a subprocess by run.sh; make = a suite run by 'make test-suite' after run.sh. -# stream passes: tick lines run.sh prints under the unit (sections and sourced suites partition them); '-' = folded into the enclosing section. standalone passes: the suite's own count when run alone; '-' = it needs run.sh's fixtures or failed on the generating host. See docs/dev/suite-profile.md. +# stream passes: tick lines run.sh printed for the unit in one run (sections and sourced suites partition them; a sourced suite keeps the ticks of its own assertions only). standalone passes: a chained or make suite's own count when run alone; '-' = it needs run.sh's fixtures or failed on the generating host. See docs/dev/suite-profile.md. section (preamble) run.sh (preamble) 58 - chained tests/test-thread-profile.py run.sh (preamble) - 18 chained tests/test-suite-liveness.sh run.sh (preamble) - 8 @@ -10,14 +10,14 @@ chained tests/test-xmrig-logging.sh run.sh (preamble) - 11 chained tests/test-config-ownership.sh run.sh (preamble) - 22 chained tests/test-feed-identity.sh run.sh (preamble) - 35 chained tests/test-grub-edit.sh run.sh (preamble) - 18 -chained tests/test-token-error-text.sh run.sh (preamble) - 0 -chained tests/test-worker-root-owned.sh run.sh (preamble) - 0 +chained tests/test-token-error-text.sh run.sh (preamble) - 8 +chained tests/test-worker-root-owned.sh run.sh (preamble) - 109 chained tests/test-config-apply-state.sh run.sh (preamble) - 1 chained tests/test-hugepages-ceiling.sh run.sh (preamble) - 19 chained tests/test-benchmark-verification.sh run.sh (preamble) - 50 chained tests/test-benchmark-support.sh run.sh (preamble) - 1 chained tests/test-stress.sh run.sh (preamble) - 22 -chained tests/test-perf-submission.sh run.sh (preamble) - - +chained tests/test-perf-submission.sh run.sh (preamble) - 1 chained tests/test-e2e-selftest.sh run.sh (preamble) - 1 chained tests/test-root-guard.sh run.sh (preamble) - 46 chained tests/test-control-hardening.sh run.sh (preamble) - 0 @@ -28,7 +28,7 @@ section unit: pool url validation (#8) run.sh unit: pool url validation (#8) 9 - section unit: native pools array + defaults (#21, #42) run.sh unit: native pools array + defaults (#21, #42) 65 - chained tests/test-pool-fields.sh run.sh unit: native pools array + defaults (#21, #42) - - section unit: config field sanitization run.sh unit: config field sanitization 42 - -chained tests/test-host-port-message.sh run.sh unit: config field sanitization - 0 +chained tests/test-host-port-message.sh run.sh unit: config field sanitization - 30 section unit: parse_config — workspace + token run.sh unit: parse_config — workspace + token 4 - section unit: rig label = pool user; API token off by default (#22) run.sh unit: rig label = pool user; API token off by default (#22) 4 - section unit: parse_config — error paths run.sh unit: parse_config — error paths 2 - @@ -96,14 +96,14 @@ section unit: install_watchdog returns non-zero when it could not render (#395) section unit: parse_config — watchdog keys (#139) run.sh unit: parse_config — watchdog keys (#139) 16 - chained tests/test-watchdog-thermal-retry.sh run.sh unit: parse_config — watchdog keys (#139) - 1 chained tests/test-watchdog-shared-host-guard.sh run.sh unit: parse_config — watchdog keys (#139) - 1 -chained tests/test-watchdog-fail-safe.sh run.sh unit: parse_config — watchdog keys (#139) - 0 +chained tests/test-watchdog-fail-safe.sh run.sh unit: parse_config — watchdog keys (#139) - 32 section unit: watchdog health check (#139) run.sh unit: watchdog health check (#139) 39 - section unit: parse_config — autotune tri-state (#95) run.sh unit: parse_config — autotune tri-state (#95) 9 - section black-box: autotune ranks by target (#95) run.sh black-box: autotune ranks by target (#95) 10 - -chained tests/test-autotune-noise.sh run.sh black-box: autotune ranks by target (#95) - 0 +chained tests/test-autotune-noise.sh run.sh black-box: autotune ranks by target (#95) - 71 section black-box: upgrade re-tunes the new build (#95) run.sh black-box: upgrade re-tunes the new build (#95) 7 - -section unit: _wait_miner_live (#95) run.sh unit: _wait_miner_live (#95) 2 - -section unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) 6 - +section unit: _wait_miner_live (#95) run.sh unit: _wait_miner_live (#95) 8 - +section unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) 0 - chained tests/test-config-mode-token-scope.sh run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) - 0 section black-box: support-bundle collects + redacts (#147) run.sh black-box: support-bundle collects + redacts (#147) 21 - section black-box: setup --dry-run plan + no-mutation guard (#146) run.sh black-box: setup --dry-run plan + no-mutation guard (#146) 67 - @@ -127,8 +127,8 @@ section unit: install_service with miner_user (#140) run.sh unit: install_servic section unit: msr-apply preset detection + masked RMW (#140) run.sh unit: msr-apply preset detection + masked RMW (#140) 17 - section unit: _reown_worker hands config+log back to the miner user (#140) run.sh unit: _reown_worker hands config+log back to the miner user (#140) 2 - section unit: apply re-renders the installed unit to the configured miner_user (#140) run.sh unit: apply re-renders the installed unit to the configured miner_user (#140) 4 - -section unit: install_service honors SERVICE_NAME override (#133) run.sh unit: install_service honors SERVICE_NAME override (#133) 36 - -section black-box: full deployment run (stubbed, native $HOST_OS path) run.sh black-box: full deployment run (stubbed, native $HOST_OS path) - - +section unit: install_service honors SERVICE_NAME override (#133) run.sh unit: install_service honors SERVICE_NAME override (#133) 4 - +section black-box: full deployment run (stubbed, native $HOST_OS path) run.sh black-box: full deployment run (stubbed, native $HOST_OS path) 32 - section black-box: re-run is idempotent (#5) run.sh black-box: re-run is idempotent (#5) 8 - section black-box: setup installs the CLI only when add_to_path is enabled (#cli) run.sh black-box: setup installs the CLI only when add_to_path is enabled (#cli) 1 - section black-box: no ANSI escapes off-terminal (#144) run.sh black-box: no ANSI escapes off-terminal (#144) 2 - @@ -140,8 +140,8 @@ section unit: doctor BIOS/firmware advisory (#78) run.sh unit: doctor BIOS/firmw section unit: doctor kernel-lockdown detection (#333) run.sh unit: doctor kernel-lockdown detection (#333) 29 - section unit: CPU ISA preflight — AES-NI / AVX2 surfaced (#338) run.sh unit: CPU ISA preflight — AES-NI / AVX2 surfaced (#338) 17 - section unit: doctor control receiver health (#278) run.sh unit: doctor control receiver health (#278) 11 - -section unit: doctor pool connection (#343) run.sh unit: doctor pool connection (#343) 13 - -sourced tests/onion-proxy.sh run.sh unit: doctor pool connection (#343) 62 0 +section unit: doctor pool connection (#343) run.sh unit: doctor pool connection (#343) 14 - +sourced tests/onion-proxy.sh run.sh unit: doctor pool connection (#343) 61 - section unit: EPYC NPS detection (#201) run.sh unit: EPYC NPS detection (#201) 12 - section unit: guided BIOS flow (#80) run.sh unit: guided BIOS flow (#80) 57 - section unit: doctor service-inactive branch (#audit) run.sh unit: doctor service-inactive branch (#audit) 3 - @@ -161,7 +161,7 @@ section black-box: tune (iterative hill-climb, multi-knob) (#54) run.sh black-bo section black-box: zero-hashrate bench iteration stays quiet (#277) run.sh black-box: zero-hashrate bench iteration stays quiet (#277) 4 - section black-box: tune restarts the service after a mid-run bench crash (#276) run.sh black-box: tune restarts the service after a mid-run bench crash (#276) 2 - section black-box: tune target follows autotune config + is announced (#tunefix) run.sh black-box: tune target follows autotune config + is announced (#tunefix) 20 - -chained tests/test-sudo-env-forward.sh run.sh black-box: tune target follows autotune config + is announced (#tunefix) - 0 +chained tests/test-sudo-env-forward.sh run.sh black-box: tune target follows autotune config + is announced (#tunefix) - 7 section black-box: tune --history surfaces periodic auto-tune (Linux) (#hist) run.sh black-box: tune --history surfaces periodic auto-tune (Linux) (#hist) 7 - section black-box: tune median-of-N noise handling (#54) run.sh black-box: tune median-of-N noise handling (#54) 4 - section black-box: tune min-delta gate (#54) run.sh black-box: tune min-delta gate (#54) 3 - @@ -188,15 +188,15 @@ section black-box: tune reservation-aware threads (#65) run.sh black-box: tune r section black-box: setup sizes the reservation for the tuned threads (#65) run.sh black-box: setup sizes the reservation for the tuned threads (#65) 6 - section black-box: runtime HugePages reservation is grow-only (#328) run.sh black-box: runtime HugePages reservation is grow-only (#328) 7 - section unit: hugepages pool ceiling bounds the grow-only write (#398) run.sh unit: hugepages pool ceiling bounds the grow-only write (#398) 13 - -section black-box: appliance mode (pithead#797 R1) run.sh black-box: appliance mode (pithead#797 R1) 99 - -sourced tests/test-donation-tor.sh run.sh black-box: appliance mode (pithead#797 R1) - - +section black-box: appliance mode (pithead#797 R1) run.sh black-box: appliance mode (pithead#797 R1) 91 - +sourced tests/test-donation-tor.sh run.sh black-box: appliance mode (pithead#797 R1) 8 - section black-box: autotune live trial + merge (#46) run.sh black-box: autotune live trial + merge (#46) 12 - section black-box: aborted autotune restores the pre-sweep prefetch mode (#347) run.sh black-box: aborted autotune restores the pre-sweep prefetch mode (#347) 7 - section black-box: tune grid search (#6) run.sh black-box: tune grid search (#6) 5 - section black-box: tune huge-pages-jit knob (#7) run.sh black-box: tune huge-pages-jit knob (#7) 3 - section unit: _thread_candidates is SMT-aware (#4) run.sh unit: _thread_candidates is SMT-aware (#4) 5 - section black-box: backup / restore round-trip run.sh black-box: backup / restore round-trip 24 - -chained tests/test-config-write-safety.sh run.sh black-box: backup / restore round-trip - 0 +chained tests/test-config-write-safety.sh run.sh black-box: backup / restore round-trip - 23 section black-box: backup leaks no staging tempdir on a set -e abort (#353) run.sh black-box: backup leaks no staging tempdir on a set -e abort (#353) 2 - section black-box: restore leaks no staging tempdir on a set -e abort (#353) run.sh black-box: restore leaks no staging tempdir on a set -e abort (#353) 2 - section black-box: support-bundle leaks no staging tempdir on a set -e abort (#353) run.sh black-box: support-bundle leaks no staging tempdir on a set -e abort (#353) 2 - @@ -206,21 +206,21 @@ section unit: config.minimal.json (starter) run.sh unit: config.minimal.json (st section unit: sister API config keys (#99) run.sh unit: sister API config keys (#99) 42 - chained tests/test-sister-reconcile.sh run.sh unit: sister API config keys (#99) - - section black-box: install_api_firewall renders + tears down the nft table (#142) run.sh black-box: install_api_firewall renders + tears down the nft table (#142) 16 - -chained tests/test-api-firewall-path.sh run.sh black-box: install_api_firewall renders + tears down the nft table (#142) - 0 +chained tests/test-api-firewall-path.sh run.sh black-box: install_api_firewall renders + tears down the nft table (#142) - 29 section black-box: install_api server/timer enable/disable (#99/#164) run.sh black-box: install_api server/timer enable/disable (#99/#164) 26 - -section unit: api-refresh produces the response files (#99/#164) run.sh unit: api-refresh produces the response files (#99/#164) 43 - -sourced tests/test-api-refresh-liveness.sh run.sh unit: api-refresh produces the response files (#99/#164) 32 - +section unit: api-refresh produces the response files (#99/#164) run.sh unit: api-refresh produces the response files (#99/#164) 28 - +sourced tests/test-api-refresh-liveness.sh run.sh unit: api-refresh produces the response files (#99/#164) 47 - chained tests/test-api-refresh-spawns.sh run.sh unit: api-refresh produces the response files (#99/#164) - 110 -chained tests/test-tune-files-regular.sh run.sh unit: api-refresh produces the response files (#99/#164) - 0 +chained tests/test-tune-files-regular.sh run.sh unit: api-refresh produces the response files (#99/#164) - 15 section black-box: the persistent api server (#164, the xmrig model) run.sh black-box: the persistent api server (#164, the xmrig model) 26 - section black-box: api-server IPv6 dual-stack bind (#243) run.sh black-box: api-server IPv6 dual-stack bind (#243) 3 - section unit: parse_config — control keys + fail-closed dual auth (#236) run.sh unit: parse_config — control keys + fail-closed dual auth (#236) 25 - section black-box: install_control units enable/disable (#236) run.sh black-box: install_control units enable/disable (#236) 31 - chained tests/test-control-firewall.sh run.sh black-box: install_control units enable/disable (#236) - - section unit: _control_commit — validate, backup, merge, atomic (#236) run.sh unit: _control_commit — validate, backup, merge, atomic (#236) 41 - -chained tests/test-control-status-write.sh run.sh unit: _control_commit — validate, backup, merge, atomic (#236) - 1 +chained tests/test-control-status-write.sh run.sh unit: _control_commit — validate, backup, merge, atomic (#236) - 31 section unit: _api_config_json — effective writable config, secrets masked (#253) run.sh unit: _api_config_json — effective writable config, secrets masked (#253) 18 - -chained tests/test-jq-config-input.sh run.sh unit: _api_config_json — effective writable config, secrets masked (#253) - 0 +chained tests/test-jq-config-input.sh run.sh unit: _api_config_json — effective writable config, secrets masked (#253) - 20 section unit: config_meta — revision + last-change provenance (#254) run.sh unit: config_meta — revision + last-change provenance (#254) 23 - section unit: _control_commit — masked pool secrets survive a pools edit (#415) run.sh unit: _control_commit — masked pool secrets survive a pools edit (#415) 55 - section unit: _control_fast_path_eligible — closed allowlist classification (#381) run.sh unit: _control_fast_path_eligible — closed allowlist classification (#381) 13 - @@ -231,7 +231,7 @@ section unit: apply() and _control_do_apply propagate a watchdog render failure section unit: control_apply orchestration + rollback (#236) run.sh unit: control_apply orchestration + rollback (#236) 77 - sourced tests/test-control-upgrade.sh run.sh unit: control_apply orchestration + rollback (#236) 68 - sourced tests/test-fetch-proxy.sh run.sh unit: control_apply orchestration + rollback (#236) 101 - -sourced tests/test-package-mode.sh run.sh unit: control_apply orchestration + rollback (#236) 30 0 +sourced tests/test-package-mode.sh run.sh unit: control_apply orchestration + rollback (#236) 30 - section unit: e2e-real git calls survive a nested sudo (#401) run.sh unit: e2e-real git calls survive a nested sudo (#401) 3 - section unit: control writable-keys drift guard — bash vs python (#236) run.sh unit: control writable-keys drift guard — bash vs python (#236) 1 - section black-box: the control server (#236) run.sh black-box: the control server (#236) 75 - @@ -244,12 +244,12 @@ section unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline p sourced tests/test-e2e-gate-fail-closed.sh run.sh unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) 152 - sourced tests/test-e2e-hammer.sh run.sh unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) 16 - section unit: rig_lock — the shared-rig flock (#183) run.sh unit: rig_lock — the shared-rig flock (#183) 24 - -section contract guard: wire-shape fixtures (#351) run.sh contract guard: wire-shape fixtures (#351) 9 - -sourced tests/test-randomx-mode.sh run.sh contract guard: wire-shape fixtures (#351) - 1 -sourced tests/daemon-pools.sh run.sh contract guard: wire-shape fixtures (#351) 142 - +section contract guard: wire-shape fixtures (#351) run.sh contract guard: wire-shape fixtures (#351) 10 - +sourced tests/test-randomx-mode.sh run.sh contract guard: wire-shape fixtures (#351) - - +sourced tests/daemon-pools.sh run.sh contract guard: wire-shape fixtures (#351) 141 - chained tests/test-l3-units.sh run.sh contract guard: wire-shape fixtures (#351) - 10 section tree hygiene: the suite writes nothing into the tracked tree (#418) run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) 2 - -chained tests/docs-replay-commands.sh run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) - - +chained tests/docs-replay-commands.sh run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) - 0 make tests/test-doctor-json.sh Makefile test-suite - 51 make tests/test-contract-credentials.sh Makefile test-suite - 1 make tests/test-access-token-readiness.sh Makefile test-suite - 9 @@ -258,12 +258,12 @@ make tests/test-staged-rebuild.sh Makefile test-suite - 1 make tests/test-package-upgrade.sh Makefile test-suite - 0 make tests/test-dependabot-coverage.sh Makefile test-suite - 1 make tests/test-security-backlog-expiry.sh Makefile test-suite - 1 -make tests/test-codeql-workflow.sh Makefile test-suite - 0 +make tests/test-codeql-workflow.sh Makefile test-suite - 1 make tests/test-tool-pin-watch.sh Makefile test-suite - 8 make tests/test-xmrig-bump.sh Makefile test-suite - 1 make tests/test-osv-file-issue.sh Makefile test-suite - 5 make tests/test-file-security-issue.sh Makefile test-suite - 3 -make tests/test-workflow-contract.sh Makefile test-suite - 0 +make tests/test-workflow-contract.sh Makefile test-suite - 2 make tests/test-docs-replay.py Makefile test-suite - 18 make tests/test-api-allowlist-probe.sh Makefile test-suite - 0 make tests/test-e2e-docs-guest.sh Makefile test-suite - 22 @@ -272,15 +272,15 @@ make tests/test-worker-proof.py Makefile test-suite - 24 make tests/test-serve-poll.py Makefile test-suite - 3 make tests/test-worker-proof.sh Makefile test-suite - 22 make tests/test-coverage-cache.sh Makefile test-suite - 1 -make tests/test-revision-key.sh Makefile test-suite - 0 -make tests/test-state-lib.sh Makefile test-suite - 0 +make tests/test-revision-key.sh Makefile test-suite - 10 +make tests/test-state-lib.sh Makefile test-suite - 72 make tests/test-homebrew-formula.sh Makefile test-suite - 6 make tests/test-e2e-gate.sh Makefile test-suite - 44 make tests/manifest-selftest.sh Makefile test-suite - 8 make tests/test-release-bundle.sh Makefile test-suite - - -make tests/test-env-override-gate.sh Makefile test-suite - 0 -make tests/test-server-deadline.py Makefile test-suite - 0 -make tests/test-build-deb.sh Makefile test-suite - 0 -make tests/test-suite-inventory.sh Makefile test-suite - - -make tests/test-suite-inventory-generate.sh Makefile test-suite - - -make tests/test-suite-profile.sh Makefile test-suite - 5 +make tests/test-env-override-gate.sh Makefile test-suite - 14 +make tests/test-server-deadline.py Makefile test-suite - 13 +make tests/test-build-deb.sh Makefile test-suite - 36 +make tests/test-suite-inventory.sh Makefile test-suite - 18 +make tests/test-suite-inventory-generate.sh Makefile test-suite - 3 +make tests/test-suite-profile.sh Makefile test-suite - 9 diff --git a/docs/dev/suite-profile-baseline.tsv b/docs/dev/suite-profile-baseline.tsv index 48e8c8d6..e1430f2d 100644 --- a/docs/dev/suite-profile-baseline.tsv +++ b/docs/dev/suite-profile-baseline.tsv @@ -1,240 +1,241 @@ -# Per-section median and p90 seconds over three runs of tests/run.sh (see suite-profile.md). Columns: median, p90, section. -264.4 264.7 black-box: appliance mode (pithead#797 R1) -52.9 53.3 black box: the msr-apply pre-start step still runs to the end as root -34.3 41.0 unit: e2e-real watchdog cleanup restores prior service state (#462) -9.9 10.4 unit: doctor's sister-feed check follows control's api implication (#507) -7.3 7.4 pool schema fields (#527) -6.1 7.0 unit: ensure_config_exists interactive first-run -5.9 6.0 unit: _control_commit — validate, backup, merge, atomic (#236) -5.8 6.8 unit: sister API config keys (#99) -5.5 5.8 unit: staged rebuild swaps in and prunes old build archives (#4, #612) -4.8 4.8 config ownership and setup service transitions (#529) -4.7 5.1 black-box: tune (iterative hill-climb, multi-knob) (#54) -4.6 5.1 (preamble) -4.5 4.9 unit: root-guard refuses root-run units on a tree a non-root user can write (#783) -4.5 4.7 black-box: tune variance-aware acceptance gate (#63) -4.4 4.5 unit: _control_commit — masked pool secrets survive a pools edit (#415) -4.3 4.4 contract guard: wire-shape fixtures (#351) -4.3 4.8 black-box: efficiency winner differs from perf winner (#79) -4.0 4.0 black-box: the control server (#236) -4.0 4.2 unit: control_apply orchestration + rollback (#236) -3.9 3.9 unit: daemon pool parsing and validation (#528) -3.6 4.1 black-box: tune wrmsr knob (#66) -3.4 3.4 unit: native pools array + defaults (#21, #42) -3.3 4.3 black-box: tune target follows autotune config + is announced (#tunefix) -3.1 3.7 unit: config field sanitization -3.1 3.2 black-box: autotune ranks by target (#95) +# Per-section median and p90 seconds over 3 runs of tests/run.sh (see suite-profile.md). Columns: median, p90, section. +# whole-suite run.sh seconds per run: 656.9, 577.5, 585.9; median 585.9, p90 656.9 +264.3 265.6 black-box: appliance mode (pithead#797 R1) +54.5 60.6 black box: the msr-apply pre-start step still runs to the end as root +33.7 43.7 unit: e2e-real watchdog cleanup restores prior service state (#462) +9.9 10.2 unit: doctor's sister-feed check follows control's api implication (#507) +7.7 9.5 pool schema fields (#527) +6.9 8.8 unit: sister API config keys (#99) +6.5 7.6 unit: _control_commit — validate, backup, merge, atomic (#236) +6.4 9.4 unit: ensure_config_exists interactive first-run +6.0 6.1 black-box: tune variance-aware acceptance gate (#63) +5.9 7.8 unit: staged rebuild swaps in and prunes old build archives (#4, #612) +5.0 8.0 config ownership and setup service transitions (#529) +5.0 6.2 unit: _control_commit — masked pool secrets survive a pools edit (#415) +4.9 6.0 (preamble) +4.8 6.0 contract guard: wire-shape fixtures (#351) +4.6 5.5 unit: root-guard refuses root-run units on a tree a non-root user can write (#783) +4.5 5.1 black-box: tune (iterative hill-climb, multi-knob) (#54) +4.4 5.2 unit: control_apply orchestration + rollback (#236) +4.4 5.4 unit: daemon pool parsing and validation (#528) +4.2 4.5 black-box: efficiency winner differs from perf winner (#79) +3.8 5.0 black-box: tune wrmsr knob (#66) +3.7 4.5 unit: native pools array + defaults (#21, #42) +3.3 4.1 unit: config field sanitization +3.3 4.5 black-box: tune target follows autotune config + is announced (#tunefix) +3.3 4.0 unit: api-refresh produces the response files (#99/#164) +3.2 4.0 black-box: autotune ranks by target (#95) +3.1 5.4 black-box: the control server (#236) 3.1 3.1 unit: _wait_miner_live (#95) -2.9 3.6 unit: api-refresh produces the response files (#99/#164) -2.7 2.8 unit: daemon node health and miner summary (#528) -2.7 3.1 unit: config_meta — revision + last-change provenance (#254) +3.1 3.7 unit: daemon node health and miner summary (#528) +3.0 3.5 unit: config_meta — revision + last-change provenance (#254) +2.5 3.0 unit: parse_config — control keys + fail-closed dual auth (#236) 2.5 2.5 unit: rig_lock — the shared-rig flock (#183) -2.3 2.3 unit: api-impact hammer dies with the phase and never holds the rig-lock fd (#653) -2.3 2.4 black-box: tune --live (API-measured) (#54) -2.2 2.2 unit: tor_socks5 routes RigForge's own fetches through one SOCKS5 proxy (#668) -2.2 2.2 unit: parse_config — control keys + fail-closed dual auth (#236) -2.1 2.3 unit: parse_config rejects a bash-inevaluable value in every numeric key (#412) -2.1 2.1 unit: control_upgrade orchestration — whitelist, anti-rollback, throttle, rollback (#308) -2.1 2.1 black-box: setup --dry-run plan + no-mutation guard (#146) -2.0 2.2 unit: onion setup and SOCKS diagnostics (#520) -1.9 1.9 unit: appliance rigs default tor_socks5 to the local Tor client (#696) -1.8 1.8 black-box: tune --confirm live A/B (#64) -1.7 1.9 black-box: autotune live trial + merge (#46) -1.7 1.7 unit: package marker makes upgrade, link and dependency paths package-aware (#782) -1.6 1.7 unit: doctor MSR mod verification (#66) -1.6 1.6 unit: parse_config — watchdog keys (#139) -1.5 1.5 unit: control_upgrade fails cleanly before checkout and re-runs a pending install (#816) -1.5 1.8 unit: doctor hashrate-capping hardware (#67) -1.5 2.0 unit: doctor kernel-lockdown detection (#333) -1.4 1.4 xmrig overlay: apply validation -1.4 1.6 unit: guided BIOS flow (#80) -1.3 1.3 unit: _control_upgrade_do fetch + reachability + checkout (#308, stub git) +2.5 3.1 unit: tor_socks5 routes RigForge's own fetches through one SOCKS5 proxy (#668) +2.5 2.8 unit: control_upgrade orchestration — whitelist, anti-rollback, throttle, rollback (#308) +2.3 2.4 unit: api-impact hammer dies with the phase and never holds the rig-lock fd (#653) +2.3 3.1 black-box: tune --live (API-measured) (#54) +2.3 3.0 unit: parse_config rejects a bash-inevaluable value in every numeric key (#412) +2.3 2.8 black-box: setup --dry-run plan + no-mutation guard (#146) +2.2 2.7 unit: onion setup and SOCKS diagnostics (#520) +2.2 3.0 unit: appliance rigs default tor_socks5 to the local Tor client (#696) +1.9 2.3 unit: package marker makes upgrade, link and dependency paths package-aware (#782) +1.8 2.4 black-box: autotune live trial + merge (#46) +1.7 2.0 unit: control_upgrade fails cleanly before checkout and re-runs a pending install (#816) +1.7 2.2 black-box: tune --confirm live A/B (#64) +1.7 2.1 unit: parse_config — watchdog keys (#139) +1.6 1.9 unit: _control_upgrade_do fetch + reachability + checkout (#308, stub git) +1.6 1.9 xmrig overlay: apply validation +1.6 2.0 unit: doctor kernel-lockdown detection (#333) +1.5 1.9 unit: guided BIOS flow (#80) +1.5 1.9 unit: doctor MSR mod verification (#66) 1.3 1.8 black-box: tune min-delta gate (#54) -1.2 1.2 unit: release e2e gates fail closed (#491) -1.2 1.4 thread placement: generated config and the cap -1.2 1.4 unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) -1.2 1.2 black-box: apply reconciles the writable control path to config (#236) -1.1 1.1 unit: _api_config_json — effective writable config, secrets masked (#253) -1.1 1.1 black-box: the persistent api server (#164, the xmrig model) -1.1 1.2 black-box: backup / restore round-trip -1.0 1.2 black-box: zero-hashrate bench iteration stays quiet (#277) -1.0 1.2 xmrig overlay: tuning pins -0.9 1.2 black-box: tune samples power under load, not idle (#81) -0.9 1.2 unit: doctor pool connection (#343) -0.9 1.1 black-box: upgrade / help / unknown command (#4) -0.9 1.2 unit: CPU ISA preflight — AES-NI / AVX2 surfaced (#338) -0.9 0.9 unit: parse_config — autotune tri-state (#95) -0.9 0.9 thread placement: overlay pin validation -0.9 0.9 unit: control_apply FULL path — a deliberately stopped rig is not rolled back (#396) -0.9 0.9 black-box: tune thermal-throttle rejection (#62) -0.8 1.2 black-box: apply reports the miner's pool connection (#343) -0.8 1.0 xmrig overlay: generation order and compatibility -0.8 0.8 black-box: support-bundle collects + redacts (#147) -0.8 1.4 unit: doctor control receiver health (#278) -0.7 0.9 unit: doctor exposure posture advisory (#sec) -0.7 0.8 unit: control_apply + REAL _control_do_apply_fast — run-state criterion, not is-active alone (#381 security review) +1.3 1.6 unit: doctor hashrate-capping hardware (#67) +1.2 1.3 black-box: zero-hashrate bench iteration stays quiet (#277) +1.2 1.6 thread placement: generated config and the cap +1.2 1.6 unit: _read_api_hashrate sends a *** when ACCESS_TOKEN is set (#125) +1.2 1.6 unit: _api_config_json — effective writable config, secrets masked (#253) +1.2 1.5 black-box: backup / restore round-trip +1.2 1.4 black-box: apply reconciles the writable control path to config (#236) +1.2 2.7 unit: release e2e gates fail closed (#491) +1.2 1.3 black-box: the persistent api server (#164, the xmrig model) +1.1 1.4 xmrig overlay: tuning pins +1.0 1.3 unit: control_apply FULL path — a deliberately stopped rig is not rolled back (#396) +1.0 1.2 unit: doctor pool connection (#343) +1.0 1.2 thread placement: overlay pin validation +1.0 1.2 black-box: upgrade / help / unknown command (#4) +1.0 1.2 unit: CPU ISA preflight — AES-NI / AVX2 surfaced (#338) +1.0 1.0 black-box: tune samples power under load, not idle (#81) +0.9 1.0 black-box: macOS process control (start/status/stop) +0.9 1.1 unit: parse_config — autotune tri-state (#95) +0.9 1.5 xmrig overlay: generation order and compatibility +0.9 1.1 black-box: support-bundle collects + redacts (#147) +0.9 1.2 black-box: apply reports the miner's pool connection (#343) +0.9 1.2 black-box: tune thermal-throttle rejection (#62) +0.8 1.1 unit: control_apply + REAL _control_do_apply_fast — run-state criterion, not is-active alone (#381 security review) +0.8 1.0 unit: doctor control receiver health (#278) +0.8 1.0 unit: doctor exposure posture advisory (#sec) +0.8 0.9 unit: pool url validation (#8) +0.7 0.9 unit: watchdog health check (#139) +0.7 1.0 black-box: tune grid search (#6) 0.7 0.9 black-box: full deployment run (stubbed, native Linux path) -0.7 0.7 unit: pool url validation (#8) -0.7 0.8 black-box: setup installs the CLI only when add_to_path is enabled (#cli) -0.7 1.0 black-box: re-run is idempotent (#5) -0.7 0.7 unit: watchdog health check (#139) -0.7 0.8 unit: DONATION validation (new) -0.7 0.7 black-box: apply on a deliberately stopped rig regenerates and holds (#396) -0.7 0.7 xmrig overlay: parse validation -0.7 0.7 black-box: tune grid search (#6) -0.6 0.7 unit: doctor miner_user + root-side MSR preset (#140) -0.6 0.6 black-box: install_control units enable/disable (#236) +0.7 0.9 xmrig overlay: parse validation +0.7 0.9 black-box: apply on a deliberately stopped rig regenerates and holds (#396) +0.7 1.0 black-box: setup installs the CLI only when add_to_path is enabled (#cli) +0.7 0.9 unit: DONATION validation (new) +0.7 0.9 unit: doctor miner_user + root-side MSR preset (#140) +0.7 0.9 black-box: install_control units enable/disable (#236) +0.7 0.9 black-box: re-run is idempotent (#5) +0.6 0.8 unit: EPYC NPS detection (#201) +0.6 0.8 black-box: install_api_firewall renders + tears down the nft table (#142) 0.6 0.6 fixture: the lscpu stub stays silent when its reader closes early (#419) 0.6 0.7 black-box: aborted autotune restores the pre-sweep prefetch mode (#347) -0.6 0.6 black-box: aborted tune --live restores the pre-sweep overrides (#347) -0.6 0.6 black-box: install_api_firewall renders + tears down the nft table (#142) -0.6 0.8 black-box: tune reservation-aware threads (#65) -0.6 0.6 unit: EPYC NPS detection (#201) -0.6 0.6 black-box: apply / bench (#11) -0.6 0.6 black-box: upgrade / help / unknown command (#4), rebuild path -0.5 0.6 unit: doctor MSR unverifiable — guard-input failures named (#367) -0.5 0.6 black-box: tune restarts the service after a mid-run bench crash (#276) -0.5 0.6 unit: parse_config hugepages_reserve_extra_mb + threads (#305) -0.5 0.5 unit: daemon sister-feed mode (#528) -0.5 0.5 black-box: command surface (#11) -0.5 0.6 unit: doctor health checks (#45) -0.5 0.9 black-box: macOS process control (start/status/stop) -0.5 0.5 unit: install failure leaves marker, rollback cleans it (#816) -0.5 0.7 black-box: uninstall reverts system changes (#12) -0.5 0.5 black-box: upgrade leaves a stopped miner stopped (#413) -0.5 1.0 unit: doctor BIOS/firmware advisory (#78) -0.5 0.5 xmrig overlay: feed and remote boundary -0.5 0.5 unit: daemon pool rendering and scope boundary (#528) -0.5 0.5 unit: check_prerequisites installs jq per package manager -0.5 0.6 black-box: tune power/temp recording (#54) -0.5 0.5 unit: restore takes the worker folder back before copying tune files +0.6 0.8 black-box: apply / bench (#11) +0.6 0.7 black-box: upgrade / help / unknown command (#4), rebuild path +0.6 0.7 black-box: aborted tune --live restores the pre-sweep overrides (#347) +0.6 0.7 unit: parse_config hugepages_reserve_extra_mb + threads (#305) +0.6 0.7 unit: doctor MSR unverifiable — guard-input failures named (#367) +0.6 0.7 black-box: tune restarts the service after a mid-run bench crash (#276) +0.5 0.7 black-box: tune reservation-aware threads (#65) +0.5 0.7 unit: install failure leaves marker, rollback cleans it (#816) +0.5 0.7 unit: daemon sister-feed mode (#528) +0.5 0.7 black-box: command surface (#11) +0.5 0.6 unit: daemon pool rendering and scope boundary (#528) +0.5 0.7 unit: doctor health checks (#45) +0.5 0.6 xmrig overlay: feed and remote boundary +0.5 0.6 black-box: upgrade leaves a stopped miner stopped (#413) +0.5 0.6 unit: doctor BIOS/firmware advisory (#78) +0.5 0.7 unit: restore takes the worker folder back before copying tune files +0.5 0.6 xmrig overlay: logging keys (#530) +0.5 0.6 black-box: uninstall reverts system changes (#12) +0.5 0.6 black-box: tune huge-pages-jit knob (#7) 0.5 0.6 black-box: tune median-of-N noise handling (#54) -0.4 0.4 xmrig overlay: logging keys (#530) -0.4 0.6 black-box: tune 1gb-pages knob when reserved (#54) -0.4 0.4 watchdog: a config that fails validation still gets the thermal stop -0.4 0.5 black-box: tune huge-pages-jit knob (#7) -0.4 0.4 unit: status hugepages shapes (#341) -0.4 0.5 thread placement: doctor and bundle evidence -0.4 0.6 unit: rig label = pool user; API token off by default (#22) +0.5 0.6 thread placement: doctor and bundle evidence +0.5 0.6 unit: status hugepages shapes (#341) +0.4 0.6 watchdog: a config that fails validation still gets the thermal stop +0.4 0.5 black-box: tune 1gb-pages knob when reserved (#54) +0.4 0.5 unit: rig label = pool user; API token off by default (#22) +0.4 0.6 unit: upgrade --check (#148) 0.4 0.5 unit: msr-apply preset detection + masked RMW (#140) -0.4 0.4 unit: upgrade --check (#148) -0.4 0.4 unit: apply re-renders the installed unit to the configured miner_user (#140) -0.4 0.4 unit: install_watchdog returns non-zero when it could not render (#395) 0.4 0.5 unit: MSR preset table values (#66) -0.4 0.9 black-box: tune built-in RAPL power path (#81) +0.4 0.5 unit: apply re-renders the installed unit to the configured miner_user (#140) 0.4 0.5 unit: link_cli installs + guards the rigforge command (#cli) -0.3 0.5 unit: power measurement helpers (#81) -0.3 0.3 black-box: api-server IPv6 dual-stack bind (#243) -0.3 0.3 unit: parse_config hugepages_pool_ceiling_mb (#398) +0.4 0.6 unit: install_watchdog returns non-zero when it could not render (#395) +0.4 0.4 unit: power measurement helpers (#81) +0.4 0.4 black-box: tune built-in RAPL power path (#81) +0.4 0.5 unit: parse_config hugepages_pool_ceiling_mb (#398) +0.4 0.4 unit: _control_fast_path_eligible — closed allowlist classification (#381) 0.3 0.4 black-box: runtime HugePages reservation is grow-only (#328) -0.3 0.3 black-box: tune --efficiency falls back without a power source (#79) +0.3 0.4 black-box: api-server IPv6 dual-stack bind (#243) +0.3 0.5 black-box: tune power/temp recording (#54) +0.3 0.4 unit: root takes the worker folder back and removes every link inside it 0.3 0.4 unit: doctor checks http.restricted in the live config (#135) -0.3 0.3 unit: root takes the worker folder back and removes every link inside it +0.3 0.4 black-box: tune --efficiency falls back without a power source (#79) +0.3 0.4 unit: parse_config — pool url used verbatim (#15) +0.3 0.4 unit: parse_config — workspace + token 0.3 0.3 unit: tune bench freq writer floors a sci-notation median to whole kHz (#266) -0.3 0.3 unit: _control_fast_path_eligible — closed allowlist classification (#381) -0.3 0.3 unit: parse_config — pool url used verbatim (#15) -0.3 0.3 unit: parse_config — workspace + token -0.3 0.3 black-box: macOS login agent (enable/disable via launchd) -0.3 0.3 black-box: consistency sweep — flags, prompts, templates (#149) -0.3 0.3 unit: _control_upgrade_do reowns what the upgrade creates to the checkout owner (#798) -0.3 0.3 unit: prepare_workspace before a root build -0.3 0.3 unit: hugepages pool ceiling bounds the grow-only write (#398) -0.3 0.3 unit: config snapshots on a root-owned tree -0.2 0.3 black-box: install_api server/timer enable/disable (#99/#164) -0.2 0.2 unit: status live summary (#143) -0.2 0.2 thread placement: tune candidates -0.2 0.2 unit: _control_upgrade_throttle_ok (#308) -0.2 0.2 max_temp_c written with a leading zero is read as a decimal number -0.2 0.2 config-gen: threads cap clamps cpu.rx (#305) -0.2 0.2 black-box: support-bundle leaks no staging tempdir on a set -e abort (#353) +0.3 0.4 unit: _control_upgrade_do reowns what the upgrade creates to the checkout owner (#798) +0.3 0.4 black-box: consistency sweep — flags, prompts, templates (#149) +0.3 0.4 black-box: macOS login agent (enable/disable via launchd) +0.3 0.4 unit: hugepages pool ceiling bounds the grow-only write (#398) +0.3 0.4 unit: prepare_workspace before a root build +0.3 0.5 unit: config snapshots on a root-owned tree +0.3 0.3 unit: status live summary (#143) +0.3 0.3 black-box: install_api server/timer enable/disable (#99/#164) +0.3 0.3 thread placement: tune candidates +0.3 0.3 unit: _control_upgrade_throttle_ok (#308) +0.2 0.3 unit: check_prerequisites installs jq per package manager +0.2 0.3 max_temp_c written with a leading zero is read as a decimal number +0.2 0.3 config-gen: threads cap clamps cpu.rx (#305) +0.2 0.3 black-box: support-bundle leaks no staging tempdir on a set -e abort (#353) 0.2 0.2 unit: xmrig_already_built detection (#4) -0.2 0.2 unit: e2e-real perf record gate (#214/#267) -0.2 0.2 black-box: setup sizes the reservation for the tuned threads (#65) 0.2 0.2 unit: compute_build_jobs caps -j by RAM (#9) +0.2 0.2 unit: real-git control-upgrade as root keeps a user-owned checkout user-owned (#798) 0.2 0.2 unit: _miner_deliberately_stopped — the predicate the #396 decision turns on -0.2 0.2 unit: _grub_proposed co-resident keep-existing guard (#305) -0.2 0.2 unit: _apply_runtime preserve-run-state — the held rig stays stopped, tune's bare call does not (#396) 0.2 0.2 unit: apply() and _control_do_apply propagate a watchdog render failure (#395) +0.2 0.2 unit: _reown_worker reconciles file ownership (#audit) +0.2 0.2 black-box: setup sizes the reservation for the tuned threads (#65) +0.2 0.2 unit: _apply_runtime preserve-run-state — the held rig stays stopped, tune's bare call does not (#396) +0.2 0.2 unit: e2e-real perf record gate (#214/#267) +0.2 0.2 xmrig overlay: HugePages thread sizing +0.2 0.2 unit: _grub_proposed co-resident keep-existing guard (#305) +0.2 0.2 unit: _reown_worker on a root-owned tree +0.2 0.2 black-box: tune --history surfaces periodic auto-tune (Linux) (#hist) +0.1 0.2 unit: a control change snapshots through the same path 0.1 0.2 unit: install_service reboot-gates the start (#audit A2) -0.1 0.1 unit: _reown_worker reconciles file ownership (#audit) -0.1 0.2 unit: util/proposed-grub.sh hardware math -0.1 0.2 black-box: tune --history surfaces periodic auto-tune (Linux) (#hist) -0.1 0.2 xmrig overlay: HugePages thread sizing -0.1 0.2 unit: e2e-real retries NEXT through timer activation (#458) -0.1 0.1 unit: _reown_worker on a root-owned tree -0.1 0.1 unit: a control change snapshots through the same path 0.1 0.2 unit: _cmdline_reserved_2mb (#305) -0.1 0.1 black-box: install_watchdog timer enable/disable (#139) -0.1 0.1 black-box: install_autotune timer enable/disable (#95 tri-state) -0.1 0.1 unit: compile_xmrig pinned-commit verification (#18) -0.1 0.1 black-box: apply reconciles the sister API to config (#99) +0.1 0.2 unit: compile_xmrig pinned-commit verification (#18) +0.1 0.2 unit: e2e-real retries NEXT through timer activation (#458) +0.1 0.2 black-box: apply reconciles the sister API to config (#99) 0.1 0.2 unit: _read_temp hwmon fallback (#208) -0.1 0.1 config-gen: IPv6 host / single-pool TLS / empty-token round-trip -0.1 0.1 unit: tune seeds keep explicit false (#265) -0.1 0.1 unit: proposed-grub.sh honours the declared pool ceiling (#410) +0.1 0.2 black-box: install_autotune timer enable/disable (#95 tri-state) +0.1 0.2 black-box: install_watchdog timer enable/disable (#139) +0.1 0.2 unit: tune seeds keep explicit false (#265) +0.1 0.2 config-gen: IPv6 host / single-pool TLS / empty-token round-trip +0.1 0.2 unit: _control_do_apply_fast — reuses install_watchdog, skips apply()/xmrig restart (#381) +0.1 0.2 unit: util/proposed-grub.sh hardware math +0.1 0.2 black-box: unreachable worker API is quiet, not an abort (#364) +0.1 0.2 config-gen: idempotent (same inputs -> identical output) 0.1 0.2 unit: install_dependencies dnf / pacman / no-manager branches -0.1 0.1 unit: _control_do_apply_fast — reuses install_watchdog, skips apply()/xmrig restart (#381) -0.1 0.1 unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) -0.1 0.1 unit: real-git control-upgrade as root keeps a user-owned checkout user-owned (#798) -0.1 0.1 config-gen: idempotent (same inputs -> identical output) -0.1 0.1 black-box: unreachable worker API is quiet, not an abort (#364) -0.1 0.1 unit: doctor service-inactive branch (#audit) -0.1 0.1 black-box: upgrade re-tunes the new build (#95) -0.1 0.3 unit: efficiency-target acceptance gate (#79) -0.1 0.1 config-gen: generic Linux (default profile) +0.1 0.2 unit: efficiency-target acceptance gate (#79) +0.1 0.2 unit: _autotune_score efficiency needs watts, else raw H/s (#95) +0.1 0.2 unit: doctor service-inactive branch (#audit) +0.1 0.2 unit: e2e-pithead dashboard leg — hardened curl + no vacuous offline pass (#390/#466) +0.1 0.2 black-box: completion script + verb-list drift guard (#145) +0.1 0.2 black-box: upgrade re-tunes the new build (#95) 0.1 0.1 unit: _grub_proposed passes the declared ceiling to proposed-grub (#410) -0.1 0.1 black-box: completion script + verb-list drift guard (#145) -0.1 0.3 unit: _autotune_score efficiency needs watts, else raw H/s (#95) -0.1 0.1 unit: apt cpupower package probe — Debian / neither exists (#327) -0.1 0.2 black-box: appliance uninstall disables with --runtime too (#353) 0.1 0.1 unit: apply reports the autotune target (#95) -0.1 0.1 unit: compile_xmrig honours XMRIG_REBUILD (#4) +0.1 0.2 unit: proposed-grub.sh honours the declared pool ceiling (#410) +0.1 0.1 unit: apt cpupower package probe — Debian / neither exists (#327) +0.1 0.1 config-gen: generic Linux (default profile) 0.1 0.1 watchdog: a miner started during a thermal hold is stopped again +0.1 0.1 unit: compile_xmrig honours XMRIG_REBUILD (#4) 0.1 0.1 unit: _worker_root_from_config validates HOME_DIR -0.1 0.1 unit: proposed-grub.sh co-resident headroom + thread cap (#305) 0.1 0.1 unit: _script_dir resolves through symlinks (#cli) +0.1 0.1 black-box: appliance uninstall disables with --runtime too (#353) 0.1 0.1 unit: _sed_escape_replacement protects the GRUB rewrites (#134) 0.1 0.1 unit: grub_merge_cmdline preserves other kernel params (#19) -0.1 0.1 config-gen: macOS overrides +0.1 0.1 unit: _thread_candidates is SMT-aware (#4) 0.1 0.1 black-box: an unreachable API never aborts a tune sampling read (#364) -0.1 0.1 config-gen: multi-pool passthrough (#21, #42) +0.1 0.3 config-gen: macOS overrides +0.1 0.1 unit: proposed-grub.sh co-resident headroom + thread cap (#305) +0.1 0.1 unit: config.minimal.json (starter) +0.1 0.2 config-gen: multi-pool passthrough (#21, #42) 0.1 0.1 config-gen: AMD EPYC (server) 0.1 0.1 config-gen: AMD Ryzen X3D — auto, not hand-pinned (#44) -0.1 0.1 unit: _thread_candidates is SMT-aware (#4) -0.1 0.1 unit: config.minimal.json (starter) +0.1 0.1 black-box: apply reconciles the autotune timer to config (#95) 0.1 0.1 unit: install_dependencies non-interactive auto-install (#74) -0.1 0.1 tree hygiene: the suite writes nothing into the tracked tree (#418) 0.1 0.1 config-gen: open API by default (no ACCESS_TOKEN) -0.1 0.1 config-gen: miner_user disables in-process MSR writes (#140) -0.1 0.1 black-box: apply reconciles the autotune timer to config (#95) -0.1 0.1 config-gen: explicit pool user / rig label (#22) 0.1 0.1 config-gen: socks5 passthrough (#400) +0.1 0.2 config-gen: miner_user disables in-process MSR writes (#140) +0.1 0.1 config-gen: explicit pool user / rig label (#22) 0.1 0.1 config-gen: tls-fingerprint passthrough (#115) 0.1 0.1 black-box: no ANSI escapes off-terminal (#144) 0.1 0.1 unit: parse_config — error paths 0.1 0.1 tuning sweeps: a bare re-apply leaves a thermally held miner stopped -0.1 0.1 unit: install_service with miner_user (#140) 0.1 0.1 unit: invalid daemon apply fails before side effects (#528) -0.1 0.1 unit: install_service honors SERVICE_NAME override (#133) 0.1 0.1 black-box: backup leaks no staging tempdir on a set -e abort (#353) -0.1 0.1 unit: install_dependencies adds versioned linux-tools when apt-cache has it (#74) 0.1 0.1 unit: grub_strip_managed (#12) +0.1 0.1 unit: install_dependencies adds versioned linux-tools when apt-cache has it (#74) +0.1 0.1 unit: install_service with miner_user (#140) +0.1 0.1 unit: install_service honors SERVICE_NAME override (#133) 0.1 0.1 unit: e2e apt prerequisites retry (#449) 0.0 0.1 unit: _reown_worker hands config+log back to the miner user (#140) -0.0 0.0 black-box: restore leaks no staging tempdir on a set -e abort (#353) -0.0 0.0 unit: append_once idempotency -0.0 0.0 unit: remove_line (#12) -0.0 0.0 unit: the backup sweep hands snapshots, not the folder -0.0 0.1 black-box: uninstall without --yes aborts on 'n' (reverts nothing) +0.0 0.3 tree hygiene: the suite writes nothing into the tracked tree (#418) +0.0 0.1 black-box: restore leaks no staging tempdir on a set -e abort (#353) +0.0 0.1 unit: the backup sweep hands snapshots, not the folder +0.0 0.1 unit: append_once idempotency +0.0 0.1 unit: remove_line (#12) +0.0 0.0 unit: the API readers never let a curl failure escape (#353/#364) 0.0 0.0 black-box: on_err names the running verb, not the stale setup default (#353) +0.0 0.0 black-box: uninstall without --yes aborts on 'n' (reverts nothing) 0.0 0.0 unit: _parse_hashrate (#11) -0.0 0.0 unit: the API readers never let a curl failure escape (#353/#364) 0.0 0.0 unit: the worker folder stays root-owned only on a root-owned tree -0.0 0.1 unit: finish_deployment points at 'start' +0.0 0.0 unit: finish_deployment points at 'start' 0.0 0.0 unit: on_err reports the failing step (#9) 0.0 0.0 unit: require_traversable_checkout — DynamicUser traversal pre-flight (#362) 0.0 0.0 unit: config.reference.json (#23) 0.0 0.0 unit: e2e-real git calls survive a nested sudo (#401) 0.0 0.0 unit: control writable-keys drift guard — bash vs python (#236) -0.0 0.0 unit: VERSION is SemVer (#3) 0.0 0.0 unit: control-upgrade git calls pin safe.directory (#308) +0.0 0.0 unit: VERSION is SemVer (#3) diff --git a/docs/dev/suite-profile.md b/docs/dev/suite-profile.md index 67f296bd..6591b099 100644 --- a/docs/dev/suite-profile.md +++ b/docs/dev/suite-profile.md @@ -1,7 +1,7 @@ # Suite profile and inventory `make test-suite` runs `tests/run.sh` (one process, thousands of assertions) -followed by a list of standalone suites. Nothing records where the time goes or +followed by a list of standalone suites. Nothing recorded where the time goes or which suites run from where, so an isolation or caching change (#624) could drop or double-run assertions without anyone noticing. This page is the measured "before" and the rule for keeping the suite inventory true. @@ -12,14 +12,22 @@ or double-run assertions without anyone noticing. This page is the measured RIGFORGE_SUITE_PROFILE=1 make test-suite ``` -With the variable set to any non-empty value (leave it unset to turn it off), the Makefile runs `tests/run.sh` through -`tests/suite-profile.py`. Without it, the recipe is the same `bash tests/run.sh` -as before. The wrapper passes the suite's stdout through unchanged and writes one -`suite-profile:` line per `== ... ==` section to stderr (seconds, tick lines -printed under it, section name), then the whole-suite total. `tests/run.sh` is not -touched; its line count is pinned by `docs/dev/file-budget.tsv`. +With the variable set to any non-empty value (leave it unset to turn it off), the +Makefile runs `tests/run.sh` through `tests/suite-profile.py`. Without it, the +recipe is the same `bash tests/run.sh` as before. The wrapper passes the suite's +stdout through unchanged and writes one `suite-profile:` line per `== ... ==` +section to stderr (seconds, tick lines printed under it, section name), then the +whole-suite total of `tests/run.sh`. `tests/run.sh` is not touched; its line count +is pinned by `docs/dev/file-budget.tsv`. + `tests/test-suite-profile.sh` proves the output is byte-identical, the exit status -is preserved and the report carries the elapsed seconds. +is preserved and the report carries the elapsed seconds, both by calling the +wrapper and by running the first recipe line that `make -n test-suite` prints with +and without the variable. A bare `--` is a usage error (status 2). + +The CI `Test suite` job sets the variable, so every CI run logs its own profile. +`python3 tests/suite-profile.py --aggregate LOG...` reads such logs (timestamped +or not) and prints per-section median and p90 seconds plus the whole-suite figures. A section's time is the time from its header line to the next header line, as seen on the pipe, so it includes the standalone suites that run inside it. Sections that @@ -28,58 +36,66 @@ rows of their own. ## Baseline -Three consecutive runs of `bash tests/run.sh` under the wrapper, with -`RIGFORGE_TEST_OVERRIDES=1` as the Makefile sets it, on a Linux x86_64 host -(Ubuntu 26.04, 8 cores). This is the same OS family as the `ubuntu-24.04` CI runner -but not the runner itself; the operator's review on rigforge#624 reports a CI whole-job median of -8.1 minutes (p90 18.7) on its own hardware. All three runs ended with `2858 passed, 0 failed` and the same -239 runtime sections. +Three runs of the CI `Test suite` job (`make test-suite` with +`RIGFORGE_SUITE_PROFILE=1`) on the `ubuntu-24.04` runner, all on head f989d68 of +the pull request that added this page: one run and two reruns of the same job. +Job ids: 145338863771, 145347061181 and 145353783831. Each run ended with +`rigforge tests: 2858 passed, 0 failed` and the same 239 sections. The same +`tests/run.sh` run without the variable (job 145314443337, head 7d47f86) ended with +the identical `2858 passed, 0 failed`. + +| Run | `tests/run.sh` seconds (profile total) | Whole `make test-suite` step seconds | +|---|---|---| +| 1 | 656.9 | 720 | +| 2 | 577.5 | 631 | +| 3 | 585.9 | 640 | -| Run | Whole-suite seconds | -|---|---| -| 1 | 568.2 | -| 2 | 575.7 | -| 3 | 589.6 | +| | Median s | p90 s (nearest rank over three runs) | +|---|---|---| +| `tests/run.sh` | 585.9 | 656.9 | +| Whole `make test-suite` | 640 | 720 | -Whole-suite median 575.7 s, p90 589.6 s (nearest rank over three runs). The standalone -suites the Makefile runs after `run.sh` took about 4.5 minutes in sequence when -measured one by one for the inventory; that figure includes starting each one cold -and is not a CI number. +The step seconds are the job's step start and end times, so they include the +recipes that follow `tests/run.sh`: 54 to 63 s for the 33 standalone suites. The +CI whole-job median of 8.1 minutes (p90 18.7) in the operator's review on +rigforge#624 covers all CI runs of the repository, not these three. -Per-section median and p90 over the three runs, the 15 slowest of 239. 180 sections -take under a second. The top five take 64.6% of the section time. +Per-section median and p90 over the three runs, the 15 slowest of 239. 173 sections +take under a second. The top three take 60% of the section time and the top five 63%. | Section | Median s | p90 s | |---|---|---| -| black-box: appliance mode (pithead#797 R1) | 264.4 | 264.7 | -| black box: the msr-apply pre-start step still runs to the end as root | 52.9 | 53.3 | -| unit: e2e-real watchdog cleanup restores prior service state (#462) | 34.3 | 41.0 | -| unit: doctor's sister-feed check follows control's api implication (#507) | 9.9 | 10.4 | -| pool schema fields (#527) | 7.3 | 7.4 | -| unit: ensure_config_exists interactive first-run | 6.1 | 7.0 | -| unit: _control_commit — validate, backup, merge, atomic (#236) | 5.9 | 6.0 | -| unit: sister API config keys (#99) | 5.8 | 6.8 | -| unit: staged rebuild swaps in and prunes old build archives (#4, #612) | 5.5 | 5.8 | -| config ownership and setup service transitions (#529) | 4.8 | 4.8 | -| black-box: tune (iterative hill-climb, multi-knob) (#54) | 4.7 | 5.1 | -| (preamble) | 4.6 | 5.1 | -| unit: root-guard refuses root-run units on a tree a non-root user can write (#783) | 4.5 | 4.9 | -| black-box: tune variance-aware acceptance gate (#63) | 4.5 | 4.7 | -| unit: _control_commit — masked pool secrets survive a pools edit (#415) | 4.4 | 4.5 | +| black-box: appliance mode (pithead#797 R1) | 264.3 | 265.6 | +| black box: the msr-apply pre-start step still runs to the end as root | 54.5 | 60.6 | +| unit: e2e-real watchdog cleanup restores prior service state (#462) | 33.7 | 43.7 | +| unit: doctor's sister-feed check follows control's api implication (#507) | 9.9 | 10.2 | +| pool schema fields (#527) | 7.7 | 9.5 | +| unit: sister API config keys (#99) | 6.9 | 8.8 | +| unit: _control_commit — validate, backup, merge, atomic (#236) | 6.5 | 7.6 | +| unit: ensure_config_exists interactive first-run | 6.4 | 9.4 | +| black-box: tune variance-aware acceptance gate (#63) | 6.0 | 6.1 | +| unit: staged rebuild swaps in and prunes old build archives (#4, #612) | 5.9 | 7.8 | +| config ownership and setup service transitions (#529) | 5.0 | 8.0 | +| unit: _control_commit — masked pool secrets survive a pools edit (#415) | 5.0 | 6.2 | +| (preamble) | 4.9 | 6.0 | +| contract guard: wire-shape fixtures (#351) | 4.8 | 6.0 | +| unit: root-guard refuses root-run units on a tree a non-root user can write (#783) | 4.6 | 5.5 | All 239 rows are committed in -[`suite-profile-baseline.tsv`](suite-profile-baseline.tsv). +[`suite-profile-baseline.tsv`](suite-profile-baseline.tsv), produced by +`python3 tests/suite-profile.py --aggregate` over the three job logs. ### The parse hotspot `parse_and_print` and `parse_rc` (`tests/run.sh`) run `source "$SCRIPT"` in a subshell for every fixture, so `rigforge.sh` is re-read and re-parsed each time. `tests/run.sh` has 223 `source "$SCRIPT"` sites. One bare `source rigforge.sh` in a -fresh `bash` costs 25 ms here (20 starts in 0.50 s). The dynamic number of sources -per run was not counted. The profile shows that the parse cost alone cannot explain -the run time: the three slowest sections, none of them parse loops, are 61% of the -total, and the rest of the unit sections are mostly under a second. Any parse-reuse -change should be measured against the per-section rows above, not assumed. +fresh `bash` cost 25 ms on a local Linux host (20 starts in 0.50 s). The dynamic +number of sources per run was not counted. The profile shows that the parse cost +alone cannot explain the run time: the three slowest sections, none of them parse +loops, are 60% of the total, and the rest of the unit sections are mostly under a +second. Any parse-reuse change should be measured against the per-section rows +above, not assumed. ## Inventory @@ -87,46 +103,68 @@ change should be measured against the per-section rows above, not assumed. order: - `section`: a `== ... ==` header in `tests/run.sh`, plus `(preamble)` for what runs - before the first header (190 rows). + before the first header (190 rows). A header that expands a variable is listed + as written, for example `linux $HOST_OS deployment`. - `sourced`: a suite sourced into `tests/run.sh`, sharing its pass counter (11). - `chained`: a suite `tests/run.sh` runs as a subprocess, including the ones run by loops and the Python ones (48). -- `make`: a suite `make test-suite` runs after `tests/run.sh` (33). +- `make`: a suite `make test-suite` runs after `tests/run.sh` (34). Columns: kind, unit, caller, call site (the run.sh section header above the call, or the make target), stream passes, standalone passes. -Stream passes are the tick lines `tests/run.sh` printed under the unit in the profiled -run. Sections and sourced suites partition the stream: the stream carries 2904 ticks, -the 2858 of `tests/run.sh`'s own counter plus 46 printed by chained suites that use the -same tick. A sourced suite that prints its own `== ... ==` header gets its own count; -one that prints none (`tests/test-donation-tor.sh`, `tests/test-randomx-mode.sh`) is -folded into the section above it and shows `-`. Chained and make rows show `-` in this -column. - -Standalone passes are the suite's own count when run alone, from its `N passed`, -`passed=N` or `Ran N tests` line, or else its count of `PASS`, `ok` and tick lines. `-` -means it needs fixtures `tests/run.sh` builds (PATH stubs, exported functions) or it -failed on the host that generated the file; `tests/test-release-bundle.sh` needs `zip`. -The standalone count of a chained suite is not added to the stream count of the section -it runs in. +Stream passes are the tick lines `tests/run.sh` printed for the unit in one run. +Sections and sourced suites partition the stream: it carries 2904 ticks, the 2858 of +`tests/run.sh`'s own counter plus 46 printed by chained suites that use the same +tick. The attribution reads the saved output: a header starts a section or a sourced +suite, and inside a sourced suite a tick whose text matches an assertion of +`tests/run.sh` and not of the suite goes back to the section, so assertions that +`tests/run.sh` makes after a `source` returns are not credited to the file. A +sourced suite that prints no header of its own is picked up at its first assertion +(`tests/test-donation-tor.sh`); `tests/test-randomx-mode.sh` prints no tick at all and +shows `-`. Chained and make rows show `-` in this column. + +Standalone passes belong to chained and make suites: the suite's own count when run +alone, from its `N passed`, `passed=N` or `Ran N tests` line, or else its count of +`PASS`, `ok` and tick lines. The generator runs them with `HOME` and `TMPDIR` in a +scratch folder. It never runs a sourced suite on its own: those are fragments that +rely on the variables and temporary folders `tests/run.sh` sets up, and one of them +writes through an unset variable. `-` means a chained suite needs fixtures +`tests/run.sh` builds, or a suite failed on the generating host +(`tests/test-release-bundle.sh` needs `zip`). A chained suite gets the path of +`rigforge.sh` as its argument only when `tests/run.sh` passes `"$SCRIPT"` to it. The standalone count of a chained suite is not added to the +stream count of the section it runs in. Disjoint means no suite file is called twice, which is the check; assertions are -not compared one by one. `tests/suite-inventory.py --check` -fails when a suite appears at two call sites, or in both `tests/run.sh` and the -Makefile `test-suite` recipe. Suites that those suites call in turn (for example -`tests/test-donation.sh` running `tests/test-e2e-donation.sh`) are not listed. +not compared one by one. `tests/suite-inventory.py --check` fails when a suite +appears at two call sites (also two identical lines in one section), when it +appears in both `tests/run.sh` and the Makefile `test-suite` recipe in any of the +recognised forms (`bash`, `sh`, `python3`, `source` or `.`, a `$ROOT`, `${ROOT}` or +repository-relative path, or direct execution), when the recipe does not run +`tests/run.sh` exactly once, and when a recipe line is not recognised. Suites that +those suites call in turn (for example `tests/test-donation.sh` running +`tests/test-e2e-donation.sh`) are not listed. ### Keeping it true `tests/test-suite-inventory.sh` runs in `make test-suite`. It fails when `tests/run.sh` or the Makefile gains or loses a section header or a suite call that `docs/dev/suite-inventory.tsv` does not list, and its cases show each of those -mutations red. After an intended change, regenerate with: +mutations red. `tests/test-suite-inventory-generate.sh` covers regeneration on a +fixture tree: a failed regeneration keeps the committed bytes, a sourced fragment is +never launched, and each unit gets its own count. + +After an intended change, take the output of a finished `tests/run.sh` (a CI log of +the `Test suite` job works, or `bash tests/run.sh`, which takes about ten minutes) and regenerate: ```sh -RIGFORGE_SUITE_PROFILE=1 make test-suite 2>profile.err >/dev/null -python3 tests/suite-inventory.py --generate profile.err +log=$(mktemp) +bash tests/run.sh >"$log" 2>/dev/null +python3 tests/suite-inventory.py --generate "$log" +rm -f "$log" ``` -The generator runs every standalone suite once, which takes a few minutes. +The generator builds the new file next to the old one, runs the selftest against it, +checks it with `--check`, records the selftest's own count and only then replaces +the committed file; any failure leaves the old file as it was. It runs every +chained and make suite once, which takes a few minutes. diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index ee65571e..78ac9037 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -27,11 +27,12 @@ re.compile(r"Ran (\d+) tests?"), ) PASS_LINE = re.compile(r"✓|\bPASS\b|^\s*ok[ :]", re.M) -ANSI = re.compile(r"\x1b\[[0-9;]*m") +ANSI = re.compile(r"(?:\x1b|\^\[)\[[0-9;]*m") LOG_PREFIX = re.compile(r"^.*?\d{4}-\d\d-\d\dT[\d:.]+Z ") MESSAGE_CALL = re.compile(r"""\b\w*(?:assert\w*|ok)\s+(["'])((?:\\.|(?!\1).)*)\1""") EXPANSION = re.compile(r"\$\{[^}]*\}|\$\([^)]*\)|\$[A-Za-z_0-9@*#?]+") LOOP_ALIAS = {"_f": "_sh"} +SCRIPT_ARGUMENT = set() def read(path): @@ -71,6 +72,8 @@ def run_sh_units(): raise SystemExit("suite-inventory: unresolved loop variable $%s in tests/run.sh" % var) for name in names: name = "tests/" + name + if '"$SCRIPT"' in line: + SCRIPT_ARGUMENT.add(name) if name == "tests/run.sh": continue sourced = re.search(SOURCE_WORD + ROOT_PREFIX + r"?" + re.escape(name), line) @@ -191,7 +194,7 @@ def attribute(units, stream_text): else: key = ("section", section) if not matcher.run_message(message): - for name, info in matcher.sourced.items(): + for name in matcher.sourced: if matcher.site_of[name] == section and matcher.sourced_message(name, message): active = name key = ("sourced", name) @@ -208,14 +211,14 @@ def count_passes(text): return len(PASS_LINE.findall(text)) -def standalone_command(kind, name, candidate): +def standalone_command(kind, name): if name.endswith(".py"): cmd = ["python3", "-B", name] if name == "tests/test-control-spool-cap.py": cmd.append("util/control-server.py") return cmd cmd = ["bash", name] - if kind == "chained": + if kind == "chained" and name in SCRIPT_ARGUMENT: cmd.append(os.path.join(ROOT, "rigforge.sh")) return cmd @@ -243,7 +246,7 @@ def measure_in(units, candidate, scratch, counts): ) try: result = subprocess.run( - standalone_command(kind, name, candidate), + standalone_command(kind, name), cwd=ROOT, env=env, capture_output=True, diff --git a/tests/test-suite-inventory-generate.sh b/tests/test-suite-inventory-generate.sh index e684f878..59bccb96 100755 --- a/tests/test-suite-inventory-generate.sh +++ b/tests/test-suite-inventory-generate.sh @@ -63,7 +63,7 @@ tick=$'\033[1;32m✓\033[0m' } >"$WORK/stream.txt" generate() { - FRAG_SENTINEL="$WORK/sentinel" SUITE_INVENTORY_ROOT="$TREE" python3 -I -B "$INV" --generate "$1" 2>&1 + env -u SUITE_INVENTORY_FILE FRAG_SENTINEL="$WORK/sentinel" SUITE_INVENTORY_ROOT="$TREE" python3 -I -B "$INV" --generate "$1" 2>&1 } before=$(cksum <"$TREE/docs/dev/suite-inventory.tsv") From c3a1bfbc96832033b9026e272dd2a6cf6afd88e3 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 15:26:29 -0600 Subject: [PATCH 06/11] tests: make the assertion-message pattern unambiguous (part of #875) Co-Authored-By: Claude Sonnet 5.5 --- tests/suite-inventory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index 78ac9037..e262c4bd 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -29,7 +29,7 @@ PASS_LINE = re.compile(r"✓|\bPASS\b|^\s*ok[ :]", re.M) ANSI = re.compile(r"(?:\x1b|\^\[)\[[0-9;]*m") LOG_PREFIX = re.compile(r"^.*?\d{4}-\d\d-\d\dT[\d:.]+Z ") -MESSAGE_CALL = re.compile(r"""\b\w*(?:assert\w*|ok)\s+(["'])((?:\\.|(?!\1).)*)\1""") +MESSAGE_CALL = re.compile(r"""\b(?:\w+_)?(?:assert\w*|ok)\s+(?:"((?:\\.|[^"\\])*)"|'([^']*)')""") EXPANSION = re.compile(r"\$\{[^}]*\}|\$\([^)]*\)|\$[A-Za-z_0-9@*#?]+") LOOP_ALIAS = {"_f": "_sh"} SCRIPT_ARGUMENT = set() @@ -124,7 +124,7 @@ def file_messages(path): if line.lstrip().startswith("#"): continue for match in MESSAGE_CALL.finditer(line): - pattern = skeleton(match.group(2)) + pattern = skeleton(match.group(1) if match.group(1) is not None else match.group(2)) if pattern is not None: found.append(pattern) return found From 509bf4828570c79d862e576229ace41ea9899c99 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:07:41 -0600 Subject: [PATCH 07/11] tests: isolate measured suites, reject failed or partial runs, handle masked headers, count result records (part of #875) Co-Authored-By: Claude Opus 5.5 --- docs/dev/suite-inventory.tsv | 32 ++-- docs/dev/suite-profile.md | 53 ++++-- tests/suite-inventory.py | 236 +++++++------------------ tests/suite-profile.py | 15 +- tests/suite_counts.py | 212 ++++++++++++++++++++++ tests/test-suite-inventory-generate.sh | 77 +++++--- tests/test-suite-profile.sh | 10 +- 7 files changed, 397 insertions(+), 238 deletions(-) create mode 100644 tests/suite_counts.py diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index 4e7a879c..4b3de379 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -3,7 +3,7 @@ # stream passes: tick lines run.sh printed for the unit in one run (sections and sourced suites partition them; a sourced suite keeps the ticks of its own assertions only). standalone passes: a chained or make suite's own count when run alone; '-' = it needs run.sh's fixtures or failed on the generating host. See docs/dev/suite-profile.md. section (preamble) run.sh (preamble) 58 - chained tests/test-thread-profile.py run.sh (preamble) - 18 -chained tests/test-suite-liveness.sh run.sh (preamble) - 8 +chained tests/test-suite-liveness.sh run.sh (preamble) - 7 chained tests/test-xmrig-overlay.sh run.sh (preamble) - 81 chained tests/test-thread-placement.sh run.sh (preamble) - 78 chained tests/test-xmrig-logging.sh run.sh (preamble) - 11 @@ -16,25 +16,25 @@ chained tests/test-config-apply-state.sh run.sh (preamble) - 1 chained tests/test-hugepages-ceiling.sh run.sh (preamble) - 19 chained tests/test-benchmark-verification.sh run.sh (preamble) - 50 chained tests/test-benchmark-support.sh run.sh (preamble) - 1 -chained tests/test-stress.sh run.sh (preamble) - 22 +chained tests/test-stress.sh run.sh (preamble) - 21 chained tests/test-perf-submission.sh run.sh (preamble) - 1 chained tests/test-e2e-selftest.sh run.sh (preamble) - 1 -chained tests/test-root-guard.sh run.sh (preamble) - 46 -chained tests/test-control-hardening.sh run.sh (preamble) - 0 +chained tests/test-root-guard.sh run.sh (preamble) - 38 +chained tests/test-control-hardening.sh run.sh (preamble) - - chained tests/test-upgrade-throttle-security.sh run.sh (preamble) - 1 chained tests/test-appliance-pools.sh run.sh (preamble) - 2 section unit: parse_config — pool url used verbatim (#15) run.sh unit: parse_config — pool url used verbatim (#15) 3 - section unit: pool url validation (#8) run.sh unit: pool url validation (#8) 9 - section unit: native pools array + defaults (#21, #42) run.sh unit: native pools array + defaults (#21, #42) 65 - -chained tests/test-pool-fields.sh run.sh unit: native pools array + defaults (#21, #42) - - +chained tests/test-pool-fields.sh run.sh unit: native pools array + defaults (#21, #42) - 66 section unit: config field sanitization run.sh unit: config field sanitization 42 - chained tests/test-host-port-message.sh run.sh unit: config field sanitization - 30 section unit: parse_config — workspace + token run.sh unit: parse_config — workspace + token 4 - section unit: rig label = pool user; API token off by default (#22) run.sh unit: rig label = pool user; API token off by default (#22) 4 - section unit: parse_config — error paths run.sh unit: parse_config — error paths 2 - section unit: ensure_config_exists interactive first-run run.sh unit: ensure_config_exists interactive first-run 19 - -chained tests/test-config-atomic.sh run.sh unit: ensure_config_exists interactive first-run - 0 -chained tests/test-shared-host.sh run.sh unit: ensure_config_exists interactive first-run - 1 +chained tests/test-config-atomic.sh run.sh unit: ensure_config_exists interactive first-run - - +chained tests/test-shared-host.sh run.sh unit: ensure_config_exists interactive first-run - - chained tests/test-shared-host-lifecycle.sh run.sh unit: ensure_config_exists interactive first-run - - chained tests/test-donation.sh run.sh unit: ensure_config_exists interactive first-run - 8 section unit: DONATION validation (new) run.sh unit: DONATION validation (new) 9 - @@ -71,7 +71,7 @@ section unit: compute_build_jobs caps -j by RAM (#9) run.sh unit: compute_build_ section unit: on_err reports the failing step (#9) run.sh unit: on_err reports the failing step (#9) 2 - section black-box: on_err names the running verb, not the stale setup default (#353) run.sh black-box: on_err names the running verb, not the stale setup default (#353) 2 - section unit: staged rebuild swaps in and prunes old build archives (#4, #612) run.sh unit: staged rebuild swaps in and prunes old build archives (#4, #612) 6 - -chained tests/test-root-input-hardening.sh run.sh unit: staged rebuild swaps in and prunes old build archives (#4, #612) - 0 +chained tests/test-root-input-hardening.sh run.sh unit: staged rebuild swaps in and prunes old build archives (#4, #612) - - section unit: xmrig_already_built detection (#4) run.sh unit: xmrig_already_built detection (#4) 6 - section unit: compile_xmrig honours XMRIG_REBUILD (#4) run.sh unit: compile_xmrig honours XMRIG_REBUILD (#4) 3 - section black-box: upgrade / help / unknown command (#4) run.sh black-box: upgrade / help / unknown command (#4) 13 - @@ -102,9 +102,9 @@ section unit: parse_config — autotune tri-state (#95) run.sh unit: parse_confi section black-box: autotune ranks by target (#95) run.sh black-box: autotune ranks by target (#95) 10 - chained tests/test-autotune-noise.sh run.sh black-box: autotune ranks by target (#95) - 71 section black-box: upgrade re-tunes the new build (#95) run.sh black-box: upgrade re-tunes the new build (#95) 7 - -section unit: _wait_miner_live (#95) run.sh unit: _wait_miner_live (#95) 8 - -section unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) 0 - -chained tests/test-config-mode-token-scope.sh run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) - 0 +section unit: _wait_miner_live (#95) run.sh unit: _wait_miner_live (#95) 2 - +section unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) 6 - +chained tests/test-config-mode-token-scope.sh run.sh unit: _read_api_hashrate sends a Bearer only when ACCESS_TOKEN is set (#125) - - section black-box: support-bundle collects + redacts (#147) run.sh black-box: support-bundle collects + redacts (#147) 21 - section black-box: setup --dry-run plan + no-mutation guard (#146) run.sh black-box: setup --dry-run plan + no-mutation guard (#146) 67 - section black-box: completion script + verb-list drift guard (#145) run.sh black-box: completion script + verb-list drift guard (#145) 13 - @@ -236,7 +236,7 @@ section unit: e2e-real git calls survive a nested sudo (#401) run.sh unit: e2e-r section unit: control writable-keys drift guard — bash vs python (#236) run.sh unit: control writable-keys drift guard — bash vs python (#236) 1 - section black-box: the control server (#236) run.sh black-box: the control server (#236) 75 - chained tests/test-control-revocation.sh run.sh black-box: the control server (#236) - 1 -chained tests/test-control-spool-cap.py run.sh black-box: the control server (#236) - 0 +chained tests/test-control-spool-cap.py run.sh black-box: the control server (#236) - - section unit: e2e-real perf record gate (#214/#267) run.sh unit: e2e-real perf record gate (#214/#267) 14 - section unit: require_traversable_checkout — DynamicUser traversal pre-flight (#362) run.sh unit: require_traversable_checkout — DynamicUser traversal pre-flight (#362) 5 - sourced tests/test-e2e-apt-prereqs.sh run.sh unit: require_traversable_checkout — DynamicUser traversal pre-flight (#362) 10 - @@ -249,13 +249,13 @@ sourced tests/test-randomx-mode.sh run.sh contract guard: wire-shape fixtures (# sourced tests/daemon-pools.sh run.sh contract guard: wire-shape fixtures (#351) 141 - chained tests/test-l3-units.sh run.sh contract guard: wire-shape fixtures (#351) - 10 section tree hygiene: the suite writes nothing into the tracked tree (#418) run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) 2 - -chained tests/docs-replay-commands.sh run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) - 0 +chained tests/docs-replay-commands.sh run.sh tree hygiene: the suite writes nothing into the tracked tree (#418) - - make tests/test-doctor-json.sh Makefile test-suite - 51 make tests/test-contract-credentials.sh Makefile test-suite - 1 make tests/test-access-token-readiness.sh Makefile test-suite - 9 make tests/test-docs-clone-pin.sh Makefile test-suite - 11 make tests/test-staged-rebuild.sh Makefile test-suite - 1 -make tests/test-package-upgrade.sh Makefile test-suite - 0 +make tests/test-package-upgrade.sh Makefile test-suite - - make tests/test-dependabot-coverage.sh Makefile test-suite - 1 make tests/test-security-backlog-expiry.sh Makefile test-suite - 1 make tests/test-codeql-workflow.sh Makefile test-suite - 1 @@ -265,7 +265,7 @@ make tests/test-osv-file-issue.sh Makefile test-suite - 5 make tests/test-file-security-issue.sh Makefile test-suite - 3 make tests/test-workflow-contract.sh Makefile test-suite - 2 make tests/test-docs-replay.py Makefile test-suite - 18 -make tests/test-api-allowlist-probe.sh Makefile test-suite - 0 +make tests/test-api-allowlist-probe.sh Makefile test-suite - - make tests/test-e2e-docs-guest.sh Makefile test-suite - 22 make tests/test-control-readiness.py Makefile test-suite - 3 make tests/test-worker-proof.py Makefile test-suite - 24 @@ -282,5 +282,5 @@ make tests/test-env-override-gate.sh Makefile test-suite - 14 make tests/test-server-deadline.py Makefile test-suite - 13 make tests/test-build-deb.sh Makefile test-suite - 36 make tests/test-suite-inventory.sh Makefile test-suite - 18 -make tests/test-suite-inventory-generate.sh Makefile test-suite - 3 +make tests/test-suite-inventory-generate.sh Makefile test-suite - 5 make tests/test-suite-profile.sh Makefile test-suite - 9 diff --git a/docs/dev/suite-profile.md b/docs/dev/suite-profile.md index 6591b099..b3c0f370 100644 --- a/docs/dev/suite-profile.md +++ b/docs/dev/suite-profile.md @@ -23,7 +23,8 @@ is pinned by `docs/dev/file-budget.tsv`. `tests/test-suite-profile.sh` proves the output is byte-identical, the exit status is preserved and the report carries the elapsed seconds, both by calling the wrapper and by running the first recipe line that `make -n test-suite` prints with -and without the variable. A bare `--` is a usage error (status 2). +and without the variable, in the environment and on the command line, with any +`MAKEFLAGS` inherited from an outer `make` cleared. A bare `--` is a usage error (status 2). The CI `Test suite` job sets the variable, so every CI run logs its own profile. `python3 tests/suite-profile.py --aggregate LOG...` reads such logs (timestamped @@ -124,16 +125,37 @@ sourced suite that prints no header of its own is picked up at its first asserti (`tests/test-donation-tor.sh`); `tests/test-randomx-mode.sh` prints no tick at all and shows `-`. Chained and make rows show `-` in this column. +A GitHub log masks secret-looking words as `***`; in the CI log the #125 header reads +`sends a *** when ACCESS_TOKEN is set`. A masked header or tick is matched with +`***` standing for any text, and a masked header that matches no unit or more than +one stops the generation. The output must end in `rigforge tests: N passed, 0 +failed` with N above zero and must have printed every section header of +`tests/run.sh`; a failed or partial run stops the generation before anything is +written. + Standalone passes belong to chained and make suites: the suite's own count when run -alone, from its `N passed`, `passed=N` or `Ran N tests` line, or else its count of -`PASS`, `ok` and tick lines. The generator runs them with `HOME` and `TMPDIR` in a -scratch folder. It never runs a sourced suite on its own: those are fragments that -rely on the variables and temporary folders `tests/run.sh` sets up, and one of them -writes through an unset variable. `-` means a chained suite needs fixtures -`tests/run.sh` builds, or a suite failed on the generating host -(`tests/test-release-bundle.sh` needs `zip`). A chained suite gets the path of -`rigforge.sh` as its argument only when `tests/run.sh` passes `"$SCRIPT"` to it. The standalone count of a chained suite is not added to the -stream count of the section it runs in. +alone, from its `N passed`, `passed=N`, `passed N` or `Ran N tests` line, or else its +result records: lines that start with a tick, `PASS` or `ok`. A closing line such as +`pool schema fields: PASS` is a footer, not a record, and counts only when the suite +prints no leading records at all. A suite that prints neither shows `-`. + +A chained suite gets the arguments `tests/run.sh` passes it, with `$SCRIPT` and +`$ROOT` resolved; one whose arguments or environment prefix need any other +`tests/run.sh` variable (stubs, a fixture folder) is not run and shows `-`. The +generator never runs a sourced suite on its own: those are fragments that rely on the +variables and temporary folders `tests/run.sh` sets up, and one of them writes through +an unset variable. `-` also means a suite failed on the generating host +(`tests/test-release-bundle.sh` needs `zip`). The standalone count of a chained suite +is not added to the stream count of the section it runs in. + +Each measured suite runs in its own process group with `HOME`, `TMPDIR` and the +Python cache in a scratch folder, and with every inherited `RIGFORGE_*` setting +removed except `RIGFORGE_TEST_OVERRIDES=1`, so a caller's `RIGFORGE_STATE` cannot be +written. Chained suites also get the control lock and revision key paths in the +scratch folder, as `tests/run.sh` gives them; make suites do not, as `make` does +not. A suite gets 120 seconds (`SUITE_INVENTORY_TIMEOUT`); when it ends or times out, +the whole process group is killed, so a background listener it started cannot +outlive it. Disjoint means no suite file is called twice, which is the check; assertions are not compared one by one. `tests/suite-inventory.py --check` fails when a suite @@ -151,16 +173,19 @@ those suites call in turn (for example `tests/test-donation.sh` running `tests/run.sh` or the Makefile gains or loses a section header or a suite call that `docs/dev/suite-inventory.tsv` does not list, and its cases show each of those mutations red. `tests/test-suite-inventory-generate.sh` covers regeneration on a -fixture tree: a failed regeneration keeps the committed bytes, a sourced fragment is -never launched, and each unit gets its own count. +fixture tree: a missing, failed or partial output keeps the committed bytes, a +sourced fragment is never launched, a measured suite writes neither the caller's +state folder nor the checkout, a timed-out suite's background child is killed, and +each unit gets its own count. After an intended change, take the output of a finished `tests/run.sh` (a CI log of the `Test suite` job works, or `bash tests/run.sh`, which takes about ten minutes) and regenerate: ```sh log=$(mktemp) -bash tests/run.sh >"$log" 2>/dev/null -python3 tests/suite-inventory.py --generate "$log" +if bash tests/run.sh >"$log" 2>/dev/null; then + python3 tests/suite-inventory.py --generate "$log" +fi rm -f "$log" ``` diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index e262c4bd..774ce7c0 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -2,11 +2,15 @@ import os import re import shlex +import importlib.util import shutil -import subprocess import sys import tempfile +HERE = os.path.dirname(os.path.abspath(__file__)) +_SPEC = importlib.util.spec_from_file_location("suite_counts", os.path.join(HERE, "suite_counts.py")) +tally = importlib.util.module_from_spec(_SPEC) +_SPEC.loader.exec_module(tally) ROOT = os.environ.get("SUITE_INVENTORY_ROOT") or os.path.dirname(os.path.dirname(os.path.abspath(__file__))) INVENTORY = os.environ.get("SUITE_INVENTORY_FILE") or os.path.join(ROOT, "docs", "dev", "suite-inventory.tsv") SELFTEST = "tests/test-suite-inventory.sh" @@ -21,18 +25,9 @@ SOURCE_WORD = r"(?:source|\.)\s+" PROFILE_PREFIX = "$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )" MAKE_COMMAND = re.compile(r"^\t(?:\w+=\S+\s+)*(?:bash|python3)\s+(?:\S+\s+)*?tests/([A-Za-z0-9_.-]+\.(?:sh|py))\s*$") -PASS_SUMMARIES = ( - re.compile(r"(\d+) passed"), - re.compile(r"passed=(\d+)"), - re.compile(r"Ran (\d+) tests?"), -) -PASS_LINE = re.compile(r"✓|\bPASS\b|^\s*ok[ :]", re.M) -ANSI = re.compile(r"(?:\x1b|\^\[)\[[0-9;]*m") -LOG_PREFIX = re.compile(r"^.*?\d{4}-\d\d-\d\dT[\d:.]+Z ") -MESSAGE_CALL = re.compile(r"""\b(?:\w+_)?(?:assert\w*|ok)\s+(?:"((?:\\.|[^"\\])*)"|'([^']*)')""") -EXPANSION = re.compile(r"\$\{[^}]*\}|\$\([^)]*\)|\$[A-Za-z_0-9@*#?]+") LOOP_ALIAS = {"_f": "_sh"} -SCRIPT_ARGUMENT = set() +ARGUMENTS = {} +REDIRECTION = re.compile(r"\s\d*[<>]+&?\S*") def read(path): @@ -47,6 +42,25 @@ def loop_values(items): return out +def call_arguments(rest): + rest = REDIRECTION.sub(" ", rest[1:] if rest.startswith('"') else rest) + lexer = shlex.shlex(rest, posix=True, punctuation_chars=True) + lexer.whitespace_split = True + out = [] + try: + for token in lexer: + if token and set(token) <= set(";&|()<>"): + break + token = token.replace("${SCRIPT}", "$SCRIPT").replace("$SCRIPT", os.path.join(ROOT, "rigforge.sh")) + token = token.replace("${ROOT}", "$ROOT").replace("$ROOT", ROOT) + if "$" in token or "`" in token: + return None + out.append(token) + except ValueError: + return None + return out + + def run_sh_units(): site = "(preamble)" units = [("section", site, "run.sh", site)] @@ -70,10 +84,12 @@ def run_sh_units(): names = ["test-%s.sh" % value for value in loops.get(LOOP_ALIAS.get(var, var), [])] if not names: raise SystemExit("suite-inventory: unresolved loop variable $%s in tests/run.sh" % var) + arguments = call_arguments(line[match.end():]) + if re.search(r"\b\w+=\S*\$\S*\s+$", line[: match.start() + 1]): + arguments = None for name in names: name = "tests/" + name - if '"$SCRIPT"' in line: - SCRIPT_ARGUMENT.add(name) + ARGUMENTS[name] = arguments if name == "tests/run.sh": continue sourced = re.search(SOURCE_WORD + ROOT_PREFIX + r"?" + re.escape(name), line) @@ -106,160 +122,39 @@ def scan(): return run_sh_units() + make_units()[0] -def skeleton(text): - text = re.sub(r"\\(.)", r"\1", text) - parts = EXPANSION.split(text) - if len("".join(parts).strip()) < 4: - return None - return re.compile(".*?".join(re.escape(part) for part in parts), re.S) - - -def file_headers(path): - return [m.group(1) for m in (HEADER.match(line) for line in read(path)) if m] - - -def file_messages(path): - found = [] - for line in read(path): - if line.lstrip().startswith("#"): - continue - for match in MESSAGE_CALL.finditer(line): - pattern = skeleton(match.group(1) if match.group(1) is not None else match.group(2)) - if pattern is not None: - found.append(pattern) - return found - - -class Matcher: - def __init__(self, units): - self.run_headers = [(skeleton(h) or re.compile(re.escape(h)), h) for h in file_headers("tests/run.sh")] - self.run_messages = file_messages("tests/run.sh") - self.sourced = {} - self.site_of = {} - for kind, name, _, site in units: - if kind == "sourced": - self.sourced[name] = { - "headers": [skeleton(h) or re.compile(re.escape(h)) for h in file_headers(name)], - "messages": file_messages(name), - } - self.site_of[name] = site - - def run_header(self, text): - for pattern, literal in self.run_headers: - if pattern.fullmatch(text): - return literal - return None - - def sourced_header(self, text): - for name, info in self.sourced.items(): - if any(p.fullmatch(text) for p in info["headers"]): - return name - return None - - def run_message(self, text): - return any(p.fullmatch(text) for p in self.run_messages) - - def sourced_message(self, name, text): - return any(p.fullmatch(text) for p in self.sourced[name]["messages"]) - - -def attribute(units, stream_text): - matcher = Matcher(units) - totals = {} - section = "(preamble)" - active = None - for raw in stream_text.splitlines(): - line = ANSI.sub("", LOG_PREFIX.sub("", raw)).strip() - if re.match(r"rigforge tests: \d+ passed", line): - break - header = re.fullmatch(r"== (.*) ==", line) - if header: - literal = matcher.run_header(header.group(1)) - if literal is not None: - section, active = literal, None - continue - name = matcher.sourced_header(header.group(1)) - if name is not None: - active = name - continue - if not line.startswith("✓ "): - continue - message = line[2:].strip() - if active is not None: - if matcher.sourced_message(active, message) or not matcher.run_message(message): - key = ("sourced", active) - else: - active = None - key = ("section", section) - else: - key = ("section", section) - if not matcher.run_message(message): - for name in matcher.sourced: - if matcher.site_of[name] == section and matcher.sourced_message(name, message): - active = name - key = ("sourced", name) - break - totals[key] = totals.get(key, 0) + 1 - return totals - - -def count_passes(text): - for pattern in PASS_SUMMARIES: - match = pattern.search(text) - if match: - return int(match.group(1)) - return len(PASS_LINE.findall(text)) - - def standalone_command(kind, name): - if name.endswith(".py"): - cmd = ["python3", "-B", name] - if name == "tests/test-control-spool-cap.py": - cmd.append("util/control-server.py") - return cmd - cmd = ["bash", name] - if kind == "chained" and name in SCRIPT_ARGUMENT: - cmd.append(os.path.join(ROOT, "rigforge.sh")) - return cmd + interpreter = ["python3", "-B"] if name.endswith(".py") else ["bash"] + if kind == "make": + return interpreter + [name] + arguments = ARGUMENTS.get(name) + if arguments is None: + return None + return interpreter + [name] + arguments def measure_standalone(units, candidate): counts = {} scratch = tempfile.mkdtemp(prefix="suite-inventory-") try: - return measure_in(units, candidate, scratch, counts) + for kind, name, _, _ in units: + if kind not in ("make", "chained") or name in counts or name == SELFTEST: + continue + cmd = standalone_command(kind, name) + if cmd is None: + sys.stderr.write("suite-inventory: %s takes run.sh fixtures as arguments; its standalone count stays '-'\n" % name) + continue + rc, text = tally.run_isolated(cmd, tally.child_environment(scratch, candidate, kind), scratch, ROOT) + if rc == 0: + counts[name] = tally.count_passes(text) + if counts[name] is None: + del counts[name] + sys.stderr.write("suite-inventory: %s prints no countable result records; its standalone count stays '-'\n" % name) + elif rc is None: + sys.stderr.write("suite-inventory: %s timed out after %ss standalone; its standalone count stays '-'\n" % (name, tally.TIMEOUT)) + else: + sys.stderr.write("suite-inventory: %s exited %d standalone; its standalone count stays '-'\n" % (name, rc)) finally: shutil.rmtree(scratch, ignore_errors=True) - - -def measure_in(units, candidate, scratch, counts): - for kind, name, _, _ in units: - if kind not in ("make", "chained") or name in counts or name == SELFTEST: - continue - env = dict( - os.environ, - RIGFORGE_TEST_OVERRIDES="1", - PYTHONDONTWRITEBYTECODE="1", - HOME=scratch, - TMPDIR=scratch, - SUITE_INVENTORY_FILE=candidate, - ) - try: - result = subprocess.run( - standalone_command(kind, name), - cwd=ROOT, - env=env, - capture_output=True, - text=True, - timeout=120, - stdin=subprocess.DEVNULL, - ) - except subprocess.TimeoutExpired: - continue - if result.returncode == 0: - counts[name] = count_passes(result.stdout + result.stderr) - else: - sys.stderr.write("suite-inventory: %s exited %d standalone; its standalone count stays '-'\n" % (name, result.returncode)) return counts @@ -330,10 +225,8 @@ def generate(stream_path): stream_text = handle.read() except OSError as error: raise SystemExit("suite-inventory: cannot read the suite output: %s" % error) - if not re.search(r"^rigforge tests: \d+ passed", "\n".join(ANSI.sub("", LOG_PREFIX.sub("", row)) for row in stream_text.splitlines()), re.M): - raise SystemExit("suite-inventory: %s is not a finished tests/run.sh output" % stream_path) units = scan() - stream = attribute(units, stream_text) + stream = tally.attribute(units, stream_text, read, HEADER) directory = os.path.dirname(INVENTORY) handle, candidate = tempfile.mkstemp(prefix=".suite-inventory-", suffix=".tsv", dir=directory) os.close(handle) @@ -345,17 +238,14 @@ def write(extra): out.write("\n".join(HEAD + render(units, stream, dict(standalone, **extra))) + "\n") write({}) - selftest = subprocess.run( - ["bash", SELFTEST], - cwd=ROOT, - env=dict(os.environ, RIGFORGE_TEST_OVERRIDES="1", SUITE_INVENTORY_FILE=candidate), - capture_output=True, - text=True, - stdin=subprocess.DEVNULL, - ) - if selftest.returncode != 0: - raise SystemExit("suite-inventory: the selftest fails on the new inventory:\n%s%s" % (selftest.stdout, selftest.stderr)) - write({SELFTEST: count_passes(selftest.stdout + selftest.stderr)}) + scratch = tempfile.mkdtemp(prefix="suite-inventory-") + try: + rc, text = tally.run_isolated(["bash", SELFTEST], tally.child_environment(scratch, candidate, "make"), scratch, ROOT) + finally: + shutil.rmtree(scratch, ignore_errors=True) + if rc != 0: + raise SystemExit("suite-inventory: the selftest fails on the new inventory:\n%s" % text) + write({SELFTEST: tally.count_passes(text)}) problems = check(candidate) if problems: raise SystemExit("suite-inventory: the new inventory does not pass --check:\n" + "\n".join(problems)) diff --git a/tests/suite-profile.py b/tests/suite-profile.py index 69d3fa9d..5f3f9c70 100755 --- a/tests/suite-profile.py +++ b/tests/suite-profile.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import re +import statistics import subprocess import sys import time @@ -50,12 +51,8 @@ def percentile(values, fraction): return ordered[min(len(ordered) - 1, max(0, int(rank) - 1))] -def median(values): - ordered = sorted(values) - middle = len(ordered) // 2 - if len(ordered) % 2: - return ordered[middle] - return (ordered[middle - 1] + ordered[middle]) / 2 +def printable(text): + return "".join(ch if ch.isprintable() else "\\x%02x" % ord(ch) for ch in text) def aggregate(paths): @@ -85,7 +82,7 @@ def aggregate(paths): for rows, order in runs[1:]: if order != names: raise SystemExit("suite-profile: the runs do not have the same sections") - out = [(name, median([rows[name] for rows, _ in runs]), percentile([rows[name] for rows, _ in runs], 0.9)) for name in names] + out = [(name, statistics.median([rows[name] for rows, _ in runs]), percentile([rows[name] for rows, _ in runs], 0.9)) for name in names] return totals, sorted(out, key=lambda row: -row[1]) @@ -93,9 +90,9 @@ def main(argv): if len(argv) >= 3 and argv[1] == "--aggregate": totals, rows = aggregate(argv[2:]) print("# Per-section median and p90 seconds over %d runs of tests/run.sh (see suite-profile.md). Columns: median, p90, section." % len(totals)) - print("# whole-suite run.sh seconds per run: %s; median %.1f, p90 %.1f" % (", ".join("%.1f" % t for t in totals), median(totals), percentile(totals, 0.9))) + print("# whole-suite run.sh seconds per run: %s; median %.1f, p90 %.1f" % (", ".join("%.1f" % t for t in totals), statistics.median(totals), percentile(totals, 0.9))) for name, mid, high in rows: - print("%.1f\t%.1f\t%s" % (mid, high, name)) + print("%.1f\t%.1f\t%s" % (mid, high, printable(name))) return 0 if len(argv) < 3 or argv[1] != "--": sys.stderr.write("usage: suite-profile.py -- command [args...] | --aggregate report...\n") diff --git a/tests/suite_counts.py b/tests/suite_counts.py new file mode 100644 index 00000000..034df7e3 --- /dev/null +++ b/tests/suite_counts.py @@ -0,0 +1,212 @@ +import os +import re +import signal +import subprocess + +TIMEOUT = float(os.environ.get("SUITE_INVENTORY_TIMEOUT") or 120) +CHILD_KEEP = ("RIGFORGE_TEST_OVERRIDES",) +CONTEXT = {} +LOG_PREFIX = re.compile(r"^.*?\d{4}-\d\d-\d\dT[\d:.]+Z ") +MESSAGE_CALL = re.compile(r"""\b(?:\w+_)?(?:assert\w*|ok)\s+(?:"((?:\\.|[^"\\])*)"|'([^']*)')""") +EXPANSION = re.compile(r"\$\{[^}]*\}|\$\([^)]*\)|\$[A-Za-z_0-9@*#?]+") +ANSI = re.compile(r"(?:\x1b|\^\[)\[[0-9;]*m") +PASS_SUMMARIES = ( + re.compile(r"(\d+) passed"), + re.compile(r"passed[= ](\d+)"), + re.compile(r"Ran (\d+) tests?"), +) +LEADING_RECORD = re.compile(r"^\s*(?:\u2713|PASS\b|ok\b)", re.M) +TRAILING_RECORD = re.compile(r"\bPASS\s*$", re.M) + +def count_passes(text): + for pattern in PASS_SUMMARIES: + match = pattern.search(text) + if match: + return int(match.group(1)) + text = ANSI.sub("", text) + leading = len(LEADING_RECORD.findall(text)) + if leading: + return leading + trailing = len(TRAILING_RECORD.findall(text)) + return trailing or None + + +def child_environment(scratch, candidate, kind): + env = {k: v for k, v in os.environ.items() if not k.startswith(("RIGFORGE_", "SUITE_INVENTORY_")) or k in CHILD_KEEP} + home = os.path.join(scratch, "home") + os.makedirs(home, exist_ok=True) + if kind == "chained": + env.update( + RIGFORGE_CONTROL_LOCK=os.path.join(scratch, "control.lock"), + RIGFORGE_REVISION_KEY=os.path.join(scratch, "revision-key"), + ) + env.update( + RIGFORGE_TEST_OVERRIDES="1", + PYTHONDONTWRITEBYTECODE="1", + PYTHONPYCACHEPREFIX=os.path.join(scratch, "pycache"), + HOME=home, + TMPDIR=scratch, + SUITE_INVENTORY_FILE=candidate, + ) + return env + + +def run_isolated(cmd, env, scratch, cwd): + out_path = os.path.join(scratch, "suite.out") + with open(out_path, "w+b") as out: + child = subprocess.Popen(cmd, cwd=cwd, env=env, stdout=out, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL, start_new_session=True) + try: + rc = child.wait(timeout=TIMEOUT) + except subprocess.TimeoutExpired: + rc = None + try: + os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: + pass + if rc is None: + child.wait() + out.seek(0) + text = out.read().decode("utf-8", "replace") + os.unlink(out_path) + return rc, text + + +def skeleton(text): + text = re.sub(r"\\(.)", r"\1", text) + parts = EXPANSION.split(text) + if len("".join(parts).strip()) < 4: + return None + return re.compile(".*?".join(re.escape(part) for part in parts), re.S) + + +def file_headers(path): + return [m.group(1) for m in (CONTEXT["header"].match(line) for line in CONTEXT["read"](path)) if m] + + +def file_messages(path): + found = [] + for line in CONTEXT["read"](path): + if line.lstrip().startswith("#"): + continue + for match in MESSAGE_CALL.finditer(line): + raw = match.group(1) if match.group(1) is not None else match.group(2) + pattern = skeleton(raw) + if pattern is not None: + found.append((pattern, re.sub(r"\\(.)", r"\1", raw))) + return found + + +class Matcher: + def __init__(self, units): + self.run_headers = [(skeleton(h) or re.compile(re.escape(h)), h) for h in file_headers("tests/run.sh")] + self.sourced_literals = [] + self.run_messages = file_messages("tests/run.sh") + self.sourced = {} + self.site_of = {} + for kind, name, _, site in units: + if kind == "sourced": + self.sourced[name] = { + "headers": [skeleton(h) or re.compile(re.escape(h)) for h in file_headers(name)], + "messages": file_messages(name), + } + self.site_of[name] = site + self.sourced_literals += [(h, name) for h in file_headers(name)] + + def run_header(self, text): + for pattern, literal in self.run_headers: + if pattern.fullmatch(text): + return literal + return None + + def masked_header(self, text): + masked = masked_pattern(text) + hits = {("section", literal) for _, literal in self.run_headers if masked.fullmatch(literal)} + hits |= {("sourced", name) for literal, name in self.sourced_literals if masked.fullmatch(literal)} + if len(hits) != 1: + raise SystemExit("suite-inventory: the masked header [%s] matches %d units; cannot attribute it" % (text, len(hits))) + return hits.pop() + + def sourced_header(self, text): + for name, info in self.sourced.items(): + if any(p.fullmatch(text) for p in info["headers"]): + return name + return None + + def run_message(self, text): + return message_matches(self.run_messages, text) + + def sourced_message(self, name, text): + return message_matches(self.sourced[name]["messages"], text) + + +def masked_pattern(text): + return re.compile(".+?".join(re.escape(part) for part in text.split("***")), re.S) + + +def message_matches(messages, text): + if "***" in text: + masked = masked_pattern(text) + return any(masked.fullmatch(raw) for _, raw in messages) + return any(pattern.fullmatch(text) for pattern, _ in messages) + + +SUMMARY = re.compile(r"rigforge tests: (\d+) passed, (\d+) failed") + + +def clean_lines(stream_text): + return [ANSI.sub("", LOG_PREFIX.sub("", raw)).strip() for raw in stream_text.splitlines()] + + +def attribute(units, stream_text, read, header): + CONTEXT.update(read=read, header=header) + matcher = Matcher(units) + totals = {} + seen = set() + section = "(preamble)" + active = None + summary = None + for line in clean_lines(stream_text): + summary = SUMMARY.match(line) + if summary: + break + header = re.fullmatch(r"== (.*) ==", line) + if header: + text = header.group(1) + literal = matcher.run_header(text) + kind = "section" if literal is not None else None + if literal is None: + name = matcher.sourced_header(text) + if name is not None: + kind, literal = "sourced", name + elif "***" in text: + kind, literal = matcher.masked_header(text) + if kind == "section": + section, active = literal, None + seen.add(literal) + elif kind == "sourced": + active = literal + continue + if not line.startswith("\u2713 "): + continue + message = line[2:].strip() + if active is not None: + if matcher.sourced_message(active, message) or not matcher.run_message(message): + key = ("sourced", active) + else: + active = None + key = ("section", section) + else: + key = ("section", section) + if not matcher.run_message(message): + for name in matcher.sourced: + if matcher.site_of[name] == section and matcher.sourced_message(name, message): + active = name + key = ("sourced", name) + break + totals[key] = totals.get(key, 0) + 1 + if summary is None or int(summary.group(2)) != 0 or int(summary.group(1)) == 0: + raise SystemExit("suite-inventory: the output does not end in a passing 'rigforge tests: N passed, 0 failed' summary") + missing = [u[1] for u in units if u[0] == "section" and u[1] != "(preamble)" and u[1] not in seen] + if missing: + raise SystemExit("suite-inventory: the output never reached %d section(s) of tests/run.sh, first [%s]" % (len(missing), missing[0])) + return totals diff --git a/tests/test-suite-inventory-generate.sh b/tests/test-suite-inventory-generate.sh index 59bccb96..dc15d789 100755 --- a/tests/test-suite-inventory-generate.sh +++ b/tests/test-suite-inventory-generate.sh @@ -10,11 +10,12 @@ fail() { exit 1 } -mkdir -p "$TREE/tests" "$TREE/docs/dev" +mkdir -p "$TREE/tests" "$TREE/docs/dev" "$WORK/external" cat >"$TREE/Makefile" <<'MAKEFILE' test-suite: bash tests/run.sh bash tests/test-a.sh + bash tests/test-slow.sh bash tests/test-suite-inventory.sh MAKEFILE cat >"$TREE/tests/run.sh" <<'RUNSH' @@ -24,66 +25,92 @@ ok "parent after headed return" echo "== linux $HOST_OS deployment ==" source "$ROOT/tests/frag-bare.sh" ok "parent after bare return" -bash "$ROOT/tests/test-chained.sh" "$SCRIPT" +bash "$ROOT/tests/test-chained.sh" "$SCRIPT" "$ROOT/tests/feed.json" +echo "== third Bearer section ==" +ok "third section check" RUNSH cat >"$TREE/tests/frag-headed.sh" <<'FRAG' echo "== headed fragment ==" touch "$FRAG_SENTINEL" assert_eq "headed one" a a -assert_eq "headed two" a a +assert_eq "$label" a a FRAG cat >"$TREE/tests/frag-bare.sh" <<'FRAG' touch "$FRAG_SENTINEL" assert_eq "bare fragment check $n" a a FRAG +printf '{}\n' >"$TREE/tests/feed.json" cat >"$TREE/tests/test-a.sh" <<'SUITE' +printf 'written\n' >"${RIGFORGE_STATE:-$HOME}/config.json" printf ' ok one\n ok two\n' SUITE cat >"$TREE/tests/test-chained.sh" <<'SUITE' -printf 'chained: 2 passed\n' +[ -f "$2" ] || exit 1 +printf 'written\n' >"${RIGFORGE_REVISION_KEY:-$PWD/revision-key}" +printf 'written\n' >"${RIGFORGE_STATE:-$HOME}/config.json" +printf ' ok one\n ok two\nchained suite: PASS\n' +SUITE +cat >"$TREE/tests/test-slow.sh" <<'SUITE' +sleep 300 & +printf '%s\n' "$!" >"$FIXTURE_PIDFILE" +sleep 60 SUITE cat >"$TREE/tests/test-suite-inventory.sh" <<'SUITE' [ -s "$SUITE_INVENTORY_FILE" ] || exit 1 printf 'selftest: 5 passed\n' SUITE printf 'OLD\n' >"$TREE/docs/dev/suite-inventory.tsv" -tick=$'\033[1;32m✓\033[0m' -{ +printf 'caller config\n' >"$WORK/external/config.json" +tick=$'^[[1;32m✓^[[0m' +stream() { printf '2026-01-01T00:00:00.1Z preamble line\n' printf '2026-01-01T00:00:00.2Z == first section ==\n' + printf '2026-01-01T00:00:00.2Z == headed fragment ==\n' printf '2026-01-01T00:00:00.3Z %s headed one\n' "$tick" - printf '2026-01-01T00:00:00.4Z %s headed two\n' "$tick" + printf '2026-01-01T00:00:00.4Z %s a fully dynamic label\n' "$tick" printf '2026-01-01T00:00:00.5Z %s parent after headed return\n' "$tick" printf '2026-01-01T00:00:00.6Z == linux Debian deployment ==\n' printf '2026-01-01T00:00:00.7Z %s bare fragment check 1\n' "$tick" printf '2026-01-01T00:00:00.8Z %s bare fragment check 2\n' "$tick" printf '2026-01-01T00:00:00.9Z %s parent after bare return\n' "$tick" - printf '2026-01-01T00:00:01.0Z rigforge tests: \033[1;32m5 passed\033[0m, 0 failed\n' + printf '2026-01-01T00:00:00.9Z == third *** section ==\n' + printf '2026-01-01T00:00:00.9Z %s third section check\n' "$tick" + printf '2026-01-01T00:00:01.0Z rigforge tests: ^[[1;32m%s passed^[[0m, %s failed\n' "$1" "$2" printf '2026-01-01T00:00:01.1Z %s a later suite tick\n' "$tick" -} >"$WORK/stream.txt" +} +stream 7 0 >"$WORK/stream.txt" +stream 6 1 >"$WORK/failed.txt" +grep -v 'third' "$WORK/stream.txt" >"$WORK/partial.txt" generate() { - env -u SUITE_INVENTORY_FILE FRAG_SENTINEL="$WORK/sentinel" SUITE_INVENTORY_ROOT="$TREE" python3 -I -B "$INV" --generate "$1" 2>&1 + env -u SUITE_INVENTORY_FILE RIGFORGE_STATE="$WORK/external" FIXTURE_PIDFILE="$WORK/slow.pid" SUITE_INVENTORY_TIMEOUT=3 \ + FRAG_SENTINEL="$WORK/sentinel" SUITE_INVENTORY_ROOT="$TREE" python3 -I -B "$INV" --generate "$1" 2>&1 } before=$(cksum <"$TREE/docs/dev/suite-inventory.tsv") -rc=0 -generate "$WORK/missing.txt" >"$WORK/out" || rc=$? -[ "$rc" -ne 0 ] || fail "a missing suite output was accepted" -[ "$(cksum <"$TREE/docs/dev/suite-inventory.tsv")" = "$before" ] || fail "a missing suite output changed the inventory" -printf 'unfinished\n' >"$WORK/unfinished.txt" -rc=0 -generate "$WORK/unfinished.txt" >"$WORK/out" || rc=$? -[ "$rc" -ne 0 ] || fail "an unfinished suite output was accepted" -[ "$(cksum <"$TREE/docs/dev/suite-inventory.tsv")" = "$before" ] || fail "an unfinished suite output changed the inventory" -printf 'PASS: a failed regeneration leaves the committed bytes alone\n' +for bad in missing failed partial; do + rc=0 + generate "$WORK/$bad.txt" >"$WORK/out" || rc=$? + [ "$rc" -ne 0 ] || fail "a $bad suite output was accepted" + [ "$(cksum <"$TREE/docs/dev/suite-inventory.tsv")" = "$before" ] || fail "a $bad suite output changed the inventory" +done +grep -q 'never reached 1 section' "$WORK/out" || fail "the partial output was not named: $(cat "$WORK/out")" +printf 'PASS: a missing, failed or partial suite output leaves the committed bytes alone\n' +(cd "$TREE" && find . -type f | sort) >"$WORK/files.before" generate "$WORK/stream.txt" >"$WORK/out" || fail "regeneration failed: $(cat "$WORK/out")" [ ! -e "$WORK/sentinel" ] || fail "regeneration launched a sourced fragment on its own" printf 'PASS: regeneration never launches a sourced fragment by itself\n' -for leftover in "$TREE"/docs/dev/.suite-inventory-*; do - [ ! -e "$leftover" ] || fail "regeneration left a temporary file" -done + +[ "$(cat "$WORK/external/config.json")" = 'caller config' ] || fail "a measured suite wrote into the caller's state folder" +(cd "$TREE" && find . -type f | sort) >"$WORK/files.after" +cmp -s "$WORK/files.before" "$WORK/files.after" || fail "a measured suite wrote into the checkout: $(diff "$WORK/files.before" "$WORK/files.after")" +printf 'PASS: measured suites write neither the caller state folder nor the checkout\n' + +pid=$(cat "$WORK/slow.pid") +! kill -0 "$pid" 2>/dev/null || fail "the timed-out suite's background child $pid is still running" +grep -q 'test-slow.sh timed out' "$WORK/out" || fail "the timeout was not reported" +printf 'PASS: a timed-out suite and its background child are killed\n' row() { awk -F'\t' -v k="$1" -v u="$2" '$1 == k && $2 == u { print $5 "/" $6 }' "$TREE/docs/dev/suite-inventory.tsv"; } want() { [ "$(row "$1" "$2")" = "$3" ] || fail "$1 $2: expected $3, got [$(row "$1" "$2")]"; } @@ -91,9 +118,11 @@ want section 'first section' 1/- want sourced tests/frag-headed.sh 2/- want section 'linux $HOST_OS deployment' 1/- want sourced tests/frag-bare.sh 2/- +want section 'third Bearer section' 1/- want chained tests/test-chained.sh -/2 want make tests/test-a.sh -/2 +want make tests/test-slow.sh -/- want make tests/test-suite-inventory.sh -/5 -printf 'PASS: every unit carries its own count, across a source return, an expanded header, indented ok lines and a log prefix\n' +printf 'PASS: every unit carries its own count across a sourced header, a source return, an expanded and a masked header, a fixture argument, a result footer and indented ok lines\n' printf 'suite inventory generation selftest: all checks passed\n' diff --git a/tests/test-suite-profile.sh b/tests/test-suite-profile.sh index 716b8a73..831bfd77 100755 --- a/tests/test-suite-profile.sh +++ b/tests/test-suite-profile.sh @@ -44,11 +44,11 @@ python3 -I "$ROOT/tests/suite-profile.py" bash "$WORK/fake.sh" >/dev/null 2>&1 | [ "$rc" = 2 ] || fail "a call without -- exited $rc, expected 2" printf 'PASS: a call without the separator is a usage error\n' -first_recipe() { env "$@" make --no-print-directory -n -C "$ROOT" test-suite | sed -n 1p; } +first_recipe() { env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL "$@" make --no-print-directory -n -C "$ROOT" test-suite | sed -n 1p; } mkdir -p "$WORK/tree/tests" ln -s "$ROOT/tests/suite-profile.py" "$WORK/tree/tests/suite-profile.py" cp "$WORK/fake.sh" "$WORK/tree/tests/run.sh" -default_line=$(first_recipe -u RIGFORGE_SUITE_PROFILE) +default_line=$(MAKEFLAGS=' -- RIGFORGE_SUITE_PROFILE=1' MAKELEVEL=1 first_recipe -u RIGFORGE_SUITE_PROFILE) profiled_line=$(first_recipe RIGFORGE_SUITE_PROFILE=1) [ "$default_line" = 'bash tests/run.sh' ] || fail "the default recipe is [$default_line], not the plain suite run" (cd "$WORK/tree" && bash -c "$default_line") >"$WORK/make-default.out" 2>"$WORK/make-default.err" @@ -56,6 +56,8 @@ cmp -s "$WORK/direct.out" "$WORK/make-default.out" || fail "the default recipe c grep -q 'suite-profile:' "$WORK/make-default.err" && fail "the default recipe printed a profile" printf 'PASS: make test-suite runs the plain suite without the toggle\n' +cmdline_line=$(env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL -u RIGFORGE_SUITE_PROFILE make --no-print-directory -n -C "$ROOT" test-suite RIGFORGE_SUITE_PROFILE=1 | sed -n 1p) +[ "$cmdline_line" = "$profiled_line" ] || fail "make test-suite RIGFORGE_SUITE_PROFILE=1 gave [$cmdline_line], the environment form [$profiled_line]" case "$profiled_line" in *'tests/suite-profile.py -- bash tests/run.sh') ;; *) fail "the toggled recipe is [$profiled_line]" ;; esac (cd "$WORK/tree" && bash -c "$profiled_line") >"$WORK/make-profiled.out" 2>"$WORK/make-profiled.err" cmp -s "$WORK/direct.out" "$WORK/make-profiled.out" || fail "the toggled recipe changed the output" @@ -78,10 +80,14 @@ for n in 1 2 3; do printf '2026-01-01T00:00:0%d.3Z suite-profile: total %d.500 s, 2 sections, 3 passed\n' "$n" "$((n * 10 + n))" } >"$WORK/run$n.log" done +printf '2026-01-01T00:00:01.4Z suite-profile: 0.100\t0\tbell\aname\n' >>"$WORK/run1.log" +printf '2026-01-01T00:00:02.4Z suite-profile: 0.100\t0\tbell\aname\n' >>"$WORK/run2.log" +printf '2026-01-01T00:00:03.4Z suite-profile: 0.100\t0\tbell\aname\n' >>"$WORK/run3.log" python3 -I "$ROOT/tests/suite-profile.py" --aggregate "$WORK/run1.log" "$WORK/run2.log" "$WORK/run3.log" >"$WORK/aggregate.tsv" grep -qxF $'20.5\t30.5\tslow section' "$WORK/aggregate.tsv" || fail "slow section median/p90 wrong: $(cat "$WORK/aggregate.tsv")" grep -qxF $'2.0\t3.0\tfast section' "$WORK/aggregate.tsv" || fail "fast section median/p90 wrong" grep -q '^# whole-suite run.sh seconds per run: 11.5, 22.5, 33.5; median 22.5, p90 33.5$' "$WORK/aggregate.tsv" || fail "totals wrong: $(cat "$WORK/aggregate.tsv")" +grep -qxF $'0.1\t0.1\tbell\\x07name' "$WORK/aggregate.tsv" || fail "a control byte in a section label was not escaped" printf 'PASS: --aggregate reads timestamped CI logs and reports per-section and whole-suite median and p90\n' printf 'suite profile selftest: all checks passed\n' From 763101e80ceff1302c73886792230da681b6b481 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:51:17 -0600 Subject: [PATCH 08/11] tests: reap measured suites on interrupt, count recipe calls past blank lines, refuse short or ambiguous output (part of #875) Co-Authored-By: Claude Opus 5.5 --- docs/dev/suite-inventory.tsv | 6 +-- docs/dev/suite-profile.md | 19 ++++++--- tests/suite-inventory.py | 7 ++- tests/suite-profile.py | 2 + tests/suite_counts.py | 13 +++--- tests/test-suite-inventory-generate.sh | 59 +++++++++++++++++++++----- tests/test-suite-inventory.sh | 15 +++++++ tests/test-suite-profile.sh | 5 +++ 8 files changed, 98 insertions(+), 28 deletions(-) diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index 4b3de379..f4612f04 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -281,6 +281,6 @@ make tests/test-release-bundle.sh Makefile test-suite - - make tests/test-env-override-gate.sh Makefile test-suite - 14 make tests/test-server-deadline.py Makefile test-suite - 13 make tests/test-build-deb.sh Makefile test-suite - 36 -make tests/test-suite-inventory.sh Makefile test-suite - 18 -make tests/test-suite-inventory-generate.sh Makefile test-suite - 5 -make tests/test-suite-profile.sh Makefile test-suite - 9 +make tests/test-suite-inventory.sh Makefile test-suite - 23 +make tests/test-suite-inventory-generate.sh Makefile test-suite - 7 +make tests/test-suite-profile.sh Makefile test-suite - 10 diff --git a/docs/dev/suite-profile.md b/docs/dev/suite-profile.md index b3c0f370..254b78aa 100644 --- a/docs/dev/suite-profile.md +++ b/docs/dev/suite-profile.md @@ -24,7 +24,8 @@ is pinned by `docs/dev/file-budget.tsv`. is preserved and the report carries the elapsed seconds, both by calling the wrapper and by running the first recipe line that `make -n test-suite` prints with and without the variable, in the environment and on the command line, with any -`MAKEFLAGS` inherited from an outer `make` cleared. A bare `--` is a usage error (status 2). +`MAKEFLAGS` inherited from an outer `make` cleared. A suite killed by a signal exits +with 128 plus the signal number through the wrapper, as it does without it. A bare `--` is a usage error (status 2). The CI `Test suite` job sets the variable, so every CI run logs its own profile. `python3 tests/suite-profile.py --aggregate LOG...` reads such logs (timestamped @@ -129,9 +130,11 @@ A GitHub log masks secret-looking words as `***`; in the CI log the #125 header `sends a *** when ACCESS_TOKEN is set`. A masked header or tick is matched with `***` standing for any text, and a masked header that matches no unit or more than one stops the generation. The output must end in `rigforge tests: N passed, 0 -failed` with N above zero and must have printed every section header of -`tests/run.sh`; a failed or partial run stops the generation before anything is -written. +failed` with N above zero, must carry at least N tick lines and must have printed +every section header of `tests/run.sh`; a failed, partial or short run stops the +generation before anything is written. Colour codes are removed both as raw escape +bytes (the suite's own output) and in the `^[` form that `gh run view --log` +prints. Standalone passes belong to chained and make suites: the suite's own count when run alone, from its `N passed`, `passed=N`, `passed N` or `Ran N tests` line, or else its @@ -154,8 +157,9 @@ removed except `RIGFORGE_TEST_OVERRIDES=1`, so a caller's `RIGFORGE_STATE` canno written. Chained suites also get the control lock and revision key paths in the scratch folder, as `tests/run.sh` gives them; make suites do not, as `make` does not. A suite gets 120 seconds (`SUITE_INVENTORY_TIMEOUT`); when it ends or times out, -the whole process group is killed, so a background listener it started cannot -outlive it. +the whole process group is killed and reaped, also when the generator itself is +interrupted, so a background listener it started cannot outlive it or its scratch +folder. Disjoint means no suite file is called twice, which is the check; assertions are not compared one by one. `tests/suite-inventory.py --check` fails when a suite @@ -163,7 +167,8 @@ appears at two call sites (also two identical lines in one section), when it appears in both `tests/run.sh` and the Makefile `test-suite` recipe in any of the recognised forms (`bash`, `sh`, `python3`, `source` or `.`, a `$ROOT`, `${ROOT}` or repository-relative path, or direct execution), when the recipe does not run -`tests/run.sh` exactly once, and when a recipe line is not recognised. Suites that +`tests/run.sh` exactly once, and when a recipe line is not recognised. Blank and +comment lines inside the recipe are skipped, as `make` skips them. Suites that those suites call in turn (for example `tests/test-donation.sh` running `tests/test-e2e-donation.sh`) are not listed. diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index 774ce7c0..ee76b2e6 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -18,9 +18,10 @@ FOR_LOOP = re.compile(r"^\s*for (\w+) in (.*?); do\b") COMMAND = r"(?:bash|sh|python3?|source|\.)(?:\s+-[\w-]+)*\s+" ROOT_PREFIX = r"(?:\"?\$\{?ROOT\}?\"?/|\./)" +CALL_PREFIX = r"(?:\"?\$\{?ROOT\}?\"?/|\"?(?:\./)?)" NAME = r"(?:([A-Za-z0-9_.-]+\.(?:sh|py))|test-(\$\w+)\.sh)" REFERENCE = re.compile( - r"(?:(?:^|[;&|(]|\s)" + COMMAND + ROOT_PREFIX + r"?tests/|(?:^\s*|[;&|(]\s*)" + ROOT_PREFIX + r"tests/)" + NAME + r"(?:(?:^|[;&|(]|\s)" + COMMAND + CALL_PREFIX + r"tests/|(?:^\s*|[;&|(]\s*)" + ROOT_PREFIX + r"tests/)" + NAME ) SOURCE_WORD = r"(?:source|\.)\s+" PROFILE_PREFIX = "$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )" @@ -92,7 +93,7 @@ def run_sh_units(): ARGUMENTS[name] = arguments if name == "tests/run.sh": continue - sourced = re.search(SOURCE_WORD + ROOT_PREFIX + r"?" + re.escape(name), line) + sourced = re.search(SOURCE_WORD + CALL_PREFIX + re.escape(name), line) units.append(("sourced" if sourced else "chained", name, "run.sh", site)) return units @@ -106,6 +107,8 @@ def make_units(): in_target = True continue if in_target: + if not line.strip() or line.lstrip().startswith("#"): + continue if not line.startswith("\t"): break match = MAKE_COMMAND.match(line.replace(PROFILE_PREFIX, "")) diff --git a/tests/suite-profile.py b/tests/suite-profile.py index 5f3f9c70..2f053acc 100755 --- a/tests/suite-profile.py +++ b/tests/suite-profile.py @@ -102,6 +102,8 @@ def main(argv): sys.stdout.buffer.write(raw) sys.stdout.buffer.flush() rc = child.wait() + if rc < 0: + rc = 128 - rc sys.stderr.write(report(*profile.result)) return rc diff --git a/tests/suite_counts.py b/tests/suite_counts.py index 034df7e3..a10ecf40 100644 --- a/tests/suite_counts.py +++ b/tests/suite_counts.py @@ -55,15 +55,16 @@ def run_isolated(cmd, env, scratch, cwd): out_path = os.path.join(scratch, "suite.out") with open(out_path, "w+b") as out: child = subprocess.Popen(cmd, cwd=cwd, env=env, stdout=out, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL, start_new_session=True) + rc = None try: rc = child.wait(timeout=TIMEOUT) except subprocess.TimeoutExpired: - rc = None - try: - os.killpg(child.pid, signal.SIGKILL) - except ProcessLookupError: pass - if rc is None: + finally: + try: + os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: + pass child.wait() out.seek(0) text = out.read().decode("utf-8", "replace") @@ -206,6 +207,8 @@ def attribute(units, stream_text, read, header): totals[key] = totals.get(key, 0) + 1 if summary is None or int(summary.group(2)) != 0 or int(summary.group(1)) == 0: raise SystemExit("suite-inventory: the output does not end in a passing 'rigforge tests: N passed, 0 failed' summary") + if sum(totals.values()) < int(summary.group(1)): + raise SystemExit("suite-inventory: the output carries %d tick lines for %s passes" % (sum(totals.values()), summary.group(1))) missing = [u[1] for u in units if u[0] == "section" and u[1] != "(preamble)" and u[1] not in seen] if missing: raise SystemExit("suite-inventory: the output never reached %d section(s) of tests/run.sh, first [%s]" % (len(missing), missing[0])) diff --git a/tests/test-suite-inventory-generate.sh b/tests/test-suite-inventory-generate.sh index dc15d789..bb13a615 100755 --- a/tests/test-suite-inventory-generate.sh +++ b/tests/test-suite-inventory-generate.sh @@ -52,7 +52,8 @@ printf ' ok one\n ok two\nchained suite: PASS\n' SUITE cat >"$TREE/tests/test-slow.sh" <<'SUITE' sleep 300 & -printf '%s\n' "$!" >"$FIXTURE_PIDFILE" +printf '%s %s\n' "$$" "$!" >"$FIXTURE_PIDFILE.tmp" +mv "$FIXTURE_PIDFILE.tmp" "$FIXTURE_PIDFILE" sleep 60 SUITE cat >"$TREE/tests/test-suite-inventory.sh" <<'SUITE' @@ -61,13 +62,13 @@ printf 'selftest: 5 passed\n' SUITE printf 'OLD\n' >"$TREE/docs/dev/suite-inventory.tsv" printf 'caller config\n' >"$WORK/external/config.json" -tick=$'^[[1;32m✓^[[0m' +tick=$'\033[1;32m\u2713\033[0m' stream() { printf '2026-01-01T00:00:00.1Z preamble line\n' printf '2026-01-01T00:00:00.2Z == first section ==\n' printf '2026-01-01T00:00:00.2Z == headed fragment ==\n' - printf '2026-01-01T00:00:00.3Z %s headed one\n' "$tick" - printf '2026-01-01T00:00:00.4Z %s a fully dynamic label\n' "$tick" + printf '2026-01-01T00:00:00.3Z %s a fully dynamic label\n' "$tick" + printf '2026-01-01T00:00:00.4Z %s headed one\n' "$tick" printf '2026-01-01T00:00:00.5Z %s parent after headed return\n' "$tick" printf '2026-01-01T00:00:00.6Z == linux Debian deployment ==\n' printf '2026-01-01T00:00:00.7Z %s bare fragment check 1\n' "$tick" @@ -75,12 +76,15 @@ stream() { printf '2026-01-01T00:00:00.9Z %s parent after bare return\n' "$tick" printf '2026-01-01T00:00:00.9Z == third *** section ==\n' printf '2026-01-01T00:00:00.9Z %s third section check\n' "$tick" - printf '2026-01-01T00:00:01.0Z rigforge tests: ^[[1;32m%s passed^[[0m, %s failed\n' "$1" "$2" + printf '2026-01-01T00:00:01.0Z rigforge tests: \033[1;32m%s passed\033[0m, %s failed\n' "$1" "$2" printf '2026-01-01T00:00:01.1Z %s a later suite tick\n' "$tick" } stream 7 0 >"$WORK/stream.txt" stream 6 1 >"$WORK/failed.txt" -grep -v 'third' "$WORK/stream.txt" >"$WORK/partial.txt" +stream 6 0 | grep -v 'third' >"$WORK/partial.txt" +sed 's/== third \*\*\* section ==/== *** section ==/' "$WORK/stream.txt" >"$WORK/ambiguous.txt" +stream 9 0 >"$WORK/short.txt" +sed $'s/\033/^[/g' "$WORK/stream.txt" >"$WORK/caret.txt" generate() { env -u SUITE_INVENTORY_FILE RIGFORGE_STATE="$WORK/external" FIXTURE_PIDFILE="$WORK/slow.pid" SUITE_INVENTORY_TIMEOUT=3 \ @@ -88,14 +92,17 @@ generate() { } before=$(cksum <"$TREE/docs/dev/suite-inventory.tsv") -for bad in missing failed partial; do +for bad in missing failed partial ambiguous short; do rc=0 generate "$WORK/$bad.txt" >"$WORK/out" || rc=$? [ "$rc" -ne 0 ] || fail "a $bad suite output was accepted" [ "$(cksum <"$TREE/docs/dev/suite-inventory.tsv")" = "$before" ] || fail "a $bad suite output changed the inventory" + cp "$WORK/out" "$WORK/out.$bad" done -grep -q 'never reached 1 section' "$WORK/out" || fail "the partial output was not named: $(cat "$WORK/out")" -printf 'PASS: a missing, failed or partial suite output leaves the committed bytes alone\n' +grep -q 'never reached 1 section' "$WORK/out.partial" || fail "the partial output was not named: $(cat "$WORK/out.partial")" +grep -q 'matches 2 units' "$WORK/out.ambiguous" || fail "the ambiguous masked header was not named: $(cat "$WORK/out.ambiguous")" +grep -q '7 tick lines for 9 passes' "$WORK/out.short" || fail "the short output was not named: $(cat "$WORK/out.short")" +printf 'PASS: a missing, failed, partial, ambiguous or short suite output leaves the committed bytes alone\n' (cd "$TREE" && find . -type f | sort) >"$WORK/files.before" generate "$WORK/stream.txt" >"$WORK/out" || fail "regeneration failed: $(cat "$WORK/out")" @@ -107,8 +114,10 @@ printf 'PASS: regeneration never launches a sourced fragment by itself\n' cmp -s "$WORK/files.before" "$WORK/files.after" || fail "a measured suite wrote into the checkout: $(diff "$WORK/files.before" "$WORK/files.after")" printf 'PASS: measured suites write neither the caller state folder nor the checkout\n' -pid=$(cat "$WORK/slow.pid") -! kill -0 "$pid" 2>/dev/null || fail "the timed-out suite's background child $pid is still running" +read -r shell_pid child_pid <"$WORK/slow.pid" +for pid in "$shell_pid" "$child_pid"; do + ! kill -0 "$pid" 2>/dev/null || fail "the timed-out suite's process $pid is still running" +done grep -q 'test-slow.sh timed out' "$WORK/out" || fail "the timeout was not reported" printf 'PASS: a timed-out suite and its background child are killed\n' @@ -125,4 +134,32 @@ want make tests/test-slow.sh -/- want make tests/test-suite-inventory.sh -/5 printf 'PASS: every unit carries its own count across a sourced header, a source return, an expanded and a masked header, a fixture argument, a result footer and indented ok lines\n' +cp "$TREE/docs/dev/suite-inventory.tsv" "$WORK/generated.tsv" +generate "$WORK/caret.txt" >"$WORK/out" || fail "a caret-escaped log was refused: $(cat "$WORK/out")" +cmp -s "$WORK/generated.tsv" "$TREE/docs/dev/suite-inventory.tsv" || fail "a caret-escaped log gave other counts than the raw output" +printf 'PASS: a gh run view log with caret escapes gives the same inventory as the raw output\n' + +rm -f "$WORK/slow.pid" +before=$(cksum <"$TREE/docs/dev/suite-inventory.tsv") +env -u SUITE_INVENTORY_FILE RIGFORGE_STATE="$WORK/external" FIXTURE_PIDFILE="$WORK/slow.pid" SUITE_INVENTORY_TIMEOUT=60 \ + FRAG_SENTINEL="$WORK/sentinel" SUITE_INVENTORY_ROOT="$TREE" \ + python3 -I -c 'import os, signal, sys; signal.signal(signal.SIGINT, signal.SIG_DFL); os.execvp(sys.argv[1], sys.argv[1:])' \ + python3 -I -B "$INV" --generate "$WORK/stream.txt" >"$WORK/out" 2>&1 & +generator=$! +for _ in $(seq 100); do + [ -s "$WORK/slow.pid" ] && break + sleep 0.1 +done +[ -s "$WORK/slow.pid" ] || fail "the slow suite never started" +kill -INT "$generator" +rc=0 +wait "$generator" || rc=$? +[ "$rc" -ne 0 ] || fail "an interrupted regeneration exited 0" +read -r shell_pid child_pid <"$WORK/slow.pid" +for pid in "$shell_pid" "$child_pid"; do + ! kill -0 "$pid" 2>/dev/null || fail "process $pid of the interrupted suite is still running" +done +[ "$(cksum <"$TREE/docs/dev/suite-inventory.tsv")" = "$before" ] || fail "an interrupted regeneration changed the inventory" +printf 'PASS: an interrupted regeneration kills the measured suite and its child and keeps the committed bytes\n' + printf 'suite inventory generation selftest: all checks passed\n' diff --git a/tests/test-suite-inventory.sh b/tests/test-suite-inventory.sh index 9feb668d..809418fc 100755 --- a/tests/test-suite-inventory.sh +++ b/tests/test-suite-inventory.sh @@ -112,4 +112,19 @@ sed 's|^\t\$(if \$(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )ba cp "$WORK/Makefile.new" "$WORK/tree/Makefile" expect_red 'a test-suite recipe that runs tests/run.sh twice is refused' 'runs tests/run.sh 2 times' +fresh_tree +printf 'bash "tests/test-doctor-json.sh"\n' >>"$WORK/tree/tests/run.sh" +expect_red 'a quoted repository-relative call to a make suite is refused' 'test-doctor-json.sh runs from both' + +for filler in '' '# a comment line' $'\t# a recipe comment'; do + fresh_tree + awk -v f="$filler" '{ print } /^\t\$\(if \$\(RIGFORGE_SUITE_PROFILE\)/ { print f }' "$WORK/tree/Makefile" >"$WORK/Makefile.new" + cp "$WORK/Makefile.new" "$WORK/tree/Makefile" + check_tree >/dev/null || fail "a [$filler] line inside the recipe hid later calls: $(check_tree)" + grep -vF 'bash tests/test-doctor-json.sh' "$WORK/tree/Makefile" >"$WORK/Makefile.new" + cp "$WORK/Makefile.new" "$WORK/tree/Makefile" + expect_red "a suite dropped after a [$filler] recipe line is refused" 'stale in docs/dev/suite-inventory.tsv' +done +printf 'PASS: blank and comment lines inside the recipe hide no call\n' + printf 'suite inventory selftest: all checks passed\n' diff --git a/tests/test-suite-profile.sh b/tests/test-suite-profile.sh index 831bfd77..30eaae81 100755 --- a/tests/test-suite-profile.sh +++ b/tests/test-suite-profile.sh @@ -90,4 +90,9 @@ grep -q '^# whole-suite run.sh seconds per run: 11.5, 22.5, 33.5; median 22.5, p grep -qxF $'0.1\t0.1\tbell\\x07name' "$WORK/aggregate.tsv" || fail "a control byte in a section label was not escaped" printf 'PASS: --aggregate reads timestamped CI logs and reports per-section and whole-suite median and p90\n' +rc=0 +python3 -I "$ROOT/tests/suite-profile.py" -- bash -c 'kill -TERM $$' >/dev/null 2>&1 || rc=$? +[ "$rc" = 143 ] || fail "a suite killed by SIGTERM exited $rc through the wrapper, expected 143 as without it" +printf 'PASS: a signal death keeps the shell exit status 128 + signal\n' + printf 'suite profile selftest: all checks passed\n' From 9213f31569ae7cab0549d36c1c1375ff0372792d Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 17:30:38 -0600 Subject: [PATCH 09/11] tests: one command per recipe line, refuse recipe conditionals, cross-check make -n, bash 3.2 fixture tick (part of #875) Co-Authored-By: Claude Opus 5.5 --- docs/dev/suite-inventory.tsv | 2 +- docs/dev/suite-profile.md | 20 ++++++--- tests/README.md | 8 +++- tests/suite-inventory.py | 44 ++++++++++++++++++-- tests/test-suite-inventory-generate.sh | 2 +- tests/test-suite-inventory.sh | 56 +++++++++++++++++++++----- 6 files changed, 108 insertions(+), 24 deletions(-) diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index f4612f04..5b0d2e77 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -281,6 +281,6 @@ make tests/test-release-bundle.sh Makefile test-suite - - make tests/test-env-override-gate.sh Makefile test-suite - 14 make tests/test-server-deadline.py Makefile test-suite - 13 make tests/test-build-deb.sh Makefile test-suite - 36 -make tests/test-suite-inventory.sh Makefile test-suite - 23 +make tests/test-suite-inventory.sh Makefile test-suite - 30 make tests/test-suite-inventory-generate.sh Makefile test-suite - 7 make tests/test-suite-profile.sh Makefile test-suite - 10 diff --git a/docs/dev/suite-profile.md b/docs/dev/suite-profile.md index 254b78aa..64b3e13e 100644 --- a/docs/dev/suite-profile.md +++ b/docs/dev/suite-profile.md @@ -166,11 +166,21 @@ not compared one by one. `tests/suite-inventory.py --check` fails when a suite appears at two call sites (also two identical lines in one section), when it appears in both `tests/run.sh` and the Makefile `test-suite` recipe in any of the recognised forms (`bash`, `sh`, `python3`, `source` or `.`, a `$ROOT`, `${ROOT}` or -repository-relative path, or direct execution), when the recipe does not run -`tests/run.sh` exactly once, and when a recipe line is not recognised. Blank and -comment lines inside the recipe are skipped, as `make` skips them. Suites that -those suites call in turn (for example `tests/test-donation.sh` running -`tests/test-e2e-donation.sh`) are not listed. +a quoted or unquoted repository-relative path, or direct execution), when the recipe +does not run `tests/run.sh` exactly once, and when a recipe line is not recognised. + +A recognised recipe line is one command: optional `NAME=value` settings with plain +values, `bash` or `python3`, optional single-letter flags, and one `tests/` file, +nothing after it. A second command on the same line (`&&`, `;`, a command +substitution) and a make conditional (`ifdef`, `ifeq`, `else`, `endif` and the +like) inside the recipe are refused as unrecognised. Blank and comment lines inside +the recipe are skipped, as `make` skips them. The check then runs +`make -n test-suite` with every inherited `MAKEFLAGS` setting and +`RIGFORGE_SUITE_PROFILE` cleared and requires exactly the recipe lines it read, in +order, so a prerequisite target or a second `test-suite` rule that overrides the +recipe cannot add or replace a suite unseen. Suites that those suites call in turn +(for example `tests/test-donation.sh` running `tests/test-e2e-donation.sh`) are not +listed. ### Keeping it true diff --git a/tests/README.md b/tests/README.md index 596e0ee6..bd901553 100644 --- a/tests/README.md +++ b/tests/README.md @@ -17,8 +17,6 @@ GitHub Test suite job, including argument inspection, password rotation and EXIT The offline `test-coverage-cache.sh` regression also runs in `make test-suite`. Coverage caches only the pinned jq download, keyed by release, Linux architecture and SHA256. - -The suite inventory (`docs/dev/suite-inventory.tsv`) lists every `run.sh` section and every standalone suite `run.sh` or `make test-suite` runs. `test-suite-inventory.sh` fails when a section header or suite call is missing from it, and `test-suite-profile.sh` covers `RIGFORGE_SUITE_PROFILE=1 make test-suite`, which prints per-section seconds to stderr. See [docs/dev/suite-profile.md](../docs/dev/suite-profile.md). Every invocation copies it into private disposable storage and verifies the checksum before use; the container mounts that verified copy read-only. A corrupt entry fails before coverage runs; remove the invalid entry from `.coverage-cache` and retry. Downloads publish atomically only after @@ -42,6 +40,12 @@ miner, populated build tree, report or previous PASS as proof for another candid compare complete assertion/input/platform manifests and collect a week of setup/verification time, CI median/p90, failures and occupied hours; missing evidence leaves acceptance open. +The suite inventory (`docs/dev/suite-inventory.tsv`) lists every `run.sh` section and every +standalone suite `run.sh` or `make test-suite` runs. `test-suite-inventory.sh` fails when a section +header or suite call is missing from it, and `test-suite-profile.sh` covers +`RIGFORGE_SUITE_PROFILE=1 make test-suite`, which prints per-section seconds to stderr. See +[docs/dev/suite-profile.md](../docs/dev/suite-profile.md). + > The split exists so CI proves everything it can on a hosted CI machine, while the things it > physically can't do (compile XMRig, reserve HugePages, write MSRs, set the governor, hash) are > proven once, by hand, on a real rig before tagging a release. diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index ee76b2e6..5a7795ad 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -4,6 +4,7 @@ import shlex import importlib.util import shutil +import subprocess import sys import tempfile @@ -25,7 +26,9 @@ ) SOURCE_WORD = r"(?:source|\.)\s+" PROFILE_PREFIX = "$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )" -MAKE_COMMAND = re.compile(r"^\t(?:\w+=\S+\s+)*(?:bash|python3)\s+(?:\S+\s+)*?tests/([A-Za-z0-9_.-]+\.(?:sh|py))\s*$") +MAKE_COMMAND = re.compile(r"^\t(?:[A-Za-z_]\w*=[\w./:-]*\s+)*(?:bash|python3)\s+(?:-[A-Za-z]+\s+)*tests/([A-Za-z0-9_.-]+\.(?:sh|py))\s*$") +CONDITIONAL = re.compile(r"^\s*(?:ifeq|ifneq|ifdef|ifndef|else|endif)\b") +DRY_RUN_CLEARED = ("MAKEFLAGS", "MFLAGS", "GNUMAKEFLAGS", "MAKELEVEL", "MAKEOVERRIDES", "RIGFORGE_SUITE_PROFILE") LOOP_ALIAS = {"_f": "_sh"} ARGUMENTS = {} REDIRECTION = re.compile(r"\s\d*[<>]+&?\S*") @@ -101,6 +104,7 @@ def run_sh_units(): def make_units(): units = [] runners = 0 + commands = [] in_target = False for line in read("Makefile"): if line.startswith("test-suite:"): @@ -109,16 +113,39 @@ def make_units(): if in_target: if not line.strip() or line.lstrip().startswith("#"): continue + if CONDITIONAL.match(line): + raise SystemExit("suite-inventory: unrecognised test-suite recipe line: %s" % line.strip()) if not line.startswith("\t"): break - match = MAKE_COMMAND.match(line.replace(PROFILE_PREFIX, "")) + if line.startswith("\t" + PROFILE_PREFIX): + line = "\t" + line[len(PROFILE_PREFIX) + 1 :] + match = MAKE_COMMAND.match(line) if match is None: raise SystemExit("suite-inventory: unrecognised test-suite recipe line: %s" % line.strip()) + commands.append(line.strip()) if match.group(1) == "run.sh": runners += 1 else: units.append(("make", "tests/" + match.group(1), "Makefile", "test-suite")) - return units, runners + return units, runners, commands + + +def dry_run(): + env = {k: v for k, v in os.environ.items() if k not in DRY_RUN_CLEARED} + try: + result = subprocess.run( + ["make", "--no-print-directory", "-n", "-C", ROOT, "test-suite"], + env=env, + capture_output=True, + text=True, + stdin=subprocess.DEVNULL, + timeout=60, + ) + except (OSError, subprocess.TimeoutExpired) as error: + return None, str(error) + if result.returncode != 0: + return None, result.stderr.strip() + return [line.strip() for line in result.stdout.splitlines() if line.strip() and not line.strip().startswith("#")], None def scan(): @@ -185,9 +212,18 @@ def committed(path=None): def check(path=None): units = scan() problems = [] - runners = make_units()[1] + _, runners, commands = make_units() if runners != 1: problems.append("the test-suite recipe runs tests/run.sh %d times; it must run once" % runners) + ran, error = dry_run() + if ran is None: + problems.append("make -n test-suite failed: %s" % error) + elif ran != commands: + extra = [c for c in ran if c not in commands] + problems.append( + "make -n test-suite runs %d commands, the test-suite recipe lists %d%s" + % (len(ran), len(commands), "; not in the recipe: %s" % extra[0] if extra else "") + ) run_files = {u[1] for u in units if u[0] in ("sourced", "chained")} make_files = {u[1] for u in units if u[0] == "make"} for name in sorted(run_files & make_files): diff --git a/tests/test-suite-inventory-generate.sh b/tests/test-suite-inventory-generate.sh index bb13a615..2f568a2d 100755 --- a/tests/test-suite-inventory-generate.sh +++ b/tests/test-suite-inventory-generate.sh @@ -62,7 +62,7 @@ printf 'selftest: 5 passed\n' SUITE printf 'OLD\n' >"$TREE/docs/dev/suite-inventory.tsv" printf 'caller config\n' >"$WORK/external/config.json" -tick=$'\033[1;32m\u2713\033[0m' +tick=$'\033[1;32m✓\033[0m' stream() { printf '2026-01-01T00:00:00.1Z preamble line\n' printf '2026-01-01T00:00:00.2Z == first section ==\n' diff --git a/tests/test-suite-inventory.sh b/tests/test-suite-inventory.sh index 809418fc..ebee6852 100755 --- a/tests/test-suite-inventory.sh +++ b/tests/test-suite-inventory.sh @@ -21,6 +21,22 @@ fresh_tree() { cp "${SUITE_INVENTORY_FILE:-$ROOT/docs/dev/suite-inventory.tsv}" "$WORK/tree/docs/dev/suite-inventory.tsv" } +PROFILE_LINE=$'\t$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )bash tests/run.sh' +DOCTOR_LINE=$'\tbash tests/test-doctor-json.sh' +LAST_LINE=$'\tbash tests/test-suite-profile.sh' + +insert_after() { + grep -qxF -- "$2" "$1" || fail "no line [$2] in $1" + A="$2" B="$3" awk '{ print } $0 == ENVIRON["A"] { print ENVIRON["B"] }' "$1" >"$1.new" + mv "$1.new" "$1" +} + +replace_line() { + grep -qxF -- "$2" "$1" || fail "no line [$2] in $1" + A="$2" B="$3" awk '$0 == ENVIRON["A"] { print ENVIRON["B"]; next } { print }' "$1" >"$1.new" + mv "$1.new" "$1" +} + check_tree() { env -u SUITE_INVENTORY_FILE SUITE_INVENTORY_ROOT="$WORK/tree" python3 -I -B "$INV" --check 2>&1; } expect_red() { @@ -63,8 +79,7 @@ cp "$WORK/Makefile.new" "$WORK/tree/Makefile" expect_red 'a suite dropped from make test-suite is refused' 'stale in docs/dev/suite-inventory.tsv' fresh_tree -sed 's|^\tbash tests/test-doctor-json.sh$|&\n\tbash tests/test-new-make-suite.sh|' "$WORK/tree/Makefile" >"$WORK/Makefile.new" -cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +insert_after "$WORK/tree/Makefile" "$DOCTOR_LINE" $'\tbash tests/test-new-make-suite.sh' expect_red 'a suite added to make test-suite is refused' 'test-new-make-suite.sh' fresh_tree @@ -89,13 +104,11 @@ check_tree >/dev/null || fail "a commented-out call was counted" printf 'PASS: a commented-out call is ignored\n' fresh_tree -sed 's|^\tbash tests/test-doctor-json.sh$|&\n\t$(MAKE) other-target|' "$WORK/tree/Makefile" >"$WORK/Makefile.new" -cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +insert_after "$WORK/tree/Makefile" "$DOCTOR_LINE" $'\t$(MAKE) other-target' expect_red 'an unrecognised test-suite recipe line is refused' 'unrecognised test-suite recipe line' fresh_tree -sed 's|^\(source "$ROOT/tests/daemon-pools.sh"\)$|\1\n\1|' "$WORK/tree/tests/run.sh" >"$WORK/run.sh.new" -cp "$WORK/run.sh.new" "$WORK/tree/tests/run.sh" +insert_after "$WORK/tree/tests/run.sh" 'source "$ROOT/tests/daemon-pools.sh"' 'source "$ROOT/tests/daemon-pools.sh"' expect_red 'a repeated call in the same section is refused' 'daemon-pools.sh is called 2 times' fresh_tree @@ -103,13 +116,13 @@ printf 'bash tests/test-doctor-json.sh\n' >>"$WORK/tree/tests/run.sh" expect_red 'a repository-relative call to a make suite is refused' 'test-doctor-json.sh runs from both' fresh_tree -grep -vxF $'\tbash tests/run.sh' "$WORK/tree/Makefile" | sed '/^\t\$(if \$(RIGFORGE_SUITE_PROFILE)/d' >"$WORK/Makefile.new" +grep -qxF -- "$PROFILE_LINE" "$WORK/tree/Makefile" || fail "no tests/run.sh line in the Makefile" +grep -vxF -- "$PROFILE_LINE" "$WORK/tree/Makefile" >"$WORK/Makefile.new" cp "$WORK/Makefile.new" "$WORK/tree/Makefile" expect_red 'a test-suite recipe without tests/run.sh is refused' 'runs tests/run.sh 0 times' fresh_tree -sed 's|^\t\$(if \$(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )bash tests/run.sh$|&\n&|' "$WORK/tree/Makefile" >"$WORK/Makefile.new" -cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +insert_after "$WORK/tree/Makefile" "$PROFILE_LINE" "$PROFILE_LINE" expect_red 'a test-suite recipe that runs tests/run.sh twice is refused' 'runs tests/run.sh 2 times' fresh_tree @@ -118,8 +131,7 @@ expect_red 'a quoted repository-relative call to a make suite is refused' 'test- for filler in '' '# a comment line' $'\t# a recipe comment'; do fresh_tree - awk -v f="$filler" '{ print } /^\t\$\(if \$\(RIGFORGE_SUITE_PROFILE\)/ { print f }' "$WORK/tree/Makefile" >"$WORK/Makefile.new" - cp "$WORK/Makefile.new" "$WORK/tree/Makefile" + insert_after "$WORK/tree/Makefile" "$PROFILE_LINE" "$filler" check_tree >/dev/null || fail "a [$filler] line inside the recipe hid later calls: $(check_tree)" grep -vF 'bash tests/test-doctor-json.sh' "$WORK/tree/Makefile" >"$WORK/Makefile.new" cp "$WORK/Makefile.new" "$WORK/tree/Makefile" @@ -127,4 +139,26 @@ for filler in '' '# a comment line' $'\t# a recipe comment'; do done printf 'PASS: blank and comment lines inside the recipe hide no call\n' +for joined in $'\tbash tests/test-new.sh && bash tests/test-doctor-json.sh' \ + $'\tbash tests/test-new.sh; bash tests/test-doctor-json.sh' \ + $'\tbash tests/run.sh && bash tests/test-doctor-json.sh' \ + $'\tX=$$(bash tests/test-new.sh) bash tests/test-doctor-json.sh'; do + fresh_tree + replace_line "$WORK/tree/Makefile" "$DOCTOR_LINE" "$joined" + expect_red "a recipe line with a second command [${joined#?}] is refused" 'unrecognised test-suite recipe line' +done + +fresh_tree +insert_after "$WORK/tree/Makefile" "$LAST_LINE" $'ifdef EXTRA\n\tbash tests/test-new.sh\nendif' +expect_red 'a conditional at the end of the recipe is refused' 'unrecognised test-suite recipe line: ifdef EXTRA' + +fresh_tree +replace_line "$WORK/tree/Makefile" "$(grep '^test-suite:' "$WORK/tree/Makefile")" 'test-suite: extra-suites' +printf '\nextra-suites:\n\tbash tests/test-new.sh\n' >>"$WORK/tree/Makefile" +expect_red 'a prerequisite that runs another suite is refused' 'not in the recipe: bash tests/test-new.sh' + +fresh_tree +printf '\ntest-suite:\n\tbash tests/test-new.sh\n' >>"$WORK/tree/Makefile" +expect_red 'a second test-suite rule that overrides the recipe is refused' 'not in the recipe: bash tests/test-new.sh' + printf 'suite inventory selftest: all checks passed\n' From 445e3b89d75c10a5b7b6bebbed63ad4c5b7061d8 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 17:59:02 -0600 Subject: [PATCH 10/11] tests: check the profiled dry run on the checkout, narrow recipe settings, scope conditionals (part of #875) Co-Authored-By: Claude Opus 5.5 --- docs/dev/suite-inventory.tsv | 2 +- docs/dev/suite-profile.md | 26 +++++++++++++--------- tests/suite-inventory.py | 42 ++++++++++++++++++++++------------- tests/test-suite-inventory.sh | 31 ++++++++++++++++++++++++-- 4 files changed, 73 insertions(+), 28 deletions(-) diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index 5b0d2e77..43da12f1 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -281,6 +281,6 @@ make tests/test-release-bundle.sh Makefile test-suite - - make tests/test-env-override-gate.sh Makefile test-suite - 14 make tests/test-server-deadline.py Makefile test-suite - 13 make tests/test-build-deb.sh Makefile test-suite - 36 -make tests/test-suite-inventory.sh Makefile test-suite - 30 +make tests/test-suite-inventory.sh Makefile test-suite - 35 make tests/test-suite-inventory-generate.sh Makefile test-suite - 7 make tests/test-suite-profile.sh Makefile test-suite - 10 diff --git a/docs/dev/suite-profile.md b/docs/dev/suite-profile.md index 64b3e13e..7adbbb6d 100644 --- a/docs/dev/suite-profile.md +++ b/docs/dev/suite-profile.md @@ -169,16 +169,22 @@ recognised forms (`bash`, `sh`, `python3`, `source` or `.`, a `$ROOT`, `${ROOT}` a quoted or unquoted repository-relative path, or direct execution), when the recipe does not run `tests/run.sh` exactly once, and when a recipe line is not recognised. -A recognised recipe line is one command: optional `NAME=value` settings with plain -values, `bash` or `python3`, optional single-letter flags, and one `tests/` file, -nothing after it. A second command on the same line (`&&`, `;`, a command -substitution) and a make conditional (`ifdef`, `ifeq`, `else`, `endif` and the -like) inside the recipe are refused as unrecognised. Blank and comment lines inside -the recipe are skipped, as `make` skips them. The check then runs -`make -n test-suite` with every inherited `MAKEFLAGS` setting and -`RIGFORGE_SUITE_PROFILE` cleared and requires exactly the recipe lines it read, in -order, so a prerequisite target or a second `test-suite` rule that overrides the -recipe cannot add or replace a suite unseen. Suites that those suites call in turn +A recognised recipe line is one command: optional `PYTHON*`, `LC_*`, `LANG` or `TZ` +settings with plain values, `bash` or `python3`, optional single-letter flags, and one +`tests/` file, nothing after it. A second command on the same line (`&&`, `;`, a +command substitution), any other setting such as `BASH_ENV`, and a make conditional +(`ifdef`, `ifeq`, `else`, `endif` and the like) that wraps a recipe line are refused +as unrecognised; a conditional below the recipe that wraps another target is not. +Blank and comment lines inside the recipe are skipped, as `make` skips them. The +check then runs `make -n test-suite` on the checkout, once with +`RIGFORGE_SUITE_PROFILE` unset and once set to 1 as CI runs it, with every +`MAKEFLAGS`, `MAKELEVEL` and `MAKEFILES` setting inherited from an outer `make` +cleared, and requires exactly the recipe lines it read, in order (the profiled run +with `tests/run.sh` behind the wrapper), so a prerequisite target, one taken only by +the profiled run, or a second `test-suite` rule that overrides the recipe cannot add, +repeat or replace a suite unseen. The selftest runs this check on the checkout +itself and its mutations on a copy that links every other top-level file, so an +included makefile is read in both. Suites that those suites call in turn (for example `tests/test-donation.sh` running `tests/test-e2e-donation.sh`) are not listed. diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index 5a7795ad..90cd40fe 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -26,9 +26,9 @@ ) SOURCE_WORD = r"(?:source|\.)\s+" PROFILE_PREFIX = "$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )" -MAKE_COMMAND = re.compile(r"^\t(?:[A-Za-z_]\w*=[\w./:-]*\s+)*(?:bash|python3)\s+(?:-[A-Za-z]+\s+)*tests/([A-Za-z0-9_.-]+\.(?:sh|py))\s*$") +MAKE_COMMAND = re.compile(r"^\t(?:(?:PYTHON[A-Z_]*|LC_[A-Z]+|LANG|TZ)=[\w./:-]*\s+)*(?:bash|python3)\s+(?:-[A-Za-z]+\s+)*tests/([A-Za-z0-9_.-]+\.(?:sh|py))\s*$") CONDITIONAL = re.compile(r"^\s*(?:ifeq|ifneq|ifdef|ifndef|else|endif)\b") -DRY_RUN_CLEARED = ("MAKEFLAGS", "MFLAGS", "GNUMAKEFLAGS", "MAKELEVEL", "MAKEOVERRIDES", "RIGFORGE_SUITE_PROFILE") +DRY_RUN_CLEARED = ("MAKEFLAGS", "MFLAGS", "GNUMAKEFLAGS", "MAKELEVEL", "MAKEOVERRIDES", "MAKEFILES", "RIGFORGE_SUITE_PROFILE") LOOP_ALIAS = {"_f": "_sh"} ARGUMENTS = {} REDIRECTION = re.compile(r"\s\d*[<>]+&?\S*") @@ -105,7 +105,9 @@ def make_units(): units = [] runners = 0 commands = [] + profiled = [] in_target = False + conditional = None for line in read("Makefile"): if line.startswith("test-suite:"): in_target = True @@ -114,24 +116,32 @@ def make_units(): if not line.strip() or line.lstrip().startswith("#"): continue if CONDITIONAL.match(line): - raise SystemExit("suite-inventory: unrecognised test-suite recipe line: %s" % line.strip()) + conditional = conditional or line.strip() + continue if not line.startswith("\t"): break + if conditional: + raise SystemExit("suite-inventory: unrecognised test-suite recipe line: %s" % conditional) + wrapper = "" if line.startswith("\t" + PROFILE_PREFIX): line = "\t" + line[len(PROFILE_PREFIX) + 1 :] + wrapper = "python3 tests/suite-profile.py -- " match = MAKE_COMMAND.match(line) if match is None: raise SystemExit("suite-inventory: unrecognised test-suite recipe line: %s" % line.strip()) commands.append(line.strip()) + profiled.append(wrapper + line.strip()) if match.group(1) == "run.sh": runners += 1 else: units.append(("make", "tests/" + match.group(1), "Makefile", "test-suite")) - return units, runners, commands + return units, runners, commands, profiled -def dry_run(): +def dry_run(profile): env = {k: v for k, v in os.environ.items() if k not in DRY_RUN_CLEARED} + if profile: + env["RIGFORGE_SUITE_PROFILE"] = "1" try: result = subprocess.run( ["make", "--no-print-directory", "-n", "-C", ROOT, "test-suite"], @@ -212,18 +222,20 @@ def committed(path=None): def check(path=None): units = scan() problems = [] - _, runners, commands = make_units() + _, runners, commands, profiled = make_units() if runners != 1: problems.append("the test-suite recipe runs tests/run.sh %d times; it must run once" % runners) - ran, error = dry_run() - if ran is None: - problems.append("make -n test-suite failed: %s" % error) - elif ran != commands: - extra = [c for c in ran if c not in commands] - problems.append( - "make -n test-suite runs %d commands, the test-suite recipe lists %d%s" - % (len(ran), len(commands), "; not in the recipe: %s" % extra[0] if extra else "") - ) + for profile, expected in ((False, commands), (True, profiled)): + ran, error = dry_run(profile) + label = "RIGFORGE_SUITE_PROFILE=1 make -n test-suite" if profile else "make -n test-suite" + if ran is None: + problems.append("%s failed: %s" % (label, error)) + elif ran != expected: + extra = [c for c in ran if c not in expected] + problems.append( + "%s runs %d commands, the test-suite recipe lists %d%s" + % (label, len(ran), len(expected), "; not in the recipe: %s" % extra[0] if extra else "") + ) run_files = {u[1] for u in units if u[0] in ("sourced", "chained")} make_files = {u[1] for u in units if u[0] == "make"} for name in sorted(run_files & make_files): diff --git a/tests/test-suite-inventory.sh b/tests/test-suite-inventory.sh index ebee6852..e60e36a8 100755 --- a/tests/test-suite-inventory.sh +++ b/tests/test-suite-inventory.sh @@ -18,6 +18,9 @@ fresh_tree() { rm "$WORK/tree/tests/run.sh" cp "$ROOT/tests/run.sh" "$WORK/tree/tests/run.sh" cp "$ROOT/Makefile" "$WORK/tree/Makefile" + for entry in "$ROOT"/*; do + [ -e "$WORK/tree/$(basename "$entry")" ] || ln -s "$entry" "$WORK/tree/$(basename "$entry")" + done cp "${SUITE_INVENTORY_FILE:-$ROOT/docs/dev/suite-inventory.tsv}" "$WORK/tree/docs/dev/suite-inventory.tsv" } @@ -47,9 +50,14 @@ expect_red() { printf 'PASS: %s\n' "$name" } +env SUITE_INVENTORY_ROOT="$ROOT" python3 -I -B "$INV" --check >/dev/null 2>&1 || + fail "the committed inventory does not match this checkout: $(env SUITE_INVENTORY_ROOT="$ROOT" python3 -I -B "$INV" --check 2>&1)" +printf 'PASS: the committed inventory matches the run.sh and Makefile calls of this checkout\n' + fresh_tree -check_tree >/dev/null || fail "the committed inventory does not match run.sh and the Makefile: $(check_tree)" -printf 'PASS: the committed inventory matches the run.sh and Makefile calls\n' +MAKEFLAGS=' -j2 -- RIGFORGE_SUITE_PROFILE=1' MAKELEVEL=1 RIGFORGE_SUITE_PROFILE=1 check_tree >/dev/null || + fail "settings inherited from an outer make broke the check: $(MAKEFLAGS=' -j2 -- RIGFORGE_SUITE_PROFILE=1' MAKELEVEL=1 check_tree)" +printf 'PASS: settings inherited from an outer make do not change the check\n' fresh_tree printf 'echo "== unit: a section nobody inventoried =="\n' >>"$WORK/tree/tests/run.sh" @@ -161,4 +169,23 @@ fresh_tree printf '\ntest-suite:\n\tbash tests/test-new.sh\n' >>"$WORK/tree/Makefile" expect_red 'a second test-suite rule that overrides the recipe is refused' 'not in the recipe: bash tests/test-new.sh' +fresh_tree +replace_line "$WORK/tree/Makefile" "$(grep '^test-suite:' "$WORK/tree/Makefile")" 'test-suite: warm-up' +printf '\nwarm-up:\n\tbash tests/run.sh\n' >>"$WORK/tree/Makefile" +expect_red 'a prerequisite that runs tests/run.sh a second time is refused' 'suite-inventory: make -n test-suite runs 36 commands, the test-suite recipe lists 35' + +fresh_tree +replace_line "$WORK/tree/Makefile" "$(grep '^test-suite:' "$WORK/tree/Makefile")" 'test-suite: $(if $(RIGFORGE_SUITE_PROFILE),profile-extra)' +printf '\nprofile-extra:\n\tbash tests/test-new.sh\n' >>"$WORK/tree/Makefile" +expect_red 'a prerequisite only the profiled run takes is refused' 'RIGFORGE_SUITE_PROFILE=1 make -n test-suite runs' + +fresh_tree +replace_line "$WORK/tree/Makefile" "$DOCTOR_LINE" $'\tBASH_ENV=tests/test-new.sh bash tests/test-doctor-json.sh' +expect_red 'a BASH_ENV setting on a recipe line is refused' 'unrecognised test-suite recipe line' + +fresh_tree +insert_after "$WORK/tree/Makefile" "$LAST_LINE" $'\nifeq ($(OS),Darwin)\nmacos-note:\n\t@echo macOS\nendif' +check_tree >/dev/null || fail "a conditional around another target after the recipe was refused: $(check_tree)" +printf 'PASS: a conditional around another target after the recipe is accepted\n' + printf 'suite inventory selftest: all checks passed\n' From f8c19846514ff7f27767511a1fffc19297da4e4a Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 18:43:27 -0600 Subject: [PATCH 11/11] tests: derive selftest anchors from the checkout, refuse a second or prerequisite-carrying test-suite rule (part of #875) Co-Authored-By: Claude Opus 5.5 --- docs/dev/suite-inventory.tsv | 2 +- docs/dev/suite-profile.md | 20 +++-- tests/suite-inventory.py | 16 ++++ tests/test-suite-inventory.sh | 137 +++++++++++++++++++++++----------- tests/test-suite-profile.sh | 9 ++- 5 files changed, 132 insertions(+), 52 deletions(-) diff --git a/docs/dev/suite-inventory.tsv b/docs/dev/suite-inventory.tsv index 43da12f1..8e74868c 100644 --- a/docs/dev/suite-inventory.tsv +++ b/docs/dev/suite-inventory.tsv @@ -281,6 +281,6 @@ make tests/test-release-bundle.sh Makefile test-suite - - make tests/test-env-override-gate.sh Makefile test-suite - 14 make tests/test-server-deadline.py Makefile test-suite - 13 make tests/test-build-deb.sh Makefile test-suite - 36 -make tests/test-suite-inventory.sh Makefile test-suite - 35 +make tests/test-suite-inventory.sh Makefile test-suite - 38 make tests/test-suite-inventory-generate.sh Makefile test-suite - 7 make tests/test-suite-profile.sh Makefile test-suite - 10 diff --git a/docs/dev/suite-profile.md b/docs/dev/suite-profile.md index 7adbbb6d..7d3eecab 100644 --- a/docs/dev/suite-profile.md +++ b/docs/dev/suite-profile.md @@ -176,15 +176,22 @@ command substitution), any other setting such as `BASH_ENV`, and a make conditio (`ifdef`, `ifeq`, `else`, `endif` and the like) that wraps a recipe line are refused as unrecognised; a conditional below the recipe that wraps another target is not. Blank and comment lines inside the recipe are skipped, as `make` skips them. The -check then runs `make -n test-suite` on the checkout, once with +Makefile must hold exactly one rule that names `test-suite` as a target, with no +other target and no prerequisite on that line, so a prerequisite gated on a make +variable (`ifdef EXTRA` around a second `test-suite:` line, or +`test-suite: $(EXTRA_SUITES)`), which a dry run with that variable unset would not +show, is refused. The check then runs `make -n test-suite` on the checkout, once with `RIGFORGE_SUITE_PROFILE` unset and once set to 1 as CI runs it, with every `MAKEFLAGS`, `MAKELEVEL` and `MAKEFILES` setting inherited from an outer `make` cleared, and requires exactly the recipe lines it read, in order (the profiled run with `tests/run.sh` behind the wrapper), so a prerequisite target, one taken only by the profiled run, or a second `test-suite` rule that overrides the recipe cannot add, -repeat or replace a suite unseen. The selftest runs this check on the checkout -itself and its mutations on a copy that links every other top-level file, so an -included makefile is read in both. Suites that those suites call in turn +repeat or replace a suite unseen. A rule in an included makefile, or under a target +name built from a variable, is seen by that dry run only, and the dry run clears +inherited settings: a prerequisite gated on a make variable there is outside the +check. The selftest runs this check on the checkout itself and its mutations on a +copy that links every other top-level file, so an included makefile is read in +both. Suites that those suites call in turn (for example `tests/test-donation.sh` running `tests/test-e2e-donation.sh`) are not listed. @@ -193,7 +200,10 @@ listed. `tests/test-suite-inventory.sh` runs in `make test-suite`. It fails when `tests/run.sh` or the Makefile gains or loses a section header or a suite call that `docs/dev/suite-inventory.tsv` does not list, and its cases show each of those -mutations red. `tests/test-suite-inventory-generate.sh` covers regeneration on a +mutations red. It takes the recipe lines, the `tests/run.sh` line, a sourced suite +and a section header it mutates from the checkout rather than from constants, so +adding or removing a suite together with its inventory row keeps it green; one case +appends a suite with its row and expects a pass. `tests/test-suite-inventory-generate.sh` covers regeneration on a fixture tree: a missing, failed or partial output keeps the committed bytes, a sourced fragment is never launched, a measured suite writes neither the caller's state folder nor the checkout, a timed-out suite's background child is killed, and diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py index 90cd40fe..fb33ed40 100755 --- a/tests/suite-inventory.py +++ b/tests/suite-inventory.py @@ -28,6 +28,7 @@ PROFILE_PREFIX = "$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )" MAKE_COMMAND = re.compile(r"^\t(?:(?:PYTHON[A-Z_]*|LC_[A-Z]+|LANG|TZ)=[\w./:-]*\s+)*(?:bash|python3)\s+(?:-[A-Za-z]+\s+)*tests/([A-Za-z0-9_.-]+\.(?:sh|py))\s*$") CONDITIONAL = re.compile(r"^\s*(?:ifeq|ifneq|ifdef|ifndef|else|endif)\b") +RULE = re.compile(r"^([^\t#:=][^:=#]*?)\s*::?(?!=)(.*)$") DRY_RUN_CLEARED = ("MAKEFLAGS", "MFLAGS", "GNUMAKEFLAGS", "MAKELEVEL", "MAKEOVERRIDES", "MAKEFILES", "RIGFORGE_SUITE_PROFILE") LOOP_ALIAS = {"_f": "_sh"} ARGUMENTS = {} @@ -138,6 +139,20 @@ def make_units(): return units, runners, commands, profiled +def rule_problems(): + rules = [] + for line in read("Makefile"): + match = RULE.match(line) + if match and "test-suite" in match.group(1).split(): + rules.append((match.group(1).strip(), match.group(2).split("#", 1)[0].strip(), line.strip())) + if len(rules) != 1: + return ["the Makefile has %d rules for test-suite; it must have one" % len(rules)] + targets, prerequisites, line = rules[0] + if targets != "test-suite" or prerequisites: + return ["the test-suite rule [%s] has other targets or prerequisites; a suite must be a recipe line" % line] + return [] + + def dry_run(profile): env = {k: v for k, v in os.environ.items() if k not in DRY_RUN_CLEARED} if profile: @@ -222,6 +237,7 @@ def committed(path=None): def check(path=None): units = scan() problems = [] + problems.extend(rule_problems()) _, runners, commands, profiled = make_units() if runners != 1: problems.append("the test-suite recipe runs tests/run.sh %d times; it must run once" % runners) diff --git a/tests/test-suite-inventory.sh b/tests/test-suite-inventory.sh index e60e36a8..31854cd6 100755 --- a/tests/test-suite-inventory.sh +++ b/tests/test-suite-inventory.sh @@ -24,9 +24,45 @@ fresh_tree() { cp "${SUITE_INVENTORY_FILE:-$ROOT/docs/dev/suite-inventory.tsv}" "$WORK/tree/docs/dev/suite-inventory.tsv" } -PROFILE_LINE=$'\t$(if $(RIGFORGE_SUITE_PROFILE),python3 tests/suite-profile.py -- )bash tests/run.sh' -DOCTOR_LINE=$'\tbash tests/test-doctor-json.sh' -LAST_LINE=$'\tbash tests/test-suite-profile.sh' +recipe_pick() { + awk -v mode="$1" ' + /^test-suite:/ { t = 1; next } + t && /^\t#/ { next } + t && /^\t/ { + n++ + last = $0 + if ($0 ~ /tests\/run\.sh$/) { + if (run == "") run = $0 + } else { + suite = $0 + if (first == "" && $0 ~ /^\tbash tests\//) first = $0 + } + next + } + t && NF && !/^#/ { exit } + END { + if (mode == "run") print run + if (mode == "first-suite") print first + if (mode == "last-suite") print suite + if (mode == "last") print last + if (mode == "count") print n + 0 + }' "$ROOT/Makefile" +} + +PROFILE_LINE=$(recipe_pick run) +MAKE_LINE=$(recipe_pick first-suite) +LAST_SUITE_LINE=$(recipe_pick last-suite) +LAST_LINE=$(recipe_pick last) +RECIPE_COUNT=$(recipe_pick count) +MAKE_SUITE=${MAKE_LINE##* } +SOURCED_LINE=$(grep -m1 -E '^source "\$ROOT/tests/[A-Za-z0-9_.-]+\.sh"$' "$ROOT/tests/run.sh" || true) +SOURCED_SUITE=${SOURCED_LINE#source \"\$ROOT/} +SOURCED_SUITE=${SOURCED_SUITE%\"} +FIRST_HEADER=$(grep -m1 -E '^echo "== .* =="$' "$ROOT/tests/run.sh" || true) +[ -n "$PROFILE_LINE" ] || fail "no tests/run.sh line in the make test-suite recipe" +[ -n "$MAKE_LINE" ] || fail "no 'bash tests/...' suite line in the make test-suite recipe" +[ -n "$SOURCED_LINE" ] || fail "no plain 'source \"\$ROOT/tests/...\"' line in tests/run.sh" +[ -n "$FIRST_HEADER" ] || fail "no section header in tests/run.sh" insert_after() { grep -qxF -- "$2" "$1" || fail "no line [$2] in $1" @@ -40,6 +76,14 @@ replace_line() { mv "$1.new" "$1" } +drop_line() { + grep -qxF -- "$2" "$1" || fail "no line [$2] in $1" + grep -vxF -- "$2" "$1" >"$1.new" || true + mv "$1.new" "$1" +} + +rule_line() { grep '^test-suite:' "$WORK/tree/Makefile"; } + check_tree() { env -u SUITE_INVENTORY_FILE SUITE_INVENTORY_ROOT="$WORK/tree" python3 -I -B "$INV" --check 2>&1; } expect_red() { @@ -50,6 +94,11 @@ expect_red() { printf 'PASS: %s\n' "$name" } +expect_green() { + check_tree >/dev/null || fail "$1: $(check_tree)" + printf 'PASS: %s\n' "$1" +} + env SUITE_INVENTORY_ROOT="$ROOT" python3 -I -B "$INV" --check >/dev/null 2>&1 || fail "the committed inventory does not match this checkout: $(env SUITE_INVENTORY_ROOT="$ROOT" python3 -I -B "$INV" --check 2>&1)" printf 'PASS: the committed inventory matches the run.sh and Makefile calls of this checkout\n' @@ -59,35 +108,38 @@ MAKEFLAGS=' -j2 -- RIGFORGE_SUITE_PROFILE=1' MAKELEVEL=1 RIGFORGE_SUITE_PROFILE= fail "settings inherited from an outer make broke the check: $(MAKEFLAGS=' -j2 -- RIGFORGE_SUITE_PROFILE=1' MAKELEVEL=1 check_tree)" printf 'PASS: settings inherited from an outer make do not change the check\n' +fresh_tree +insert_after "$WORK/tree/Makefile" "$LAST_LINE" $'\tbash tests/test-inventory-selftest-appended.sh' +printf 'printf "PASS: listed\\n"\n' >"$WORK/tree/tests/test-inventory-selftest-appended.sh" +printf 'make\ttests/test-inventory-selftest-appended.sh\tMakefile\ttest-suite\t-\t-\n' >>"$WORK/tree/docs/dev/suite-inventory.tsv" +expect_green 'a suite appended to the recipe together with its inventory row is accepted' + fresh_tree printf 'echo "== unit: a section nobody inventoried =="\n' >>"$WORK/tree/tests/run.sh" expect_red 'a new run.sh section header is refused' 'a section nobody inventoried' fresh_tree -header=$(grep -m1 '^echo "== unit: parse_config' "$WORK/tree/tests/run.sh") -grep -vxF -- "$header" "$WORK/tree/tests/run.sh" >"$WORK/run.sh.new" -cp "$WORK/run.sh.new" "$WORK/tree/tests/run.sh" +drop_line "$WORK/tree/tests/run.sh" "$FIRST_HEADER" expect_red 'a removed run.sh section header is refused' 'stale in docs/dev/suite-inventory.tsv' fresh_tree -printf 'bash "$ROOT/tests/test-doctor-json.sh"\n' >>"$WORK/tree/tests/run.sh" -expect_red 'a suite run by both run.sh and make test-suite is refused' 'test-doctor-json.sh runs from both' +printf 'bash "$ROOT/%s"\n' "$MAKE_SUITE" >>"$WORK/tree/tests/run.sh" +expect_red 'a suite run by both run.sh and make test-suite is refused' "$MAKE_SUITE runs from both" fresh_tree printf 'bash "$ROOT/tests/test-not-inventoried.sh"\n' >>"$WORK/tree/tests/run.sh" expect_red 'a new chained suite call is refused' 'test-not-inventoried.sh' fresh_tree -printf 'source "$ROOT/tests/daemon-pools.sh"\n' >>"$WORK/tree/tests/run.sh" -expect_red 'a suite called a second time is refused' 'daemon-pools.sh is called 2 times' +printf '%s\n' "$SOURCED_LINE" >>"$WORK/tree/tests/run.sh" +expect_red 'a suite called a second time is refused' "$SOURCED_SUITE is called 2 times" fresh_tree -grep -vF 'bash tests/test-doctor-json.sh' "$WORK/tree/Makefile" >"$WORK/Makefile.new" -cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +drop_line "$WORK/tree/Makefile" "$MAKE_LINE" expect_red 'a suite dropped from make test-suite is refused' 'stale in docs/dev/suite-inventory.tsv' fresh_tree -insert_after "$WORK/tree/Makefile" "$DOCTOR_LINE" $'\tbash tests/test-new-make-suite.sh' +insert_after "$WORK/tree/Makefile" "$MAKE_LINE" $'\tbash tests/test-new-make-suite.sh' expect_red 'a suite added to make test-suite is refused' 'test-new-make-suite.sh' fresh_tree @@ -108,25 +160,22 @@ expect_red 'a printf section header is refused' 'a printed header' fresh_tree printf '# bash "$ROOT/tests/test-commented.sh"\n' >>"$WORK/tree/tests/run.sh" -check_tree >/dev/null || fail "a commented-out call was counted" -printf 'PASS: a commented-out call is ignored\n' +expect_green 'a commented-out call is ignored' fresh_tree -insert_after "$WORK/tree/Makefile" "$DOCTOR_LINE" $'\t$(MAKE) other-target' +insert_after "$WORK/tree/Makefile" "$MAKE_LINE" $'\t$(MAKE) other-target' expect_red 'an unrecognised test-suite recipe line is refused' 'unrecognised test-suite recipe line' fresh_tree -insert_after "$WORK/tree/tests/run.sh" 'source "$ROOT/tests/daemon-pools.sh"' 'source "$ROOT/tests/daemon-pools.sh"' -expect_red 'a repeated call in the same section is refused' 'daemon-pools.sh is called 2 times' +insert_after "$WORK/tree/tests/run.sh" "$SOURCED_LINE" "$SOURCED_LINE" +expect_red 'a repeated call in the same section is refused' "$SOURCED_SUITE is called 2 times" fresh_tree -printf 'bash tests/test-doctor-json.sh\n' >>"$WORK/tree/tests/run.sh" -expect_red 'a repository-relative call to a make suite is refused' 'test-doctor-json.sh runs from both' +printf 'bash %s\n' "$MAKE_SUITE" >>"$WORK/tree/tests/run.sh" +expect_red 'a repository-relative call to a make suite is refused' "$MAKE_SUITE runs from both" fresh_tree -grep -qxF -- "$PROFILE_LINE" "$WORK/tree/Makefile" || fail "no tests/run.sh line in the Makefile" -grep -vxF -- "$PROFILE_LINE" "$WORK/tree/Makefile" >"$WORK/Makefile.new" -cp "$WORK/Makefile.new" "$WORK/tree/Makefile" +drop_line "$WORK/tree/Makefile" "$PROFILE_LINE" expect_red 'a test-suite recipe without tests/run.sh is refused' 'runs tests/run.sh 0 times' fresh_tree @@ -134,26 +183,26 @@ insert_after "$WORK/tree/Makefile" "$PROFILE_LINE" "$PROFILE_LINE" expect_red 'a test-suite recipe that runs tests/run.sh twice is refused' 'runs tests/run.sh 2 times' fresh_tree -printf 'bash "tests/test-doctor-json.sh"\n' >>"$WORK/tree/tests/run.sh" -expect_red 'a quoted repository-relative call to a make suite is refused' 'test-doctor-json.sh runs from both' +printf 'bash "%s"\n' "$MAKE_SUITE" >>"$WORK/tree/tests/run.sh" +expect_red 'a quoted repository-relative call to a make suite is refused' "$MAKE_SUITE runs from both" for filler in '' '# a comment line' $'\t# a recipe comment'; do fresh_tree insert_after "$WORK/tree/Makefile" "$PROFILE_LINE" "$filler" check_tree >/dev/null || fail "a [$filler] line inside the recipe hid later calls: $(check_tree)" - grep -vF 'bash tests/test-doctor-json.sh' "$WORK/tree/Makefile" >"$WORK/Makefile.new" - cp "$WORK/Makefile.new" "$WORK/tree/Makefile" + drop_line "$WORK/tree/Makefile" "$LAST_SUITE_LINE" expect_red "a suite dropped after a [$filler] recipe line is refused" 'stale in docs/dev/suite-inventory.tsv' done printf 'PASS: blank and comment lines inside the recipe hide no call\n' -for joined in $'\tbash tests/test-new.sh && bash tests/test-doctor-json.sh' \ - $'\tbash tests/test-new.sh; bash tests/test-doctor-json.sh' \ - $'\tbash tests/run.sh && bash tests/test-doctor-json.sh' \ - $'\tX=$$(bash tests/test-new.sh) bash tests/test-doctor-json.sh'; do +for joined in $'\tbash tests/test-new.sh && '"${MAKE_LINE#?}" \ + $'\tbash tests/test-new.sh; '"${MAKE_LINE#?}" \ + $'\tbash tests/run.sh && '"${MAKE_LINE#?}" \ + $'\tX=$$(bash tests/test-new.sh) '"${MAKE_LINE#?}" \ + $'\tBASH_ENV=tests/test-new.sh '"${MAKE_LINE#?}"; do fresh_tree - replace_line "$WORK/tree/Makefile" "$DOCTOR_LINE" "$joined" - expect_red "a recipe line with a second command [${joined#?}] is refused" 'unrecognised test-suite recipe line' + replace_line "$WORK/tree/Makefile" "$MAKE_LINE" "$joined" + expect_red "a recipe line with a second command or a foreign setting [${joined#?}] is refused" 'unrecognised test-suite recipe line' done fresh_tree @@ -161,7 +210,11 @@ insert_after "$WORK/tree/Makefile" "$LAST_LINE" $'ifdef EXTRA\n\tbash tests/test expect_red 'a conditional at the end of the recipe is refused' 'unrecognised test-suite recipe line: ifdef EXTRA' fresh_tree -replace_line "$WORK/tree/Makefile" "$(grep '^test-suite:' "$WORK/tree/Makefile")" 'test-suite: extra-suites' +insert_after "$WORK/tree/Makefile" "$LAST_LINE" $'\nifeq ($(OS),Darwin)\nmacos-note:\n\t@echo macOS\nendif' +expect_green 'a conditional around another target after the recipe is accepted' + +fresh_tree +replace_line "$WORK/tree/Makefile" "$(rule_line)" 'test-suite: extra-suites' printf '\nextra-suites:\n\tbash tests/test-new.sh\n' >>"$WORK/tree/Makefile" expect_red 'a prerequisite that runs another suite is refused' 'not in the recipe: bash tests/test-new.sh' @@ -170,22 +223,22 @@ printf '\ntest-suite:\n\tbash tests/test-new.sh\n' >>"$WORK/tree/Makefile" expect_red 'a second test-suite rule that overrides the recipe is refused' 'not in the recipe: bash tests/test-new.sh' fresh_tree -replace_line "$WORK/tree/Makefile" "$(grep '^test-suite:' "$WORK/tree/Makefile")" 'test-suite: warm-up' +replace_line "$WORK/tree/Makefile" "$(rule_line)" 'test-suite: warm-up' printf '\nwarm-up:\n\tbash tests/run.sh\n' >>"$WORK/tree/Makefile" -expect_red 'a prerequisite that runs tests/run.sh a second time is refused' 'suite-inventory: make -n test-suite runs 36 commands, the test-suite recipe lists 35' +expect_red 'a prerequisite that runs tests/run.sh a second time is refused' \ + "suite-inventory: make -n test-suite runs $((RECIPE_COUNT + 1)) commands, the test-suite recipe lists $RECIPE_COUNT" fresh_tree -replace_line "$WORK/tree/Makefile" "$(grep '^test-suite:' "$WORK/tree/Makefile")" 'test-suite: $(if $(RIGFORGE_SUITE_PROFILE),profile-extra)' +replace_line "$WORK/tree/Makefile" "$(rule_line)" 'test-suite: $(if $(RIGFORGE_SUITE_PROFILE),profile-extra)' printf '\nprofile-extra:\n\tbash tests/test-new.sh\n' >>"$WORK/tree/Makefile" expect_red 'a prerequisite only the profiled run takes is refused' 'RIGFORGE_SUITE_PROFILE=1 make -n test-suite runs' fresh_tree -replace_line "$WORK/tree/Makefile" "$DOCTOR_LINE" $'\tBASH_ENV=tests/test-new.sh bash tests/test-doctor-json.sh' -expect_red 'a BASH_ENV setting on a recipe line is refused' 'unrecognised test-suite recipe line' +printf '\nifdef EXTRA\ntest-suite: extra-suites\nendif\n\nextra-suites:\n\tbash tests/test-new.sh\n' >>"$WORK/tree/Makefile" +expect_red 'a test-suite prerequisite gated on a make variable is refused' 'the Makefile has 2 rules for test-suite' fresh_tree -insert_after "$WORK/tree/Makefile" "$LAST_LINE" $'\nifeq ($(OS),Darwin)\nmacos-note:\n\t@echo macOS\nendif' -check_tree >/dev/null || fail "a conditional around another target after the recipe was refused: $(check_tree)" -printf 'PASS: a conditional around another target after the recipe is accepted\n' +replace_line "$WORK/tree/Makefile" "$(rule_line)" 'test-suite: $(EXTRA_SUITES)' +expect_red 'a test-suite prerequisite taken from a make variable is refused' 'has other targets or prerequisites' printf 'suite inventory selftest: all checks passed\n' diff --git a/tests/test-suite-profile.sh b/tests/test-suite-profile.sh index 30eaae81..ced1fc45 100755 --- a/tests/test-suite-profile.sh +++ b/tests/test-suite-profile.sh @@ -44,19 +44,20 @@ python3 -I "$ROOT/tests/suite-profile.py" bash "$WORK/fake.sh" >/dev/null 2>&1 | [ "$rc" = 2 ] || fail "a call without -- exited $rc, expected 2" printf 'PASS: a call without the separator is a usage error\n' -first_recipe() { env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL "$@" make --no-print-directory -n -C "$ROOT" test-suite | sed -n 1p; } +run_line() { awk '/tests\/run\.sh$/ && !found { print; found = 1 }'; } +run_recipe() { env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL "$@" make --no-print-directory -n -C "$ROOT" test-suite | run_line; } mkdir -p "$WORK/tree/tests" ln -s "$ROOT/tests/suite-profile.py" "$WORK/tree/tests/suite-profile.py" cp "$WORK/fake.sh" "$WORK/tree/tests/run.sh" -default_line=$(MAKEFLAGS=' -- RIGFORGE_SUITE_PROFILE=1' MAKELEVEL=1 first_recipe -u RIGFORGE_SUITE_PROFILE) -profiled_line=$(first_recipe RIGFORGE_SUITE_PROFILE=1) +default_line=$(MAKEFLAGS=' -- RIGFORGE_SUITE_PROFILE=1' MAKELEVEL=1 run_recipe -u RIGFORGE_SUITE_PROFILE) +profiled_line=$(run_recipe RIGFORGE_SUITE_PROFILE=1) [ "$default_line" = 'bash tests/run.sh' ] || fail "the default recipe is [$default_line], not the plain suite run" (cd "$WORK/tree" && bash -c "$default_line") >"$WORK/make-default.out" 2>"$WORK/make-default.err" cmp -s "$WORK/direct.out" "$WORK/make-default.out" || fail "the default recipe changed the output" grep -q 'suite-profile:' "$WORK/make-default.err" && fail "the default recipe printed a profile" printf 'PASS: make test-suite runs the plain suite without the toggle\n' -cmdline_line=$(env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL -u RIGFORGE_SUITE_PROFILE make --no-print-directory -n -C "$ROOT" test-suite RIGFORGE_SUITE_PROFILE=1 | sed -n 1p) +cmdline_line=$(env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL -u RIGFORGE_SUITE_PROFILE make --no-print-directory -n -C "$ROOT" test-suite RIGFORGE_SUITE_PROFILE=1 | run_line) [ "$cmdline_line" = "$profiled_line" ] || fail "make test-suite RIGFORGE_SUITE_PROFILE=1 gave [$cmdline_line], the environment form [$profiled_line]" case "$profiled_line" in *'tests/suite-profile.py -- bash tests/run.sh') ;; *) fail "the toggled recipe is [$profiled_line]" ;; esac (cd "$WORK/tree" && bash -c "$profiled_line") >"$WORK/make-profiled.out" 2>"$WORK/make-profiled.err"