| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #!/usr/bin/env python3
- """Coverage gates: percent motion sim/formal targets exist and mention contract."""
- from __future__ import annotations
- import unittest
- from pathlib import Path
- from tools.prod2u_p4_harness import load_target_manifest
- ROOT = Path(__file__).resolve().parents[2]
- def _read(relative: str) -> str:
- return (ROOT / relative).read_text(encoding="utf-8", errors="replace")
- class ProductContractCoverageTests(unittest.TestCase):
- def test_planner_tb_covers_half_up_samples(self):
- planner = _read("tests/sim/door_percent_planner_tb.v")
- for marker in (
- "run_case(13'd100, 8'd50, 13'd50)",
- "run_case(13'd3, 8'd50, 13'd2)",
- "run_case(13'd5000, 8'd50, 13'd2500)",
- ):
- self.assertIn(marker, planner)
- def test_motion_tb_covers_startup_and_snapshot(self):
- motion = _read("tests/sim/door_motion_controller_tb.v")
- self.assertIn("startup_complete", motion)
- self.assertIn("status byte0", motion.lower() + motion)
- self.assertIn("8'h47", motion)
- def test_runtime_limit_and_cal_cover_hard_stop(self):
- runtime = _read("tests/sim/prod2u_p4_normal_v3_top_runtime_limit_tb.v")
- formal = _read("tests/formal/runtime_limit_hard_stop_formal.v")
- self.assertIn("truncate", runtime.lower() + formal.lower())
- self.assertIn("selected_limit", formal)
- self.assertIn("gated_step", formal)
- def test_manifest_names_match_files(self):
- manifest = load_target_manifest()
- for name in manifest["layers"]["icarus"]:
- path = ROOT / "tests" / "sim" / f"{name}.v"
- self.assertTrue(path.is_file(), name)
- for entry in manifest["layers"]["formal"]:
- path = ROOT / "tests" / "formal" / f"{entry['name']}.sby"
- self.assertTrue(path.is_file(), entry["name"])
- def test_no_legacy_jog_tb_in_manifest(self):
- manifest = load_target_manifest()
- icarus = set(manifest["layers"]["icarus"])
- for banned in (
- "door_motor_engine_tb",
- "door_action_dispatcher_tb",
- "startup_close_seek_tb",
- "startup_motor_stop_tb",
- ):
- self.assertNotIn(banned, icarus)
- if __name__ == "__main__":
- unittest.main()
|