Skip to content

Commit

Permalink
test: Initial PMM GTest units. WIP.
Browse files Browse the repository at this point in the history
Signed-off-by: TunaCici <[email protected]>
  • Loading branch information
TunaCici committed Jan 17, 2024
1 parent 394da6e commit a7bc5d7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Kernel/Include/Memory/Physical.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ typedef struct free_area_struct {

uint64_t init_allocator(const void *start, const void *end);

/* Private functions - TEST ONLY */
void __clear_page_area(uint8_t *addr, uint32_t size);
uint64_t __block_to_idx(const list_head_t *block, const uint32_t order);
list_head_t* __buddy(const list_head_t *block, const uint32_t order);
void __try_to_mark(list_head_t *block, const uint32_t order);
void __append_to_order(list_head_t *block, const uint32_t order);
void __remove_from_order(list_head_t *block, const uint32_t order);

/* Allocate a single page / 2^order number of pages */
void* alloc_page();
void* alloc_pages(const uint32_t order);
Expand Down
32 changes: 31 additions & 1 deletion Tests/MemoryPhysical.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
#include <_types/_uint64_t.h>
#include <_types/_uint8_t.h>
#include <stdint.h>

#include "gtest/gtest.h"
#include <sys/types.h>

extern "C" {
#include "Memory/PageDef.h"
#include "Memory/BootMem.h"
#include "Memory/Physical.h"
}

TEST(MemoryPhysical, TODO)
/* TODO: Explain what's going on here */
#define TEST_PM_PLAYGROUND_SIZE 8 * 1024 * 1024 + SIZEOF_BLOCK(MAX_ORDER - 1) - 1

TEST(MemoryPhysical, __clear_page_area)
{
uint8_t *playground = new uint8_t[PAGE_SIZE];
for (auto i = 0; i < PAGE_SIZE; i++) {
playground[i] = 42;
}

__clear_page_area(playground, PAGE_SIZE);

for (auto i = 0; i < PAGE_SIZE; i++) {
EXPECT_EQ(playground[i], 0);
}
}

TEST(MemoryPhysical, __budy)
{
list_head_t *addr = 0x0;

for (auto i = 0; i < MAX_ORDER; i++) {
list_head_t *buddy = __buddy(addr, i);
EXPECT_EQ(buddy, (list_head_t*) SIZEOF_BLOCK(i));

list_head_t *buddyBuddy = __buddy(buddy, i);
EXPECT_EQ(buddyBuddy, addr);
}
}

0 comments on commit a7bc5d7

Please sign in to comment.