/root/bitcoin/src/test/fuzz/checkqueue.cpp
Line | Count | Source |
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 | 51.2k | explicit DumbCheck(const bool _result) : result(_result) |
19 | 51.2k | { |
20 | 51.2k | } |
21 | | |
22 | | std::optional<int> operator()() const |
23 | 3.70k | { |
24 | 3.70k | if (result) return std::nullopt; Branch (24:13): [True: 3.55k, False: 142]
|
25 | 142 | return 1; |
26 | 3.70k | } |
27 | | }; |
28 | | } // namespace |
29 | | |
30 | | FUZZ_TARGET(checkqueue) |
31 | 163 | { |
32 | 163 | FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
33 | | |
34 | 163 | const unsigned int batch_size = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1024); |
35 | 163 | CCheckQueue<DumbCheck> check_queue_1{batch_size, /*worker_threads_num=*/0}; |
36 | 163 | CCheckQueue<DumbCheck> check_queue_2{batch_size, /*worker_threads_num=*/0}; |
37 | 163 | std::vector<DumbCheck> checks_1; |
38 | 163 | std::vector<DumbCheck> checks_2; |
39 | 163 | const int size = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 1024); |
40 | 25.8k | for (int i = 0; i < size; ++i) { Branch (40:21): [True: 25.6k, False: 163]
|
41 | 25.6k | const bool result = fuzzed_data_provider.ConsumeBool(); |
42 | 25.6k | checks_1.emplace_back(result); |
43 | 25.6k | checks_2.emplace_back(result); |
44 | 25.6k | } |
45 | 163 | if (fuzzed_data_provider.ConsumeBool()) { Branch (45:9): [True: 121, False: 42]
|
46 | 121 | check_queue_1.Add(std::move(checks_1)); |
47 | 121 | } |
48 | 163 | if (fuzzed_data_provider.ConsumeBool()) { Branch (48:9): [True: 115, False: 48]
|
49 | 115 | (void)check_queue_1.Complete(); |
50 | 115 | } |
51 | | |
52 | 163 | CCheckQueueControl<DumbCheck> check_queue_control{check_queue_2}; |
53 | 163 | if (fuzzed_data_provider.ConsumeBool()) { Branch (53:9): [True: 71, False: 92]
|
54 | 71 | check_queue_control.Add(std::move(checks_2)); |
55 | 71 | } |
56 | 163 | if (fuzzed_data_provider.ConsumeBool()) { Branch (56:9): [True: 21, False: 142]
|
57 | 21 | (void)check_queue_control.Complete(); |
58 | 21 | } |
59 | 163 | } |