diff options
author | Dhruv Mehta <856960+dhruv@users.noreply.github.com> | 2021-05-23 08:10:25 -0700 |
---|---|---|
committer | Dhruv Mehta <856960+dhruv@users.noreply.github.com> | 2021-05-25 08:08:34 -0700 |
commit | 654472a461bc9d1603c46dcb7a5b2dc87a44045a (patch) | |
tree | 9f764382d46ccb2a843b3af25a94ea2e905779d6 | |
parent | be4171679b8eab8205e04ff86140329bd67878a0 (diff) | |
download | bitcoin-654472a461bc9d1603c46dcb7a5b2dc87a44045a.tar.xz |
[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-
-rw-r--r-- | src/Makefile.test.include | 2 | ||||
-rw-r--r-- | src/test/fuzz/p2p_transport_serialization.cpp (renamed from src/test/fuzz/p2p_transport_deserializer.cpp) | 10 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/Makefile.test.include b/src/Makefile.test.include index dc79ea3125..35bff51438 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -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 \ diff --git a/src/test/fuzz/p2p_transport_deserializer.cpp b/src/test/fuzz/p2p_transport_serialization.cpp index 3a1fdaad8f..2618a2a398 100644 --- a/src/test/fuzz/p2p_transport_deserializer.cpp +++ b/src/test/fuzz/p2p_transport_serialization.cpp @@ -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); } } } |