Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
checkqueue.cpp
Go to the documentation of this file.
1
// Copyright (c) 2020-present 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
>
6
#include <
test/fuzz/FuzzedDataProvider.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
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
30
FUZZ_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
}
FuzzedDataProvider.h
checkqueue.h
CCheckQueueControl
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
Definition
checkqueue.h:209
CCheckQueueControl::Complete
std::optional< R > Complete()
Definition
checkqueue.h:221
CCheckQueueControl::Add
void Add(std::vector< T > &&vChecks)
Definition
checkqueue.h:228
CCheckQueue
Queue for verifications that have to be performed.
Definition
checkqueue.h:34
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedDataProvider::ConsumeIntegralInRange
T ConsumeIntegralInRange(T min, T max)
Definition
FuzzedDataProvider.h:205
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
util.h
Generated on
for Bitcoin Core by
1.17.0