"""The O05 benchmark report: produced, complete and agreement-checked (timings not asserted).""" from __future__ import annotations import json import pytest from obliteratus.analysis import kernel_benchmark as kb from obliteratus.analysis import kernel_fixtures as kf pytestmark = pytest.mark.cpu @pytest.fixture(scope="module") def report(): return kb.run_benchmark(quick=True) def test_report_covers_every_arm_with_host_labelled_costs(report): assert report["schema"] == kb.SCHEMA and "host-specific" in report["host_note"] assert [case["fixture"] for case in report["gate"]] == list(kf.GATE_FIXTURES) for case in report["gate"]: for arm in (case["reference"]["cost"], case["batched"]["cost"], case["sketch"]["cost"]): assert len(arm["wall_seconds"]) == 1 and "peak_rss_growth_bytes" in arm json.dumps(report) def test_batched_arms_agree_and_sketch_never_flips_a_gate_decision(report): for case in report["gate"]: batched = case["batched"]["agreement"] assert batched["within_tolerance"] and batched["decision_disagreements"] == 0 assert case["batched"]["gate_decision"] == case["reference"]["gate_decision"] sketch = case["sketch"] if sketch["status"] == "approximate": assert sketch["agreement"]["decision_disagreements"] == 0 assert sketch["gate_decision"] == case["reference"]["gate_decision"] else: assert sketch["status"] == "inconclusive" and sketch["reason"] assert report["subspace"]["subspace_null"]["within_tolerance"] assert not report["subspace"]["verdict_disagreement"] assert report["discovery"]["agreement"]["within_tolerance"] def test_tail_fixture_reports_the_signal_variance_alone_would_lose(report): tail = next(case for case in report["low_rank"] if case["fixture"] == "tail_signal") assert tail["variance_only_signal_loss"] > report["budget"]["signal"] assert tail["exact"]["selected_rank"] > tail["exact"]["variance_only_rank"] assert not tail["rank_disagreement"] and max(tail["subspace_angles_deg"]) < 1.0 flat = next(case for case in report["low_rank"] if case["fixture"] == "flat") assert flat["exact"]["status"] == "inconclusive" and "subspace_angles_deg" not in flat def test_measure_without_proc_and_cli_output(tmp_path, monkeypatch): monkeypatch.setattr(kb, "_rss", lambda: None) result, cost = kb.measure(lambda: 7, repeats=2, warmup=0) assert result == 7 and len(cost["wall_seconds"]) == 2 assert cost["peak_rss_growth_bytes"] is None monkeypatch.setattr(kb, "run_benchmark", lambda **kw: {"called": kw}) threads = [] monkeypatch.setattr(kb.torch, "set_num_threads", threads.append) out = tmp_path / "bench.json" assert kb.main(["--output", str(out), "--quick", "--threads", "1"]) == 0 assert json.loads(out.read_text()) == {"called": {"quick": True, "repeats": 1}} assert threads == [1] with pytest.raises(SystemExit): kb.main(["--output", str(out), "--repeats", "0"])