Bitcoin Core
31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
test
caches_tests.cpp
Go to the documentation of this file.
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
using namespace
node
;
11
12
BOOST_AUTO_TEST_SUITE
(
caches_tests
)
13
14
BOOST_AUTO_TEST_CASE
(
oversized_dbcache_warning
)
15
{
16
// memory restricted setup - cap is DEFAULT_DB_CACHE (450 MiB)
17
BOOST_CHECK
(!
ShouldWarnOversizedDbCache
(
/*dbcache=*/
4
_MiB
,
/*total_ram=*/
1024
_MiB
));
// Under cap
18
BOOST_CHECK
(
ShouldWarnOversizedDbCache
(
/*dbcache=*/
512
_MiB
,
/*total_ram=*/
1024
_MiB
));
// At cap
19
BOOST_CHECK
(
ShouldWarnOversizedDbCache
(
/*dbcache=*/
1500
_MiB
,
/*total_ram=*/
1024
_MiB
));
// Over cap
20
21
// 2 GiB RAM - cap is 75%
22
BOOST_CHECK
(!
ShouldWarnOversizedDbCache
(
/*dbcache=*/
1500
_MiB
,
/*total_ram=*/
2048
_MiB
));
// Under cap
23
BOOST_CHECK
(
ShouldWarnOversizedDbCache
(
/*dbcache=*/
1600
_MiB
,
/*total_ram=*/
2048
_MiB
));
// Over cap
24
25
if
constexpr
(
SIZE_MAX
==
UINT64_MAX
) {
26
// 4 GiB RAM - cap is 75%
27
BOOST_CHECK
(!
ShouldWarnOversizedDbCache
(
/*dbcache=*/
2500
_MiB
,
/*total_ram=*/
4096
_MiB
));
// Under cap
28
BOOST_CHECK
(
ShouldWarnOversizedDbCache
(
/*dbcache=*/
3500
_MiB
,
/*total_ram=*/
4096
_MiB
));
// Over cap
29
30
// 8 GiB RAM - cap is 75%
31
BOOST_CHECK
(!
ShouldWarnOversizedDbCache
(
/*dbcache=*/
6000
_MiB
,
/*total_ram=*/
8192
_MiB
));
// Under cap
32
BOOST_CHECK
(
ShouldWarnOversizedDbCache
(
/*dbcache=*/
7000
_MiB
,
/*total_ram=*/
8192
_MiB
));
// Over cap
33
34
// 16 GiB RAM - cap is 75%
35
BOOST_CHECK
(!
ShouldWarnOversizedDbCache
(
/*dbcache=*/
10'000
_MiB
,
/*total_ram=*/
16384
_MiB
));
// Under cap
36
BOOST_CHECK
(
ShouldWarnOversizedDbCache
(
/*dbcache=*/
15'000
_MiB
,
/*total_ram=*/
16384
_MiB
));
// Over cap
37
38
// 32 GiB RAM - cap is 75%
39
BOOST_CHECK
(!
ShouldWarnOversizedDbCache
(
/*dbcache=*/
20'000
_MiB
,
/*total_ram=*/
32768
_MiB
));
// Under cap
40
BOOST_CHECK
(
ShouldWarnOversizedDbCache
(
/*dbcache=*/
30'000
_MiB
,
/*total_ram=*/
32768
_MiB
));
// Over cap
41
}
42
}
43
44
BOOST_AUTO_TEST_SUITE_END
()
byte_units.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
Definition
caches_tests.cpp:14
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
node
Definition
messages.h:21
node::ShouldWarnOversizedDbCache
constexpr bool ShouldWarnOversizedDbCache(size_t dbcache, size_t total_ram) noexcept
Definition
caches.h:32
caches.h
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition
object.cpp:16
Ticks
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition
time.h:73
Generated on Thu Apr 16 2026 09:42:38 for Bitcoin Core by
1.10.0