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 36955bd2..d3d433b1 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,9 @@ 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-inventory-generate.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..8e74868c --- /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 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) - 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 +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) - 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) - 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) - 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) - 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 - - +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 - +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) - - +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) - 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) - 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 - +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 - +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) 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 - +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) 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 - +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) - 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 - +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) 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 - 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 - +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) - 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) 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) - 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) - 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) - 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 - +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 - +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) - - +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) 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) - - +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 - - +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 +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 - 2 +make tests/test-docs-replay.py Makefile test-suite - 18 +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 +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 - 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 - 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 - 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-baseline.tsv b/docs/dev/suite-profile-baseline.tsv new file mode 100644 index 00000000..e1430f2d --- /dev/null +++ b/docs/dev/suite-profile-baseline.tsv @@ -0,0 +1,241 @@ +# 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) +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.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.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.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.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.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.5 unit: MSR preset table values (#66) +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.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.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.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.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: 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: 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.2 unit: _cmdline_reserved_2mb (#305) +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.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.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 unit: apply reports the autotune target (#95) +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: _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 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.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 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 config-gen: open API by default (no ACCESS_TOKEN) +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: invalid daemon apply fails before side effects (#528) +0.1 0.1 black-box: backup leaks no staging tempdir on a set -e abort (#353) +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.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 worker folder stays root-owned only on a root-owned tree +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: 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 new file mode 100644 index 00000000..7d3eecab --- /dev/null +++ b/docs/dev/suite-profile.md @@ -0,0 +1,226 @@ +# Suite profile and inventory + +`make test-suite` runs `tests/run.sh` (one process, thousands of assertions) +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. + +## Profiling a run + +```sh +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 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, 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 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 +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 +a sourced suite prints for itself (for example `tests/test-control-upgrade.sh`) are +rows of their own. + +## Baseline + +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 | + +| | Median s | p90 s (nearest rank over three runs) | +|---|---|---| +| `tests/run.sh` | 585.9 | 656.9 | +| Whole `make test-suite` | 640 | 720 | + +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. 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.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), 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` 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 + +`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). 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` (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 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. + +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, 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 +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 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 +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 +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 `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 +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. 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. + +### 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. 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 +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) +if bash tests/run.sh >"$log" 2>/dev/null; then + python3 tests/suite-inventory.py --generate "$log" +fi +rm -f "$log" +``` + +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/README.md b/tests/README.md index 521f15b8..bd901553 100644 --- a/tests/README.md +++ b/tests/README.md @@ -40,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/manifest.json b/tests/manifest.json index 85a6ac89..8dd7f3a0 100644 --- a/tests/manifest.json +++ b/tests/manifest.json @@ -644,6 +644,55 @@ "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-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", + "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": [] } ] } diff --git a/tests/suite-inventory.py b/tests/suite-inventory.py new file mode 100755 index 00000000..fb33ed40 --- /dev/null +++ b/tests/suite-inventory.py @@ -0,0 +1,342 @@ +#!/usr/bin/env python3 +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" +HEADER = re.compile(r"""^\s*(?:echo|printf)\s+(?:-\w+\s+)?["']== (.*) ==(?:\\n)?["'](?:\s*>.*)?$""") +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 + 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 -- )" +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 = {} +REDIRECTION = re.compile(r"\s\d*[<>]+&?\S*") + + +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 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)] + loops = {} + for line in read("tests/run.sh"): + if line.lstrip().startswith("#"): + continue + 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): + 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) + 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 + ARGUMENTS[name] = arguments + if name == "tests/run.sh": + continue + sourced = re.search(SOURCE_WORD + CALL_PREFIX + re.escape(name), line) + units.append(("sourced" if sourced else "chained", name, "run.sh", site)) + return units + + +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 + continue + if in_target: + if not line.strip() or line.lstrip().startswith("#"): + continue + if CONDITIONAL.match(line): + 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, 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: + env["RIGFORGE_SUITE_PROFILE"] = "1" + 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(): + return run_sh_units() + make_units()[0] + + +def standalone_command(kind, name): + 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: + 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) + 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), 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 + + +def stripped(lines): + return [line.rsplit("\t", 2)[0] for line in lines if line and not line.startswith("#")] + + +def committed(path=None): + with open(path or INVENTORY, encoding="utf-8") as handle: + return handle.read().splitlines() + + +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) + 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): + 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) + lines = committed(path) + have = stripped(lines) + want = stripped(render(units)) + for line in want: + 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 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 + + +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) + units = scan() + 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) + 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({}) + 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)) + os.replace(candidate, INVENTORY) + finally: + if os.path.exists(candidate): + os.unlink(candidate) + + +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": + generate(argv[2]) + return 0 + sys.stderr.write("usage: suite-inventory.py --check | --generate SUITE_STDOUT_FILE\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..2f053acc --- /dev/null +++ b/tests/suite-profile.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +import re +import statistics +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" + + +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 printable(text): + return "".join(ch if ch.isprintable() else "\\x%02x" % ord(ch) for ch in text) + + +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, 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]) + + +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), statistics.median(totals), percentile(totals, 0.9))) + for name, mid, high in rows: + 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") + 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() + if rc < 0: + rc = 128 - rc + sys.stderr.write(report(*profile.result)) + return rc + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/tests/suite_counts.py b/tests/suite_counts.py new file mode 100644 index 00000000..a10ecf40 --- /dev/null +++ b/tests/suite_counts.py @@ -0,0 +1,215 @@ +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) + rc = None + try: + rc = child.wait(timeout=TIMEOUT) + except subprocess.TimeoutExpired: + pass + finally: + try: + os.killpg(child.pid, signal.SIGKILL) + except ProcessLookupError: + pass + 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") + 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])) + return totals diff --git a/tests/test-suite-inventory-generate.sh b/tests/test-suite-inventory-generate.sh new file mode 100755 index 00000000..2f568a2d --- /dev/null +++ b/tests/test-suite-inventory-generate.sh @@ -0,0 +1,165 @@ +#!/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" "$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' +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" "$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 "$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' +[ -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 %s\n' "$$" "$!" >"$FIXTURE_PIDFILE.tmp" +mv "$FIXTURE_PIDFILE.tmp" "$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" +printf 'caller config\n' >"$WORK/external/config.json" +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' + printf '2026-01-01T00:00:00.2Z == headed fragment ==\n' + 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" + 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: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: \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" +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 \ + FRAG_SENTINEL="$WORK/sentinel" SUITE_INVENTORY_ROOT="$TREE" python3 -I -B "$INV" --generate "$1" 2>&1 +} + +before=$(cksum <"$TREE/docs/dev/suite-inventory.tsv") +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.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")" +[ ! -e "$WORK/sentinel" ] || fail "regeneration launched a sourced fragment on its own" +printf 'PASS: regeneration never launches a sourced fragment by itself\n' + +[ "$(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' + +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' + +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 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 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 new file mode 100755 index 00000000..31854cd6 --- /dev/null +++ b/tests/test-suite-inventory.sh @@ -0,0 +1,244 @@ +#!/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" + 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" +} + +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" + 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" +} + +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() { + 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" +} + +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' + +fresh_tree +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 +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 +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/%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 '%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 +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" "$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 +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" +expect_green 'a commented-out call is ignored' + +fresh_tree +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" "$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 %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 +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 +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 "%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)" + 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 && '"${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" "$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 +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 +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' + +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" "$(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 $((RECIPE_COUNT + 1)) commands, the test-suite recipe lists $RECIPE_COUNT" + +fresh_tree +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 +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 +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 new file mode 100755 index 00000000..ced1fc45 --- /dev/null +++ b/tests/test-suite-profile.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 +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' + +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 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 | 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" +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 +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' + +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'