mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-31 08:13:52 +02:00
Merge bitcoin/bitcoin#31901: contrib: Add deterministic-unittest-coverage
fa99c3b544test: Exclude SeedStartup from coverage counts (MarcoFalke)fa579d663dcontrib: Add deterministic-unittest-coverage (MarcoFalke)fa3940b1cbcontrib: deterministic-fuzz-coverage fixups (MarcoFalke)faf905b9b6doc: Remove unused -fPIC (MarcoFalke)fa1e0a7228gitignore: target/ (MarcoFalke) Pull request description: The `contrib/devtools/test_deterministic_coverage.sh` script is problematic: * It is written in bash. This can lead to issues when running with the ancient bash version shipped by macOS by default, or can lead to other compatibility issues, such as https://github.com/bitcoin/bitcoin/pull/31588#discussion_r1946784827. Also, pipefail isn't set, so IO errors may be silently ignored. * It is based on gcov. This can lead to issues, such as https://github.com/bitcoin/bitcoin/pull/31588#pullrequestreview-2602169248 (possibly due to prefix-map), or https://github.com/bitcoin/bitcoin/pull/31588#issuecomment-2646395385 (gcovr processing error), or https://github.com/bitcoin/bitcoin/pull/31588#pullrequestreview-2605954001 (gcovr assertion error). * The script is severely outdated, with the last update to `NON_DETERMINISTIC_TESTS` being in the prior decade. Instead of patching around all issues one-by-one, just provide a fresh rewrite, based on the recently added `deterministic-fuzz-coverage` tool based on clang, llvm-cov, and llvm-profdata. (Initial feedback indicates that this is a more promising attempt: https://github.com/bitcoin/bitcoin/pull/31588#issuecomment-2649356408 and https://github.com/bitcoin/bitcoin/pull/31588#issuecomment-2649354598). The new tool also sets `RANDOM_CTX_SEED=21` as suggested by hodlinator in https://github.com/bitcoin/bitcoin/pull/31588#issuecomment-2650784726. ACKs for top commit: Prabhat1308: Concept ACK [`fa99c3b`](fa99c3b544) hodlinator: re-ACKfa99c3b544brunoerg: light ACKfa99c3b544dergoegge: tACKfa99c3b544janb84: Concept ACK [fa99c3b](fa99c3b544) Tree-SHA512: 491d5e6413d929395a5c7caea54817bdc1a0e00562c9728a374d4e92f2e2017dba4a770ecdb2e7317e049df9fdeb390d83c90dff9aa5709f97aa3f6a0e70cdb4
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
add_library(test_util STATIC EXCLUDE_FROM_ALL
|
||||
blockfilter.cpp
|
||||
coins.cpp
|
||||
coverage.cpp
|
||||
index.cpp
|
||||
json.cpp
|
||||
logging.cpp
|
||||
|
||||
23
src/test/util/coverage.cpp
Normal file
23
src/test/util/coverage.cpp
Normal 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
10
src/test/util/coverage.h
Normal 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
|
||||
@@ -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;
|
||||
}()};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user