Skip to content

Commit 417b6ce

Browse files
committed
Merge bitcoin/bitcoin#30156: fuzz: More accurate coverage reports
949abeb [fuzz] Avoid collecting initialization coverage (dergoegge) Pull request description: Our coverage reports include coverage of initialization code, which can be misleading when trying to evaluate the coverage a fuzz harness achieves through fuzzing alone. This PR proposes to make fuzz coverage reports more accurate by resetting coverage counters after initialization code has been run. This makes it easier to evaluate which code was actually reached through fuzzing (e.g. to spot fuzz blockers). ACKs for top commit: maflcko: utACK 949abeb brunoerg: nice, utACK 949abeb Tree-SHA512: c8579bda4f3d71d199b9331fbe6316fce375a906743d0bc216bb94958dc03fdc9a951ea50cfeb487494a75668ae3c16471a82f7e5fdd912d781dc29d063e2c5b
2 parents 5895602 + 949abeb commit 417b6ce

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/fuzz/fuzz.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,26 @@ void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target,
7979
static std::string_view g_fuzz_target;
8080
static const TypeTestOneInput* g_test_one_input{nullptr};
8181

82+
83+
#if defined(__clang__) && defined(__linux__)
84+
extern "C" void __llvm_profile_reset_counters(void) __attribute__((weak));
85+
extern "C" void __gcov_reset(void) __attribute__((weak));
86+
87+
void ResetCoverageCounters()
88+
{
89+
if (__llvm_profile_reset_counters) {
90+
__llvm_profile_reset_counters();
91+
}
92+
93+
if (__gcov_reset) {
94+
__gcov_reset();
95+
}
96+
}
97+
#else
98+
void ResetCoverageCounters() {}
99+
#endif
100+
101+
82102
void initialize()
83103
{
84104
// Terminate immediately if a fuzzing harness ever tries to create a TCP socket.
@@ -129,6 +149,8 @@ void initialize()
129149
Assert(!g_test_one_input);
130150
g_test_one_input = &it->second.test_one_input;
131151
it->second.opts.init();
152+
153+
ResetCoverageCounters();
132154
}
133155

134156
#if defined(PROVIDE_FUZZ_MAIN_FUNCTION)

0 commit comments

Comments
 (0)