Skip to content

Commit

Permalink
[DROP]: Refactor test setup to print error messages
Browse files Browse the repository at this point in the history
Just to check CI errors. Do not merge.
  • Loading branch information
furszy committed Nov 6, 2024
1 parent 8297773 commit 804be58
Show file tree
Hide file tree
Showing 42 changed files with 259 additions and 162 deletions.
2 changes: 1 addition & 1 deletion src/bench/block_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

static void AssembleBlock(benchmark::Bench& bench)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
const auto test_setup = MakeNoLogFileContext<TestingSetup>();

CScriptWitness witness;
witness.stack.push_back(WITNESS_STACK_ELEM_OP_TRUE);
Expand Down
2 changes: 1 addition & 1 deletion src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

static void DuplicateInputs(benchmark::Bench& bench)
{
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
const auto testing_setup = MakeNoLogFileContext<TestingSetup>();

const CScript SCRIPT_PUB{CScript(OP_TRUE)};

Expand Down
2 changes: 1 addition & 1 deletion src/bench/load_external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
static void LoadExternalBlockFile(benchmark::Bench& bench)
{
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
const auto testing_setup{MakeNoLogFileContext<TestingSetup>(ChainType::MAIN)};

// Create a single block as in the blocks files (magic bytes, block size,
// block data) as a stream object.
Expand Down
2 changes: 1 addition & 1 deletion src/bench/mempool_eviction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void AddTx(const CTransactionRef& tx, const CAmount& nFee, CTxMemPool& po
// unique transactions for a more meaningful performance measurement.
static void MempoolEviction(benchmark::Bench& bench)
{
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
const auto testing_setup = MakeNoLogFileContext<TestingSetup>();

CMutableTransaction tx1 = CMutableTransaction();
tx1.vin.resize(1);
Expand Down
2 changes: 1 addition & 1 deletion src/bench/mempool_stress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void ComplexMemPool(benchmark::Bench& bench)
childTxs = static_cast<int>(bench.complexityN());
}
std::vector<CTransactionRef> ordered_coins = CreateOrderedCoins(det_rand, childTxs, /*min_ancestors=*/1);
const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN);
const auto testing_setup = MakeNoLogFileContext<TestingSetup>(ChainType::MAIN);
CTxMemPool& pool = *testing_setup.get()->m_node.mempool;
LOCK2(cs_main, pool.cs);
bench.run([&]() NO_THREAD_SAFETY_ANALYSIS {
Expand Down
4 changes: 2 additions & 2 deletions src/bench/readblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static FlatFilePos WriteBlockToDisk(ChainstateManager& chainman)

static void ReadBlockFromDiskTest(benchmark::Bench& bench)
{
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
const auto testing_setup{MakeNoLogFileContext<TestingSetup>(ChainType::MAIN)};
ChainstateManager& chainman{*testing_setup->m_node.chainman};

CBlock block;
Expand All @@ -44,7 +44,7 @@ static void ReadBlockFromDiskTest(benchmark::Bench& bench)

static void ReadRawBlockFromDiskTest(benchmark::Bench& bench)
{
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
const auto testing_setup{MakeNoLogFileContext<TestingSetup>(ChainType::MAIN)};
ChainstateManager& chainman{*testing_setup->m_node.chainman};

std::vector<uint8_t> block_data;
Expand Down
2 changes: 1 addition & 1 deletion src/bench/rpc_blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace {

struct TestBlockAndIndex {
const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<TestingSetup>(ChainType::MAIN)};
CBlock block{};
uint256 blockHash{};
CBlockIndex blockindex{};
Expand Down
2 changes: 1 addition & 1 deletion src/bench/rpc_mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void AddTx(const CTransactionRef& tx, const CAmount& fee, CTxMemPool& poo

static void RpcMempool(benchmark::Bench& bench)
{
const auto testing_setup = MakeNoLogFileContext<const ChainTestingSetup>(ChainType::MAIN);
const auto testing_setup = MakeNoLogFileContext<ChainTestingSetup>(ChainType::MAIN);
CTxMemPool& pool = *Assert(testing_setup->m_node.mempool);
LOCK2(cs_main, pool.cs);

Expand Down
2 changes: 1 addition & 1 deletion src/bench/wallet_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
namespace wallet {
static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
const auto test_setup = MakeNoLogFileContext<TestingSetup>();

const auto& ADDRESS_WATCHONLY = ADDRESS_BCRT1_UNSPENDABLE;

Expand Down
4 changes: 2 additions & 2 deletions src/bench/wallet_create_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct PreSelectInputs {

static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type, bool allow_other_inputs, std::optional<PreSelectInputs> preset_inputs)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
const auto test_setup = MakeNoLogFileContext<TestingSetup>();

// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
SetMockTime(test_setup->m_node.chainman->GetParams().GenesisBlock().nTime);
Expand Down Expand Up @@ -161,7 +161,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type

static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType>& output_type)
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
const auto test_setup = MakeNoLogFileContext<TestingSetup>();
// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
SetMockTime(test_setup->m_node.chainman->GetParams().GenesisBlock().nTime);
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
Expand Down
1 change: 1 addition & 0 deletions src/qt/test/addressbooktests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void EditAddressAndSubmit(
void TestAddAddressesToSendBook(interfaces::Node& node)
{
TestChain100Setup test;
test.setup();
auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
test.m_node.wallet_loader = wallet_loader.get();
node.setContext(&test.m_node);
Expand Down
1 change: 1 addition & 0 deletions src/qt/test/rpcnestedtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void RPCNestedTests::rpcNestedTests()
}

TestingSetup test;
test.setup();
m_node.setContext(&test.m_node);

if (RPCIsInWarmup(nullptr)) SetRPCWarmupFinished();
Expand Down
1 change: 1 addition & 0 deletions src/qt/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ int main(int argc, char* argv[])
// All tests must use their own testing setup (if needed).
fs::create_directories([] {
BasicTestingSetup dummy{ChainType::REGTEST};
dummy.setup();
return gArgs.GetDataDirNet() / "blocks";
}());

Expand Down
1 change: 1 addition & 0 deletions src/qt/test/wallettests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ void TestGUI(interfaces::Node& node)
{
// Set up wallet and chain with 105 blocks (5 mature blocks for spending).
TestChain100Setup test;
test.setup();
for (int i = 0; i < 5; ++i) {
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/connman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int32_t GetCheckRatio()

void initialize_connman()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>();
g_setup = testing_setup.get();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/load_external_block_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TestingSetup* g_setup;

void initialize_load_external_block_file()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>();
g_setup = testing_setup.get();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/mini_miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const TestingSetup* g_setup;
std::deque<COutPoint> g_available_coins;
void initialize_miner()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>();
g_setup = testing_setup.get();
for (uint32_t i = 0; i < uint32_t{100}; ++i) {
g_available_coins.emplace_back(Txid::FromUint256(uint256::ZERO), i);
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/p2p_handshake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const TestingSetup* g_setup;

void initialize()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>(
/*chain_type=*/ChainType::REGTEST);
g_setup = testing_setup.get();
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/fuzz/p2p_headers_presync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class HeadersSyncSetup : public TestingSetup
public:
HeadersSyncSetup(const ChainType chain_type, TestOpts opts) : TestingSetup(chain_type, opts)
{

}

void setup()
{
TestingSetup::setup();
PeerManager::Options peerman_opts;
node::ApplyArgsManOptions(*m_node.args, peerman_opts);
peerman_opts.max_headers_result = FUZZ_MAX_HEADERS_RESULTS;
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/package_eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct MockedTxPool : public CTxMemPool {

void initialize_tx_pool()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>();
g_setup = testing_setup.get();

for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/partially_downloaded_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const TestingSetup* g_setup;

void initialize_pdb()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>();
g_setup = testing_setup.get();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/process_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void initialize_process_message()
Assert(std::count(ALL_NET_MESSAGE_TYPES.begin(), ALL_NET_MESSAGE_TYPES.end(), LIMIT_TO_MESSAGE_TYPE)); // Unknown message type passed
}

static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>(
/*chain_type=*/ChainType::REGTEST,
{.extra_args = {"-txreconciliation"}});
g_setup = testing_setup.get();
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/process_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const TestingSetup* g_setup;

void initialize_process_messages()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>(
/*chain_type=*/ChainType::REGTEST,
{.extra_args = {"-txreconciliation"}});
g_setup = testing_setup.get();
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/socks5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ decltype(g_socks5_recv_timeout) default_socks5_recv_timeout;

void initialize_socks5()
{
static const auto testing_setup = MakeNoLogFileContext<const BasicTestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<BasicTestingSetup>();
default_socks5_recv_timeout = g_socks5_recv_timeout;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct MockedTxPool : public CTxMemPool {

void initialize_tx_pool()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>();
g_setup = testing_setup.get();

for (int i = 0; i < 2 * COINBASE_MATURITY; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/txdownloadman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static std::vector<COutPoint> PickCoins(FuzzedDataProvider& fuzzed_data_provider

void initialize()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>();
g_setup = testing_setup.get();
for (uint32_t i = 0; i < uint32_t{NUM_COINS}; ++i) {
COINS[i] = COutPoint{Txid::FromUint256((HashWriter() << i).GetHash()), i};
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/validation_load_mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const TestingSetup* g_setup;

void initialize_validation_load_mempool()
{
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
static const auto testing_setup = MakeNoLogFileContext<TestingSetup>();
g_setup = testing_setup.get();
}

Expand Down
23 changes: 14 additions & 9 deletions src/test/logging_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@ struct LogSetup : public BasicTestingSetup {
std::unordered_map<BCLog::LogFlags, BCLog::Level> prev_category_levels;
BCLog::Level prev_log_level;

LogSetup() : prev_log_path{LogInstance().m_file_path},
tmp_log_path{m_args.GetDataDirBase() / "tmp_debug.log"},
prev_reopen_file{LogInstance().m_reopen_file},
prev_print_to_file{LogInstance().m_print_to_file},
prev_log_timestamps{LogInstance().m_log_timestamps},
prev_log_threadnames{LogInstance().m_log_threadnames},
prev_log_sourcelocations{LogInstance().m_log_sourcelocations},
prev_category_levels{LogInstance().CategoryLevels()},
prev_log_level{LogInstance().LogLevel()}
LogSetup() {}

void setup()
{
BasicTestingSetup::setup();
prev_log_path = LogInstance().m_file_path;
tmp_log_path = m_args.GetDataDirBase() / "tmp_debug.log";
prev_reopen_file = LogInstance().m_reopen_file;
prev_print_to_file = LogInstance().m_print_to_file;
prev_log_timestamps = LogInstance().m_log_timestamps;
prev_log_threadnames = LogInstance().m_log_threadnames;
prev_log_sourcelocations = LogInstance().m_log_sourcelocations;
prev_category_levels = LogInstance().CategoryLevels();
prev_log_level = LogInstance().LogLevel();

LogInstance().m_file_path = tmp_log_path;
LogInstance().m_reopen_file = true;
LogInstance().m_print_to_file = true;
Expand Down
Loading

0 comments on commit 804be58

Please sign in to comment.