Просмотр исходного кода

fix(formal): parse Yosys JNY property cells

root 3 месяцев назад
Родитель
Сommit
1faab79dc6
2 измененных файлов с 40 добавлено и 3 удалено
  1. 24 0
      tests/unit/test_6400_formal_contract.py
  2. 16 3
      tools/run_6400_formal.py

+ 24 - 0
tests/unit/test_6400_formal_contract.py

@@ -7,6 +7,8 @@ import json
 from pathlib import Path
 import re
 
+from tools.run_6400_formal import compiled_property_ids, property_cell_ids
+
 
 ROOT = Path(__file__).resolve().parents[2]
 FORMAL = ROOT / "tests" / "formal"
@@ -74,3 +76,25 @@ def test_runner_is_fail_closed_and_commit_bound() -> None:
     assert "PROD2U_CONTAINER_DIGEST" in runner
     assert '"source_tree_sha256"' in runner
     assert '"bitstream_sha256": None' in runner
+
+
+def test_runner_reads_yosys_jny_property_cell_sorts(tmp_path: Path) -> None:
+    model = tmp_path / "model"
+    model.mkdir()
+    (model / "design.json").write_text(json.dumps({
+        "modules": [{
+            "name": "formal_top",
+            "cell_sorts": [
+                {"type": "$assert", "cells": [{"name": "$assert$source.v:1$1"}]},
+                {"type": "$cover", "cells": [{"name": "$cover$source.v:2$2"}]},
+            ],
+        }],
+    }), encoding="utf-8")
+    assertions, covers, design_hash, failures = compiled_property_ids(tmp_path)
+    assert assertions == ["formal_top.$assert$source.v:1$1"]
+    assert covers == ["formal_top.$cover$source.v:2$2"]
+    assert len(design_hash) == 64
+    assert failures == []
+    assert property_cell_ids(["formal_top.dut.$cover$source.v:2$2"]) == {
+        "$cover$source.v:2$2"
+    }

+ 16 - 3
tools/run_6400_formal.py

@@ -203,15 +203,16 @@ def compiled_property_ids(workdir: Path) -> tuple[list[str], list[str], str, lis
         for module in modules if isinstance(modules, list) else []:
             module_name = str(module.get("name", ""))
             for cell_sort in module.get("cell_sorts", []):
+                sort_type = str(cell_sort.get("type", ""))
                 for cell in cell_sort.get("cells", []):
                     name = str(cell.get("name", ""))
                     flavor = cell.get("parameters", {}).get("FLAVOR")
                     if not module_name or not name:
                         continue
                     identifier = f"{module_name}.{name}"
-                    if flavor == "assert":
+                    if sort_type == "$assert" or flavor == "assert":
                         assertions.add(identifier)
-                    elif flavor == "cover":
+                    elif sort_type == "$cover" or flavor == "cover":
                         covers.add(identifier)
     except (OSError, UnicodeError, json.JSONDecodeError, AttributeError, TypeError) as exc:
         failures.append(f"compiled_properties_unavailable:{type(exc).__name__}")
@@ -231,6 +232,16 @@ def cover_hit_ids(workdir: Path) -> list[str]:
     return sorted(hits)
 
 
+def property_cell_ids(values: Iterable[str]) -> set[str]:
+    """Normalize JNY module IDs and SBY hierarchical IDs to cell names."""
+    normalized: set[str] = set()
+    for value in values:
+        positions = [value.rfind(marker) for marker in ("$assert$", "$cover$")]
+        start = max(positions)
+        normalized.add(value[start:] if start >= 0 else value)
+    return normalized
+
+
 def relative_artifacts(workdir: Path, pattern: str) -> list[dict[str, str]]:
     return [
         {"path": path.relative_to(ROOT).as_posix(), "sha256": sha256_file(path)}
@@ -298,7 +309,7 @@ def run_job(job: dict[str, Any], run_root: Path, timeout: int) -> dict[str, Any]
         hits = cover_hit_ids(workdir)
         if not covers:
             failures.append("compiled_covers_missing")
-        if set(hits) != set(covers):
+        if property_cell_ids(hits) != property_cell_ids(covers):
             failures.append(f"cover_hit_set_mismatch:{len(hits)}/{len(covers)}")
         if not relative_artifacts(workdir, "*.vcd"):
             failures.append("cover_trace_missing")
@@ -321,6 +332,8 @@ def run_job(job: dict[str, Any], run_root: Path, timeout: int) -> dict[str, Any]
         "compiled_design_sha256": design_hash,
         "compiled_assertion_count": len(assertions),
         "compiled_cover_count": len(covers),
+        "compiled_assertion_ids": assertions,
+        "compiled_cover_ids": covers,
         "cover_hit_ids": cover_hit_ids(workdir) if target["mode"] == "cover" else [],
         "traces": relative_artifacts(workdir, "*.vcd") if target["mode"] == "cover" else [],
         "evidence_failures": failures,