Coverage Report

Created: 2026-06-18 19:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/test/fuzz/util/check_globals.cpp
Line
Count
Source
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 <test/fuzz/util/check_globals.h>
6
7
#include <test/util/random.h>
8
#include <util/time.h>
9
10
#include <iostream>
11
#include <memory>
12
#include <optional>
13
#include <string>
14
15
struct CheckGlobalsImpl {
16
    CheckGlobalsImpl()
17
1.56k
    {
18
1.56k
        g_used_g_prng = false;
19
1.56k
        g_seeded_g_prng_zero = false;
20
1.56k
        g_used_system_time = false;
21
1.56k
        SetMockTime(0s);
22
1.56k
        MockableSteadyClock::ClearMockTime();
23
1.56k
    }
24
    ~CheckGlobalsImpl()
25
1.56k
    {
26
1.56k
        if (g_used_g_prng && !g_seeded_g_prng_zero) {
  Branch (26:13): [True: 637, False: 931]
  Branch (26:30): [True: 0, False: 637]
27
0
            std::cerr << "\n\n"
28
0
                         "The current fuzz target used the global random state.\n\n"
29
30
0
                         "This is acceptable, but requires the fuzz target to call \n"
31
0
                         "SeedRandomStateForTest(SeedRand::ZEROS) in the first line \n"
32
0
                         "of the FUZZ_TARGET function.\n\n"
33
34
0
                         "An alternative solution would be to avoid any use of globals.\n\n"
35
36
0
                         "Without a solution, fuzz instability and non-determinism can lead \n"
37
0
                         "to non-reproducible bugs or inefficient fuzzing.\n\n"
38
0
                      << std::endl;
39
0
            std::abort(); // Abort, because AFL may try to recover from a std::exit
40
0
        }
41
42
1.56k
        if (g_used_system_time) {
  Branch (42:13): [True: 0, False: 1.56k]
43
0
            std::cerr << "\n\n"
44
0
                         "The current fuzz target accessed system time.\n\n"
45
46
0
                         "This is acceptable, but requires the fuzz target to use \n"
47
0
                         "a FakeNodeClock, SteadyClockContext or call \n"
48
0
                         "SetMockTime() at the \n" "beginning of processing the \n"
49
0
                         "fuzz input.\n\n"
50
51
0
                         "Without setting mock time, time-dependent behavior can lead \n"
52
0
                         "to non-reproducible bugs or inefficient fuzzing.\n\n"
53
0
                      << std::endl;
54
0
            std::abort();
55
0
        }
56
1.56k
    }
57
};
58
59
1.56k
CheckGlobals::CheckGlobals() : m_impl(std::make_unique<CheckGlobalsImpl>()) {}
60
1.56k
CheckGlobals::~CheckGlobals() = default;