Bitcoin Core  22.99.0
P2P Digital Currency
checkqueue.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 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 
14 namespace {
15 struct DumbCheck {
16  const bool result = false;
17 
18  DumbCheck() = default;
19 
20  explicit DumbCheck(const bool _result) : result(_result)
21  {
22  }
23 
24  bool operator()() const
25  {
26  return result;
27  }
28 
29  void swap(DumbCheck& x)
30  {
31  }
32 };
33 } // namespace
34 
35 FUZZ_TARGET(checkqueue)
36 {
37  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
38 
39  const unsigned int batch_size = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1024);
40  CCheckQueue<DumbCheck> check_queue_1{batch_size};
41  CCheckQueue<DumbCheck> check_queue_2{batch_size};
42  std::vector<DumbCheck> checks_1;
43  std::vector<DumbCheck> checks_2;
44  const int size = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 1024);
45  for (int i = 0; i < size; ++i) {
46  const bool result = fuzzed_data_provider.ConsumeBool();
47  checks_1.emplace_back(result);
48  checks_2.emplace_back(result);
49  }
50  if (fuzzed_data_provider.ConsumeBool()) {
51  check_queue_1.Add(checks_1);
52  }
53  if (fuzzed_data_provider.ConsumeBool()) {
54  (void)check_queue_1.Wait();
55  }
56 
57  CCheckQueueControl<DumbCheck> check_queue_control{&check_queue_2};
58  if (fuzzed_data_provider.ConsumeBool()) {
59  check_queue_control.Add(checks_2);
60  }
61  if (fuzzed_data_provider.ConsumeBool()) {
62  (void)check_queue_control.Wait();
63  }
64 }
util.h
CCheckQueueControl::Add
void Add(std::vector< T > &vChecks)
Definition: checkqueue.h:231
checkqueue.h
CCheckQueue
Queue for verifications that have to be performed.
Definition: checkqueue.h:29
FUZZ_TARGET
FUZZ_TARGET(checkqueue)
Definition: checkqueue.cpp:35
FuzzedDataProvider.h
CCheckQueueControl
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
Definition: checkqueue.h:16
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition: FuzzedDataProvider.h:288
FuzzedDataProvider::ConsumeIntegralInRange
T ConsumeIntegralInRange(T min, T max)
Definition: FuzzedDataProvider.h:204