test_project_structure.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env python3
  2. """Repository layout contract: MRDIMM top plus isolated 6400 top."""
  3. from __future__ import annotations
  4. import sys
  5. import unittest
  6. from pathlib import Path
  7. ROOT = Path(__file__).resolve().parents[1]
  8. TOOLS = ROOT / "tools"
  9. if str(TOOLS) not in sys.path:
  10. sys.path.insert(0, str(TOOLS))
  11. import test_profiles # noqa: E402
  12. class ProjectStructureTests(unittest.TestCase):
  13. def test_new_architecture_and_evidence_directories_exist(self) -> None:
  14. profile = test_profiles.detect_test_profile(ROOT)
  15. required = test_profiles.structure_required_paths(profile)
  16. for relative in required:
  17. with self.subTest(relative=relative, profile=profile):
  18. # Compact trees may nest under source/; accept either layout.
  19. candidates = (
  20. ROOT / relative,
  21. ROOT / "source" / relative,
  22. )
  23. self.assertTrue(
  24. any(path.is_file() for path in candidates),
  25. f"{relative} missing under profile={profile}",
  26. )
  27. if not test_profiles.requires_reference_legacy_rtl(profile):
  28. for relative in test_profiles.REFERENCE_ONLY_PATHS:
  29. with self.subTest(relative=relative, profile=profile):
  30. # Detached compact must not require excluded legacy_rtl.
  31. self.assertFalse(
  32. test_profiles.requires_reference_legacy_rtl(profile),
  33. "review-compact-detached must not require legacy_rtl",
  34. )
  35. def test_only_canonical_top_is_active(self) -> None:
  36. top_dirs = (
  37. ROOT / "src" / "top",
  38. ROOT / "source" / "src" / "top",
  39. )
  40. top_dir = next((path for path in top_dirs if path.is_dir()), None)
  41. self.assertIsNotNone(top_dir, "src/top missing")
  42. assert top_dir is not None
  43. tops = sorted(path.name for path in top_dir.glob("*.v"))
  44. self.assertEqual(
  45. tops,
  46. ["prod2u_6400_front_back_top.v", "prod2u_p4_normal_v3_top.v"],
  47. )
  48. def test_active_td_and_build_inputs_exclude_retired_protocol(self) -> None:
  49. def _read(*parts: str) -> str:
  50. for base in (ROOT, ROOT / "source"):
  51. path = base.joinpath(*parts)
  52. if path.is_file():
  53. return path.read_text(encoding="utf-8")
  54. self.fail(f"missing {'/'.join(parts)}")
  55. return ""
  56. active = "\n".join(
  57. [
  58. _read("td", "syn", "prod2u_p4_normal_v3.tcl"),
  59. _read("td", "phy", "prod2u_p4_normal_v3.tcl"),
  60. _read("td", "prod2u_p4_normal_v3.prj"),
  61. _read("tools", "prod2u_p4_normal_v3_build.py"),
  62. ]
  63. ).casefold()
  64. for retired in ("binary921", "921600", "response_scheduler", "host_ack", "jog", "motor_compat", "solenoid"):
  65. self.assertNotIn(retired, active)
  66. def test_phase2_top_port_shape_has_three_axis_and_six_limits(self) -> None:
  67. top_path = None
  68. for base in (ROOT, ROOT / "source"):
  69. candidate = base / "src" / "top" / "prod2u_p4_normal_v3_top.v"
  70. if candidate.is_file():
  71. top_path = candidate
  72. break
  73. self.assertIsNotNone(top_path)
  74. assert top_path is not None
  75. top = top_path.read_text(encoding="ascii")
  76. self.assertIn("output wire [7:0] ptc_pwm_out", top)
  77. self.assertIn("output wire [3:0] fan_pwm_out", top)
  78. for port in ("z_step", "z_dir", "x_limit_ls", "x_limit_hs", "z_limit_hs"):
  79. self.assertIn(port, top)
  80. self.assertNotIn("intake_solenoid_out", top)
  81. if __name__ == "__main__":
  82. unittest.main()