mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
fuzz: Initialize a TestingSetup for test_one_input
For fuzz tests that need it.
This commit is contained in:
parent
0d61634c06
commit
ee0ab1e959
3 changed files with 15 additions and 3 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
const TestingSetup* g_setup;
|
||||||
const Coin EMPTY_COIN{};
|
const Coin EMPTY_COIN{};
|
||||||
|
|
||||||
bool operator==(const Coin& a, const Coin& b)
|
bool operator==(const Coin& a, const Coin& b)
|
||||||
|
@ -39,6 +40,7 @@ bool operator==(const Coin& a, const Coin& b)
|
||||||
void initialize_coins_view()
|
void initialize_coins_view()
|
||||||
{
|
{
|
||||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
|
g_setup = testing_setup.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
|
FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
|
||||||
|
@ -268,7 +270,7 @@ FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
|
||||||
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
|
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
|
||||||
bool expected_code_path = false;
|
bool expected_code_path = false;
|
||||||
try {
|
try {
|
||||||
(void)GetUTXOStats(&coins_view_cache, WITH_LOCK(::cs_main, return std::ref(g_chainman.m_blockman)), stats);
|
(void)GetUTXOStats(&coins_view_cache, WITH_LOCK(::cs_main, return std::ref(g_setup->m_node.chainman->m_blockman)), stats);
|
||||||
} catch (const std::logic_error&) {
|
} catch (const std::logic_error&) {
|
||||||
expected_code_path = true;
|
expected_code_path = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,14 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const TestingSetup* g_setup;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void initialize_load_external_block_file()
|
void initialize_load_external_block_file()
|
||||||
{
|
{
|
||||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
|
g_setup = testing_setup.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
FUZZ_TARGET_INIT(load_external_block_file, initialize_load_external_block_file)
|
FUZZ_TARGET_INIT(load_external_block_file, initialize_load_external_block_file)
|
||||||
|
@ -27,5 +32,5 @@ FUZZ_TARGET_INIT(load_external_block_file, initialize_load_external_block_file)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FlatFilePos flat_file_pos;
|
FlatFilePos flat_file_pos;
|
||||||
::ChainstateActive().LoadExternalBlockFile(Params(), fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
|
g_setup->m_node.chainman->ActiveChainstate().LoadExternalBlockFile(Params(), fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,14 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const TestingSetup* g_setup;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void initialize_validation_load_mempool()
|
void initialize_validation_load_mempool()
|
||||||
{
|
{
|
||||||
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
|
||||||
|
g_setup = testing_setup.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
|
FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
|
||||||
|
@ -29,6 +34,6 @@ FUZZ_TARGET_INIT(validation_load_mempool, initialize_validation_load_mempool)
|
||||||
auto fuzzed_fopen = [&](const fs::path&, const char*) {
|
auto fuzzed_fopen = [&](const fs::path&, const char*) {
|
||||||
return fuzzed_file_provider.open();
|
return fuzzed_file_provider.open();
|
||||||
};
|
};
|
||||||
(void)LoadMempool(pool, ::ChainstateActive(), fuzzed_fopen);
|
(void)LoadMempool(pool, g_setup->m_node.chainman->ActiveChainstate(), fuzzed_fopen);
|
||||||
(void)DumpMempool(pool, fuzzed_fopen, true);
|
(void)DumpMempool(pool, fuzzed_fopen, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue