Consolidate testing memory setup
This commit is contained in:
@@ -6,37 +6,25 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "kutil/address_manager.h"
|
||||
#include "kutil/heap_manager.h"
|
||||
#include "kutil/memory.h"
|
||||
#include "catch.hpp"
|
||||
|
||||
using namespace kutil;
|
||||
|
||||
extern void * grow_callback(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;
|
||||
static const size_t max_block = 1ull << 36;
|
||||
static const size_t start = max_block;
|
||||
static const size_t GB = 1ull << 30;
|
||||
|
||||
TEST_CASE( "Buddy addresses tests", "[address buddy]" )
|
||||
{
|
||||
heap_manager mm(grow_callback);
|
||||
kutil::setup::set_heap(&mm);
|
||||
|
||||
using clock = std::chrono::system_clock;
|
||||
unsigned seed = clock::now().time_since_epoch().count();
|
||||
std::default_random_engine rng(seed);
|
||||
|
||||
address_manager am;
|
||||
am.add_regions(start, max_block * 2);
|
||||
|
||||
// Blocks should be:
|
||||
// 36: 0-64G, 64-128G
|
||||
|
||||
uintptr_t a = am.allocate(0x4000); // under 64K min
|
||||
uintptr_t b = am.allocate(0x4000);
|
||||
CHECK( b == a + (1<<16));
|
||||
uintptr_t a = am.allocate(0x400); // under min
|
||||
uintptr_t b = am.allocate(0x400);
|
||||
CHECK( b == a + address_manager::min_alloc);
|
||||
|
||||
am.free(a);
|
||||
am.free(b);
|
||||
@@ -77,7 +65,4 @@ TEST_CASE( "Buddy addresses tests", "[address buddy]" )
|
||||
b = am.allocate(max_block);
|
||||
CHECK( b == start + max_block );
|
||||
CHECK( a == start );
|
||||
|
||||
kutil::setup::set_heap(nullptr);
|
||||
free_memory();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user