Skip to content

Commit d5b4c0b

Browse files
committed
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
1 parent ce881bf commit d5b4c0b

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/test/pool_tests.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,20 @@ BOOST_AUTO_TEST_CASE(random_allocations)
156156

157157
BOOST_AUTO_TEST_CASE(memusage_test)
158158
{
159-
auto std_map = std::unordered_map<int, int>{};
160-
161-
using Map = std::unordered_map<int,
162-
int,
163-
std::hash<int>,
164-
std::equal_to<int>,
165-
PoolAllocator<std::pair<const int, int>,
166-
sizeof(std::pair<const int, int>) + sizeof(void*) * 4>>;
159+
auto std_map = std::unordered_map<int64_t, int64_t>{};
160+
161+
using Map = std::unordered_map<int64_t,
162+
int64_t,
163+
std::hash<int64_t>,
164+
std::equal_to<int64_t>,
165+
PoolAllocator<std::pair<const int64_t, int64_t>,
166+
sizeof(std::pair<const int64_t, int64_t>) + sizeof(void*) * 4>>;
167167
auto resource = Map::allocator_type::ResourceType(1024);
168168

169169
PoolResourceTester::CheckAllDataAccountedFor(resource);
170170

171171
{
172-
auto resource_map = Map{0, std::hash<int>{}, std::equal_to<int>{}, &resource};
172+
auto resource_map = Map{0, std::hash<int64_t>{}, std::equal_to<int64_t>{}, &resource};
173173

174174
// can't have the same resource usage
175175
BOOST_TEST(memusage::DynamicUsage(std_map) != memusage::DynamicUsage(resource_map));
@@ -181,6 +181,11 @@ BOOST_AUTO_TEST_CASE(memusage_test)
181181

182182
// Eventually the resource_map should have a much lower memory usage because it has less malloc overhead
183183
BOOST_TEST(memusage::DynamicUsage(resource_map) <= memusage::DynamicUsage(std_map) * 90 / 100);
184+
185+
// Make sure the pool is actually used by the nodes
186+
auto max_nodes_per_chunk = resource.ChunkSizeBytes() / sizeof(Map::value_type);
187+
auto min_num_allocated_chunks = resource_map.size() / max_nodes_per_chunk + 1;
188+
BOOST_TEST(resource.NumAllocatedChunks() >= min_num_allocated_chunks);
184189
}
185190

186191
PoolResourceTester::CheckAllDataAccountedFor(resource);

0 commit comments

Comments
 (0)