| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- #!/usr/bin/env python3
- """Top-level project structure contract tests for the converged CPLD project."""
- from __future__ import annotations
- import re
- import unittest
- from pathlib import Path
- ROOT = Path(__file__).resolve().parents[1]
- THIS_FILE = Path(__file__).resolve()
- WORKSPACE_PATH_MARKER = re.compile(r"(?<![A-Za-z0-9_])workspace[\\/]")
- LEGACY_CHAIN_MARKERS = [
- "bringup",
- "raw_cr",
- "raw-cr",
- "cr_raw",
- "cr-raw",
- "sensor_raw",
- "sensor-raw",
- "host_control_pwm",
- "host-control-pwm",
- "host_sensor_pwm_debug921",
- "host-sensor-pwm-debug921",
- "j6_system_debug",
- "j6-system-debug",
- "j6_system_top",
- "j6-system-top",
- "j6sys",
- "uart_rs232_system",
- ]
- class ProjectStructureTests(unittest.TestCase):
- def test_converged_engineering_layout_has_single_user_bitstream_top(self) -> None:
- required_dirs = [
- "src/rtl",
- "src/top",
- "tests/sim",
- "tests/formal",
- "tools",
- "td/syn",
- "td/phy",
- "config",
- "constraints",
- "docs",
- "schemas",
- "reference/original/schematics",
- "test_vectors",
- ]
- for rel in required_dirs:
- self.assertTrue((ROOT / rel).is_dir(), rel)
- required_files = [
- "src/rtl/pid_core.v",
- "src/rtl/uart_rx_8n1.v",
- "src/rtl/uart_tx_8n1.v",
- "src/rtl/bmc_uart_raw48_poll_lite.v",
- "src/top/uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top.v",
- "src/top/uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921_top.v",
- "src/top/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart_debug921_top.v",
- "src/top/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_debug921_top.v",
- "src/top/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_debug921_top.v",
- "src/top/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_binary921_top.v",
- "src/top/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_binary921_top.v",
- "src/top/prod2u_bmc_replay_binary921_top.v",
- "src/rtl/binary921_crc16.v",
- "src/rtl/binary921_frame_tx.v",
- "src/rtl/binary921_host_rx.v",
- "src/rtl/binary921_diag_core.v",
- "tests/sim/uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top_tb.v",
- "tests/sim/uart_rs232_j6_host_sensor_real_fan_ptc_binary921_top_tb.v",
- "constraints/uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921.adc",
- "constraints/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart_debug921.adc",
- "constraints/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_debug921.adc",
- "constraints/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_debug921.adc",
- "constraints/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_binary921.adc",
- "constraints/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_binary921.adc",
- "constraints/prod2u_bmc_replay_binary921.adc",
- "td/uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921.prj",
- "td/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart_debug921.prj",
- "td/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_debug921.prj",
- "td/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_debug921.prj",
- "td/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_binary921.prj",
- "td/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_binary921.prj",
- "td/prod2u_bmc_replay_binary921.prj",
- "td/syn/uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921.tcl",
- "td/syn/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart_debug921.tcl",
- "td/syn/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_debug921.tcl",
- "td/syn/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_debug921.tcl",
- "td/syn/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_binary921.tcl",
- "td/syn/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_binary921.tcl",
- "td/syn/prod2u_bmc_replay_binary921.tcl",
- "td/phy/uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921.tcl",
- "td/phy/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart_debug921.tcl",
- "td/phy/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_debug921.tcl",
- "td/phy/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_debug921.tcl",
- "td/phy/uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_binary921.tcl",
- "td/phy/uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_binary921.tcl",
- "td/phy/prod2u_bmc_replay_binary921.tcl",
- "tools/pid_harness.py",
- "tools/binary921.py",
- "tools/bmc_replay_uart.py",
- "tools/uart_receipts.py",
- "tools/pin_inventory.py",
- "tools/package_j6_host_sensor_real_fan_ptc_debug921.ps1",
- "tools/remote/collect-j6-host-sensor-real-fan-ptc.ps1",
- "schemas/final_gate_v2_receipt.schema.json",
- "schemas/real_bmc_j6_windows_gate_v2_receipt.schema.json",
- "schemas/cpld_bmc_acceptance_v1_receipt.schema.json",
- "schemas/real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt.schema.json",
- "docs/j6-host-sensor-real-fan-ptc-debug921-runbook.zh-CN.md",
- "reference/original/schematics/FCB_FPGA+MCU0611.pdf",
- ]
- for rel in required_files:
- self.assertTrue((ROOT / rel).is_file(), rel)
- self.assertEqual(
- sorted(path.name for path in (ROOT / "tools" / "remote").glob("*.ps1")),
- ["collect-j6-host-sensor-real-fan-ptc.ps1"],
- )
- def test_old_standalone_j6_diagnostic_entrypoints_are_removed(self) -> None:
- active_roots = ["src/top", "tests/sim", "td", "td/syn", "td/phy", "constraints", "tools", "tools/remote", "schemas", "docs"]
- offenders: list[str] = []
- for root_name in active_roots:
- root = ROOT / root_name
- if not root.exists():
- continue
- for path in root.rglob("*"):
- if not path.is_file():
- continue
- rel = path.relative_to(ROOT).as_posix()
- if rel in {
- "tools/uart_receipts.py",
- "tools/pid_harness.py",
- "tools/bmc_replay_uart.py",
- "docs/verification-gates-v2.zh-CN.md",
- "schemas/real_bmc_j6_windows_gate_v2_receipt.schema.json",
- }:
- continue
- lowered = path.name.lower()
- if any(marker in lowered for marker in LEGACY_CHAIN_MARKERS):
- offenders.append(rel)
- self.assertEqual(offenders, [])
- def test_workspace_is_not_an_active_project_entrypoint(self) -> None:
- self.assertFalse((ROOT / "workspace").exists(), "deprecated workspace tree must not remain active")
- def test_active_text_files_do_not_reference_workspace_entrypoints(self) -> None:
- active_roots = ["src", "tests", "tools", "td", "config", "constraints", "docs", "schemas"]
- offenders: list[str] = []
- for root_name in active_roots:
- root = ROOT / root_name
- if not root.exists():
- continue
- for path in root.rglob("*"):
- if not path.is_file() or path.suffix.lower() in {".png", ".jpg", ".jpeg", ".pdf", ".pyc"}:
- continue
- if "__pycache__" in path.parts or path.resolve() == THIS_FILE or path.name == "verify_pid_study.py":
- continue
- text = path.read_text(encoding="utf-8", errors="replace")
- if WORKSPACE_PATH_MARKER.search(text):
- offenders.append(path.relative_to(ROOT).as_posix())
- self.assertEqual(offenders, [])
- def test_latest_top_matches_locked_serial_and_real_fan_ptc_interface(self) -> None:
- top = (ROOT / "src/top/uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top.v").read_text(
- encoding="utf-8",
- errors="replace",
- )
- module_header = top.split(");", 1)[0]
- for marker in [
- "bmc_uart_rx",
- "bmc_uart_tx",
- "debug_uart_rx",
- "debug_uart_tx",
- "host_uart_rx",
- "host_uart_tx",
- "ptc_pwm_out",
- "fan_pwm_out",
- "fan_fg_in",
- "fan_install_in",
- "SET PTC 01..24",
- "SET FAN 01..04",
- "GET SENSOR",
- "SET PID ENABLE",
- "pid_active=0",
- "J6CMD",
- "J6RAW",
- "J6TEMP",
- ]:
- self.assertIn(marker, top)
- self.assertIn("output wire [23:0] ptc_pwm_out", module_header)
- self.assertIn("output wire [3:0] fan_pwm_out", module_header)
- self.assertIn("input wire [7:0] fan_fg_in", module_header)
- self.assertIn("input wire [3:0] fan_install_in", module_header)
- self.assertNotIn("PROGRAM_FLASH", top)
- self.assertNotIn("ERASE_FLASH", top)
- def test_two_user_td_profiles_elaborate_distinct_wrapper_tops(self) -> None:
- profiles = {
- "uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921": 0,
- "uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart_debug921": 1,
- "uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_debug921": 0,
- "uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_debug921": 1,
- }
- for stem, pin_profile in profiles.items():
- with self.subTest(stem=stem):
- wrapper_path = ROOT / "src" / "top" / f"{stem}_top.v"
- wrapper = wrapper_path.read_text(encoding="utf-8", errors="replace")
- self.assertIn(f"module {stem}_top", wrapper)
- self.assertIn("uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top #(", wrapper)
- self.assertIn(f".PIN_PROFILE({pin_profile})", wrapper)
- prj_text = (ROOT / "td" / f"{stem}.prj").read_text(encoding="utf-8")
- self.assertIn("../src/top/uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top.v", prj_text)
- self.assertIn(f"../src/top/{stem}_top.v", prj_text)
- self.assertIn(f"<MODULE>{stem}_top</MODULE>", prj_text)
- syn_text = (ROOT / "td" / "syn" / f"{stem}.tcl").read_text(encoding="utf-8")
- self.assertIn("analyze -file {src/top/uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top.v}", syn_text)
- self.assertIn(f"analyze -file {{src/top/{stem}_top.v}}", syn_text)
- self.assertIn(f"elaborate -top {{{stem}_top}}", syn_text)
- def test_binary921_profiles_use_binary_diag_core_not_ascii_debug921_top(self) -> None:
- profiles = {
- "uart_rs232_j6_host_sensor_real_fan_ptc_debug_photo_uart_bmc_replay_binary921": 0,
- "uart_rs232_j6_host_sensor_real_fan_ptc_formal_uart1_bmc_replay_binary921": 1,
- }
- for stem, pin_profile in profiles.items():
- with self.subTest(stem=stem):
- wrapper_path = ROOT / "src" / "top" / f"{stem}_top.v"
- wrapper = wrapper_path.read_text(encoding="utf-8", errors="replace")
- self.assertIn(f"module {stem}_top", wrapper)
- self.assertIn("binary921_diag_core #(", wrapper)
- self.assertIn(f".PIN_PROFILE({pin_profile})", wrapper)
- self.assertNotIn("uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top #(", wrapper)
- prj_text = (ROOT / "td" / f"{stem}.prj").read_text(encoding="utf-8")
- self.assertIn("../src/rtl/binary921_diag_core.v", prj_text)
- self.assertIn(f"../src/top/{stem}_top.v", prj_text)
- self.assertIn(f"<MODULE>{stem}_top</MODULE>", prj_text)
- syn_text = (ROOT / "td" / "syn" / f"{stem}.tcl").read_text(encoding="utf-8")
- self.assertIn("analyze -file {src/rtl/binary921_diag_core.v}", syn_text)
- self.assertNotIn("analyze -file {src/top/uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top.v}", syn_text)
- self.assertIn(f"elaborate -top {{{stem}_top}}", syn_text)
- def test_production_two_uart_binary921_top_uses_combined_uart_and_real_pin_constraints(self) -> None:
- stem = "prod2u_bmc_replay_binary921"
- wrapper_path = ROOT / "src" / "top" / f"{stem}_top.v"
- constraint_path = ROOT / "constraints" / f"{stem}.adc"
- wrapper = wrapper_path.read_text(encoding="utf-8", errors="replace")
- self.assertIn(f"module {stem}_top", wrapper)
- self.assertIn("binary921_diag_core #(", wrapper)
- self.assertIn(".COMBINED_HOST_DEBUG_UART(1)", wrapper)
- self.assertIn(".PIN_PROFILE(2)", wrapper)
- self.assertIn(".HOST_UART_CLKS_PER_BIT(HOST_UART_CLKS_PER_BIT)", wrapper)
- self.assertNotIn("debug_uart_rx", wrapper.split(");", 1)[0])
- self.assertNotIn("debug_uart_tx", wrapper.split(");", 1)[0])
- constraints = constraint_path.read_text(encoding="utf-8", errors="replace")
- self.assertIn("{ bmc_uart_tx } { LOCATION = L10", constraints)
- self.assertIn("{ bmc_uart_rx } { LOCATION = M9", constraints)
- self.assertIn("{ host_uart_tx } { LOCATION = M10", constraints)
- self.assertIn("{ host_uart_rx } { LOCATION = N11", constraints)
- self.assertNotIn("debug_uart", constraints)
- self.assertIn("{ ptc_pwm_out[2] } { LOCATION = T4", constraints)
- self.assertIn("{ fan_pwm_out[0] } { LOCATION = C4", constraints)
- prj_text = (ROOT / "td" / f"{stem}.prj").read_text(encoding="utf-8")
- self.assertIn("../src/rtl/binary921_diag_core.v", prj_text)
- self.assertIn(f"../src/top/{stem}_top.v", prj_text)
- self.assertIn(f"<MODULE>{stem}_top</MODULE>", prj_text)
- syn_text = (ROOT / "td" / "syn" / f"{stem}.tcl").read_text(encoding="utf-8")
- self.assertIn("analyze -file {src/rtl/binary921_diag_core.v}", syn_text)
- self.assertIn(f"elaborate -top {{{stem}_top}}", syn_text)
- self.assertIn(f"read_adc {{constraints/{stem}.adc}}", syn_text)
- def test_binary921_host_rx_crc_output_is_net_for_td_frontend(self) -> None:
- for path in [
- ROOT / "src" / "rtl" / "binary921_host_rx.v",
- ROOT / "src" / "rtl" / "binary921_frame_tx.v",
- ]:
- with self.subTest(path=path.name):
- source = path.read_text(encoding="utf-8", errors="replace")
- self.assertIn("wire [15:0] crc_next;", source)
- self.assertNotIn("reg [15:0] crc_next;", source)
- if __name__ == "__main__":
- unittest.main()
|