test_6400_td_parser.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. from __future__ import annotations
  2. import importlib.util
  3. import json
  4. from pathlib import Path
  5. ROOT = Path(__file__).resolve().parents[2]
  6. SCRIPT = ROOT / "tools/run_6400_td.py"
  7. SPEC = importlib.util.spec_from_file_location("run_6400_td", SCRIPT)
  8. assert SPEC is not None and SPEC.loader is not None
  9. run_6400_td = importlib.util.module_from_spec(SPEC)
  10. SPEC.loader.exec_module(run_6400_td)
  11. def test_td_synthesis_uses_source_root_for_generated_includes() -> None:
  12. script = (ROOT / "td/syn/prod2u_6400_front_back.tcl").read_text(encoding="utf-8")
  13. closure = json.loads(
  14. (ROOT / "products/6400-control/source-closure.json").read_text(encoding="utf-8")
  15. )
  16. expected_verilog = [path for path in closure["sources"] if path.endswith(".v")]
  17. assert "analyze -file [src $relative] -include_dir $source_root" in script
  18. assert [f"analyze_src {{{path}}}" for path in expected_verilog] == [
  19. line for line in script.splitlines() if line.startswith("analyze_src {")
  20. ]
  21. def test_parse_metrics_uses_routed_slacks_slices_and_lut_fallback(tmp_path: Path) -> None:
  22. (tmp_path / "syn").mkdir()
  23. (tmp_path / "phy").mkdir()
  24. (tmp_path / "bitgen").mkdir()
  25. (tmp_path / "syn/prod2u_6400_front_back_gate.area").write_text(
  26. "#lut 321\n#reg 222\n#bram 3\n#dsp 1\n",
  27. encoding="utf-8",
  28. )
  29. (tmp_path / "phy/prod2u_6400_front_back_phy.area").write_text("", encoding="utf-8")
  30. (tmp_path / "phy/prod2u_6400_front_back_pr.timing").write_text(
  31. """SWNS: 12.500ns, STNS: 0.000ns
  32. HWNS: 0.250ns, HTNS: 0.000ns
  33. Fmax: 100.000MHz
  34. Max: SWNS 12.500ns, 0 Viol Endpoints, 10 Total Endpoints
  35. Min: HWNS 0.250ns, 0 Viol Endpoints, 10 Total Endpoints
  36. """,
  37. encoding="utf-8",
  38. )
  39. (tmp_path / "syn/syn.log").write_text("packed: 9 mslices, 11 lslices\n", encoding="utf-8")
  40. (tmp_path / "phy/phy.log").write_text("routed: 7 mslices, 8 lslices\n", encoding="utf-8")
  41. metrics = run_6400_td.parse_metrics(tmp_path)
  42. assert metrics["total_luts"] == 321
  43. assert metrics["total_luts_source"] == "#lut_fallback"
  44. assert metrics["mslice"] == 7
  45. assert metrics["lslice"] == 8
  46. assert metrics["packed_slices"] == 15
  47. assert metrics["setup_slack_ns"] == 12.5
  48. assert metrics["hold_slack_ns"] == 0.25
  49. assert metrics["violation_endpoint_counts"] == [0, 0]
  50. def _stage_records(log: Path) -> dict[str, dict[str, object]]:
  51. return {"syn": {"log": str(log)}}
  52. def test_warning_audit_allows_only_the_two_frozen_ttl_unknowns(tmp_path: Path) -> None:
  53. log = tmp_path / "syn.log"
  54. log.write_text(
  55. """SYN-6021 CRITICAL-WARNING: 2 out of 43 logical ports has no user assigned specific location constraint.
  56. Bitgen will abort unless unconstr_io is enabled.
  57. No ADC ports: host_ttl_rx, host_ttl_tx.
  58. RUN-1001 : No hold violation.
  59. """,
  60. encoding="utf-8",
  61. )
  62. audit = run_6400_td.warning_audit(_stage_records(log))
  63. assert audit["status"] == "PASS"
  64. assert audit["observed_unbound_ports"] == ["host_ttl_rx", "host_ttl_tx"]
  65. assert audit["blocking_count"] == 0
  66. def test_warning_audit_rejects_any_additional_unbound_port(tmp_path: Path) -> None:
  67. log = tmp_path / "syn.log"
  68. log.write_text(
  69. "No ADC ports: host_ttl_rx, host_ttl_tx, mystery_output.\n",
  70. encoding="utf-8",
  71. )
  72. audit = run_6400_td.warning_audit(_stage_records(log))
  73. assert audit["status"] == "FAIL"
  74. assert audit["unexpected_unbound_ports"] == ["mystery_output"]
  75. def test_warning_audit_keeps_real_td_errors_blocking(tmp_path: Path) -> None:
  76. log = tmp_path / "syn.log"
  77. log.write_text(
  78. """No ADC ports: host_ttl_rx, host_ttl_tx.
  79. PDS-9001 ERROR: routing failed
  80. """,
  81. encoding="utf-8",
  82. )
  83. audit = run_6400_td.warning_audit(_stage_records(log))
  84. assert audit["status"] == "FAIL"
  85. assert any("routing failed" in line for line in audit["blocking"])