Skip to content

Commit 7f122a4

Browse files
committed
fuzz: non-addrman fuzz tests: override-able check ratio
Make it possible to override from the command line (without recompiling) the addrman check ratio in non-addrman fuzz tests (connman and deserialize) instead of hardcoding it to 0: ``` FUZZ=connman ./src/test/fuzz/fuzz --checkaddrman=5 ```
1 parent 3bd83e2 commit 7f122a4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/test/fuzz/connman.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,29 @@
1212
#include <test/fuzz/fuzz.h>
1313
#include <test/fuzz/util.h>
1414
#include <test/util/setup_common.h>
15+
#include <util/system.h>
1516
#include <util/translation.h>
1617

1718
#include <cstdint>
1819
#include <vector>
1920

21+
namespace {
22+
const BasicTestingSetup* g_setup;
23+
} // namespace
24+
2025
void initialize_connman()
2126
{
2227
static const auto testing_setup = MakeNoLogFileContext<>();
28+
g_setup = testing_setup.get();
2329
}
2430

2531
FUZZ_TARGET_INIT(connman, initialize_connman)
2632
{
2733
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
2834
SetMockTime(ConsumeTime(fuzzed_data_provider));
29-
AddrMan addrman(/*asmap=*/std::vector<bool>(), /*deterministic=*/false, /*consistency_check_ratio=*/0);
35+
AddrMan addrman(/*asmap=*/std::vector<bool>(),
36+
/*deterministic=*/false,
37+
g_setup->m_node.args->GetIntArg("-checkaddrman", 0));
3038
CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>(), addrman, fuzzed_data_provider.ConsumeBool()};
3139
CNetAddr random_netaddr;
3240
CNode random_node = ConsumeNode(fuzzed_data_provider);

src/test/fuzz/deserialize.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#include <pubkey.h>
2323
#include <script/keyorigin.h>
2424
#include <streams.h>
25+
#include <test/util/setup_common.h>
2526
#include <undo.h>
27+
#include <util/system.h>
2628
#include <version.h>
2729

2830
#include <exception>
@@ -35,8 +37,15 @@
3537

3638
using node::SnapshotMetadata;
3739

40+
namespace {
41+
const BasicTestingSetup* g_setup;
42+
} // namespace
43+
3844
void initialize_deserialize()
3945
{
46+
static const auto testing_setup = MakeNoLogFileContext<>();
47+
g_setup = testing_setup.get();
48+
4049
// Fuzzers using pubkey must hold an ECCVerifyHandle.
4150
static const ECCVerifyHandle verify_handle;
4251
}
@@ -191,7 +200,9 @@ FUZZ_TARGET_DESERIALIZE(blockmerkleroot, {
191200
BlockMerkleRoot(block, &mutated);
192201
})
193202
FUZZ_TARGET_DESERIALIZE(addrman_deserialize, {
194-
AddrMan am(/*asmap=*/std::vector<bool>(), /*deterministic=*/false, /*consistency_check_ratio=*/0);
203+
AddrMan am(/*asmap=*/std::vector<bool>(),
204+
/*deterministic=*/false,
205+
g_setup->m_node.args->GetIntArg("-checkaddrman", 0));
195206
DeserializeFromFuzzingInput(buffer, am);
196207
})
197208
FUZZ_TARGET_DESERIALIZE(blockheader_deserialize, {

0 commit comments

Comments
 (0)