|
| 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> |
| 6 | +#include <optional.h> |
| 7 | +#include <test/fuzz/FuzzedDataProvider.h> |
| 8 | +#include <test/fuzz/fuzz.h> |
| 9 | +#include <test/fuzz/util.h> |
| 10 | + |
| 11 | +#include <cstdint> |
| 12 | +#include <string> |
| 13 | +#include <vector> |
| 14 | + |
| 15 | +namespace { |
| 16 | +struct DumbCheck { |
| 17 | + const bool result = false; |
| 18 | + |
| 19 | + DumbCheck() = default; |
| 20 | + |
| 21 | + explicit DumbCheck(const bool _result) : result(_result) |
| 22 | + { |
| 23 | + } |
| 24 | + |
| 25 | + bool operator()() const |
| 26 | + { |
| 27 | + return result; |
| 28 | + } |
| 29 | + |
| 30 | + void swap(DumbCheck& x) |
| 31 | + { |
| 32 | + } |
| 33 | +}; |
| 34 | +} // namespace |
| 35 | + |
| 36 | +void test_one_input(const std::vector<uint8_t>& buffer) |
| 37 | +{ |
| 38 | + FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
| 39 | + |
| 40 | + const unsigned int batch_size = fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 1024); |
| 41 | + CCheckQueue<DumbCheck> check_queue_1{batch_size}; |
| 42 | + CCheckQueue<DumbCheck> check_queue_2{batch_size}; |
| 43 | + std::vector<DumbCheck> checks_1; |
| 44 | + std::vector<DumbCheck> checks_2; |
| 45 | + const int size = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 1024); |
| 46 | + for (int i = 0; i < size; ++i) { |
| 47 | + const bool result = fuzzed_data_provider.ConsumeBool(); |
| 48 | + checks_1.emplace_back(result); |
| 49 | + checks_2.emplace_back(result); |
| 50 | + } |
| 51 | + if (fuzzed_data_provider.ConsumeBool()) { |
| 52 | + check_queue_1.Add(checks_1); |
| 53 | + } |
| 54 | + if (fuzzed_data_provider.ConsumeBool()) { |
| 55 | + (void)check_queue_1.Wait(); |
| 56 | + } |
| 57 | + |
| 58 | + CCheckQueueControl<DumbCheck> check_queue_control{&check_queue_2}; |
| 59 | + if (fuzzed_data_provider.ConsumeBool()) { |
| 60 | + check_queue_control.Add(checks_2); |
| 61 | + } |
| 62 | + if (fuzzed_data_provider.ConsumeBool()) { |
| 63 | + (void)check_queue_control.Wait(); |
| 64 | + } |
| 65 | +} |
0 commit comments