Frame allocator class added
This commit is contained in:
53
src/tests/frame_allocator.cpp
Normal file
53
src/tests/frame_allocator.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user