[fuzz] Add serialization to deserialization test

Before commit:
306853	REDUCE cov: 798 ft: 5820 corp: 150/375Kb lim: 68333 exec/s: 1382 rss: 461Mb L: 254/63171 MS: 1 EraseBytes-
1453105	REDUCE cov: 798 ft: 5820 corp: 150/369Kb lim: 79613 exec/s: 1467 rss: 461Mb L: 6027/60873 MS: 1 EraseBytes-

After commit:
303389	NEW    cov: 1202 ft: 8382 corp: 157/382Kb lim: 68189 exec/s: 1451 rss: 447Mb L: 1386/65459 MS: 1 CopyPart-
1428759	REDUCE cov: 1202 ft: 8512 corp: 169/389Kb lim: 78749 exec/s: 1528 rss: 463Mb L: 1627/60488 MS: 1 EraseBytes-
This commit is contained in:
Dhruv Mehta 2021-05-23 08:10:25 -07:00
parent be4171679b
commit 654472a461
2 changed files with 9 additions and 3 deletions

View file

@ -257,7 +257,7 @@ test_fuzz_fuzz_SOURCES = \
test/fuzz/netaddress.cpp \
test/fuzz/netbase_dns_lookup.cpp \
test/fuzz/node_eviction.cpp \
test/fuzz/p2p_transport_deserializer.cpp \
test/fuzz/p2p_transport_serialization.cpp \
test/fuzz/parse_hd_keypath.cpp \
test/fuzz/parse_iso8601.cpp \
test/fuzz/parse_numbers.cpp \

View file

@ -4,6 +4,7 @@
#include <chainparams.h>
#include <net.h>
#include <netmessagemaker.h>
#include <protocol.h>
#include <test/fuzz/fuzz.h>
@ -13,15 +14,16 @@
#include <optional>
#include <vector>
void initialize_p2p_transport_deserializer()
void initialize_p2p_transport_serialization()
{
SelectParams(CBaseChainParams::REGTEST);
}
FUZZ_TARGET_INIT(p2p_transport_deserializer, initialize_p2p_transport_deserializer)
FUZZ_TARGET_INIT(p2p_transport_serialization, initialize_p2p_transport_serialization)
{
// Construct deserializer, with a dummy NodeId
V1TransportDeserializer deserializer{Params(), (NodeId)0, SER_NETWORK, INIT_PROTO_VERSION};
V1TransportSerializer serializer{};
Span<const uint8_t> msg_bytes{buffer};
while (msg_bytes.size() > 0) {
const int handled = deserializer.Read(msg_bytes);
@ -37,6 +39,10 @@ FUZZ_TARGET_INIT(p2p_transport_deserializer, initialize_p2p_transport_deserializ
assert(result->m_raw_message_size <= buffer.size());
assert(result->m_raw_message_size == CMessageHeader::HEADER_SIZE + result->m_message_size);
assert(result->m_time == m_time);
std::vector<unsigned char> header;
auto msg = CNetMsgMaker{result->m_recv.GetVersion()}.Make(result->m_command, MakeUCharSpan(result->m_recv));
serializer.prepareForTransport(msg, header);
}
}
}