mirror of https://github.com/bitcoin/bitcoin.git
fuzz: add Fuzzed NetEventsInterface and use it in connman tests
This commit is contained in:
parent
e883b37768
commit
e6a917c8f8
|
@ -51,6 +51,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
|
|||
}
|
||||
}
|
||||
AddrManDeterministic& addr_man{*addr_man_ptr};
|
||||
auto net_events{ConsumeNetEvents(fuzzed_data_provider)};
|
||||
ConnmanTestMsg connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||
addr_man,
|
||||
|
@ -60,6 +61,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
|
|||
|
||||
const uint64_t max_outbound_limit{fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
|
||||
CConnman::Options options;
|
||||
options.m_msgproc = &net_events;
|
||||
options.nMaxOutboundLimit = max_outbound_limit;
|
||||
connman.Init(options);
|
||||
|
||||
|
|
|
@ -139,6 +139,25 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class FuzzedNetEvents : public NetEventsInterface
|
||||
{
|
||||
public:
|
||||
FuzzedNetEvents(FuzzedDataProvider& fdp) : m_fdp(fdp) {}
|
||||
|
||||
virtual void InitializeNode(const CNode&, ServiceFlags) override {}
|
||||
|
||||
virtual void FinalizeNode(const CNode&) override {}
|
||||
|
||||
virtual bool HasAllDesirableServiceFlags(ServiceFlags) const override { return m_fdp.ConsumeBool(); }
|
||||
|
||||
virtual bool ProcessMessages(CNode*, std::atomic<bool>&) override { return m_fdp.ConsumeBool(); }
|
||||
|
||||
virtual bool SendMessages(CNode*) override { return m_fdp.ConsumeBool(); }
|
||||
|
||||
private:
|
||||
FuzzedDataProvider& m_fdp;
|
||||
};
|
||||
|
||||
class FuzzedSock : public Sock
|
||||
{
|
||||
FuzzedDataProvider& m_fuzzed_data_provider;
|
||||
|
@ -203,6 +222,11 @@ public:
|
|||
bool IsConnected(std::string& errmsg) const override;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline FuzzedNetEvents ConsumeNetEvents(FuzzedDataProvider& fdp) noexcept
|
||||
{
|
||||
return FuzzedNetEvents{fdp};
|
||||
}
|
||||
|
||||
[[nodiscard]] inline FuzzedSock ConsumeSock(FuzzedDataProvider& fuzzed_data_provider)
|
||||
{
|
||||
return FuzzedSock{fuzzed_data_provider};
|
||||
|
|
Loading…
Reference in New Issue