Bitcoin Core 30.99.0
P2P Digital Currency
caches_tests.cpp
Go to the documentation of this file.
1#include <node/caches.h>
2#include <util/byte_units.h>
3
4#include <boost/test/unit_test.hpp>
5
6using namespace node;
7
8BOOST_AUTO_TEST_SUITE(caches_tests)
9
10BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
11{
12 // memory restricted setup - cap is DEFAULT_DB_CACHE (450 MiB)
13 BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/4_MiB, /*total_ram=*/1024_MiB)); // Under cap
14 BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/512_MiB, /*total_ram=*/1024_MiB)); // At cap
15 BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/1024_MiB)); // Over cap
16
17 // 2 GiB RAM - cap is 75%
18 BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/1500_MiB, /*total_ram=*/2048_MiB)); // Under cap
19 BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/1600_MiB, /*total_ram=*/2048_MiB)); // Over cap
20
21 if constexpr (SIZE_MAX == UINT64_MAX) {
22 // 4 GiB RAM - cap is 75%
23 BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/2500_MiB, /*total_ram=*/4096_MiB)); // Under cap
24 BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/3500_MiB, /*total_ram=*/4096_MiB)); // Over cap
25
26 // 8 GiB RAM - cap is 75%
27 BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/6000_MiB, /*total_ram=*/8192_MiB)); // Under cap
28 BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/7000_MiB, /*total_ram=*/8192_MiB)); // Over cap
29
30 // 16 GiB RAM - cap is 75%
31 BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/10'000_MiB, /*total_ram=*/16384_MiB)); // Under cap
32 BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/15'000_MiB, /*total_ram=*/16384_MiB)); // Over cap
33
34 // 32 GiB RAM - cap is 75%
35 BOOST_CHECK(!ShouldWarnOversizedDbCache(/*dbcache=*/20'000_MiB, /*total_ram=*/32768_MiB)); // Under cap
36 BOOST_CHECK( ShouldWarnOversizedDbCache(/*dbcache=*/30'000_MiB, /*total_ram=*/32768_MiB)); // Over cap
37 }
38}
39
BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
BOOST_AUTO_TEST_SUITE_END()
Definition: messages.h:20
constexpr bool ShouldWarnOversizedDbCache(size_t dbcache, size_t total_ram) noexcept
Definition: caches.h:30
#define BOOST_CHECK(expr)
Definition: object.cpp:17