coverage.reporter

CoverageReporter: merge, load, and render coverage from collected .gcda files.

This module replaces the old Pipeline class. It does not fetch .gcda files (that is handled by otto test --cov via GcdaFetcher). Instead it takes directories of already-collected .gcda files, merges them with lcov, loads the results into a CoverageStore, and renders an HTML report.

Coverage tiers are user-defined. The reporter accepts an ordered list of (tier_name, info_path) pairs where the order is the precedence order — first entry has highest precedence in the renderer’s winner-take-all row coloring and column layout. A None info_path marks the implicit system tier produced by merging the supplied .gcda directories with lcov; only the tier named TIER_SYSTEM is allowed to omit a path.

Typical usage from the otto cov CLI command:

reporter = CoverageReporter(
    gcda_dirs=[run1 / "cov" / "host1", run1 / "cov" / "host2"],
    source_root=Path("/home/me/myproduct"),
    output_dir=Path("./cov_report"),
    tiers=[("unit", Path("u.info")), ("system", None)],
)
store = await reporter.run()
otto.coverage.reporter.read_cov_source_root(cov_dirs)

Read the source root from coverage metadata written by otto test --cov.

Looks for .otto_cov_meta.json in each cov_dir. Returns the sut_dir from the first metadata file found.

Parameters:

cov_dirs – Coverage directories (each containing host subdirs and a .otto_cov_meta.json sidecar).

Return type:

Path

Returns:

The source root path.

Raises:

FileNotFoundError – If no metadata file is found in any cov dir.

otto.coverage.reporter.read_cov_source_roots(cov_dirs)

Read per-host source roots from coverage metadata.

Returns a mapping of host directory name → source root Path. If no source_roots info is present in the metadata, or if no metadata file is found, returns an empty dict.

Return type:

dict[str, Path]

otto.coverage.reporter.read_cov_toolchains(cov_dirs)

Read per-host toolchain info from coverage metadata.

Returns a mapping of host directory name → Toolchain. If no toolchain info is present in the metadata, returns an empty dict.

Return type:

dict[str, Toolchain]

otto.coverage.reporter.discover_gcda_dirs(cov_dirs)

Collect all per-host .gcda directories from one or more cov/ directories.

Each cov_dir is expected to contain per-host subdirectories:

cov_dir/
  host_id_1/
  host_id_2/
Return type:

list[Path]

Returns:

List of per-host directories containing .gcda files.

class otto.coverage.reporter.CoverageReporter(gcda_dirs, source_root, output_dir, project_name='Coverage Report', toolchains=None, tiers=None, source_roots=None)

Bases: object

Merge, load, and render coverage from pre-collected .gcda files.

Parameters:
  • gcda_dirs – Per-host directories containing .gcda files.

  • source_root – Local source tree root (used for path mapping and .gcno discovery). Acts as the fallback for hosts that have no entry in source_roots.

  • output_dir – Directory for the HTML report output.

  • project_name – Title shown in the HTML report.

  • toolchains – Per-host toolchains keyed by host directory name. When a host has no entry the pipeline falls back to gcno-based auto-discovery, then to system defaults.

  • tiers – Ordered list of (tier_name, info_path | None) pairs. Order is precedence order — first entry wins in the renderer’s winner-take-all row coloring. None paths are only valid for the system tier and indicate the implicit lcov-merged output of gcda_dirs. Defaults to [("system", None)] when omitted.

  • source_roots – Per-host source roots keyed by gcda-dir name (i.e. the host id). When provided, each host’s .gcda files are captured against its own .gcno directory instead of the shared source_root fallback. Hosts with no entry fall back to source_root.

async run()

Execute the coverage merge, load, and render pipeline.

Return type:

CoverageStore

Returns:

A populated CoverageStore with all coverage data.

async otto.coverage.reporter.run_coverage_report(cov_dirs, report_dir, project_name='Coverage Report', tier_specs=None)

Render an HTML coverage report from one or more cov/ directories.

Shared entry point used by both otto cov report (multiple cov dirs, one per run) and otto test --cov-report (single cov dir produced by the test run just completed).

Reads the source root and per-host toolchains from .otto_cov_meta.json inside the cov dirs, discovers per-host gcda subdirs, and runs CoverageReporter.

Return type:

CoverageStore | None

Returns:

The populated CoverageStore, or None if no coverage data is available (no metadata file or no gcda subdirs found).