test: Exclude SeedStartup from coverage counts

This commit is contained in:
MarcoFalke 2025-02-25 09:45:01 +01:00
parent fa579d663d
commit fa99c3b544
No known key found for this signature in database
5 changed files with 37 additions and 19 deletions

View File

@ -7,6 +7,7 @@
#include <netaddress.h>
#include <netbase.h>
#include <test/fuzz/util/check_globals.h>
#include <test/util/coverage.h>
#include <test/util/random.h>
#include <test/util/setup_common.h>
#include <util/check.h>
@ -89,25 +90,6 @@ const std::function<std::string()> 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

View File

@ -5,6 +5,7 @@
add_library(test_util STATIC EXCLUDE_FROM_ALL
blockfilter.cpp
coins.cpp
coverage.cpp
index.cpp
json.cpp
logging.cpp

View File

@ -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 <test/util/coverage.h>
#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

10
src/test/util/coverage.h Normal file
View File

@ -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

View File

@ -37,6 +37,7 @@
#include <scheduler.h>
#include <script/sigcache.h>
#include <streams.h>
#include <test/util/coverage.h>
#include <test/util/net.h>
#include <test/util/random.h>
#include <test/util/txmempool.h>
@ -80,6 +81,7 @@ static const bool g_rng_temp_path_init{[] {
Assert(!g_used_g_prng);
(void)g_rng_temp_path.rand64();
g_used_g_prng = false;
ResetCoverageCounters(); // The seed strengthen in SeedStartup is not deterministic, so exclude it from coverage counts
return true;
}()};