fuzz: add Fuzzed NetEventsInterface and use it in connman tests
This commit is contained in:
2 files changed
+26
No files matched your search
@@ -51,6 +51,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
AddrManDeterministic& addr_man{*addr_man_ptr};
|
AddrManDeterministic& addr_man{*addr_man_ptr};
|
||||||
|
auto net_events{ConsumeNetEvents(fuzzed_data_provider)};
|
||||||
ConnmanTestMsg connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
ConnmanTestMsg connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||||
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
||||||
addr_man,
|
addr_man,
|
||||||
@@ -60,6 +61,7 @@ FUZZ_TARGET(connman, .init = initialize_connman)
|
|||||||
|
|
||||||
const uint64_t max_outbound_limit{fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
|
const uint64_t max_outbound_limit{fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
|
||||||
CConnman::Options options;
|
CConnman::Options options;
|
||||||
|
options.m_msgproc = &net_events;
|
||||||
options.nMaxOutboundLimit = max_outbound_limit;
|
options.nMaxOutboundLimit = max_outbound_limit;
|
||||||
connman.Init(options);
|
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
|
class FuzzedSock : public Sock
|
||||||
{
|
{
|
||||||
FuzzedDataProvider& m_fuzzed_data_provider;
|
FuzzedDataProvider& m_fuzzed_data_provider;
|
||||||
@@ -203,6 +222,11 @@ public:
|
|||||||
bool IsConnected(std::string& errmsg) const override;
|
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)
|
[[nodiscard]] inline FuzzedSock ConsumeSock(FuzzedDataProvider& fuzzed_data_provider)
|
||||||
{
|
{
|
||||||
return FuzzedSock{fuzzed_data_provider};
|
return FuzzedSock{fuzzed_data_provider};
|
||||||
|
|||||||
Reference in new issue
Block a user