Skip to content

Commit 949abeb

Browse files
committed
[fuzz] Avoid collecting initialization coverage
1 parent 6f36624 commit 949abeb

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)