test_motion_params_binding.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. """Generated motion params must bind into the production top instance."""
  3. from __future__ import annotations
  4. import re
  5. import unittest
  6. from pathlib import Path
  7. ROOT = Path(__file__).resolve().parents[2]
  8. TOP = ROOT / "src/top/prod2u_p4_normal_v3_top.v"
  9. PARAMS = ROOT / "src/generated/prod2u_door_temp_params.vh"
  10. CONTROLLER = ROOT / "src/modules/door_motion_controller.v"
  11. class MotionParamsBindingTests(unittest.TestCase):
  12. def test_generated_defines_match_contract(self) -> None:
  13. text = PARAMS.read_text(encoding="utf-8")
  14. self.assertIn("`define P4_MOTION_SERVICE_CLKS 625", text)
  15. self.assertIn("`define P4_PHASE_FACTOR 5120", text)
  16. self.assertIn("`define P4_CAL_RAMP_UNIT 8", text)
  17. def test_top_passes_generated_motion_params(self) -> None:
  18. text = TOP.read_text(encoding="utf-8")
  19. self.assertIn(".MOTION_SERVICE_CLKS(`P4_MOTION_SERVICE_CLKS)", text)
  20. self.assertIn(".PHASE_FACTOR(`P4_PHASE_FACTOR)", text)
  21. self.assertIn(".CAL_RAMP_UNIT(`P4_CAL_RAMP_UNIT)", text)
  22. def test_controller_exposes_params(self) -> None:
  23. text = CONTROLLER.read_text(encoding="utf-8")
  24. self.assertIn("parameter integer MOTION_SERVICE_CLKS", text)
  25. self.assertIn("parameter integer PHASE_FACTOR", text)
  26. self.assertIn("parameter integer CAL_RAMP_UNIT", text)
  27. if __name__ == "__main__":
  28. unittest.main()