Skip to content

Commit bee23ce

Browse files
committed
Merge bitcoin/bitcoin#30399: test: Add arguments for creating a slimmer TestingSetup
f46b220 fuzz: Use BasicTestingSetup for coins_view target (TheCharlatan) 9e2a723 test: Add arguments for creating a slimmer setup (TheCharlatan) Pull request description: This adds arguments to some of the testing setup constructors for creating an environment without networking and a validation interface. This is useful for improving the performance of the utxo snapshot fuzz test, which constructs a new TestingSetup on each iteration. Using this slimmed down `TestingSetup` in future might also make the tests a bit faster when run in aggregate. ACKs for top commit: maflcko: review ACK f46b220 dergoegge: utACK f46b220 Tree-SHA512: 9dc62512b127b781fc9e2d8ef2b5a9b06ebb927a8294b6d872001c553984a7eb1f348e0257b32435b34b5505b5d0323f73bdd572a673da272d3e1e8538ab49d6
2 parents 30e8a79 + f46b220 commit bee23ce

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

src/test/fuzz/coins_view.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <vector>
2828

2929
namespace {
30-
const TestingSetup* g_setup;
3130
const Coin EMPTY_COIN{};
3231

3332
bool operator==(const Coin& a, const Coin& b)
@@ -39,8 +38,7 @@ bool operator==(const Coin& a, const Coin& b)
3938

4039
void initialize_coins_view()
4140
{
42-
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
43-
g_setup = testing_setup.get();
41+
static const auto testing_setup = MakeNoLogFileContext<>();
4442
}
4543

4644
FUZZ_TARGET(coins_view, .init = initialize_coins_view)

src/test/fuzz/utxo_snapshot.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ void initialize_chain()
3131
FUZZ_TARGET(utxo_snapshot, .init = initialize_chain)
3232
{
3333
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
34-
std::unique_ptr<const TestingSetup> setup{MakeNoLogFileContext<const TestingSetup>()};
34+
std::unique_ptr<const TestingSetup> setup{
35+
MakeNoLogFileContext<const TestingSetup>(
36+
ChainType::REGTEST,
37+
TestOpts{
38+
.setup_net = false,
39+
.setup_validation_interface = false,
40+
})};
3541
const auto& node = setup->m_node;
3642
auto& chainman{*node.chainman};
3743

src/test/util/setup_common.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,11 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
230230

231231
// We have to run a scheduler thread to prevent ActivateBestChain
232232
// from blocking due to queue overrun.
233-
m_node.scheduler = std::make_unique<CScheduler>();
234-
m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); });
235-
m_node.validation_signals = std::make_unique<ValidationSignals>(std::make_unique<SerialTaskRunner>(*m_node.scheduler));
233+
if (opts.setup_validation_interface) {
234+
m_node.scheduler = std::make_unique<CScheduler>();
235+
m_node.scheduler->m_service_thread = std::thread(util::TraceThread, "scheduler", [&] { m_node.scheduler->serviceQueue(); });
236+
m_node.validation_signals = std::make_unique<ValidationSignals>(std::make_unique<SerialTaskRunner>(*m_node.scheduler));
237+
}
236238

237239
m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>(FeeestPath(*m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES);
238240
bilingual_str error{};
@@ -267,7 +269,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, TestOpts opts)
267269
ChainTestingSetup::~ChainTestingSetup()
268270
{
269271
if (m_node.scheduler) m_node.scheduler->stop();
270-
m_node.validation_signals->FlushBackgroundCallbacks();
272+
if (m_node.validation_signals) m_node.validation_signals->FlushBackgroundCallbacks();
271273
m_node.connman.reset();
272274
m_node.banman.reset();
273275
m_node.addrman.reset();
@@ -318,6 +320,8 @@ TestingSetup::TestingSetup(
318320

319321
LoadVerifyActivateChainstate();
320322

323+
if (!opts.setup_net) return;
324+
321325
m_node.netgroupman = std::make_unique<NetGroupManager>(/*asmap=*/std::vector<bool>());
322326
m_node.addrman = std::make_unique<AddrMan>(*m_node.netgroupman,
323327
/*deterministic=*/false,

src/test/util/setup_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ struct TestOpts {
5353
std::vector<const char*> extra_args{};
5454
bool coins_db_in_memory{true};
5555
bool block_tree_db_in_memory{true};
56+
bool setup_net{true};
57+
bool setup_validation_interface{true};
5658
};
5759

5860
/** Basic testing setup.

0 commit comments

Comments
 (0)