mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-25 11:20:49 +02:00
tests: Add fuzzing harness for classes/functions in checkqueue.h
This commit is contained in:
parent
2df5701e90
commit
57890b2555
@ -28,6 +28,7 @@ FUZZ_TARGETS = \
|
||||
test/fuzz/bloom_filter \
|
||||
test/fuzz/bloomfilter_deserialize \
|
||||
test/fuzz/chain \
|
||||
test/fuzz/checkqueue \
|
||||
test/fuzz/coins_deserialize \
|
||||
test/fuzz/decode_tx \
|
||||
test/fuzz/descriptor_parse \
|
||||
@ -431,6 +432,12 @@ test_fuzz_chain_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
test_fuzz_chain_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_chain_SOURCES = test/fuzz/chain.cpp
|
||||
|
||||
test_fuzz_checkqueue_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_checkqueue_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_checkqueue_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
test_fuzz_checkqueue_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_checkqueue_SOURCES = test/fuzz/checkqueue.cpp
|
||||
|
||||
test_fuzz_coins_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DCOINS_DESERIALIZE=1
|
||||
test_fuzz_coins_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_coins_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
65
src/test/fuzz/checkqueue.cpp
Normal file
65
src/test/fuzz/checkqueue.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <checkqueue.h>
|
||||
#include <optional.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
struct DumbCheck {
|
||||
const bool result = false;
|
||||
|
||||
DumbCheck() = default;
|
||||
|
||||
explicit DumbCheck(const bool _result) : result(_result)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator()() const
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
void swap(DumbCheck& x)
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||
|
||||
const unsigned int batch_size = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1024);
|
||||
CCheckQueue<DumbCheck> check_queue_1{batch_size};
|
||||
CCheckQueue<DumbCheck> check_queue_2{batch_size};
|
||||
std::vector<DumbCheck> checks_1;
|
||||
std::vector<DumbCheck> checks_2;
|
||||
const int size = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 1024);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
const bool result = fuzzed_data_provider.ConsumeBool();
|
||||
checks_1.emplace_back(result);
|
||||
checks_2.emplace_back(result);
|
||||
}
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
check_queue_1.Add(checks_1);
|
||||
}
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
(void)check_queue_1.Wait();
|
||||
}
|
||||
|
||||
CCheckQueueControl<DumbCheck> check_queue_control{&check_queue_2};
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
check_queue_control.Add(checks_2);
|
||||
}
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
(void)check_queue_control.Wait();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user