LCOV - code coverage report
Current view: top level - src/test - caches_tests.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 100.0 % 12 12
Test Date: 2026-07-17 06:52:43 Functions: 100.0 % 3 3
Branches: 52.9 % 70 37

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or https://opensource.org/license/mit.
       4                 :             : 
       5                 :             : #include <node/caches.h>
       6                 :             : #include <util/byte_units.h>
       7                 :             : 
       8                 :             : #include <boost/test/unit_test.hpp>
       9                 :             : 
      10                 :             : #include <cstdint>
      11                 :             : 
      12                 :             : using namespace node;
      13                 :             : 
      14                 :             : namespace {
      15                 :           6 : void CheckDbCacheWarnThreshold(uint64_t threshold, uint64_t total_ram)
      16                 :             : {
      17   [ +  +  +  - ]:          14 :     BOOST_CHECK(!ShouldWarnOversizedDbCache(threshold, total_ram));
      18         [ +  - ]:          12 :     BOOST_CHECK( ShouldWarnOversizedDbCache(threshold + 1, total_ram));
      19                 :           6 : }
      20                 :             : } // namespace
      21                 :             : 
      22                 :             : BOOST_AUTO_TEST_SUITE(caches_tests)
      23                 :             : 
      24   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  -  +  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          -  +  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      25                 :             : {
      26         [ +  - ]:           2 :     BOOST_CHECK(!ShouldWarnOversizedDbCache(MIN_DB_CACHE, 1_GiB));
      27                 :             : 
      28                 :             :     // Below DBCACHE_WARNING_RESERVED_RAM the existing fixed default dominates.
      29                 :           1 :     CheckDbCacheWarnThreshold(DEFAULT_DB_CACHE, 1_GiB);
      30                 :           1 :     CheckDbCacheWarnThreshold(DEFAULT_DB_CACHE, DBCACHE_WARNING_RESERVED_RAM);
      31                 :             : 
      32                 :             :     // Above DBCACHE_WARNING_RESERVED_RAM the warning fires at 75% of the headroom.
      33                 :           1 :     CheckDbCacheWarnThreshold(((3_GiB - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, 3_GiB);
      34                 :             : 
      35         [ +  + ]:           4 :     for (const auto total_ram : {8_GiB, 16_GiB, 32_GiB}) {
      36                 :           3 :         CheckDbCacheWarnThreshold(((total_ram - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, total_ram);
      37                 :             :     }
      38                 :           1 : }
      39                 :             : 
      40                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1