|
@@ -1093,6 +1093,39 @@ def formal_cover_hit_ids(*texts: str) -> list[str]:
|
|
|
return sorted(hits)
|
|
return sorted(hits)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def formal_status_token(status_raw: str) -> str:
|
|
|
|
|
+ token = status_raw.strip().split()[0] if status_raw.strip() else ""
|
|
|
|
|
+ return token.upper() if token else "MISSING"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def formal_workdir_log_texts(workdir: Path) -> list[str]:
|
|
|
|
|
+ texts: list[str] = []
|
|
|
|
|
+ logfile = workdir / "logfile.txt"
|
|
|
|
|
+ if logfile.is_file():
|
|
|
|
|
+ texts.append(logfile.read_text(encoding="utf-8", errors="replace"))
|
|
|
|
|
+ if workdir.is_dir():
|
|
|
|
|
+ for engine_log in sorted(workdir.glob("engine_*/logfile.txt")):
|
|
|
|
|
+ texts.append(engine_log.read_text(encoding="utf-8", errors="replace"))
|
|
|
|
|
+ return texts
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def formal_workdir_marker_failures(workdir: Path, status_token: str) -> list[str]:
|
|
|
|
|
+ failures: list[str] = []
|
|
|
|
|
+ if not workdir.is_dir():
|
|
|
|
|
+ return failures
|
|
|
|
|
+ has_fail = (workdir / "FAIL").is_file()
|
|
|
|
|
+ has_pass = (workdir / "PASS").is_file()
|
|
|
|
|
+ if has_fail and has_pass:
|
|
|
|
|
+ failures.append("formal_workdir_marker_conflict:fail_and_pass")
|
|
|
|
|
+ if has_fail and status_token == "PASS":
|
|
|
|
|
+ failures.append("formal_workdir_marker_conflict:fail_marker_with_pass_status")
|
|
|
|
|
+ if status_token == "PASS" and not has_pass:
|
|
|
|
|
+ failures.append("formal_workdir_marker_missing:pass_status_without_pass_marker")
|
|
|
|
|
+ if status_token.startswith("FAIL") and not has_fail:
|
|
|
|
|
+ failures.append("formal_workdir_marker_missing:fail_status_without_fail_marker")
|
|
|
|
|
+ return failures
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def formal_task_modes(sby_file: Path, tasks: Sequence[str]) -> dict[str, str]:
|
|
def formal_task_modes(sby_file: Path, tasks: Sequence[str]) -> dict[str, str]:
|
|
|
task_modes: dict[str, str] = {}
|
|
task_modes: dict[str, str] = {}
|
|
|
global_mode = ""
|
|
global_mode = ""
|
|
@@ -1127,25 +1160,30 @@ def formal_task_evidence(
|
|
|
mode: str,
|
|
mode: str,
|
|
|
workdir: Path,
|
|
workdir: Path,
|
|
|
configured_engines: Sequence[str],
|
|
configured_engines: Sequence[str],
|
|
|
|
|
+ returncode: int | None = None,
|
|
|
|
|
+ timed_out: bool = False,
|
|
|
) -> dict[str, Any]:
|
|
) -> dict[str, Any]:
|
|
|
status_path = workdir / "status"
|
|
status_path = workdir / "status"
|
|
|
status_raw = ""
|
|
status_raw = ""
|
|
|
if status_path.is_file():
|
|
if status_path.is_file():
|
|
|
status_raw = status_path.read_text(encoding="utf-8", errors="replace").strip()
|
|
status_raw = status_path.read_text(encoding="utf-8", errors="replace").strip()
|
|
|
- status = status_raw.split()[0].upper() if status_raw else "MISSING"
|
|
|
|
|
|
|
+ status = formal_status_token(status_raw)
|
|
|
trace_files = sorted(str(path) for path in workdir.rglob("*.vcd")) if workdir.is_dir() else []
|
|
trace_files = sorted(str(path) for path in workdir.rglob("*.vcd")) if workdir.is_dir() else []
|
|
|
- pass_summary = workdir / "PASS"
|
|
|
|
|
- artifact_texts = [
|
|
|
|
|
- pass_summary.read_text(encoding="utf-8", errors="replace")
|
|
|
|
|
- ] if pass_summary.is_file() else []
|
|
|
|
|
- cover_hit_ids = formal_cover_hit_ids(*artifact_texts)
|
|
|
|
|
|
|
+ cover_hit_ids = formal_cover_hit_ids(*formal_workdir_log_texts(workdir))
|
|
|
runtime_evidence = formal_runtime_evidence(workdir, configured_engines)
|
|
runtime_evidence = formal_runtime_evidence(workdir, configured_engines)
|
|
|
compiled_properties = formal_compiled_property_counts(workdir)
|
|
compiled_properties = formal_compiled_property_counts(workdir)
|
|
|
evidence_failures: list[str] = [
|
|
evidence_failures: list[str] = [
|
|
|
*runtime_evidence["failures"],
|
|
*runtime_evidence["failures"],
|
|
|
*compiled_properties["failures"],
|
|
*compiled_properties["failures"],
|
|
|
|
|
+ *formal_workdir_marker_failures(workdir, status),
|
|
|
]
|
|
]
|
|
|
- if status != "PASS":
|
|
|
|
|
|
|
+ if timed_out:
|
|
|
|
|
+ evidence_failures.append(f"formal_task_timeout:{name}")
|
|
|
|
|
+ if returncode not in (None, 0):
|
|
|
|
|
+ evidence_failures.append(f"formal_task_returncode_nonzero:{name}:{returncode}")
|
|
|
|
|
+ if status == "MISSING":
|
|
|
|
|
+ evidence_failures.append(f"formal_task_status_missing:{name}")
|
|
|
|
|
+ elif status != "PASS":
|
|
|
evidence_failures.append(f"formal_task_status_not_pass:{name}:{status}")
|
|
evidence_failures.append(f"formal_task_status_not_pass:{name}:{status}")
|
|
|
if mode in {"prove", "bmc"} and compiled_properties["assertion_count"] <= 0:
|
|
if mode in {"prove", "bmc"} and compiled_properties["assertion_count"] <= 0:
|
|
|
evidence_failures.append(f"formal_compiled_assertions_missing:{name}")
|
|
evidence_failures.append(f"formal_compiled_assertions_missing:{name}")
|
|
@@ -1170,6 +1208,8 @@ def formal_task_evidence(
|
|
|
"workdir": str(workdir),
|
|
"workdir": str(workdir),
|
|
|
"trace_files": trace_files,
|
|
"trace_files": trace_files,
|
|
|
"cover_hit_ids": cover_hit_ids,
|
|
"cover_hit_ids": cover_hit_ids,
|
|
|
|
|
+ "returncode": returncode,
|
|
|
|
|
+ "timed_out": timed_out,
|
|
|
"configured_engines": runtime_evidence["configured_engines"],
|
|
"configured_engines": runtime_evidence["configured_engines"],
|
|
|
"observed_engines": runtime_evidence["observed_engines"],
|
|
"observed_engines": runtime_evidence["observed_engines"],
|
|
|
"solvers": runtime_evidence["solvers"],
|
|
"solvers": runtime_evidence["solvers"],
|
|
@@ -1183,6 +1223,41 @@ def formal_task_evidence(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def formal_target_status_from_tasks(
|
|
|
|
|
+ *,
|
|
|
|
|
+ task_process_results: Sequence[Mapping[str, Any]],
|
|
|
|
|
+ task_results: Sequence[Mapping[str, Any]],
|
|
|
|
|
+) -> tuple[str, int | None]:
|
|
|
|
|
+ if any(item.get("status") == "fail_timeout" for item in task_process_results):
|
|
|
|
|
+ return "fail_timeout", None
|
|
|
|
|
+ if any(item.get("status") != "pass" for item in task_process_results):
|
|
|
|
|
+ result_status = "fail"
|
|
|
|
|
+ else:
|
|
|
|
|
+ result_status = "pass"
|
|
|
|
|
+ evidence_failures = [
|
|
|
|
|
+ failure
|
|
|
|
|
+ for task_result in task_results
|
|
|
|
|
+ for failure in task_result.get("evidence_failures", [])
|
|
|
|
|
+ ]
|
|
|
|
|
+ if result_status != "fail_timeout" and evidence_failures:
|
|
|
|
|
+ result_status = "fail_evidence"
|
|
|
|
|
+ nonzero_returncodes = [
|
|
|
|
|
+ item["returncode"]
|
|
|
|
|
+ for item in task_process_results
|
|
|
|
|
+ if item.get("returncode") not in (None, 0)
|
|
|
|
|
+ ]
|
|
|
|
|
+ returncode: int | None = (
|
|
|
|
|
+ int(nonzero_returncodes[0])
|
|
|
|
|
+ if nonzero_returncodes
|
|
|
|
|
+ else (None if result_status == "fail_timeout" else 0)
|
|
|
|
|
+ )
|
|
|
|
|
+ return result_status, returncode
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def formal_top_status_from_targets(targets: Sequence[Mapping[str, Any]]) -> bool:
|
|
|
|
|
+ return bool(targets) and all(item.get("status") == "pass" for item in targets)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _missing_tools(schema: str, layer: str, missing: Sequence[str], **extra: Any) -> dict[str, Any]:
|
|
def _missing_tools(schema: str, layer: str, missing: Sequence[str], **extra: Any) -> dict[str, Any]:
|
|
|
return {
|
|
return {
|
|
|
"schema": schema,
|
|
"schema": schema,
|
|
@@ -1745,6 +1820,8 @@ def formal_payload(
|
|
|
|
|
|
|
|
def run_task(task_name: str, task_workdir: Path) -> dict[str, Any]:
|
|
def run_task(task_name: str, task_workdir: Path) -> dict[str, Any]:
|
|
|
nonlocal formal_commands
|
|
nonlocal formal_commands
|
|
|
|
|
+ if task_workdir.exists():
|
|
|
|
|
+ shutil.rmtree(task_workdir)
|
|
|
command = [str(sby), "-f", "-d", str(task_workdir), str(sby_file)]
|
|
command = [str(sby), "-f", "-d", str(task_workdir), str(sby_file)]
|
|
|
if tasks:
|
|
if tasks:
|
|
|
command.append(task_name)
|
|
command.append(task_name)
|
|
@@ -1763,6 +1840,7 @@ def formal_payload(
|
|
|
return {
|
|
return {
|
|
|
"status": "pass" if completed.returncode == 0 else "fail",
|
|
"status": "pass" if completed.returncode == 0 else "fail",
|
|
|
"returncode": completed.returncode,
|
|
"returncode": completed.returncode,
|
|
|
|
|
+ "timed_out": False,
|
|
|
"stdout": completed.stdout,
|
|
"stdout": completed.stdout,
|
|
|
"stderr": completed.stderr,
|
|
"stderr": completed.stderr,
|
|
|
}
|
|
}
|
|
@@ -1770,6 +1848,7 @@ def formal_payload(
|
|
|
return {
|
|
return {
|
|
|
"status": "fail_timeout",
|
|
"status": "fail_timeout",
|
|
|
"returncode": None,
|
|
"returncode": None,
|
|
|
|
|
+ "timed_out": True,
|
|
|
"stdout": (
|
|
"stdout": (
|
|
|
exc.stdout.decode(errors="replace")
|
|
exc.stdout.decode(errors="replace")
|
|
|
if isinstance(exc.stdout, bytes)
|
|
if isinstance(exc.stdout, bytes)
|
|
@@ -1793,21 +1872,24 @@ def formal_payload(
|
|
|
]
|
|
]
|
|
|
task_process_results = [future.result() for future in task_futures]
|
|
task_process_results = [future.result() for future in task_futures]
|
|
|
|
|
|
|
|
- if any(item["status"] == "fail_timeout" for item in task_process_results):
|
|
|
|
|
- result_status = "fail_timeout"
|
|
|
|
|
- elif any(item["status"] != "pass" for item in task_process_results):
|
|
|
|
|
- result_status = "fail"
|
|
|
|
|
- else:
|
|
|
|
|
- result_status = "pass"
|
|
|
|
|
- nonzero_returncodes = [
|
|
|
|
|
- item["returncode"]
|
|
|
|
|
- for item in task_process_results
|
|
|
|
|
- if item["returncode"] not in (None, 0)
|
|
|
|
|
|
|
+ task_results = [
|
|
|
|
|
+ formal_task_evidence(
|
|
|
|
|
+ name=task_name,
|
|
|
|
|
+ mode=task_modes[task_name],
|
|
|
|
|
+ workdir=task_workdir,
|
|
|
|
|
+ configured_engines=input_evidence["task_engines"].get(task_name, []),
|
|
|
|
|
+ returncode=process_result["returncode"],
|
|
|
|
|
+ timed_out=bool(process_result.get("timed_out")),
|
|
|
|
|
+ )
|
|
|
|
|
+ for (task_name, task_workdir), process_result in zip(
|
|
|
|
|
+ zip(task_names, task_workdirs, strict=True),
|
|
|
|
|
+ task_process_results,
|
|
|
|
|
+ strict=True,
|
|
|
|
|
+ )
|
|
|
]
|
|
]
|
|
|
- returncode: int | None = (
|
|
|
|
|
- int(nonzero_returncodes[0])
|
|
|
|
|
- if nonzero_returncodes
|
|
|
|
|
- else (None if result_status == "fail_timeout" else 0)
|
|
|
|
|
|
|
+ result_status, returncode = formal_target_status_from_tasks(
|
|
|
|
|
+ task_process_results=task_process_results,
|
|
|
|
|
+ task_results=task_results,
|
|
|
)
|
|
)
|
|
|
stdout = "\n".join(
|
|
stdout = "\n".join(
|
|
|
f"[{task_name}]\n{item['stdout']}".rstrip()
|
|
f"[{task_name}]\n{item['stdout']}".rstrip()
|
|
@@ -1819,15 +1901,6 @@ def formal_payload(
|
|
|
for task_name, item in zip(task_names, task_process_results, strict=True)
|
|
for task_name, item in zip(task_names, task_process_results, strict=True)
|
|
|
if item["stderr"]
|
|
if item["stderr"]
|
|
|
)
|
|
)
|
|
|
- task_results = [
|
|
|
|
|
- formal_task_evidence(
|
|
|
|
|
- name=task_name,
|
|
|
|
|
- mode=task_modes[task_name],
|
|
|
|
|
- workdir=task_workdir,
|
|
|
|
|
- configured_engines=input_evidence["task_engines"].get(task_name, []),
|
|
|
|
|
- )
|
|
|
|
|
- for task_name, task_workdir in zip(task_names, task_workdirs, strict=True)
|
|
|
|
|
- ]
|
|
|
|
|
trace_files = sorted(
|
|
trace_files = sorted(
|
|
|
{
|
|
{
|
|
|
trace_file
|
|
trace_file
|
|
@@ -1852,7 +1925,7 @@ def formal_payload(
|
|
|
evidence_failures.append("formal_assertions_missing")
|
|
evidence_failures.append("formal_assertions_missing")
|
|
|
if cover_required and int(property_counts["cover_count"]) <= 0:
|
|
if cover_required and int(property_counts["cover_count"]) <= 0:
|
|
|
evidence_failures.append("formal_cover_properties_missing")
|
|
evidence_failures.append("formal_cover_properties_missing")
|
|
|
- if result_status != "fail_timeout" and evidence_failures:
|
|
|
|
|
|
|
+ if result_status == "pass" and evidence_failures:
|
|
|
result_status = "fail_evidence"
|
|
result_status = "fail_evidence"
|
|
|
results.append(
|
|
results.append(
|
|
|
{
|
|
{
|
|
@@ -1885,17 +1958,19 @@ def formal_payload(
|
|
|
)
|
|
)
|
|
|
toolchain = formal_toolchain_evidence(sby, yosys, observed_solvers, resolved)
|
|
toolchain = formal_toolchain_evidence(sby, yosys, observed_solvers, resolved)
|
|
|
passed = (
|
|
passed = (
|
|
|
- bool(results) and
|
|
|
|
|
- all(item["status"] == "pass" for item in results) and
|
|
|
|
|
|
|
+ formal_top_status_from_targets(results) and
|
|
|
target_manifest["status"] == "pass" and
|
|
target_manifest["status"] == "pass" and
|
|
|
toolchain["status"] == "pass"
|
|
toolchain["status"] == "pass"
|
|
|
)
|
|
)
|
|
|
|
|
+ harness_path = Path(__file__)
|
|
|
result = {
|
|
result = {
|
|
|
"schema": FORMAL_RECEIPT_SCHEMA,
|
|
"schema": FORMAL_RECEIPT_SCHEMA,
|
|
|
"status": "pass" if passed else "fail",
|
|
"status": "pass" if passed else "fail",
|
|
|
"verification_layer": "formal",
|
|
"verification_layer": "formal",
|
|
|
"profile": PROFILE,
|
|
"profile": PROFILE,
|
|
|
"work_root": str(resolved),
|
|
"work_root": str(resolved),
|
|
|
|
|
+ "runner_source_sha256": sha256_file(harness_path),
|
|
|
|
|
+ "formal_manifest_sha256": sha256_file(TARGET_MANIFEST_PATH),
|
|
|
"targets": results,
|
|
"targets": results,
|
|
|
"toolchain": toolchain,
|
|
"toolchain": toolchain,
|
|
|
"target_manifest": target_manifest,
|
|
"target_manifest": target_manifest,
|