Skip to content

Commit 5fbf9e5

Browse files
authored
Merge pull request #511 from KFilipek/gcov_enable
Enable gcov
2 parents 9c59759 + 909870b commit 5fbf9e5

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ option(USE_UBSAN "Enable UndefinedBehaviorSanitizer checks" OFF)
4949
option(USE_TSAN "Enable ThreadSanitizer checks" OFF)
5050
option(USE_MSAN "Enable MemorySanitizer checks" OFF)
5151
option(USE_VALGRIND "Enable Valgrind instrumentation" OFF)
52+
option(USE_GCOV "Enable gcov support" OFF)
5253

5354
# set UMF_PROXY_LIB_BASED_ON_POOL to one of: SCALABLE or JEMALLOC
5455
set(KNOWN_PROXY_LIB_POOLS SCALABLE JEMALLOC)

CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Extending public API](#extending-public-api)
1111
- [License](#license)
1212
- [Adding new dependency](#adding-new-dependency)
13+
- [Code coverage](#code-coverage)
1314

1415
Below you'll find instructions on how to contribute to UMF, either with code changes
1516
or issues. All contributions are most welcome!
@@ -202,3 +203,20 @@ New dependency: dependency_name
202203
license: SPDX license tag
203204
origin: https://dependency_origin.com
204205
```
206+
207+
## Code coverage
208+
209+
After adding a new functionality add tests and check coverage before and after the change.
210+
To do this, enable coverage instrumentation by turning on the USE_GCOV flag in CMake.
211+
Coverage instrumentation feature is supported only by GCC and Clang.
212+
An example flow might look like the following:
213+
214+
```bash
215+
$ cmake -B build -DUSE_GCOV=1 -DCMAKE_BUILD_TYPE=Debug
216+
$ cmake --build build -j
217+
$ cd build
218+
$ ctest
219+
$ apt install lcov
220+
$ lcov --capture --directory . --output-file coverage.info
221+
$ genhtml -o html_report coverage.info
222+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ List of options provided by CMake:
125125
| USE_TSAN | Enable ThreadSanitizer checks | ON/OFF | OFF |
126126
| USE_MSAN | Enable MemorySanitizer checks | ON/OFF | OFF |
127127
| USE_VALGRIND | Enable Valgrind instrumentation | ON/OFF | OFF |
128+
| USE_GCOV | Enable gcov support (Linux only) | ON/OFF | OFF |
128129

129130
## Architecture: memory pools and providers
130131

cmake/helpers.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ function(add_umf_target_compile_options name)
104104
${name} PRIVATE -Werror -fno-omit-frame-pointer
105105
-fstack-protector-strong)
106106
endif()
107+
if(USE_GCOV)
108+
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
109+
message(FATAL_ERROR "To use gcov, the build type must be Debug")
110+
endif()
111+
target_compile_options(${name} PRIVATE --coverage)
112+
endif()
107113
elseif(MSVC)
108114
target_compile_options(
109115
${name}
@@ -121,6 +127,13 @@ function(add_umf_target_link_options name)
121127
if(NOT MSVC)
122128
if(NOT APPLE)
123129
target_link_options(${name} PRIVATE "LINKER:-z,relro,-z,now")
130+
if(USE_GCOV)
131+
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
132+
message(
133+
FATAL_ERROR "To use gcov, the build type must be Debug")
134+
endif()
135+
target_link_options(${name} PRIVATE --coverage)
136+
endif()
124137
endif()
125138
elseif(MSVC)
126139
target_link_options(

0 commit comments

Comments
 (0)