0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

Merge bitcoin/bitcoin#30156: fuzz: More accurate coverage reports

949abebea0 [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 949abebea0
  brunoerg:
    nice, utACK 949abebea0

Tree-SHA512: c8579bda4f3d71d199b9331fbe6316fce375a906743d0bc216bb94958dc03fdc9a951ea50cfeb487494a75668ae3c16471a82f7e5fdd912d781dc29d063e2c5b
This commit is contained in:
merge-script 2024-05-29 09:34:48 +01:00
commit 417b6cecee
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -79,6 +79,26 @@ void FuzzFrameworkRegisterTarget(std::string_view name, TypeTestOneInput target,
static std::string_view g_fuzz_target;
static const TypeTestOneInput* g_test_one_input{nullptr};
#if defined(__clang__) && defined(__linux__)
extern "C" void __llvm_profile_reset_counters(void) __attribute__((weak));
extern "C" void __gcov_reset(void) __attribute__((weak));
void ResetCoverageCounters()
{
if (__llvm_profile_reset_counters) {
__llvm_profile_reset_counters();
}
if (__gcov_reset) {
__gcov_reset();
}
}
#else
void ResetCoverageCounters() {}
#endif
void initialize()
{
// Terminate immediately if a fuzzing harness ever tries to create a TCP socket.
@ -129,6 +149,8 @@ void initialize()
Assert(!g_test_one_input);
g_test_one_input = &it->second.test_one_input;
it->second.opts.init();
ResetCoverageCounters();
}
#if defined(PROVIDE_FUZZ_MAIN_FUNCTION)