10 #include <boost/test/unit_test.hpp>
18 void *synth_base =
reinterpret_cast<void*
>(0x08000000);
19 const size_t synth_size = 1024*1024;
20 Arena b(synth_base, synth_size, 16);
21 void *chunk = b.
alloc(1000);
37 }
catch(std::runtime_error &)
41 void *a0 = b.
alloc(128);
42 void *a1 = b.
alloc(256);
43 void *a2 = b.
alloc(512);
56 void *a3 = b.
alloc(128);
70 std::vector<void*> addr;
76 for (
int x=0; x<1024; ++x)
77 addr.push_back(b.
alloc(1024));
81 for (
int x=0; x<1024; ++x)
88 for (
int x=0; x<1024; ++x)
89 addr.push_back(b.
alloc(1024));
90 for (
int x=0; x<1024; ++x)
97 for (
int x=0; x<2048; ++x)
98 addr.push_back(b.
alloc(x+1));
99 for (
int x=0; x<2048; ++x)
100 b.
free(addr[((x*23)%2048)^242]);
105 for (
int x=0; x<2048; ++x)
107 uint32_t s = 0x12345678;
108 for (
int x=0; x<5000; ++x) {
109 int idx = s & (addr.size()-1);
110 if (s & 0x80000000) {
113 }
else if(!addr[idx]) {
114 addr[idx] = b.
alloc((s >> 16) & 2047);
121 for (
void *ptr: addr)
136 *lockingSuccess =
false;
142 *lockingSuccess =
true;
145 return reinterpret_cast<void*
>(0x08000000 + (
count<<24));
154 return std::numeric_limits<size_t>::max();
170 void *invalid_toosmall = pool.
alloc(0);
193 void *a6 = pool.
alloc(16);
215 void *a0 = pool.
alloc(16);
218 *((uint32_t*)a0) = 0x1234;
225 }
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.
TestLockedPageAllocator(int count_in, int lockedcount_in)
size_t GetLimit()
Get the total limit on the amount of memory that may be locked by this process, in bytes.
void FreeLocked(void *addr, size_t len)
Unlock and free memory pages.
void * AllocateLocked(size_t len, bool *lockingSuccess)
Allocate and lock memory pages.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)