Skip to content

Commit c33e2c3

Browse files
committed
[src] Add vPlan coverage to final summary report
Signed-off-by: martin-velay <mvelay@lowrisc.org>
1 parent 85c57d9 commit c33e2c3

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/dvsim/job/deploy.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,8 @@ class CovVPlan(Deploy):
10451045

10461046
def __init__(self, cov_report_job, sim_cfg) -> None:
10471047
self.report_job = cov_report_job
1048+
# Populated by post_finish() once the job completes successfully.
1049+
self.vplan_coverage: float | None = None
10481050
super().__init__(sim_cfg)
10491051
self.dependencies.append(cov_report_job)
10501052

@@ -1081,6 +1083,31 @@ def _set_attrs(self) -> None:
10811083
self.gen_html = f"{self.odir}/vplan_annotated.html"
10821084
self.output_dirs = [self.odir]
10831085

1086+
def post_finish(self) -> Callable[[JobStatus], None]:
1087+
"""Get post finish callback."""
1088+
1089+
def callback(status: JobStatus) -> None:
1090+
"""Extract the overall vPlan normalised coverage from the annotated HJSON."""
1091+
if self.dry_run or status != JobStatus.PASSED:
1092+
return
1093+
hjson_path = Path(self.annotated_hjson)
1094+
if not hjson_path.exists():
1095+
return
1096+
try:
1097+
import hjson # noqa: PLC0415
1098+
1099+
with hjson_path.open() as f:
1100+
data = hjson.load(f)
1101+
# HJSON vPlans are keyed: {dut_name: {fields...}}
1102+
root_node = next(iter(data.values()), {})
1103+
raw = root_node.get("Normalized_Coverage")
1104+
if raw is not None:
1105+
self.vplan_coverage = float(str(raw).rstrip(" %"))
1106+
except Exception: # noqa: BLE001
1107+
log.debug("Could not extract vPlan coverage from '%s'.", hjson_path)
1108+
1109+
return callback
1110+
10841111
def _construct_cmd(self) -> str:
10851112
"""Construct the pure bash shell command, bypassing the base Makefile assumption."""
10861113
import shlex

src/dvsim/sim/data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ class SimFlowResults(BaseModel):
194194
"""Optional path linking to the generated coverage report dashboard page."""
195195
vplan_report_page: Path | None
196196
"""Optional path linking to the generated verification plan (vPlan) reports."""
197+
vplan_coverage: float | None = None
198+
"""Overall normalised coverage (%) extracted from the back-annotated vPlan."""
197199

198200
failed_jobs: BucketedFailures
199201
"""Bucketed failed job overview."""

src/dvsim/sim/flow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,10 @@ def make_test_result(tr) -> TestResult | None:
834834
cov_report_page = Path(cov_report_dir, self.cov_report_page)
835835

836836
vplan_report_page = None
837+
vplan_coverage = None
837838
if getattr(self, "cov_vplan_deploy", None):
838839
vplan_report_page = Path(self.scratch_path) / CovVPlan.target / "vplan_annotated.html"
840+
vplan_coverage = self.cov_vplan_deploy.vplan_coverage
839841

840842
failures = BucketedFailures.from_job_status(results=run_results)
841843
if failures.buckets:
@@ -852,6 +854,7 @@ def make_test_result(tr) -> TestResult | None:
852854
coverage=coverage_model,
853855
cov_report_page=cov_report_page,
854856
vplan_report_page=vplan_report_page,
857+
vplan_coverage=vplan_coverage,
855858
failed_jobs=failures,
856859
passed=total_passed,
857860
total=total_runs,

src/dvsim/sim/report.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ def render_coverage_table(self, results: SimFlowResults) -> str:
335335
report_md = "## Coverage Results"
336336
if results.vplan_report_page:
337337
report_md += f"\n### [vPlan Dashboard]({results.vplan_report_page})"
338+
if results.vplan_coverage is not None:
339+
report_md += f"\n\nVerification Plan Coverage: {results.vplan_coverage:.2f} %\n"
338340
if results.cov_report_page:
339341
report_md += f"\n### [Coverage Dashboard]({results.cov_report_page})"
340342
if cov_results:

0 commit comments

Comments
 (0)