forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaches_tests.cpp
More file actions
41 lines (30 loc) · 1.3 KB
/
Copy pathcaches_tests.cpp
File metadata and controls
41 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://opensource.org/license/mit.
#include <kernel/caches.h>
#include <node/caches.h>
#include <util/byte_units.h>
#include <boost/test/unit_test.hpp>
#include <cstdint>
using namespace node;
namespace {
void CheckDbCacheWarnThreshold(uint64_t threshold, uint64_t total_ram)
{
BOOST_CHECK(!ShouldWarnOversizedDbCache(threshold, total_ram));
BOOST_CHECK( ShouldWarnOversizedDbCache(threshold + 1, total_ram));
}
} // namespace
BOOST_AUTO_TEST_SUITE(caches_tests)
BOOST_AUTO_TEST_CASE(oversized_dbcache_warning)
{
BOOST_CHECK(!ShouldWarnOversizedDbCache(MIN_DBCACHE_BYTES, 1_GiB));
// Below DBCACHE_WARNING_RESERVED_RAM the existing fixed default dominates.
CheckDbCacheWarnThreshold(DEFAULT_KERNEL_CACHE, 1_GiB);
CheckDbCacheWarnThreshold(DEFAULT_KERNEL_CACHE, DBCACHE_WARNING_RESERVED_RAM);
// Above DBCACHE_WARNING_RESERVED_RAM the warning fires at 75% of the headroom.
CheckDbCacheWarnThreshold(((3_GiB - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, 3_GiB);
for (const auto total_ram : {8_GiB, 16_GiB, 32_GiB}) {
CheckDbCacheWarnThreshold(((total_ram - DBCACHE_WARNING_RESERVED_RAM) / 4) * 3, total_ram);
}
}
BOOST_AUTO_TEST_SUITE_END()