"""Read one ``run__.log`` body. Markers come from the env-gen checker and testbench templates and from the generated Makefile's log grep. Text that matches none of them stays unset. """ from __future__ import annotations import re from dataclasses import dataclass # checker.sv.tmpl, tb_top.sv.tmpl, and generate_makefile.py. _FUNCTIONAL = re.compile( r"\[SB\] mismatch|\[SB\] unexpected output|\[SVA\]|\[EOC\] scoreboard|" r"\[SB_SUMMARY\][^\n]*(?:failed=[1-9]\d*|residue=[1-9]\d*)" ) _CLEAN = re.compile(r"\*\*\* PASS|\[SB_SUMMARY\][^\n]*failed=0\b[^\n]*residue=0\b|\[WATCHDOG\]") @dataclass(frozen=True) class RunLogSummary: """Whether one run log shows a functional failure. ``None`` means the log could not be judged. It is not a miss. """ functional_hit: bool | None def read_run_log(text: str) -> RunLogSummary: """Return whether ``text`` shows a scoreboard or assertion failure.""" if not isinstance(text, str): raise TypeError("text must be a string") if not text.strip(): return RunLogSummary(functional_hit=None) if _FUNCTIONAL.search(text): return RunLogSummary(functional_hit=True) if _CLEAN.search(text): return RunLogSummary(functional_hit=False) return RunLogSummary(functional_hit=None)