summaryrefslogtreecommitdiff
path: root/tools/tests/test_check_budgets.py
diff options
context:
space:
mode:
authorcirakg <cirakg@cirakg.xyz>2026-10-18 20:28:09 +0200
committercirakg <cirakg@cirakg.xyz>2026-10-18 20:28:09 +0200
commit2071e2beda763137416ac386d4bb953711ec995d (patch)
treebdcf840cb457f8286c1d967410f98972eb99b50a /tools/tests/test_check_budgets.py
parenta9b1dc8bd9354973eabd72f56d82b2eab6f48d56 (diff)
test(tools): add test-log judge, docs and policy checks with tests
- ciq_test_report.py: decides pass/fail from Run No Evil output instead of monkeydo's unreliable exit code; writes JUnit XML. - check_docs.py: offline check of relative links and GitHub anchors. - lint_project.py: project rules (headers, no logging outside Diag, no secret-like literals, no network APIs or permissions). - check_budgets.py with budgets.json: perf and memory gates. - make_icon.py: reproducible launcher icon. - 31 pytest tests, including Hypothesis fuzzing of the log parser and integration checks against the real docs and sources; ruff and mypy (strict) clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/tests/test_check_budgets.py')
-rw-r--r--tools/tests/test_check_budgets.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/tests/test_check_budgets.py b/tools/tests/test_check_budgets.py
new file mode 100644
index 0000000..35cc2f8
--- /dev/null
+++ b/tools/tests/test_check_budgets.py
@@ -0,0 +1,45 @@
+"""Tests for tools/check_budgets.py (perf and memory budgets)."""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+
+import check_budgets as cb
+
+FRAME = 'DIAG {"event":"first_frame","startup_ms":250,"mem_used":100000,"mem_total":524288}'
+
+
+def test_reads_events_and_skips_noise() -> None:
+ text = f"Device Version 1\n{FRAME}\nDIAG {{not json\nsome DIAG line\n"
+ assert cb.read_events(text) == [
+ {"event": "first_frame", "startup_ms": 250, "mem_used": 100000, "mem_total": 524288}
+ ]
+
+
+def test_measure_perf_and_memory() -> None:
+ events = cb.read_events(FRAME)
+ assert cb.measure("perf", events) == {"startup_ms": 250.0}
+ assert cb.measure("mem", events) == {"mem_used_fraction": 100000 / 524288}
+ assert cb.measure("perf", []) == {}
+
+
+def run(tmp_path: Path, kind: str, log_text: str, budgets: dict[str, dict[str, float]]) -> int:
+ log = tmp_path / "fr255s.log"
+ log.write_text(log_text, encoding="utf-8")
+ budget_file = tmp_path / "budgets.json"
+ budget_file.write_text(json.dumps(budgets), encoding="utf-8")
+ return cb.main([kind, str(log), "--budgets", str(budget_file), "--summary", str(tmp_path / "s.json")])
+
+
+def test_within_budget(tmp_path: Path) -> None:
+ assert run(tmp_path, "perf", FRAME, {"perf": {"startup_ms": 300}}) == cb.EXIT_OK
+ assert json.loads((tmp_path / "s.json").read_text()) == {"fr255s": {"startup_ms": 250.0}}
+
+
+def test_over_budget(tmp_path: Path) -> None:
+ assert run(tmp_path, "mem", FRAME, {"mem": {"mem_used_fraction": 0.1}}) == cb.EXIT_OVER
+
+
+def test_missing_diagnostics(tmp_path: Path) -> None:
+ assert run(tmp_path, "perf", "app crashed\n", {"perf": {"startup_ms": 300}}) == cb.EXIT_MISSING