from __future__ import annotations import importlib.util import json from pathlib import Path ROOT = Path(__file__).resolve().parents[2] SCRIPT = ROOT / "tools/run_6400_td.py" SPEC = importlib.util.spec_from_file_location("run_6400_td", SCRIPT) assert SPEC is not None and SPEC.loader is not None run_6400_td = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(run_6400_td) def test_td_synthesis_uses_source_root_for_generated_includes() -> None: script = (ROOT / "td/syn/prod2u_6400_front_back.tcl").read_text(encoding="utf-8") closure = json.loads( (ROOT / "products/6400-control/source-closure.json").read_text(encoding="utf-8") ) expected_verilog = [path for path in closure["sources"] if path.endswith(".v")] assert "analyze -file [src $relative] -include_dir $source_root" in script assert [f"analyze_src {{{path}}}" for path in expected_verilog] == [ line for line in script.splitlines() if line.startswith("analyze_src {") ] def test_parse_metrics_uses_routed_slacks_slices_and_lut_fallback(tmp_path: Path) -> None: (tmp_path / "syn").mkdir() (tmp_path / "phy").mkdir() (tmp_path / "bitgen").mkdir() (tmp_path / "syn/prod2u_6400_front_back_gate.area").write_text( "#lut 321\n#reg 222\n#bram 3\n#dsp 1\n", encoding="utf-8", ) (tmp_path / "phy/prod2u_6400_front_back_phy.area").write_text("", encoding="utf-8") (tmp_path / "phy/prod2u_6400_front_back_pr.timing").write_text( """SWNS: 12.500ns, STNS: 0.000ns HWNS: 0.250ns, HTNS: 0.000ns Fmax: 100.000MHz Max: SWNS 12.500ns, 0 Viol Endpoints, 10 Total Endpoints Min: HWNS 0.250ns, 0 Viol Endpoints, 10 Total Endpoints """, encoding="utf-8", ) (tmp_path / "syn/syn.log").write_text("packed: 9 mslices, 11 lslices\n", encoding="utf-8") (tmp_path / "phy/phy.log").write_text("routed: 7 mslices, 8 lslices\n", encoding="utf-8") metrics = run_6400_td.parse_metrics(tmp_path) assert metrics["total_luts"] == 321 assert metrics["total_luts_source"] == "#lut_fallback" assert metrics["mslice"] == 7 assert metrics["lslice"] == 8 assert metrics["packed_slices"] == 15 assert metrics["setup_slack_ns"] == 12.5 assert metrics["hold_slack_ns"] == 0.25 assert metrics["violation_endpoint_counts"] == [0, 0] def _stage_records(log: Path) -> dict[str, dict[str, object]]: return {"syn": {"log": str(log)}} def test_warning_audit_allows_only_the_two_frozen_ttl_unknowns(tmp_path: Path) -> None: log = tmp_path / "syn.log" log.write_text( """SYN-6021 CRITICAL-WARNING: 2 out of 43 logical ports has no user assigned specific location constraint. Bitgen will abort unless unconstr_io is enabled. No ADC ports: host_ttl_rx, host_ttl_tx. RUN-1001 : No hold violation. """, encoding="utf-8", ) audit = run_6400_td.warning_audit(_stage_records(log)) assert audit["status"] == "PASS" assert audit["observed_unbound_ports"] == ["host_ttl_rx", "host_ttl_tx"] assert audit["blocking_count"] == 0 def test_warning_audit_rejects_any_additional_unbound_port(tmp_path: Path) -> None: log = tmp_path / "syn.log" log.write_text( "No ADC ports: host_ttl_rx, host_ttl_tx, mystery_output.\n", encoding="utf-8", ) audit = run_6400_td.warning_audit(_stage_records(log)) assert audit["status"] == "FAIL" assert audit["unexpected_unbound_ports"] == ["mystery_output"] def test_warning_audit_keeps_real_td_errors_blocking(tmp_path: Path) -> None: log = tmp_path / "syn.log" log.write_text( """No ADC ports: host_ttl_rx, host_ttl_tx. PDS-9001 ERROR: routing failed """, encoding="utf-8", ) audit = run_6400_td.warning_audit(_stage_records(log)) assert audit["status"] == "FAIL" assert any("routing failed" in line for line in audit["blocking"])