aboutsummaryrefslogtreecommitdiff
path: root/src/test/pool_tests.cpp
diff options
context:
space:
mode:
authorMartin Leitner-Ankerl <martin.ankerl@gmail.com>2023-11-19 18:43:15 +0100
committerfanquake <fanquake@gmail.com>2023-11-22 11:33:12 +0000
commit1488648104718fe727e4a0784120cc95bf232bdb (patch)
treee6c855415d30328f1fb5c374a7e0e9fd9b47543d /src/test/pool_tests.cpp
parentbcc183cccefdc84a09e43965d6b88a8bec3a5446 (diff)
pool: change memusage_test to use int64_t, add allocation check
If alignment of the PoolAllocator would be insufficient, then the test would fail. This also catches the issue with ARM 32bit, where int64_t is aligned to 8 bytes but void* is aligned to 4 bytes. The test adds a check to ensure the pool has allocated a minimum number of chunks Github-Pull: #28913 Rebased-From: d5b4c0b69e543de51bb37d602d488ee0949ba185
Diffstat (limited to 'src/test/pool_tests.cpp')
-rw-r--r--src/test/pool_tests.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/test/pool_tests.cpp b/src/test/pool_tests.cpp
index 2663e088eb..5ad4afa3a1 100644
--- a/src/test/pool_tests.cpp
+++ b/src/test/pool_tests.cpp
@@ -156,20 +156,20 @@ BOOST_AUTO_TEST_CASE(random_allocations)
BOOST_AUTO_TEST_CASE(memusage_test)
{
- auto std_map = std::unordered_map<int, int>{};
-
- using Map = std::unordered_map<int,
- int,
- std::hash<int>,
- std::equal_to<int>,
- PoolAllocator<std::pair<const int, int>,
- sizeof(std::pair<const int, int>) + sizeof(void*) * 4>>;
+ auto std_map = std::unordered_map<int64_t, int64_t>{};
+
+ using Map = std::unordered_map<int64_t,
+ int64_t,
+ std::hash<int64_t>,
+ std::equal_to<int64_t>,
+ PoolAllocator<std::pair<const int64_t, int64_t>,
+ sizeof(std::pair<const int64_t, int64_t>) + sizeof(void*) * 4>>;
auto resource = Map::allocator_type::ResourceType(1024);
PoolResourceTester::CheckAllDataAccountedFor(resource);
{
- auto resource_map = Map{0, std::hash<int>{}, std::equal_to<int>{}, &resource};
+ auto resource_map = Map{0, std::hash<int64_t>{}, std::equal_to<int64_t>{}, &resource};
// can't have the same resource usage
BOOST_TEST(memusage::DynamicUsage(std_map) != memusage::DynamicUsage(resource_map));
@@ -181,6 +181,11 @@ BOOST_AUTO_TEST_CASE(memusage_test)
// Eventually the resource_map should have a much lower memory usage because it has less malloc overhead
BOOST_TEST(memusage::DynamicUsage(resource_map) <= memusage::DynamicUsage(std_map) * 90 / 100);
+
+ // Make sure the pool is actually used by the nodes
+ auto max_nodes_per_chunk = resource.ChunkSizeBytes() / sizeof(Map::value_type);
+ auto min_num_allocated_chunks = resource_map.size() / max_nodes_per_chunk + 1;
+ BOOST_TEST(resource.NumAllocatedChunks() >= min_num_allocated_chunks);
}
PoolResourceTester::CheckAllDataAccountedFor(resource);