LCOV - code coverage report
Current view: top level - src/test/fuzz - node_eviction.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 24 24
Test Date: 2026-03-28 03:58:45 Functions: 100.0 % 2 2
Branches: 68.8 % 16 11

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2020-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 <net.h>
       6                 :             : #include <protocol.h>
       7                 :             : #include <test/fuzz/FuzzedDataProvider.h>
       8                 :             : #include <test/fuzz/fuzz.h>
       9                 :             : #include <test/fuzz/util.h>
      10                 :             : #include <test/fuzz/util/net.h>
      11                 :             : 
      12                 :             : #include <algorithm>
      13                 :             : #include <cassert>
      14                 :             : #include <cstdint>
      15                 :             : #include <optional>
      16                 :             : #include <vector>
      17                 :             : 
      18         [ +  - ]:         739 : FUZZ_TARGET(node_eviction)
      19                 :             : {
      20                 :         281 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      21                 :         281 :     std::vector<NodeEvictionCandidate> eviction_candidates;
      22   [ +  +  +  - ]:        7681 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000)
      23                 :             :     {
      24         [ +  - ]:       22200 :         eviction_candidates.push_back({
      25                 :        7400 :             /*id=*/fuzzed_data_provider.ConsumeIntegral<NodeId>(),
      26                 :        7400 :             /*m_connected=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),
      27                 :        7400 :             /*m_min_ping_time=*/ConsumeDuration<decltype(NodeEvictionCandidate::m_min_ping_time)>(fuzzed_data_provider, /*min=*/std::chrono::years{-1}, /*max=*/decltype(CNode::m_min_ping_time.load())::max()),
      28                 :        7400 :             /*m_last_block_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),
      29                 :        7400 :             /*m_last_tx_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),
      30                 :        7400 :             /*fRelevantServices=*/fuzzed_data_provider.ConsumeBool(),
      31                 :        7400 :             /*m_relay_txs=*/fuzzed_data_provider.ConsumeBool(),
      32                 :        7400 :             /*fBloomFilter=*/fuzzed_data_provider.ConsumeBool(),
      33                 :        7400 :             /*nKeyedNetGroup=*/fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
      34                 :        7400 :             /*prefer_evict=*/fuzzed_data_provider.ConsumeBool(),
      35                 :        7400 :             /*m_is_local=*/fuzzed_data_provider.ConsumeBool(),
      36                 :        7400 :             /*m_network=*/fuzzed_data_provider.PickValueInArray(ALL_NETWORKS),
      37                 :        7400 :             /*m_noban=*/fuzzed_data_provider.ConsumeBool(),
      38                 :        7400 :             /*m_conn_type=*/fuzzed_data_provider.PickValueInArray(ALL_CONNECTION_TYPES),
      39                 :             :         });
      40                 :             :     }
      41                 :             :     // Make a copy since eviction_candidates may be in some valid but otherwise
      42                 :             :     // indeterminate state after the SelectNodeToEvict(&&) call.
      43         [ +  - ]:         281 :     const std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates;
      44         [ +  - ]:         281 :     const std::optional<NodeId> node_to_evict = SelectNodeToEvict(std::move(eviction_candidates));
      45         [ +  + ]:         281 :     if (node_to_evict) {
      46         [ +  + ]:        1607 :         assert(std::any_of(eviction_candidates_copy.begin(), eviction_candidates_copy.end(), [&node_to_evict](const NodeEvictionCandidate& eviction_candidate) { return *node_to_evict == eviction_candidate.id; }));
      47                 :             :     }
      48                 :         281 : }
        

Generated by: LCOV version 2.0-1