Bitcoin Core 28.99.0
P2P Digital Currency
checkqueue.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <checkqueue.h>
7#include <test/fuzz/fuzz.h>
8#include <test/fuzz/util.h>
9
10#include <cstdint>
11#include <string>
12#include <vector>
13
14namespace {
15struct DumbCheck {
16 bool result = false;
17
18 explicit DumbCheck(const bool _result) : result(_result)
19 {
20 }
21
22 std::optional<int> operator()() const
23 {
24 if (result) return std::nullopt;
25 return 1;
26 }
27};
28} // namespace
29
30FUZZ_TARGET(checkqueue)
31{
32 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
33
34 const unsigned int batch_size = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1024);
35 CCheckQueue<DumbCheck> check_queue_1{batch_size, /*worker_threads_num=*/0};
36 CCheckQueue<DumbCheck> check_queue_2{batch_size, /*worker_threads_num=*/0};
37 std::vector<DumbCheck> checks_1;
38 std::vector<DumbCheck> checks_2;
39 const int size = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 1024);
40 for (int i = 0; i < size; ++i) {
41 const bool result = fuzzed_data_provider.ConsumeBool();
42 checks_1.emplace_back(result);
43 checks_2.emplace_back(result);
44 }
45 if (fuzzed_data_provider.ConsumeBool()) {
46 check_queue_1.Add(std::move(checks_1));
47 }
48 if (fuzzed_data_provider.ConsumeBool()) {
49 (void)check_queue_1.Complete();
50 }
51
52 CCheckQueueControl<DumbCheck> check_queue_control{&check_queue_2};
53 if (fuzzed_data_provider.ConsumeBool()) {
54 check_queue_control.Add(std::move(checks_2));
55 }
56 if (fuzzed_data_provider.ConsumeBool()) {
57 (void)check_queue_control.Complete();
58 }
59}
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
Definition: checkqueue.h:209
void Add(std::vector< T > &&vChecks)
Definition: checkqueue.h:234
Queue for verifications that have to be performed.
Definition: checkqueue.h:34
T ConsumeIntegralInRange(T min, T max)
FUZZ_TARGET(checkqueue)
Definition: checkqueue.cpp:30