14#include <boost/test/unit_test.hpp>
16BOOST_AUTO_TEST_SUITE(allocator_tests)
22 void *synth_base =
reinterpret_cast<void*
>(0x08000000);
23 const size_t synth_size = 1024*1024;
24 Arena b(synth_base, synth_size, 16);
25 void *chunk = b.
alloc(1000);
41 }
catch(std::runtime_error &)
45 void *a0 = b.
alloc(128);
46 void *a1 = b.
alloc(256);
47 void *a2 = b.
alloc(512);
60 void *a3 = b.
alloc(128);
74 std::vector<void*> addr;
81 for (
int x=0; x<1024; ++x)
82 addr.push_back(b.
alloc(1024));
86 for (
int x=0; x<1024; ++x)
93 for (
int x=0; x<1024; ++x)
94 addr.push_back(b.
alloc(1024));
95 for (
int x=0; x<1024; ++x)
102 for (
int x=0; x<2048; ++x)
103 addr.push_back(b.
alloc(x+1));
104 for (
int x=0; x<2048; ++x)
105 b.
free(addr[((x*23)%2048)^242]);
110 for (
int x=0; x<2048; ++x)
111 addr.push_back(
nullptr);
112 uint32_t
s = 0x12345678;
113 for (
int x=0; x<5000; ++x) {
114 int idx =
s & (addr.size()-1);
115 if (
s & 0x80000000) {
118 }
else if(!addr[idx]) {
119 addr[idx] = b.
alloc((
s >> 16) & 2047);
126 for (
void *ptr: addr)
141 *lockingSuccess =
false;
147 *lockingSuccess =
true;
150 return reinterpret_cast<void*
>(uint64_t{
static_cast<uint64_t
>(0x08000000) + (
count << 24)});
159 return std::numeric_limits<size_t>::max();
169 std::unique_ptr<LockedPageAllocator> x = std::make_unique<TestLockedPageAllocator>(3, 1);
175 void *invalid_toosmall = pool.
alloc(0);
198 void *a6 = pool.
alloc(16);
220 void *a0 = pool.
alloc(16);
223 *((uint32_t*)a0) = 0x1234;
230 }
catch(std::runtime_error &)
BOOST_AUTO_TEST_CASE(arena_tests)
void * alloc(size_t size)
Allocate size bytes from this arena.
Stats stats() const
Get arena usage statistics.
void free(void *ptr)
Free a previously allocated chunk of memory.
OS-dependent allocation and deallocation of locked/pinned memory pages.
Pool for locked memory chunks.
void free(void *ptr)
Free a previously allocated chunk of memory.
Stats stats() const
Get pool usage statistics.
void * alloc(size_t size)
Allocate size bytes from this arena.
static const size_t ARENA_SIZE
Size of one arena of locked memory.
Singleton class to keep track of locked (ie, non-swappable) memory, for use in std::allocator templat...
static LockedPoolManager & Instance()
Return the current instance, or create it once.
Mock LockedPageAllocator for testing.
void FreeLocked(void *addr, size_t len) override
Unlock and free memory pages.
size_t GetLimit() override
Get the total limit on the amount of memory that may be locked by this process, in bytes.
TestLockedPageAllocator(int count_in, int lockedcount_in)
void * AllocateLocked(size_t len, bool *lockingSuccess) override
Allocate and lock memory pages.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)