blob: 7d107995aa415504f9ea1a704ea8d40ff9049f26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// 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 <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) noexcept
{
}
};
} // namespace
FUZZ_TARGET(checkqueue)
{
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();
}
}
|