Skip to content

Enable gcov #511

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

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ option(USE_UBSAN "Enable UndefinedBehaviorSanitizer checks" OFF)
option(USE_TSAN "Enable ThreadSanitizer checks" OFF)
option(USE_MSAN "Enable MemorySanitizer checks" OFF)
option(USE_VALGRIND "Enable Valgrind instrumentation" OFF)
option(USE_GCOV "Enable gcov support" OFF)

# set UMF_PROXY_LIB_BASED_ON_POOL to one of: SCALABLE or JEMALLOC
set(KNOWN_PROXY_LIB_POOLS SCALABLE JEMALLOC)
Expand Down
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- [Extending public API](#extending-public-api)
- [License](#license)
- [Adding new dependency](#adding-new-dependency)
- [Code coverage](#code-coverage)

Below you'll find instructions on how to contribute to UMF, either with code changes
or issues. All contributions are most welcome!
Expand Down Expand Up @@ -202,3 +203,20 @@ New dependency: dependency_name
license: SPDX license tag
origin: https://dependency_origin.com
```

## Code coverage

After adding a new functionality add tests and check coverage before and after the change.
To do this, enable coverage instrumentation by turning on the USE_GCOV flag in CMake.
Coverage instrumentation feature is supported only by GCC and Clang.
An example flow might look like the following:

```bash
$ cmake -B build -DUSE_GCOV=1 -DCMAKE_BUILD_TYPE=Debug
$ cmake --build build -j
$ cd build
$ ctest
$ apt install lcov
$ lcov --capture --directory . --output-file coverage.info
$ genhtml -o html_report coverage.info
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ List of options provided by CMake:
| USE_TSAN | Enable ThreadSanitizer checks | ON/OFF | OFF |
| USE_MSAN | Enable MemorySanitizer checks | ON/OFF | OFF |
| USE_VALGRIND | Enable Valgrind instrumentation | ON/OFF | OFF |
| USE_GCOV | Enable gcov support (Linux only) | ON/OFF | OFF |

## Architecture: memory pools and providers

Expand Down
13 changes: 13 additions & 0 deletions cmake/helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ function(add_umf_target_compile_options name)
${name} PRIVATE -Werror -fno-omit-frame-pointer
-fstack-protector-strong)
endif()
if(USE_GCOV)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(FATAL_ERROR "To use gcov, the build type must be Debug")
Copy link
Contributor

Choose a reason for hiding this comment

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

is it truly a fatal error? I guess we get a different results for Release, but it should work, right...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the Clang documentation:

gcov - A GCC-compatible coverage implementation which operates on DebugInfo. This is enabled by -ftest-coverage or --coverage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Soo.. it might work in the build type "RelWithDebInfo"...?

endif()
target_compile_options(${name} PRIVATE --coverage)
endif()
elseif(MSVC)
target_compile_options(
${name}
Expand All @@ -121,6 +127,13 @@ function(add_umf_target_link_options name)
if(NOT MSVC)
if(NOT APPLE)
target_link_options(${name} PRIVATE "LINKER:-z,relro,-z,now")
if(USE_GCOV)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(
FATAL_ERROR "To use gcov, the build type must be Debug")
endif()
target_link_options(${name} PRIVATE --coverage)
endif()
endif()
elseif(MSVC)
target_link_options(
Expand Down