11#include <boost/test/unit_test.hpp>
15#include <unordered_map>
30 void* block = resource.Allocate(8, 8);
35 resource.Deallocate(block, 8, 8);
40 void* b = resource.Allocate(8, 1);
45 resource.Deallocate(block, 8, 1);
51 b = resource.Allocate(8, 16);
58 resource.Deallocate(block, 8, 16);
64 block = resource.Allocate(16, 8);
69 resource.Deallocate(block, 16, 8);
76 void*
p = resource.Allocate(0, 1);
80 resource.Deallocate(
p, 0, 1);
93 auto data = std::vector<std::span<uint8_t>>();
107 for (
auto const& span : data) {
108 for (
auto x : span) {
111 std::destroy(span.data(), span.data() + span.size());
112 resource.Deallocate(span.data(), span.size(), 1);
130 for (
size_t i = 0; i < 1000; ++i) {
134 std::size_t alignment = std::size_t{1} << m_rng.randrange(8);
135 std::size_t size = (m_rng.randrange(200) / alignment + 1) * alignment;
136 void* ptr = resource.Allocate(size, alignment);
143 resource.Deallocate(x.ptr, x.bytes, x.alignment);
151 resource.Deallocate(x.ptr, x.bytes, x.alignment);
159 auto std_map = std::unordered_map<int64_t, int64_t>{};
161 using Map = std::unordered_map<
int64_t,
164 std::equal_to<int64_t>,
166 sizeof(std::pair<const int64_t, int64_t>) +
sizeof(
void*) * 4>>;
167 auto resource = Map::allocator_type::ResourceType(1024);
172 auto resource_map = Map{0, std::hash<int64_t>{}, std::equal_to<int64_t>{}, &resource};
177 for (
size_t i = 0; i < 10000; ++i) {
Forwards all allocations/deallocations to the PoolResource.
static void CheckAllDataAccountedFor(const PoolResource< MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES > &resource)
Once all blocks are given back to the resource, tests that the freelists are consistent:
static std::size_t AvailableMemoryFromChunk(const PoolResource< MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES > &resource)
How many bytes are still available from the last allocated chunk.
static std::vector< std::size_t > FreeListSizes(const PoolResource< MAX_BLOCK_SIZE_BYTES, ALIGN_BYTES > &resource)
Extracts the number of elements per freelist.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
BOOST_AUTO_TEST_CASE(basic_allocating)
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.