Explorar o código

fix(resource): classify TD evidence precisely

root hai 3 meses
pai
achega
47f3ead1bb

+ 105 - 0
tests/unit/test_6400_architecture_td_ab_parser.py

@@ -0,0 +1,105 @@
+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

+ 128 - 16
tools/run_6400_architecture_td_ab.py

@@ -35,6 +35,9 @@ TRIALS = {
 }
 CANDIDATES = tuple(top for pair in TRIALS.values() for top in pair)
 
+TIMING_MEASURED = "MEASURED_REGISTER_TO_REGISTER_PATH"
+TIMING_NOT_APPLICABLE = "NOT_APPLICABLE_NO_REG_TO_REG_PATH"
+
 
 def sha256(path: Path) -> str:
     digest = hashlib.sha256()
@@ -116,9 +119,24 @@ def parse_candidate(top: str, root: Path) -> dict[str, object]:
     slice_matches = re.findall(r"(\d+)\s+mslices,\s+(\d+)\s+lslices", log_text, re.IGNORECASE)
     mslice = int(slice_matches[-1][0]) if slice_matches else None
     lslice = int(slice_matches[-1][1]) if slice_matches else None
+    reported_total_luts = first_int(area, (r"^#Total_luts\s+(\d+)",))
+    lut = first_int(area, (r"^#lut\s+(\d+)",))
+    fmax_mhz = first_float(
+        timing,
+        (r"Fmax[^\n]*?([0-9]+(?:\.[0-9]+)?)\s*MHz", r"([0-9]+(?:\.[0-9]+)?)\s*MHz"),
+    )
+    register_to_register_path = bool(
+        re.search(r"^From Clock\s*:\s*\S+", timing, re.IGNORECASE | re.MULTILINE)
+        and re.search(r"^To Clock\s*:\s*\S+", timing, re.IGNORECASE | re.MULTILINE)
+    )
+    violation_endpoint_counts = [
+        int(value)
+        for value in re.findall(r"(\d+)\s+Viol Endpoints", timing, re.IGNORECASE)
+    ]
     metrics = {
-        "total_luts": first_int(area, (r"^#Total_luts\s+(\d+)",)),
-        "lut": first_int(area, (r"^#lut\s+(\d+)",)),
+        "total_luts": reported_total_luts if reported_total_luts is not None else lut,
+        "total_luts_source": "#Total_luts" if reported_total_luts is not None else "#lut_fallback",
+        "lut": lut,
         "registers": first_int(area, (r"^#reg\s+(\d+)",)),
         "dsp": first_int(area, (r"^#dsp\s+(\d+)",)),
         "eram_bram": first_int(area, (r"^#(?:eram|bram)\s+(\d+)",)),
@@ -126,15 +144,28 @@ def parse_candidate(top: str, root: Path) -> dict[str, object]:
         "lslice": lslice,
         "packed_slices": mslice + lslice if mslice is not None and lslice is not None else None,
         "packed_slices_derivation": "mslice_plus_lslice",
-        "fmax_mhz": first_float(
-            timing,
-            (r"Fmax[^\n]*?([0-9]+(?:\.[0-9]+)?)\s*MHz", r"([0-9]+(?:\.[0-9]+)?)\s*MHz"),
+        "fmax_mhz": fmax_mhz,
+        "timing_applicability": (
+            TIMING_MEASURED if register_to_register_path else TIMING_NOT_APPLICABLE
+        ),
+        "register_to_register_path_present": register_to_register_path,
+        "violation_endpoint_counts": violation_endpoint_counts,
+        "all_violation_endpoint_counts_zero": all(
+            value == 0 for value in violation_endpoint_counts
         ),
         "setup_slack_ns": first_float(
-            timing, (r"(?:Setup|WNS)[^\n]*?(-?[0-9]+(?:\.[0-9]+)?)\s*ns",)
+            timing,
+            (
+                r"^\s*SWNS\s*:\s*(-?[0-9]+(?:\.[0-9]+)?)\s*ns",
+                r"(?:Setup|WNS)[^\n]*?(-?[0-9]+(?:\.[0-9]+)?)\s*ns",
+            ),
         ),
         "hold_slack_ns": first_float(
-            timing, (r"(?:Hold|HWNS)[^\n]*?(-?[0-9]+(?:\.[0-9]+)?)\s*ns",)
+            timing,
+            (
+                r"^\s*HWNS\s*:\s*(-?[0-9]+(?:\.[0-9]+)?)\s*ns",
+                r"(?:Hold|HWNS)[^\n]*?(-?[0-9]+(?:\.[0-9]+)?)\s*ns",
+            ),
         ),
     }
     return {
@@ -150,22 +181,101 @@ def parse_candidate(top: str, root: Path) -> dict[str, object]:
     }
 
 
+def evaluate_timing(metrics: dict[str, object]) -> dict[str, object]:
+    """Evaluate timing while distinguishing designs with no reg-to-reg path."""
+    setup_slack = metrics["setup_slack_ns"]
+    hold_slack = metrics["hold_slack_ns"]
+    violation_counts = metrics["violation_endpoint_counts"]
+    common_pass = bool(
+        setup_slack is not None
+        and hold_slack is not None
+        and setup_slack >= 0.0
+        and hold_slack >= 0.0
+        and all(value == 0 for value in violation_counts)
+    )
+    applicability = metrics["timing_applicability"]
+    if applicability == TIMING_NOT_APPLICABLE:
+        passed = common_pass and metrics["fmax_mhz"] is None
+        return {
+            "status": "PASS" if passed else "FAIL",
+            "classification": TIMING_NOT_APPLICABLE,
+            "fmax_requirement": "NOT_APPLICABLE",
+            "meets_25mhz": None,
+            "reason": (
+                "No register-to-register path; all reported setup/hold slacks and "
+                "violation counts are non-negative/zero."
+                if passed
+                else "No register-to-register path, but timing status is incomplete or failing."
+            ),
+        }
+
+    fmax_mhz = metrics["fmax_mhz"]
+    passed = bool(
+        common_pass
+        and violation_counts
+        and fmax_mhz is not None
+        and fmax_mhz >= 25.0
+    )
+    return {
+        "status": "PASS" if passed else "FAIL",
+        "classification": TIMING_MEASURED,
+        "fmax_requirement": "AT_LEAST_25_MHZ",
+        "meets_25mhz": bool(fmax_mhz is not None and fmax_mhz >= 25.0),
+        "reason": (
+            "Register-to-register Fmax and all setup/hold checks pass."
+            if passed
+            else "Register-to-register timing is missing, below 25 MHz, or has violations."
+        ),
+    }
+
+
 def warning_audit(log_path: Path) -> dict[str, object]:
     lines = log_path.read_text(encoding="utf-8", errors="replace").splitlines()
+    severity = re.compile(
+        r"^\s*(?:(?:[A-Z][A-Z0-9_-]*-\d+)\s+)?"
+        r"(?:CRITICAL-WARNING|WARNING|ERROR|FATAL)\s*:",
+        re.IGNORECASE,
+    )
     noteworthy = [
         line.strip()
         for line in lines
-        if re.search(r"\b(?:warning|error|fatal|unrouted|violation)\b", line, re.IGNORECASE)
+        if severity.search(line)
+        or re.search(
+            r"Bitgen will abort|No ADC ports:|\bunrouted\b|\bviolations?\b",
+            line,
+            re.IGNORECASE,
+        )
     ]
+    allowlisted = [
+        line
+        for line in noteworthy
+        if re.search(r"\bSYN-6021\b|Bitgen will abort|No ADC ports:", line, re.IGNORECASE)
+    ]
+    blocking_patterns = (
+        re.compile(
+            r"^\s*(?:(?:[A-Z][A-Z0-9_-]*-\d+)\s+)?(?:ERROR|FATAL)\s*:",
+            re.IGNORECASE,
+        ),
+        re.compile(r"^\s*\[(?:ERROR|FATAL)\]", re.IGNORECASE),
+        re.compile(
+            r"\b(?:synthesis|placement|place\s*&\s*route|routing|route|fit|bitgen)"
+            r"\s+(?:failed|failure)\b",
+            re.IGNORECASE,
+        ),
+        re.compile(r"\b(?:setup|hold|timing)\s+(?:check\s+)?(?:failed|failure)\b", re.IGNORECASE),
+        re.compile(r"(?:\b[1-9]\d*\s+unrouted\b|\bunrouted\s*[:=]\s*[1-9]\d*)", re.IGNORECASE),
+    )
     blocking = [
         line
         for line in noteworthy
-        if re.search(r"\b(?:error|fatal|unrouted|timing violation)\b", line, re.IGNORECASE)
+        if any(pattern.search(line) for pattern in blocking_patterns)
     ]
     return {
         "status": "FAIL" if blocking else "PASS",
         "noteworthy_count": len(noteworthy),
         "blocking_count": len(blocking),
+        "allowlisted_expected_count": len(allowlisted),
+        "allowlisted_expected": allowlisted[:100],
         "noteworthy": noteworthy[:200],
         "blocking": blocking[:100],
     }
@@ -232,15 +342,16 @@ def main(argv: list[str] | None = None) -> int:
         metrics = parsed["metrics"]
         required_metrics = (
             "total_luts", "lut", "registers", "dsp", "eram_bram", "mslice",
-            "lslice", "packed_slices", "fmax_mhz", "setup_slack_ns", "hold_slack_ns",
+            "lslice", "packed_slices", "setup_slack_ns", "hold_slack_ns",
         )
         missing_metrics = [name for name in required_metrics if metrics[name] is None]
-        timing_pass = bool(
-            not missing_metrics
-            and metrics["fmax_mhz"] >= 25.0
-            and metrics["setup_slack_ns"] >= 0.0
-            and metrics["hold_slack_ns"] >= 0.0
-        )
+        if (
+            metrics["timing_applicability"] == TIMING_MEASURED
+            and metrics["fmax_mhz"] is None
+        ):
+            missing_metrics.append("fmax_mhz")
+        timing_evaluation = evaluate_timing(metrics)
+        timing_pass = timing_evaluation["status"] == "PASS"
         candidate_status = "PASS" if (
             run["exit_code"] == 0
             and not run["timed_out"]
@@ -257,6 +368,7 @@ def main(argv: list[str] | None = None) -> int:
             "missing_outputs": missing,
             "missing_metrics": missing_metrics,
             "timing_pass_25mhz": timing_pass,
+            "timing_evaluation": timing_evaluation,
             "warning_audit": audit,
             "outputs": {
                 name: {"path": str(path), "sha256": sha256(path)}