LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
test_slab.cxx
Go to the documentation of this file.
1#include <lfostest.h>
2
3namespace LFOS {
4 extern "C" {
5 #include <slab.c>
6 }
7
8 TEST(KernelSlab, Simple) {
9 const size_t size = 1024 * 1024;
10
11 void* memory = malloc(size);
12 init_slab((ptr_t)memory, (uint64_t)memory + size, 1024);
13
14 SlabHeader* slab = (SlabHeader*)memory;
15 ptr_t alloc1 = slab_alloc(slab);
16
17 EXPECT_EQ(alloc1, (uint64_t)memory + 1024) << "correct pointer returned";
18
19 SlabIndexType idx2 = slab_index(slab, (uint64_t)memory + 2048);
20 EXPECT_EQ(idx2, 1) << "correct index returned";
21
22 free((void*)memory);
23 }
24}
uint64_t ptr_t
Definition arch.h:17
unsigned long uint64_t
Definition arch.h:14
void * malloc(size_t size)
Definition string.c:169
void free(void *ptr)
Definition string.c:180
uint16_t size
Size of the loaded file.
Definition loader.h:5
TEST(KernelServiceDiscovery, Basic)
Definition test_sd.cxx:20
ptr_t slab_alloc(SlabHeader *slab)
Definition slab.c:22
void init_slab(ptr_t mem_start, ptr_t mem_end, size_t allocation_size)
Definition slab.c:6
static SlabIndexType slab_index(const SlabHeader *slab, const ptr_t mem)
Definition slab.h:76
uint16_t SlabIndexType
Type for indexing objects in a Slab region.
Definition slab.h:7
Header of a Slab region.
Definition slab.h:10