test_product_contract_coverage.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. """Coverage gates: percent motion sim/formal targets exist and mention contract."""
  3. from __future__ import annotations
  4. import unittest
  5. from pathlib import Path
  6. from tools.prod2u_p4_harness import load_target_manifest
  7. ROOT = Path(__file__).resolve().parents[2]
  8. def _read(relative: str) -> str:
  9. return (ROOT / relative).read_text(encoding="utf-8", errors="replace")
  10. class ProductContractCoverageTests(unittest.TestCase):
  11. def test_planner_tb_covers_half_up_samples(self):
  12. planner = _read("tests/sim/door_percent_planner_tb.v")
  13. for marker in (
  14. "run_case(13'd100, 8'd50, 13'd50)",
  15. "run_case(13'd3, 8'd50, 13'd2)",
  16. "run_case(13'd5000, 8'd50, 13'd2500)",
  17. ):
  18. self.assertIn(marker, planner)
  19. def test_motion_tb_covers_startup_and_snapshot(self):
  20. motion = _read("tests/sim/door_motion_controller_tb.v")
  21. self.assertIn("startup_complete", motion)
  22. self.assertIn("status byte0", motion.lower() + motion)
  23. self.assertIn("8'h47", motion)
  24. def test_runtime_limit_and_cal_cover_hard_stop(self):
  25. runtime = _read("tests/sim/prod2u_p4_normal_v3_top_runtime_limit_tb.v")
  26. formal = _read("tests/formal/runtime_limit_hard_stop_formal.v")
  27. self.assertIn("truncate", runtime.lower() + formal.lower())
  28. self.assertIn("selected_limit", formal)
  29. self.assertIn("gated_step", formal)
  30. def test_manifest_names_match_files(self):
  31. manifest = load_target_manifest()
  32. for name in manifest["layers"]["icarus"]:
  33. path = ROOT / "tests" / "sim" / f"{name}.v"
  34. self.assertTrue(path.is_file(), name)
  35. for entry in manifest["layers"]["formal"]:
  36. path = ROOT / "tests" / "formal" / f"{entry['name']}.sby"
  37. self.assertTrue(path.is_file(), entry["name"])
  38. def test_no_legacy_jog_tb_in_manifest(self):
  39. manifest = load_target_manifest()
  40. icarus = set(manifest["layers"]["icarus"])
  41. for banned in (
  42. "door_motor_engine_tb",
  43. "door_action_dispatcher_tb",
  44. "startup_close_seek_tb",
  45. "startup_motor_stop_tb",
  46. ):
  47. self.assertNotIn(banned, icarus)
  48. if __name__ == "__main__":
  49. unittest.main()