from __future__ import annotations import importlib.util from pathlib import Path ROOT = Path(__file__).resolve().parents[2] SCRIPT = ROOT / "tools/run_6400_architecture_td_ab.py" SPEC = importlib.util.spec_from_file_location("architecture_td_ab", SCRIPT) assert SPEC is not None and SPEC.loader is not None architecture_td_ab = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(architecture_td_ab) def _write_candidate(tmp_path: Path, top: str, timing: str, log: str) -> Path: (tmp_path / f"{top}_gate.area").write_text( "#lut 8\n#reg 0\n#bram 0\n#dsp 0\n", encoding="utf-8", ) (tmp_path / f"{top}_pr.area").write_text("", encoding="utf-8") (tmp_path / f"{top}_pr.timing").write_text(timing, encoding="utf-8") (tmp_path / "td.log").write_text(log, encoding="utf-8") return tmp_path def test_lut_fallback_and_no_reg_to_reg_timing_are_explicit(tmp_path: Path) -> None: root = _write_candidate( tmp_path, "candidate", """Timing Status SWNS: 0.000ns, STNS: 0.000ns HWNS: 0.000ns, HTNS: 0.000ns Intra clock domain timing -------------------------------------------------- """, "PDS: 2 mslices, 3 lslices\n", ) metrics = architecture_td_ab.parse_candidate("candidate", root)["metrics"] evaluation = architecture_td_ab.evaluate_timing(metrics) assert metrics["total_luts"] == 8 assert metrics["total_luts_source"] == "#lut_fallback" assert metrics["fmax_mhz"] is None assert metrics["violation_endpoint_counts"] == [] assert metrics["timing_applicability"] == architecture_td_ab.TIMING_NOT_APPLICABLE assert evaluation["status"] == "PASS" assert evaluation["fmax_requirement"] == "NOT_APPLICABLE" def test_measured_timing_parses_every_violation_endpoint_count(tmp_path: Path) -> None: root = _write_candidate( tmp_path, "candidate", """Timing Status SWNS: 36.587ns, STNS: 0.000ns HWNS: 0.384ns, HTNS: 0.000ns From Clock : ab_clk To Clock : ab_clk Fmax : 292.997MHz Max : SWNS 36.587ns, 0 Viol Endpoints, 37 Total Endpoints Min : HWNS 0.384ns, 0 Viol Endpoints, 37 Total Endpoints """, "PDS: 8 mslices, 9 lslices\n", ) metrics = architecture_td_ab.parse_candidate("candidate", root)["metrics"] evaluation = architecture_td_ab.evaluate_timing(metrics) assert metrics["violation_endpoint_counts"] == [0, 0] assert metrics["register_to_register_path_present"] is True assert metrics["fmax_mhz"] == 292.997 assert evaluation["status"] == "PASS" assert evaluation["meets_25mhz"] is True def test_expected_unassigned_io_warning_is_not_a_blocker(tmp_path: Path) -> None: log = tmp_path / "td.log" log.write_text( """SYN-6021 CRITICAL-WARNING: 82 out of 83 logical ports has no user assigned specific location constraint. Bitgen will abort. If insist on bitgen with risk, please set unconstr_io. No ADC ports: control[31:0], error[15:0]. control[0]:N8, error[0]:T7 RUN-1001 : Exported violations RUN-1001 : No hold violation. """, encoding="utf-8", ) audit = architecture_td_ab.warning_audit(log) assert audit["status"] == "PASS" assert audit["blocking_count"] == 0 assert audit["allowlisted_expected_count"] == 3 assert not any("error[0]" in line for line in audit["noteworthy"]) def test_actual_td_error_remains_blocking(tmp_path: Path) -> None: log = tmp_path / "td.log" log.write_text("PDS-9001 ERROR: routing failed\n", encoding="utf-8") audit = architecture_td_ab.warning_audit(log) assert audit["status"] == "FAIL" assert audit["blocking_count"] == 1