From fa99c3b544b631cfe34d52fb5e71636aedb1b423 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Tue, 25 Feb 2025 09:45:01 +0100 Subject: [PATCH] test: Exclude SeedStartup from coverage counts --- src/test/fuzz/fuzz.cpp | 20 +------------------- src/test/util/CMakeLists.txt | 1 + src/test/util/coverage.cpp | 23 +++++++++++++++++++++++ src/test/util/coverage.h | 10 ++++++++++ src/test/util/setup_common.cpp | 2 ++ 5 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 src/test/util/coverage.cpp create mode 100644 src/test/util/coverage.h diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index 5b5abe2fe23..30766700b9d 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -89,25 +90,6 @@ const std::function G_TEST_GET_FULL_NAME{[]{ return std::string{g_fuzz_target}; }}; -#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 - - static void initialize() { // By default, make the RNG deterministic with a fixed seed. This will affect all diff --git a/src/test/util/CMakeLists.txt b/src/test/util/CMakeLists.txt index 5d88d1da3ec..cd7c4c01183 100644 --- a/src/test/util/CMakeLists.txt +++ b/src/test/util/CMakeLists.txt @@ -5,6 +5,7 @@ add_library(test_util STATIC EXCLUDE_FROM_ALL blockfilter.cpp coins.cpp + coverage.cpp index.cpp json.cpp logging.cpp diff --git a/src/test/util/coverage.cpp b/src/test/util/coverage.cpp new file mode 100644 index 00000000000..bbf068a6fa0 --- /dev/null +++ b/src/test/util/coverage.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2025-present The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#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 diff --git a/src/test/util/coverage.h b/src/test/util/coverage.h new file mode 100644 index 00000000000..1de62e3ae5f --- /dev/null +++ b/src/test/util/coverage.h @@ -0,0 +1,10 @@ +// Copyright (c) 2025-present The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_TEST_UTIL_COVERAGE_H +#define BITCOIN_TEST_UTIL_COVERAGE_H + +void ResetCoverageCounters(); + +#endif // BITCOIN_TEST_UTIL_COVERAGE_H diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index bf26997c076..083ba3bd6d8 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -37,6 +37,7 @@ #include #include