File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 5
5
#include < test/fuzz/util/check_globals.h>
6
6
7
7
#include < test/util/random.h>
8
+ #include < util/time.h>
8
9
9
10
#include < iostream>
10
11
#include < memory>
@@ -16,6 +17,8 @@ struct CheckGlobalsImpl {
16
17
{
17
18
g_used_g_prng = false ;
18
19
g_seeded_g_prng_zero = false ;
20
+ g_used_system_time = false ;
21
+ SetMockTime (0s);
19
22
}
20
23
~CheckGlobalsImpl ()
21
24
{
@@ -34,6 +37,19 @@ struct CheckGlobalsImpl {
34
37
<< std::endl;
35
38
std::abort (); // Abort, because AFL may try to recover from a std::exit
36
39
}
40
+
41
+ if (g_used_system_time) {
42
+ std::cerr << " \n\n "
43
+ " The current fuzz target accessed system time.\n\n "
44
+
45
+ " This is acceptable, but requires the fuzz target to call \n "
46
+ " SetMockTime() at the beginning of processing the fuzz input.\n\n "
47
+
48
+ " Without setting mock time, time-dependent behavior can lead \n "
49
+ " to non-reproducible bugs or inefficient fuzzing.\n\n "
50
+ << std::endl;
51
+ std::abort ();
52
+ }
37
53
}
38
54
};
39
55
Original file line number Diff line number Diff line change 5
5
#ifndef BITCOIN_TEST_FUZZ_UTIL_CHECK_GLOBALS_H
6
6
#define BITCOIN_TEST_FUZZ_UTIL_CHECK_GLOBALS_H
7
7
8
+ #include < atomic>
8
9
#include < memory>
9
10
#include < optional>
10
11
#include < string>
11
12
13
+ extern std::atomic<bool > g_used_system_time;
14
+
12
15
struct CheckGlobalsImpl ;
13
16
struct CheckGlobals {
14
17
CheckGlobals ();
Original file line number Diff line number Diff line change 20
20
void UninterruptibleSleep (const std::chrono::microseconds& n) { std::this_thread::sleep_for (n); }
21
21
22
22
static std::atomic<std::chrono::seconds> g_mock_time{}; // !< For testing
23
+ std::atomic<bool > g_used_system_time{false };
23
24
24
25
NodeClock::time_point NodeClock::now () noexcept
25
26
{
26
27
const auto mocktime{g_mock_time.load (std::memory_order_relaxed)};
28
+ if (!mocktime.count ()) {
29
+ g_used_system_time = true ;
30
+ }
27
31
const auto ret{
28
32
mocktime.count () ?
29
33
mocktime :
You can’t perform that action at this time.
0 commit comments