Replace regex dependency parser with gcov line-level coverage pruning#1273
Replace regex dependency parser with gcov line-level coverage pruning#1273sbryngelson wants to merge 3 commits intoMFlowCode:masterfrom
Conversation
Replaces the manually-maintained test_mapping.json and regex-based dependency_parser.py with a fully automated approach using gfortran gcov instrumentation. Key changes: - Add toolchain/mfc/test/coverage.py: build coverage cache by running all tests with a --gcov build, recording which .fpp line numbers each test executes; filter tests by intersecting git diff -U0 line ranges against per-test coverage data - Add --build-coverage-cache flag to ./mfc.sh test - Replace --only-changes implementation in test.py with coverage-based filter - Add --line-marker-format=gfortran5 to CMakeLists.txt Fypp invocation so gcov correctly maps coverage to .fpp line numbers (not .f90 line numbers) - Delete dependency_parser.py (530 lines) and test_mapping.json (148 lines) - Add 43 unit tests covering all corner cases: exact line hits, no-overlap, large-module line granularity, GPU #ifdef blocks, stale cache, new files Workflow: ./mfc.sh build --gcov -j 8 # one-time: build with coverage ./mfc.sh test --build-coverage-cache # one-time: populate cache (~2-3x time) ./mfc.sh test --only-changes -j 8 # fast: only tests covering changed lines Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude Code ReviewHead SHA: 015ac92
Summary
Findings[BLOCKER]
[HIGH]
[HIGH] Silent failure in
try:
case.run([PRE_PROCESS, SIMULATION], gpus=set())
except Exception:
# Continue even if the test fails — we only need .gcda data
passIf a bug causes many tests to fail, the cache will contain entries where every test covers 0 lines. A subsequent [HIGH]
COVERAGE_CACHE_PATH = Path(common.MFC_ROOT_DIR) / "toolchain/mfc/test/test_coverage_cache.json"Every function that uses the cache accepts a [MEDIUM]
[MEDIUM]
if covered_lines & set(range(start, end + 1)):For a large diff hunk (e.g., entire 5000-line file replaced), this allocates a 5000-element Python set per test per changed range. Since if any(start <= line <= end for line in covered_lines):Or use [MINOR] Unit test import mechanism is fragile
Improvement Opportunities
|
Claude Code ReviewHead SHA: 8b88b8b Summary
Findings🔴 High —
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1273 +/- ##
==========================================
- Coverage 44.05% 44.04% -0.02%
==========================================
Files 70 70
Lines 20496 20492 -4
Branches 1991 1992 +1
==========================================
- Hits 9029 9025 -4
+ Misses 10328 10327 -1
- Partials 1139 1140 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Three bugs found during integration testing on Phoenix: - gcov 12 outputs raw JSON, not gzip; added fallback parsing - Symlink paths (/storage/scratch1 vs /storage/home) caused relpath mismatch; use os.path.realpath() before computing relative paths - Missing case.delete_output()/create_directory() before case.run() caused silent test failures during cache build Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude Code ReviewHead SHA: 6e7f5be
Summary
Findings❌ Critical —
|
Summary
test_mapping.jsonand regex-baseddependency_parser.pywith a fully automated gcov instrumentation approach for--only-changestest pruningtoolchain/mfc/test/coverage.pybuilds a coverage cache by running all tests with a--gcovbuild, recording which.fppline numbers each test executes, then filters tests by intersectinggit diff -U0line ranges against per-test coverage data--build-coverage-cacheflag to./mfc.sh testand--line-marker-format=gfortran5to Fypp invocation so gcov correctly maps coverage to.fpp(not.f90) line numbers#ifdefblocks, stale cache, new files)Why
The previous regex parser had critical gaps:
#includemacro files (parallel_macros.fppetc.) were invisible — changing them ran 0 teststest_mapping.jsonThe gcov approach is completely automated (no JSON to maintain), correct by construction (the compiler is the oracle), and line-granular.
Workflow
Test plan
--gcovand run--build-coverage-cacheon CI-like Linux (gfortran)--only-changescorrectly prunes tests when only a few.fpplines changecases.py) trigger full suitecases.pymodification) falls back to full suitepython -m pytest toolchain/mfc/test/test_coverage_unit.py🤖 Generated with Claude Code