Skip to content

Simplify coverage_to_md.py by switching component-level gcovr output to --json-summary #315

@TheRedSwabian

Description

@TheRedSwabian

Context

Currently, coverage_to_md.py receives gcovr trace format JSON (--json) for component-level coverage and must manually compute coverage statistics by iterating over raw per-line data. This adds ~50 lines of computation logic that duplicates what gcovr already calculates internally:

  • _compute_line_coverage_from_trace()
  • _compute_branch_coverage_from_trace()
  • _compute_condition_coverage_from_trace()

The variant-level merged coverage already uses --json-summary-pretty (see common.cmake line 641), proving the format works in our pipeline. However, the per-component JSON (coverage.json) is still generated with --json (trace format) because it also serves as input for --add-tracefile aggregation at the variant level.

Proposed Solution

Add a lightweight conversion step per component that produces a summary JSON from the existing trace file:

# Existing (keep for --add-tracefile aggregation):
COMMAND ${GCOVR_EXE} --root ... --json --output coverage.json ...

# New (convert trace to summary for coverage_to_md.py):
COMMAND ${GCOVR_EXE} --add-tracefile coverage.json --json-summary-pretty --output coverage-summary.json

Then point coverage_to_md.py at coverage-summary.json instead of coverage.json.

Changes Required

1. common.cmake (3 locations)

Location Current Change
Line ~793 (component test suite) Only generates trace JSON Add --json-summary-pretty conversion command
Line ~410 (component_report target) --json coverage.json --json coverage-summary.json
Line ~582 (variant component coverage md) --json coverage.json --json coverage-summary.json

Note: Line 614 (variant reports target) already uses variant-coverage.json which is summary format — no change needed.

2. coverage_to_md.py

  • Remove _compute_line_coverage_from_trace() (~6 lines)
  • Remove _compute_branch_coverage_from_trace() (~8 lines)
  • Remove _compute_condition_coverage_from_trace() (~8 lines)
  • Remove trace format detection and dual-path logic
  • Read summary fields directly: lines_covered, lines_total, branches_covered, branches_total, condition_covered, condition_total
  • Simplify generate_coverage_markdown() accordingly

3. Unit Tests (tests/unit/test_coverage_to_md.py)

  • Remove trace-format test fixtures and test cases
  • Simplify remaining tests to use summary-format fixtures only

Prerequisites

Requirement Status
gcovr >= 8.6 Already pinned in pyproject.toml
--json-summary includes per-file condition_covered / condition_total Confirmed for gcovr 8.6

Breaking Change

This is a breaking change for anyone consuming coverage_to_md.py's --json argument with trace-format files. The trace file itself (coverage.json) is still generated, so --add-tracefile pipelines are unaffected. Only coverage_to_md.py changes its expected input format.

Acceptance Criteria

  • coverage_to_md.py only supports gcovr summary format (no trace parsing)
  • Component reports show correct line, branch, and condition coverage
  • Variant-level aggregation (--add-tracefile) still works unchanged
  • All existing unit and integration tests pass (updated as needed)
  • No _compute_*_from_trace() functions remain in the codebase

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions