You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16Lines changed: 16 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ This is a collection of quite useful scripts that expand the possibilities for b
15
15
-[1b - Via target commands](#1b---via-target-commands)
16
16
-[Example 2: Target instrumented, but with regex pattern of files to be excluded from report](#example-2-target-instrumented-but-with-regex-pattern-of-files-to-be-excluded-from-report)
17
17
-[Example 3: Target added to the 'ccov' and 'ccov-all' targets](#example-3-target-added-to-the-ccov-and-ccov-all-targets)
18
+
-[Example 4: Hook all targets](#example-4-hook-all-targets)
@@ -136,6 +137,7 @@ To enable any code coverage instrumentation/targets, the single CMake option of
136
137
From this point, there are two primary methods for adding instrumentation to targets:
137
138
1. A blanket instrumentation by calling `add_code_coverage()`, where all targets in that directory and all subdirectories are automatically instrumented.
138
139
2. Per-target instrumentation by calling `target_code_coverage(<TARGET_NAME>)`, where the target is given and thus only that target is instrumented. This applies to both libraries and executables.
140
+
3. Automatically add coverage for each target with `-DCCOV_TARGETS_HOOK=On` and `-DCCOV_TARGETS_HOOK_ARGS=...` for default values, requires `add_code_coverage()` or similar.
139
141
140
142
To add coverage targets, such as calling `make ccov` to generate the actual coverage information for perusal or consumption, call `target_code_coverage(<TARGET_NAME>)` on an *executable* target.
target_code_coverage(theExe AUTO ALL EXCLUDE non_covered.cpp test/*) # As an executable target, adds to the 'ccov' and ccov-all' targets, and the reports will exclude the non-covered.cpp file, and any files in a test/ folder.
185
187
```
186
188
189
+
#### Example 4: Hook all targets
190
+
```
191
+
# this could be as well command line argument
192
+
set(CCOV_TARGETS_HOOK ON) # enable 'add_executable' and 'add_library' hooks
193
+
set(CCOV_TARGETS_HOOK_ARGS ALL AUTO) # set default arguments for coverage
194
+
195
+
add_code_coverage() # Adds instrumentation to all targets
196
+
197
+
add_library(theLib lib.cpp) # ccov-theLib target will be add
198
+
199
+
add_executable(theExe main.cpp) # ccov-theExe target will be add
> American fuzzy lop is a security-oriented fuzzer that employs a novel type of compile-time instrumentation and genetic algorithms to automatically discover clean, interesting test cases that trigger new internal states in the targeted binary. This substantially improves the functional coverage for the fuzzed code. The compact synthesized corpora produced by the tool are also useful for seeding other, more labor- or resource-intensive testing regimes down the road.
Copy file name to clipboardExpand all lines: code-coverage.cmake
+42Lines changed: 42 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -72,13 +72,36 @@
72
72
# add_executable(theExe main.cpp non_covered.cpp)
73
73
# target_code_coverage(theExe AUTO ALL EXCLUDE non_covered.cpp test/*) # As an executable target, adds to the 'ccov' and ccov-all' targets, and the reports will exclude the non-covered.cpp file, and any files in a test/ folder.
74
74
# ~~~
75
+
#
76
+
# Example 4: Hook all targets
77
+
#
78
+
# ~~~
79
+
# set(CCOV_TARGETS_HOOK ON) # enable 'add_executable' and 'add_library' hooks
80
+
# set(CCOV_TARGETS_HOOK_ARGS ALL AUTO) # set default arguments for coverage
81
+
#
82
+
# add_code_coverage() # Adds instrumentation to all targets
83
+
#
84
+
# add_library(theLib lib.cpp) # ccov-theLib target will be add
85
+
#
86
+
# add_executable(theExe main.cpp) # ccov-theExe target will be add
87
+
# target_link_libraries(theExe PRIVATE theLib)
88
+
# ~~~
75
89
76
90
# Options
77
91
option(
78
92
CODE_COVERAGE
79
93
"Builds targets with code coverage instrumentation. (Requires GCC or Clang)"
80
94
OFF)
81
95
96
+
option(
97
+
CCOV_TARGETS_HOOK
98
+
"Autocapture all new targets."
99
+
OFF)
100
+
101
+
option(
102
+
CCOV_TARGETS_HOOK_ARGS
103
+
"Default arguments for all hooked targets.")
104
+
82
105
# Programs
83
106
find_program(LLVM_COV_PATH llvm-cov)
84
107
find_program(LLVM_PROFDATA_PATH llvm-profdata)
@@ -181,6 +204,25 @@ if(CODE_COVERAGE AND NOT CODE_COVERAGE_ADDED)
181
204
else()
182
205
message(FATAL_ERROR "Code coverage requires Clang or GCC. Aborting.")
183
206
endif()
207
+
208
+
if (CCOV_TARGETS_HOOK)
209
+
if (COMMAND _add_executable)
210
+
message(FATAL_ERROR "add_executable was already redefined. Only one redefinitions is allowed.")
0 commit comments