Add test_fuzzing_harnesses.sh
for easy verification that our fuzz harnesses work the way we expect them to work. One thing tested is that we are able to reach different unique code paths when varying input.
Each fuzz target is given one second of running time after which coverage is evaluated.
Intentionally running without a starting corpus to make sure the fuzzers can evolve from thin air :)
The total running time of test_fuzzing_harnesses.sh
is less than a minute.
Example output:
0$ CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzzer,undefined
1$ make
2$ contrib/devtools/test_fuzzing_harnesses.sh
3Found 21 fuzz harnesses to test.
4
5Testing fuzzer address_deserialize during 1 second(s)
6A subset of reached functions:
7 NEW_FUNC[1/6]: 0x5592a0fa3430 in CDataStream& CDataStream::operator>><CAddress&>(CAddress&) src/./streams.h:460
8 NEW_FUNC[2/6]: 0x5592a0fa4950 in void CAddress::SerializationOp<CDataStream, CSerActionUnserialize>(CDataStream&, CSerActionUnserialize) src/./protocol.h:337
9 NEW_FUNC[3/6]: 0x5592a1ed2360 in CService::CService() src/netaddress.cpp:570
10 NEW_FUNC[4/6]: 0x5592a1f03670 in CAddress::CAddress() src/protocol.cpp:145
11 NEW_FUNC[5/6]: 0x5592a1f03780 in CAddress::Init() src/protocol.cpp:156
12 NEW_FUNC[0/3]: 0x5592a0fa5440 in void SerReadWriteMany<CDataStream, CService&>(CDataStream&, CSerActionUnserialize, CService&) src/./serialize.h:989
13 NEW_FUNC[1/3]: 0x5592a0fa5670 in void CService::SerializationOp<CDataStream, CSerActionUnserialize>(CDataStream&, CSerActionUnserialize) src/./netaddress.h:167
14 NEW_FUNC[2/3]: 0x5592a0fa5ac0 in void BigEndian<unsigned short>::Unserialize<CDataStream>(CDataStream&) src/./serialize.h:474
15stat::number_of_executed_units: 10343
16stat::average_exec_per_sec: 5171
17stat::new_units_added: 41
18stat::slowest_unit_time_sec: 0
19stat::peak_rss_mb: 147
20Number of unique code paths reached during fuzzing round: 13
21
22Testing fuzzer addrman_deserialize during 1 second(s)
23A subset of reached functions:
24 NEW_FUNC[0/61]: 0x55c567eabaa0 in UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::UniqueLock(AnnotatedMixin<std::recursive_mutex>&, char const*, char const*, int, bool) src/./sync.h:146
25 NEW_FUNC[1/61]: 0x55c567eabf00 in UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::~UniqueLock() src/./sync.h:165
26 NEW_FUNC[2/61]: 0x55c567eae5b0 in FastRandomContext::FillByteBuffer() src/./random.h:114
27 NEW_FUNC[3/61]: 0x55c567eca850 in uint256::uint256() src/./uint256.h:123
28 NEW_FUNC[4/61]: 0x55c567ed4f50 in UniqueLock<AnnotatedMixin<std::recursive_mutex>, std::unique_lock<std::recursive_mutex> >::Enter(char const*, char const*, int) src/./sync.h:123
29 NEW_FUNC[12/61]: 0x55c567f07320 in CDataStream& CDataStream::operator>><unsigned char&>(unsigned char&) src/./streams.h:460
30 NEW_FUNC[13/61]: 0x55c567f1d750 in CAddrMan::CAddrMan() src/./addrman.h:481
31 NEW_FUNC[14/61]: 0x55c567f1dec0 in CDataStream& CDataStream::operator>><CAddrMan&>(CAddrMan&) src/./streams.h:460
32 NEW_FUNC[15/61]: 0x55c567f1e050 in CAddrMan::~CAddrMan() src/./addrman.h:486
33 NEW_FUNC[16/61]: 0x55c567f1e250 in CAddrMan::Clear() src/./addrman.h:457
34stat::number_of_executed_units: 394
35stat::average_exec_per_sec: 197
36stat::new_units_added: 14
37stat::slowest_unit_time_sec: 0
38stat::peak_rss_mb: 111
39Number of unique code paths reached during fuzzing round: 12
40
41…
42
43All fuzz harnesses seem to work as expected.
Commits:
- Add
contrib/devtools/test_fuzzing_harnesses.sh
- Run
test_fuzzing_harnesses.sh
as part ofRUN_FUZZ_TESTS
in Travis - Enable UBSan for Travis fuzzer job