LCOV - code coverage report
Current view: top level - src/test/fuzz - node_eviction.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 29 29 100.0 %
Date: 2023-10-05 15:40:34 Functions: 8 8 100.0 %
Branches: 35 64 54.7 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2020-2022 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         [ +  - ]:        173 : 
      18   [ +  -  -  + ]:        875 : FUZZ_TARGET(node_eviction)
      19                 :            : {
      20                 :        356 :     FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
      21                 :        356 :     std::vector<NodeEvictionCandidate> eviction_candidates;
      22   [ +  -  +  +  :     613679 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
                   +  + ]
      23         [ +  - ]:    3066615 :         eviction_candidates.push_back({
      24         [ +  - ]:     613323 :             /*id=*/fuzzed_data_provider.ConsumeIntegral<NodeId>(),
      25   [ +  -  +  -  :     613496 :             /*m_connected=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
                   +  - ]
      26   [ +  -  +  - ]:     613323 :             /*m_min_ping_time=*/std::chrono::microseconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
      27   [ +  -  +  - ]:     613323 :             /*m_last_block_time=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
      28   [ +  -  +  - ]:     613323 :             /*m_last_tx_time=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
      29         [ +  - ]:     613323 :             /*fRelevantServices=*/fuzzed_data_provider.ConsumeBool(),
      30         [ +  - ]:     613323 :             /*m_relay_txs=*/fuzzed_data_provider.ConsumeBool(),
      31         [ +  - ]:     613323 :             /*fBloomFilter=*/fuzzed_data_provider.ConsumeBool(),
      32         [ +  - ]:     613323 :             /*nKeyedNetGroup=*/fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
      33         [ +  - ]:     613323 :             /*prefer_evict=*/fuzzed_data_provider.ConsumeBool(),
      34         [ +  - ]:     613323 :             /*m_is_local=*/fuzzed_data_provider.ConsumeBool(),
      35         [ +  - ]:     613323 :             /*m_network=*/fuzzed_data_provider.PickValueInArray(ALL_NETWORKS),
      36         [ +  - ]:     613323 :             /*m_noban=*/fuzzed_data_provider.ConsumeBool(),
      37         [ +  - ]:     613323 :             /*m_conn_type=*/fuzzed_data_provider.PickValueInArray(ALL_CONNECTION_TYPES),
      38                 :            :         });
      39                 :     613323 :     }
      40                 :            :     // Make a copy since eviction_candidates may be in some valid but otherwise
      41                 :            :     // indeterminate state after the SelectNodeToEvict(&&) call.
      42         [ +  - ]:        356 :     const std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates;
      43         [ +  - ]:        356 :     const std::optional<NodeId> node_to_evict = SelectNodeToEvict(std::move(eviction_candidates));
      44         [ +  + ]:        356 :     if (node_to_evict) {
      45   [ +  -  -  + ]:      25026 :         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; }));
      46                 :        314 :     }
      47                 :        356 : }

Generated by: LCOV version 1.14