/root/bitcoin/src/test/fuzz/util/threadinterrupt.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2024-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 | | #ifndef BITCOIN_TEST_FUZZ_UTIL_THREADINTERRUPT_H |
6 | | #define BITCOIN_TEST_FUZZ_UTIL_THREADINTERRUPT_H |
7 | | |
8 | | #include <test/fuzz/FuzzedDataProvider.h> |
9 | | #include <util/threadinterrupt.h> |
10 | | |
11 | | #include <memory> |
12 | | |
13 | | /** |
14 | | * Mocked CThreadInterrupt that returns "randomly" whether it is interrupted and never sleeps. |
15 | | */ |
16 | | class FuzzedThreadInterrupt : public CThreadInterrupt |
17 | | { |
18 | | public: |
19 | | explicit FuzzedThreadInterrupt(FuzzedDataProvider& fuzzed_data_provider); |
20 | | |
21 | | virtual bool interrupted() const override; |
22 | | virtual bool sleep_for(Clock::duration) override; |
23 | | |
24 | | private: |
25 | | FuzzedDataProvider& m_fuzzed_data_provider; |
26 | | }; |
27 | | |
28 | | [[nodiscard]] inline std::shared_ptr<CThreadInterrupt> ConsumeThreadInterrupt(FuzzedDataProvider& fuzzed_data_provider) |
29 | 0 | { |
30 | 0 | return std::make_shared<FuzzedThreadInterrupt>(fuzzed_data_provider); |
31 | 0 | } |
32 | | |
33 | | #endif // BITCOIN_TEST_FUZZ_UTIL_THREADINTERRUPT_H |