Skip to content

tests: harden topotest gcov coverage setup and reporting - #22104

Merged
riw777 merged 2 commits into
FRRouting:masterfrom
Jafaral:gcov-fixes
May 30, 2026
Merged

tests: harden topotest gcov coverage setup and reporting#22104
riw777 merged 2 commits into
FRRouting:masterfrom
Jafaral:gcov-fixes

Conversation

@Jafaral

@Jafaral Jafaral commented May 29, 2026

Copy link
Copy Markdown
Member
  • Exit immediately during pytest configure when --cov-topotest is used without a gcov-enabled build, with a clear message instead of failing every test with missing GCOV_* env var errors.
  • Make parallel coverage collection reliable under xdist by compiling gcov builds with -fprofile-update=atomic and having lcov ignore corrupted counters so full topotest runs still produce coverage.info.

Exit during pytest configure if no *.gcno files are found, instead of
running all topotests and failing with missing GCOV_* env var KeyErrors.

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
@frrbot frrbot Bot added the tests Topotests, make check, etc label May 29, 2026
@greptile-apps

greptile-apps Bot commented May 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR hardens the gcov/lcov coverage infrastructure for topotests in two ways: it adds early failure with clear diagnostics when --cov-topotest is used without a gcov-enabled build, and it makes parallel coverage collection reliable by adding -fprofile-update=atomic to the build flags and a version-aware lcov_ignore_errors() helper that restricts lcov 2.x-only --ignore-errors categories (negative, unexecuted) to systems where they are actually supported.

  • configure.ac: -fprofile-update=atomic is added via AC_C_FLAG, so it is silently skipped on compilers that don't support it (GCC < 9).
  • conftest.py / munet/native.py: setup_coverage now calls pytest.exit() with an actionable message instead of warning-and-returning; coverage_finish guards against missing env vars; both lcov invocations delegate to the new lcov_ignore_errors(commander) helper.
  • munet/base.py: New lcov_ignore_errors() function probes lcov --version stdout and returns negative,gcov,source,unexecuted for lcov 2.x or the safe gcov,source subset for lcov 1.x, fixing the compatibility issue flagged in earlier reviews.

Confidence Score: 5/5

Safe to merge β€” all changes are confined to the gcov/lcov coverage tooling path and do not touch any FRR daemon code or test logic.

The changes are narrowly scoped: early-exit guards in setup_coverage, a new version-detection helper for lcov, and one new compiler flag gated behind AC_C_FLAG. The lcov 1.x/2.x compatibility concern raised in prior reviews is correctly resolved by probing lcov --version stdout and restricting 2.x-only categories to matching systems. The -fprofile-update=atomic flag is silently dropped by AC_C_FLAG on compilers that don't support it, so there is no risk of breaking older build environments.

No files require special attention.

Important Files Changed

Filename Overview
tests/topotests/munet/base.py Adds lcov_ignore_errors() helper that version-gates lcov 2.x-only error categories, correctly resolving the prior lcov 1.x compatibility concern.
tests/topotests/conftest.py setup_coverage now exits early with actionable diagnostics; coverage_finish guards against missing env vars; lcov capture uses version-aware --ignore-errors via the new helper.
tests/topotests/munet/native.py Adopts lcov_ignore_errors() for the munet-path lcov invocation, mirroring the fix in conftest.py.
configure.ac Adds -fprofile-update=atomic under AC_C_FLAG so it is only applied when the compiler supports it, enabling race-free counter updates during parallel xdist runs.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["pytest --cov-topotest"] --> B["setup_coverage()"]
    B --> C{build dir exists?}
    C -- No --> D["pytest.exit() with clear message"]
    C -- Yes --> E["find zebra_nb.gcno"]
    E --> F{gcno files found?}
    F -- No --> G["pytest.exit() with rebuild instructions"]
    F -- Yes --> H["Set FRR_BUILD_DIR / GCOV_PREFIX env vars"]
    H --> I["Run tests (FRR writes .gcda files)"]
    I --> J["coverage_finish()"]
    J --> K{FRR_BUILD_DIR and GCOV_PREFIX set?}
    K -- No --> L["Log warning and return"]
    K -- Yes --> M["lcov_ignore_errors(commander)"]
    M --> N["lcov --version"]
    N --> O{LCOV version 2?}
    O -- Yes --> P["negative,gcov,source,unexecuted"]
    O -- No --> Q["gcov,source"]
    P & Q --> R["lcov --capture --ignore-errors ..."]
    R --> S["coverage.info"]
    S --> T["lcov --summary"]
Loading

Reviews (2): Last reviewed commit: "tests: make gcov coverage robust under p..." | Re-trigger Greptile

Comment thread tests/topotests/munet/native.py
Use -fprofile-update=atomic for gcov builds and tell lcov to ignore
corrupted counters so xdist runs can still produce coverage.info.

Signed-off-by: Jafar Al-Gharaibeh <jafar@atcorp.com>
@Jafaral

Jafaral commented May 29, 2026

Copy link
Copy Markdown
Member Author

@greptile review

@donaldsharp

Copy link
Copy Markdown
Member

once ci finishes I'll get this in

@riw777 riw777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@riw777
riw777 merged commit e517182 into FRRouting:master May 30, 2026
24 checks passed
@Jafaral
Jafaral deleted the gcov-fixes branch May 30, 2026 15:02
@Jafaral

Jafaral commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

@Mergifyio backport stable/10.6 stable/10.5

@mergify

mergify Bot commented Jun 1, 2026

Copy link
Copy Markdown

backport stable/10.6 stable/10.5

βœ… Backports have been created

Details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport master size/M tests Topotests, make check, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants