-
Notifications
You must be signed in to change notification settings - Fork 291
Add support for generating coverage reports w/ gcov #4489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
d-torrance
wants to merge
9
commits into
Macaulay2:development
Choose a base branch
from
d-torrance:gcov
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−1
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8976b29
Add --enable-gcov configure option for engine code coverage
d-torrance bb58c90
Add GCOV cmake option for engine code coverage
d-torrance e469175
Make coverage report path a clickable terminal hyperlink
d-torrance 3077d8b
Set a gcovr function merge mode so coverage-report doesn't error
d-torrance 2d12c71
Drop -fprofile-abs-path from the coverage flags
d-torrance 433573e
Clean up the --enable-gcov configure.ac style
d-torrance 45b0c85
configure: set gcov flags after Fortran library detection
d-torrance 6579b07
coverage-report: fix source resolution for out-of-tree builds
d-torrance ab5a5f4
gcov.cmake: match the autotools coverage-report target
d-torrance File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # gcc/gcov code coverage (configure with -DGCOV=ON). | ||
| # Instrumentation flags are added in configure.cmake; this module only provides | ||
| # convenience targets to clear and report on the accumulated .gcda data. The data | ||
| # itself is generated automatically whenever a binary built in coverage mode exits | ||
| # (the unit tests, ctest, or the M2 binary run on your own code). | ||
| # | ||
| # By default the report covers the whole source tree; pass extra gcovr options | ||
| # via GCOVR_OPTIONS, e.g. -DGCOVR_OPTIONS="--filter Macaulay2/e/" to scope it to | ||
| # the engine, or "--exclude .*/unit-tests/.*" to drop the test sources. | ||
| # | ||
| # Usage: | ||
| # cmake -S . -B BUILD/cov -GNinja -DGCOV=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON | ||
| # cmake --build BUILD/cov --target M2-engine M2-unit-tests | ||
| # cmake --build BUILD/cov --target coverage-reset # start from a clean slate | ||
| # ctest --test-dir BUILD/cov -R unit-tests # (or run M2 however you like) | ||
| # cmake --build BUILD/cov --target coverage-report # writes coverage/index.html | ||
|
|
||
| if(GCOV) | ||
| find_program(GCOVR NAMES gcovr) | ||
| set(_coverage_dir ${CMAKE_BINARY_DIR}/coverage) | ||
| set(_coverage_index ${_coverage_dir}/index.html) | ||
| set(GCOVR_OPTIONS "" CACHE STRING | ||
| "Extra options passed to gcovr for the coverage-report target") | ||
| separate_arguments(_gcovr_options UNIX_COMMAND "${GCOVR_OPTIONS}") | ||
|
|
||
| # coverage-reset clears all accumulated data; the M2 binary may have written | ||
| # .gcda anywhere in the tree, so this is deliberately not engine-scoped. | ||
| add_custom_target(coverage-reset | ||
| COMMENT "Deleting accumulated .gcda coverage counters" | ||
| COMMAND find ${CMAKE_BINARY_DIR} -name "*.gcda" -delete) | ||
|
|
||
| if(NOT GCOVR) | ||
| message(WARNING "GCOV is ON but gcovr was not found; the 'coverage-report' target will not be created. Install gcovr (e.g. 'pip install gcovr').") | ||
| else() | ||
| add_custom_target(coverage-report | ||
| COMMENT "Generating gcov/gcovr coverage report" | ||
| COMMAND ${CMAKE_COMMAND} -E make_directory ${_coverage_dir} | ||
| # Pass the build tree as a positional search path (not --object-directory) | ||
| # so gcovr runs gcov in each data file's own directory, matching the | ||
| # autotools target. | ||
| COMMAND ${GCOVR} | ||
| --root ${CMAKE_SOURCE_DIR} | ||
| ${CMAKE_BINARY_DIR} | ||
| # gcov can report a function on multiple lines (inlines at -O0); merge | ||
| # those instead of erroring, attributing the function to its first line. | ||
| --merge-mode-functions=merge-use-line-min | ||
| ${_gcovr_options} | ||
| --html-details ${_coverage_index} | ||
| --print-summary | ||
| # Print the report path as an OSC 8 terminal hyperlink so it is clickable. | ||
| # The printf format is a bracket argument (no CMake escaping); the report | ||
| # path is passed as $1 to sh. | ||
| COMMAND sh -c [==[printf '%s\033]8;;file://%s%s\033\\%s\033]8;;\033\\\n' 'Coverage report: ' "$(hostname)" "$1" "$1"]==] sh "${_coverage_index}" | ||
| USES_TERMINAL) | ||
| endif() | ||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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-reportjob would catch toolchain andgcovrinvocation problems.AI-assisted review comment made by GPT 4.6-Sol under Andrew's direction in order to observe deeper code reaches.