Skip to content

Add support for generating coverage reports w/ gcov - #4489

Open
d-torrance wants to merge 3 commits into
Macaulay2:developmentfrom
d-torrance:gcov
Open

Add support for generating coverage reports w/ gcov#4489
d-torrance wants to merge 3 commits into
Macaulay2:developmentfrom
d-torrance:gcov

Conversation

@d-torrance

Copy link
Copy Markdown
Member

This replaces MichaelABurr#65

As discussed in the C++ refactoring group Zoom meeting yesterday: If we build M2 using ./configure --enable-gcov, then we can run make coverage-report to get a gcovr-generated coverage report of the engine and interpreter. In particular, everything that was covered since we built M2 (or ran make coverage-reset).

This will be useful to figuring out which features still need unit testing (e.g., by running make coverage-reset && make -C Macaulay2/e check && make coverage-report, we can see what all the unit tests hit.) There's also CMake support that I haven't tested.

AI Disclosure

🤖 This was Claude through and through 🤖

@mikestillman

Copy link
Copy Markdown
Member

I suppose we need to install gcovr first? Where should we put that info? I don't want (or can't) install using pip globally...

@mikestillman

Copy link
Copy Markdown
Member

Here is one set of instructions (from chatgpt). Sound reasonable? (I've never used pipx before).

Do the following once (using homebrew, on mac)

brew install pipx
pipx ensurepath
pipx install gcovr

Restart a terminal, do

gcovr --version

to upgrade or remove:

pipx upgrade gcovr
pipx uninstall gcovr

@d-torrance

Copy link
Copy Markdown
Member Author

It's available from most package managers (apt install gcovr, brew install gcovr, etc.) Maybe we should add a wiki page or something? Since it isn't a build dependency and we only need it for generating the reports, I think it might be overkill to check for it

@d-torrance

Copy link
Copy Markdown
Member Author

Yeah pipx is cool for scripts written in Python. But gcovr itself is in Homebrew, so I don't think that's necessary -- just brew install gcovr.

@mikestillman

Copy link
Copy Markdown
Member

The info about pipx suggested by chatGPT is too complicated and not needed on a mac: I believe just doing brew install gcovr does the trick.

@d-torrance d-torrance added the Infrastructure GitHub workflows, etc. label Aug 3, 2026
Comment thread M2/cmake/gcov.cmake Outdated

if(GCOV)
find_program(GCOVR NAMES gcovr)
set(_coverage_dir ${CMAKE_BINARY_DIR}/coverage)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add a small CI smoke test with coverage enabled, especially for the CMake path? The current checks all use the default GCOV=OFF, so they don't exercise the instrumentation flags or either coverage target; the PR also notes that the CMake support hasn't been tested. Even a minimal configure/build/run/coverage-report job would catch toolchain and gcovr invocation problems.

AI-assisted review comment made by GPT 4.6-Sol under Andrew's direction in order to observe deeper code reaches.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That sounds like a great idea, but I think it's out of scope for this PR. In particular, I don't think we want a distinct coverage-enabled build running as part of our usual test_build.yml workflow that runs during every PR.

But maybe like a weekly build that runs the report for the engine unit tests and uploads it to GitHub pages or something.

@d-torrance d-torrance added the AI-generated This PR contains AI-generated code label Aug 12, 2026
d-torrance and others added 3 commits August 12, 2026 15:00
A copy-and-paste slip in the (currently dormant) Clang source-based
coverage module: LLVM_COV was searched for under the name clang-format.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Build with --coverage -O0 (and without stripping), modeled on
--enable-profile.  The flags are applied after the Fortran/BLAS/LAPACK
detection, since gfortran expands --coverage to -lgcov, which would
otherwise be baked into FCLIBS/BLAS_LIBS and collide with the compiler's
own coverage runtime at link time.

Coverage data (.gcda) is generated automatically whenever a
coverage-built binary exits, so no target runs the tests for you: just
run the unit tests, "make check", or the M2 binary on your own code.
Two new top-level targets clear and report on the accumulated data:

  coverage-reset   delete accumulated .gcda (tree-wide)
  coverage-report  produce an HTML report via gcovr, whose path is
                   printed as a clickable OSC 8 terminal hyperlink

The report covers the whole tree by default; narrow it by overriding
COVERAGE_ROOT/COVERAGE_OBJDIR or with GCOVR_OPTIONS.  The object tree is
handed to gcovr as a positional search path rather than via
--object-directory, which would pin gcov to a single directory and fail
to resolve sources for objects built in deeper VPATH subdirectories.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The cmake counterpart of --enable-gcov: -DGCOV=ON builds with
--coverage -O0, mirroring the PROFILING flag block, and the new
cmake/gcov.cmake provides coverage-reset and coverage-report targets
matching the autotools ones.  Extra gcovr options may be passed with
-DGCOVR_OPTIONS="...".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@d-torrance

Copy link
Copy Markdown
Member Author

Finally got around to testing the cmake version. It was broken lol. Claude fixed it up, cleaned up the code, and squashed everything down to 3 logical commits.

For review, this is how it works. First install gcovr (brew install gcovr, apt install gcovr, etc.). Then:

autotools

./configure --enable-gcov # + whatever other options
make -jN # N = number of cores
# C-c once you have a working binary (we really need "make M2-core" lol)
make coverage-reset
# run whatever M2 code you want to look at
make coverage-report

cmake

cmake -DGCOV=ON # + whatever other options
ninja M2-core
ninja coverage-reset
# run whatever M2 code you want to look at
ninja coverage-report

@andrew-tawfeek andrew-tawfeek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good. I verified both generated Autotools and CMake coverage paths with GCC and gcovr: instrumentation produced counter data, coverage-report wrote a nonempty HTML report, and coverage-reset removed the counters. The Autotools configuration also applied --coverage -O0 after Fortran and BLAS detection and disabled stripping as intended.

AI-assisted PR review alongside GPT 5.6-Sol

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

Labels

AI-generated This PR contains AI-generated code Infrastructure GitHub workflows, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants