Skip to content

Commit 83bdbbd

Browse files
committed
Merge #21003: test: Move MakeNoLogFileContext to libtest_util, and use it in bench
fa576b4 Move MakeNoLogFileContext to common libtest_util, and use it in bench (MarcoFalke) Pull request description: To avoid verbose code duplication, which may lead to accidental mishaps https://github.com/bitcoin/bitcoin/pull/20998/files#r563624041. Also fix a nit I found in bitcoin/bitcoin#20946 (comment). ACKs for top commit: dongcarl: Light Code-Review ACK fa576b4 fanquake: ACK fa576b4 Tree-SHA512: d39ac9c0957813ebb20ed13bd25a8ef8469377ce2651245638bd761c796feac2a17e30dd16f1e5c8db57737fb918c81d56a3d784c33258275e426a1b11e69eb2
2 parents 7450a01 + fa576b4 commit 83bdbbd

15 files changed

+38
-52
lines changed

src/bench/block_assemble.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616

1717
static void AssembleBlock(benchmark::Bench& bench)
1818
{
19-
TestingSetup test_setup{
20-
CBaseChainParams::REGTEST,
21-
/* extra_args */ {
22-
"-nodebuglogfile",
23-
"-nodebug",
24-
},
25-
};
19+
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
2620

2721
const std::vector<unsigned char> op_true{OP_TRUE};
2822
CScriptWitness witness;
@@ -38,7 +32,7 @@ static void AssembleBlock(benchmark::Bench& bench)
3832
std::array<CTransactionRef, NUM_BLOCKS - COINBASE_MATURITY + 1> txs;
3933
for (size_t b{0}; b < NUM_BLOCKS; ++b) {
4034
CMutableTransaction tx;
41-
tx.vin.push_back(MineBlock(test_setup.m_node, SCRIPT_PUB));
35+
tx.vin.push_back(MineBlock(test_setup->m_node, SCRIPT_PUB));
4236
tx.vin.back().scriptWitness = witness;
4337
tx.vout.emplace_back(1337, SCRIPT_PUB);
4438
if (NUM_BLOCKS - b >= COINBASE_MATURITY)
@@ -48,13 +42,13 @@ static void AssembleBlock(benchmark::Bench& bench)
4842
LOCK(::cs_main); // Required for ::AcceptToMemoryPool.
4943

5044
for (const auto& txr : txs) {
51-
const MempoolAcceptResult res = ::AcceptToMemoryPool(::ChainstateActive(), *test_setup.m_node.mempool, txr, false /* bypass_limits */);
45+
const MempoolAcceptResult res = ::AcceptToMemoryPool(::ChainstateActive(), *test_setup->m_node.mempool, txr, false /* bypass_limits */);
5246
assert(res.m_result_type == MempoolAcceptResult::ResultType::VALID);
5347
}
5448
}
5549

5650
bench.run([&] {
57-
PrepareBlock(test_setup.m_node, SCRIPT_PUB);
51+
PrepareBlock(test_setup->m_node, SCRIPT_PUB);
5852
});
5953
}
6054

src/bench/duplicate_inputs.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@
1414

1515
static void DuplicateInputs(benchmark::Bench& bench)
1616
{
17-
TestingSetup test_setup{
18-
CBaseChainParams::REGTEST,
19-
/* extra_args */ {
20-
"-nodebuglogfile",
21-
"-nodebug",
22-
},
23-
};
17+
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
2418

2519
const CScript SCRIPT_PUB{CScript(OP_TRUE)};
2620

src/bench/mempool_eviction.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& po
2525
// unique transactions for a more meaningful performance measurement.
2626
static void MempoolEviction(benchmark::Bench& bench)
2727
{
28-
TestingSetup test_setup{
29-
CBaseChainParams::REGTEST,
30-
/* extra_args */ {
31-
"-nodebuglogfile",
32-
"-nodebug",
33-
},
34-
};
28+
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
3529

3630
CMutableTransaction tx1 = CMutableTransaction();
3731
tx1.vin.resize(1);

src/bench/mempool_stress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void ComplexMemPool(benchmark::Bench& bench)
7979
ordered_coins.emplace_back(MakeTransactionRef(tx));
8080
available_coins.emplace_back(ordered_coins.back(), tx_counter++);
8181
}
82-
TestingSetup test_setup;
82+
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN);
8383
CTxMemPool pool;
8484
LOCK2(cs_main, pool.cs);
8585
bench.run([&]() NO_THREAD_SAFETY_ANALYSIS {

src/bench/rpc_blockchain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace {
1616

1717
struct TestBlockAndIndex {
18-
TestingSetup test_setup{};
18+
const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN)};
1919
CBlock block{};
2020
uint256 blockHash{};
2121
CBlockIndex blockindex{};

src/bench/wallet_balance.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,24 @@
1414

1515
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_watchonly, const bool add_mine)
1616
{
17-
TestingSetup test_setup{
18-
CBaseChainParams::REGTEST,
19-
/* extra_args */ {
20-
"-nodebuglogfile",
21-
"-nodebug",
22-
},
23-
};
17+
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
2418

2519
const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;
2620

27-
CWallet wallet{test_setup.m_node.chain.get(), "", CreateMockWalletDatabase()};
21+
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockWalletDatabase()};
2822
{
2923
wallet.SetupLegacyScriptPubKeyMan();
3024
bool first_run;
3125
if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) assert(false);
3226
}
33-
auto handler = test_setup.m_node.chain->handleNotifications({&wallet, [](CWallet*) {}});
27+
auto handler = test_setup->m_node.chain->handleNotifications({&wallet, [](CWallet*) {}});
3428

3529
const Optional<std::string> address_mine{add_mine ? Optional<std::string>{getnewaddress(wallet)} : nullopt};
3630
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);
3731

3832
for (int i = 0; i < 100; ++i) {
39-
generatetoaddress(test_setup.m_node, address_mine.value_or(ADDRESS_WATCHONLY));
40-
generatetoaddress(test_setup.m_node, ADDRESS_WATCHONLY);
33+
generatetoaddress(test_setup->m_node, address_mine.value_or(ADDRESS_WATCHONLY));
34+
generatetoaddress(test_setup->m_node, ADDRESS_WATCHONLY);
4135
}
4236
SyncWithValidationInterfaceQueue();
4337

src/test/fuzz/banman.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <test/fuzz/FuzzedDataProvider.h>
99
#include <test/fuzz/fuzz.h>
1010
#include <test/fuzz/util.h>
11+
#include <test/util/setup_common.h>
1112
#include <util/system.h>
1213

1314
#include <cstdint>

src/test/fuzz/coins_view.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <test/fuzz/FuzzedDataProvider.h>
1717
#include <test/fuzz/fuzz.h>
1818
#include <test/fuzz/util.h>
19+
#include <test/util/setup_common.h>
1920
#include <validation.h>
2021

2122
#include <cstdint>

src/test/fuzz/connman.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <test/fuzz/FuzzedDataProvider.h>
1111
#include <test/fuzz/fuzz.h>
1212
#include <test/fuzz/util.h>
13+
#include <test/util/setup_common.h>
1314
#include <util/translation.h>
1415

1516
#include <cstdint>

src/test/fuzz/data_stream.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <test/fuzz/FuzzedDataProvider.h>
88
#include <test/fuzz/fuzz.h>
99
#include <test/fuzz/util.h>
10+
#include <test/util/setup_common.h>
1011

1112
#include <cstdint>
1213
#include <vector>

0 commit comments

Comments
 (0)