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 55#include < test/fuzz/util/check_globals.h>
66
77#include < test/util/random.h>
8+ #include < util/time.h>
89
910#include < iostream>
1011#include < memory>
@@ -16,6 +17,8 @@ struct CheckGlobalsImpl {
1617 {
1718 g_used_g_prng = false ;
1819 g_seeded_g_prng_zero = false ;
20+ g_used_system_time = false ;
21+ SetMockTime (0s);
1922 }
2023 ~CheckGlobalsImpl ()
2124 {
@@ -34,6 +37,19 @@ struct CheckGlobalsImpl {
3437 << std::endl;
3538 std::abort (); // Abort, because AFL may try to recover from a std::exit
3639 }
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+ }
3753 }
3854};
3955
Original file line number Diff line number Diff line change 55#ifndef BITCOIN_TEST_FUZZ_UTIL_CHECK_GLOBALS_H
66#define BITCOIN_TEST_FUZZ_UTIL_CHECK_GLOBALS_H
77
8+ #include < atomic>
89#include < memory>
910#include < optional>
1011#include < string>
1112
13+ extern std::atomic<bool > g_used_system_time;
14+
1215struct CheckGlobalsImpl ;
1316struct CheckGlobals {
1417 CheckGlobals ();
Original file line number Diff line number Diff line change 2020void UninterruptibleSleep (const std::chrono::microseconds& n) { std::this_thread::sleep_for (n); }
2121
2222static std::atomic<std::chrono::seconds> g_mock_time{}; // !< For testing
23+ std::atomic<bool > g_used_system_time{false };
2324
2425NodeClock::time_point NodeClock::now () noexcept
2526{
2627 const auto mocktime{g_mock_time.load (std::memory_order_relaxed)};
28+ if (!mocktime.count ()) {
29+ g_used_system_time = true ;
30+ }
2731 const auto ret{
2832 mocktime.count () ?
2933 mocktime :
You can’t perform that action at this time.
0 commit comments