Frame allocator class added

This commit is contained in:
Justin C. Miller
2019-02-25 21:19:43 -08:00
parent 5901237fee
commit 626eec4a31
5 changed files with 320 additions and 3 deletions

View File

@@ -0,0 +1,53 @@
#include "kutil/frame_allocator.h"
#include "kutil/heap_manager.h"
#include "kutil/memory.h"
#include "catch.hpp"
using namespace kutil;
extern void * grow_callback(void*, size_t);
extern void free_memory();
const size_t max_block = 1ull << 36;
const size_t start = max_block;
const size_t GB = 1ull << 30;
TEST_CASE( "Frame allocator tests", "[memory frame]" )
{
heap_manager mm(nullptr, grow_callback);
kutil::setup::set_heap(&mm);
frame_block_list free;
frame_block_list used;
frame_block_list cache;
auto *f = new frame_block_list::item_type;
f->address = 0x1000;
f->count = 1;
free.sorted_insert(f);
f = new frame_block_list::item_type;
f->address = 0x2000;
f->count = 1;
free.sorted_insert(f);
frame_allocator fa(
std::move(free),
std::move(used),
std::move(cache));
uintptr_t a = 0;
size_t c = fa.allocate(2, &a);
CHECK( a == 0x1000 );
CHECK( c == 2 );
fa.free(a, 2);
a = 0;
c = fa.allocate(2, &a);
CHECK( a == 0x1000 );
CHECK( c == 2 );
kutil::setup::set_heap(nullptr);
free_memory();
}