Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
timeoffsets.cpp
Go to the documentation of this file.
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
#include <
node/timeoffsets.h
>
6
#include <
node/warnings.h
>
7
#include <
test/fuzz/FuzzedDataProvider.h
>
8
#include <
test/fuzz/fuzz.h
>
9
#include <
test/util/setup_common.h
>
10
11
#include <chrono>
12
#include <cstdint>
13
#include <functional>
14
15
void
initialize_timeoffsets
()
16
{
17
static
const
auto
testing_setup =
MakeNoLogFileContext<>
(
ChainType::MAIN
);
18
}
19
20
FUZZ_TARGET
(timeoffsets, .
init
=
initialize_timeoffsets
)
21
{
22
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
23
node::Warnings
warnings{};
24
TimeOffsets
offsets{warnings};
25
LIMITED_WHILE
(fuzzed_data_provider.
remaining_bytes
() > 0, 4'000) {
26
(void)offsets.
Median
();
27
offsets.
Add
(std::chrono::seconds{fuzzed_data_provider.
ConsumeIntegral
<std::chrono::seconds::rep>()});
28
offsets.
WarnIfOutOfSync
();
29
}
30
}
FuzzedDataProvider.h
ChainType::MAIN
@ MAIN
Definition
chaintype.h:12
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::remaining_bytes
size_t remaining_bytes()
Definition
FuzzedDataProvider.h:85
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition
FuzzedDataProvider.h:195
TimeOffsets
Definition
timeoffsets.h:19
TimeOffsets::Add
void Add(std::chrono::seconds offset) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Add a new time offset sample.
Definition
timeoffsets.cpp:22
TimeOffsets::WarnIfOutOfSync
bool WarnIfOutOfSync() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Raise warnings if the median time offset exceeds the warnings threshold.
Definition
timeoffsets.cpp:46
TimeOffsets::Median
std::chrono::seconds Median() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Compute and return the median of the collected time offset samples.
Definition
timeoffsets.cpp:34
node::Warnings
Manages warning messages within a node.
Definition
warnings.h:40
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
LIMITED_WHILE
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition
fuzz.h:22
init
Definition
bitcoin-gui.cpp:17
setup_common.h
MakeNoLogFileContext
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
Definition
setup_common.h:250
initialize_timeoffsets
void initialize_timeoffsets()
Definition
timeoffsets.cpp:15
timeoffsets.h
warnings.h
Generated on
for Bitcoin Core by
1.18.0