#!/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"(? 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", "tests/sim/uart_rs232_j6_host_sensor_real_fan_ptc_debug921_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", "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/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/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", "tools/pid_harness.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", "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, } 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"{stem}_top", 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) if __name__ == "__main__": unittest.main()