Add raw LCOV function diagnostics
Linux / verify (pull_request) Successful in 2m11s
Linux / changed-scope-coverage (pull_request) Skipped
Linux / keyless-cuda (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 16s
Linux / linux-static-cli (pull_request) Successful in 5m13s
Linux / release-cli (pull_request) Skipped

This commit is contained in:
Pavlo Ratushnyi
2026-10-07 03:23:47 +02:00
parent 1068d3a4d3
commit 4cb41467dd
2 changed files with 66 additions and 0 deletions
+39
View File
@@ -420,6 +420,40 @@ def coverage_report(records: list[dict], scopes: dict[str, tuple[list[dict], set
return {"baseline": BASELINE, "files": files, "totals": totals}
def raw_function_diagnostics(records: list[dict], scopes: dict[str, tuple[list[dict], set[int]]]) -> str:
"""Render raw LCOV function rows for selected zero-hit entries without changing metrics."""
by_path = _merge_lcov(records)
rows = ["Raw LCOV FN/FNDA diagnostics for selected zero-hit functions:"]
for path in RUST_FILES:
functions, test_lines = scopes[path]
source_records = by_path.get(path, [])
metrics = _file_metrics(source_records, functions, test_lines)
misses = {(item["line"], item["name"])
for item in metrics["functions"]["misses"]}
if not misses:
continue
raw_fn = sorted({(line, name) for record in source_records for line, name in record["fn"]
if _inside(line, functions, test_lines)})
raw_fnda = {}
for record in source_records:
for count, name in record["fnda"]:
raw_fnda.setdefault(name, []).append(count)
rows.append(f"{path}:")
for line, name in sorted(misses):
rows.append(f" zero-hit FN:{line},{name}")
enclosing = [item for item in functions if item["start"] <= line <= item["end"]]
related = [(fn_line, fn_name) for fn_line, fn_name in raw_fn
if any(item["start"] <= fn_line <= item["end"] for item in enclosing)]
for fn_line, fn_name in related:
counts = raw_fnda.get(fn_name, [])
raw_counts = ",".join(str(value) for value in counts) if counts else "<no exact FNDA>"
rows.append(f" raw FN:{fn_line},{fn_name}")
rows.append(f" exact raw FNDA:{raw_counts},{fn_name}")
if len(rows) == 1:
return ""
return "\n".join(rows) + "\n"
def _run(command: list[str], root: Path, env: dict | None = None) -> subprocess.CompletedProcess:
return subprocess.run(command, cwd=root, env=env, text=True, capture_output=True, check=False)
@@ -636,6 +670,11 @@ def run_coverage(root: Path, out: Path) -> int:
state["failure"] = f"{type(error).__name__}: {error}"
_write_summary(out, state)
print((out / "summary.txt").read_text(), end="")
if "totals" in state:
diagnostics = raw_function_diagnostics(parse_lcov((out / "coverage.raw.lcov").read_text()), scopes)
if diagnostics:
(out / "function-diagnostics.txt").write_text(diagnostics)
print(diagnostics, end="")
return 0 if state["passed"] else 1
+27
View File
@@ -100,6 +100,33 @@ pub fn with_test_only_block() {
self.assertFalse(any("a.rs:4" in line for line in COVERAGE.summary_lines(
{**report, "passed": True})))
def test_raw_function_diagnostics_show_fn_and_exact_fnda_without_changing_metrics(self) -> None:
path = "control-plane/src/kar_writer.rs"
lcov = (f"SF:{path}\nFN:10,crate::write_section\nFNDA:1,crate::write_section\n"
"FN:12,crate::write_section::{closure#0}\n"
"FNDA:0,crate::write_section::{closure#0}\nDA:10,1\nDA:12,0\n"
"BRDA:12,0,0,0\nend_of_record\n")
records = [COVERAGE.parse_lcov(lcov)[0]]
records.extend(COVERAGE.parse_lcov(_lcov(other))[0]
for other in COVERAGE.RUST_FILES if other != path)
scopes = {name: ([], set()) for name in COVERAGE.RUST_FILES}
scopes[path] = ([{"name": "write_section", "start": 10, "end": 14}], set())
before = COVERAGE.coverage_report(records, scopes)
diagnostics = COVERAGE.raw_function_diagnostics(records, scopes)
after = COVERAGE.coverage_report(records, scopes)
self.assertEqual(before, after)
self.assertIn("zero-hit FN:12,crate::write_section::{closure#0}", diagnostics)
self.assertIn("raw FN:12,crate::write_section::{closure#0}", diagnostics)
self.assertIn("exact raw FNDA:0,crate::write_section::{closure#0}", diagnostics)
self.assertNotIn("zero-hit FN:10,crate::write_section", diagnostics)
def test_raw_function_diagnostics_are_empty_when_all_selected_functions_hit(self) -> None:
path = "control-plane/src/kar_writer.rs"
records = COVERAGE.parse_lcov(_lcov(path))[0:]
scopes = {name: ([], set()) for name in COVERAGE.RUST_FILES}
scopes[path] = ([{"name": "live", "start": 1, "end": 3}], set())
self.assertEqual(COVERAGE.raw_function_diagnostics(records, scopes), "")
def test_cargo_json_selects_only_the_package_lib_test_executable(self) -> None:
with tempfile.TemporaryDirectory() as directory:
binary = Path(directory) / "strata_control-test"