Skip to content

Commit 808a77d

Browse files
fanquakePastaPastaPasta
authored andcommitted
Merge 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
1 parent 3ca42ba commit 808a77d

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
@@ -76,6 +76,26 @@ void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target,
7676
static std::string_view g_fuzz_target;
7777
static const TypeTestOneInput* g_test_one_input{nullptr};
7878

79+
80+
#if defined(__clang__) && defined(__linux__)
81+
extern "C" void __llvm_profile_reset_counters(void) __attribute__((weak));
82+
extern "C" void __gcov_reset(void) __attribute__((weak));
83+
84+
void ResetCoverageCounters()
85+
{
86+
if (__llvm_profile_reset_counters) {
87+
__llvm_profile_reset_counters();
88+
}
89+
90+
if (__gcov_reset) {
91+
__gcov_reset();
92+
}
93+
}
94+
#else
95+
void ResetCoverageCounters() {}
96+
#endif
97+
98+
7999
void initialize()
80100
{
81101
// Terminate immediately if a fuzzing harness ever tries to create a TCP socket.
@@ -126,6 +146,8 @@ void initialize()
126146
Assert(!g_test_one_input);
127147
g_test_one_input = &it->second.test_one_input;
128148
it->second.opts.init();
149+
150+
ResetCoverageCounters();
129151
}
130152

131153
#if defined(PROVIDE_FUZZ_MAIN_FUNCTION)

0 commit comments

Comments
 (0)