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
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ This is a collection of quite useful scripts that expand the possibilities for b
16
16
-[1b - Via target commands](#1b---via-target-commands)
17
17
-[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)
18
18
-[Example 3: Target added to the 'ccov' and 'ccov-all' targets](#example-3-target-added-to-the-ccov-and-ccov-all-targets)
19
+
-[Example 4: Hook all targets](#example-4-hook-all-targets)
@@ -176,6 +177,7 @@ To enable any code coverage instrumentation/targets, the single CMake option of
176
177
From this point, there are two primary methods for adding instrumentation to targets:
177
178
1. A blanket instrumentation by calling `add_code_coverage()`, where all targets in that directory and all subdirectories are automatically instrumented.
178
179
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.
180
+
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.
179
181
180
182
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.
225
227
```
226
228
229
+
#### Example 4: Hook all targets
230
+
```
231
+
# this could be as well command line argument
232
+
set(CCOV_TARGETS_HOOK ON) # enable 'add_executable' and 'add_library' hooks
233
+
set(CCOV_TARGETS_HOOK_ARGS ALL AUTO) # set default arguments for coverage
234
+
235
+
add_code_coverage() # Adds instrumentation to all targets
236
+
237
+
add_library(theLib lib.cpp) # ccov-theLib target will be add
238
+
239
+
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)
@@ -189,6 +212,25 @@ if(CODE_COVERAGE AND NOT CODE_COVERAGE_ADDED)
189
212
else()
190
213
message(FATAL_ERROR "Code coverage requires Clang or GCC. Aborting.")
191
214
endif()
215
+
216
+
if (CCOV_TARGETS_HOOK)
217
+
if (COMMAND _add_executable)
218
+
message(FATAL_ERROR "add_executable was already redefined. Only one redefinitions is allowed.")
0 commit comments