mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
fuzz: make it possible to mock (fuzz) CThreadInterrupt
* Make the methods of `CThreadInterrupt` virtual and store a pointer to it in `CConnman`, thus making it possible to override with a mocked instance. * Initialize `CConnman::m_interrupt_net` from the constructor, making it possible for callers to supply mocked version. * Introduce `FuzzedThreadInterrupt` and `ConsumeThreadInterrupt()` and use them in `src/test/fuzz/connman.cpp` and `src/test/fuzz/i2p.cpp`. This improves the CPU utilization of the `connman` fuzz test. As a nice side effect, the `std::shared_ptr` used for `CConnman::m_interrupt_net` resolves the possible lifetime issues with it (see the removed comment for that variable).
This commit is contained in:
@@ -50,10 +50,10 @@ BOOST_AUTO_TEST_CASE(unlimited_recv)
|
||||
return std::make_unique<StaticContentsSock>(std::string(i2p::sam::MAX_MSG_SIZE + 1, 'a'));
|
||||
};
|
||||
|
||||
CThreadInterrupt interrupt;
|
||||
auto interrupt{std::make_shared<CThreadInterrupt>()};
|
||||
const std::optional<CService> addr{Lookup("127.0.0.1", 9000, false)};
|
||||
const Proxy sam_proxy(addr.value(), /*tor_stream_isolation=*/false);
|
||||
i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key", sam_proxy, &interrupt);
|
||||
i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key", sam_proxy, interrupt);
|
||||
|
||||
{
|
||||
ASSERT_DEBUG_LOG("Creating persistent SAM session");
|
||||
@@ -112,12 +112,12 @@ BOOST_AUTO_TEST_CASE(listen_ok_accept_fail)
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
CThreadInterrupt interrupt;
|
||||
auto interrupt{std::make_shared<CThreadInterrupt>()};
|
||||
const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), /*port=*/7656};
|
||||
const Proxy sam_proxy(addr, /*tor_stream_isolation=*/false);
|
||||
i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key",
|
||||
sam_proxy,
|
||||
&interrupt);
|
||||
interrupt);
|
||||
|
||||
i2p::Connection conn;
|
||||
for (size_t i = 0; i < 5; ++i) {
|
||||
@@ -155,10 +155,10 @@ BOOST_AUTO_TEST_CASE(damaged_private_key)
|
||||
"391 bytes"}}) {
|
||||
BOOST_REQUIRE(WriteBinaryFile(i2p_private_key_file, file_contents));
|
||||
|
||||
CThreadInterrupt interrupt;
|
||||
auto interrupt{std::make_shared<CThreadInterrupt>()};
|
||||
const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), /*port=*/7656};
|
||||
const Proxy sam_proxy{addr, /*tor_stream_isolation=*/false};
|
||||
i2p::sam::Session session(i2p_private_key_file, sam_proxy, &interrupt);
|
||||
i2p::sam::Session session(i2p_private_key_file, sam_proxy, interrupt);
|
||||
|
||||
{
|
||||
ASSERT_DEBUG_LOG("Creating persistent SAM session");
|
||||
|
||||
Reference in New Issue
Block a user