diff options
| author | cirakg <cirakg@cirakg.xyz> | 2026-10-18 21:10:37 +0200 |
|---|---|---|
| committer | cirakg <cirakg@cirakg.xyz> | 2026-10-18 21:10:37 +0200 |
| commit | 2292bf700d28ade39cf2d64b45509e6db21034bc (patch) | |
| tree | ef455320d39ebe51db236219dbbda2b148dcbe18 /tools/tests/test_check_budgets.py | |
| parent | 85f1ecabd7f58f306b2a042376209ac8cf49ab9b (diff) | |
test(tools): add screenshot, budget and product checks; enforce file headers
- sim_screenshot.py finds the device drawing in the simulator window,
crops the screen and compares it with approved golden images.
- check_budgets.py reads key=value DIAG/HARNESS lines (the simulator
console escapes quotes, so JSON was dropped).
- ciq_test_report.py accepts SDK 9.2.0's real summary line
`PASSED (passed=N, failed=N, errors=N)`; a captured log is a fixture.
- gen_products.py checks all manifest products are watches with
API 5.0+ and at least 512 KB for apps.
- lint_project.py rule HDR001: every file carries the Author/Summary
header (JSON keys, PNG text chunks; generated package-lock exempt).
- make_icon.py --all draws one icon per launcher size in use.
- Golden screenshots for fr255s, venusq2, fr70 and fr965.
- 44 tests, warnings as errors, 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.py | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/tools/tests/test_check_budgets.py b/tools/tests/test_check_budgets.py index 35cc2f8..2262a0b 100644 --- a/tools/tests/test_check_budgets.py +++ b/tools/tests/test_check_budgets.py @@ -1,30 +1,37 @@ +# Author: cirakg & claude ai +# Summary: Tests for tools/check_budgets.py (start-up time and memory budgets). """Tests for tools/check_budgets.py (perf and memory budgets).""" from __future__ import annotations import json +from collections.abc import Mapping from pathlib import Path import check_budgets as cb -FRAME = 'DIAG {"event":"first_frame","startup_ms":250,"mem_used":100000,"mem_total":524288}' +FRAME = "DIAG first_frame startup_ms=12 mem_used=100000 mem_total=524288" +WALL = "HARNESS first_frame wall_ms=2310" 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} - ] + text = f"Device Version 1\n{FRAME}\nDIAG broken\n{WALL}\nDIAG first_frame startup_ms=99 mem_used=1 mem_total=2\n" + events = cb.read_events(text) + # Only the first occurrence of each event counts. + assert events == { + "DIAG.first_frame": {"startup_ms": 12.0, "mem_used": 100000.0, "mem_total": 524288.0}, + "HARNESS.first_frame": {"wall_ms": 2310.0}, + } def test_measure_perf_and_memory() -> None: - events = cb.read_events(FRAME) - assert cb.measure("perf", events) == {"startup_ms": 250.0} + events = cb.read_events(f"{FRAME}\n{WALL}") + assert cb.measure("perf", events) == {"startup_ms": 12.0, "first_frame_wall_ms": 2310.0} assert cb.measure("mem", events) == {"mem_used_fraction": 100000 / 524288} - assert cb.measure("perf", []) == {} + assert cb.measure("perf", {}) == {} -def run(tmp_path: Path, kind: str, log_text: str, budgets: dict[str, dict[str, float]]) -> int: +def run(tmp_path: Path, kind: str, log_text: str, budgets: Mapping[str, Mapping[str, float]]) -> int: log = tmp_path / "fr255s.log" log.write_text(log_text, encoding="utf-8") budget_file = tmp_path / "budgets.json" @@ -33,13 +40,20 @@ def run(tmp_path: Path, kind: str, log_text: str, budgets: dict[str, dict[str, f 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}} + budgets = {"perf": {"startup_ms": 300, "first_frame_wall_ms": 5000}} + assert run(tmp_path, "perf", f"{FRAME}\n{WALL}", budgets) == cb.EXIT_OK + summary = json.loads((tmp_path / "s.json").read_text()) + assert summary == {"fr255s": {"startup_ms": 12.0, "first_frame_wall_ms": 2310.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_budgeted_value_not_measured(tmp_path: Path) -> None: + budgets = {"perf": {"first_frame_wall_ms": 5000}} + assert run(tmp_path, "perf", FRAME, budgets) == cb.EXIT_MISSING + + def test_missing_diagnostics(tmp_path: Path) -> None: assert run(tmp_path, "perf", "app crashed\n", {"perf": {"startup_ms": 300}}) == cb.EXIT_MISSING |
