58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
// vim: ft=c
|
|
#include <ttest.h>
|
|
|
|
#include <memory.h>
|
|
#undef P2V
|
|
#define P2V(addr) ((void *)((uintptr_t)(addr)+1))
|
|
#undef V2P
|
|
#define V2P(addr) ((uintptr_t)(addr)-1)
|
|
#include "pmm.c"
|
|
|
|
struct {
|
|
uint8_t data[PAGE_SIZE];
|
|
}__attribute__((packed)) mem[2];
|
|
|
|
TEST(alloc_returns_freed_page)
|
|
{
|
|
pmm_free(V2P(&mem[0]));
|
|
uintptr_t a = pmm_alloc();
|
|
ASSERT_EQ_PTR(a, V2P(&mem[0]));
|
|
}
|
|
TEST(alloc_returns_0_if_no_free_pages)
|
|
{
|
|
uintptr_t a = pmm_alloc();
|
|
ASSERT_EQ_PTR(a, 0);
|
|
}
|
|
TEST(alloc_zero_after_all_free_pages)
|
|
{
|
|
pmm_free(V2P(&mem[0]));
|
|
pmm_alloc();
|
|
uintptr_t a = pmm_alloc();
|
|
ASSERT_EQ_PTR(a, 0);
|
|
}
|
|
|
|
TEST(alloc_two_pages___first_page_is_not_zero)
|
|
{
|
|
pmm_free(V2P(&mem[0]));
|
|
pmm_free(V2P(&mem[1]));
|
|
uintptr_t a = pmm_alloc();
|
|
pmm_alloc();
|
|
ASSERT_NEQ_PTR(a, 0);
|
|
}
|
|
TEST(alloc_two_pages___second_page_is_not_zero)
|
|
{
|
|
pmm_free(V2P(&mem[0]));
|
|
pmm_free(V2P(&mem[1]));
|
|
pmm_alloc();
|
|
uintptr_t a = pmm_alloc();
|
|
ASSERT_NEQ_PTR(a, 0);
|
|
}
|
|
TEST(alloc_two_pages___doesnt_return_same_page_twice)
|
|
{
|
|
pmm_free(V2P(&mem[0]));
|
|
pmm_free(V2P(&mem[1]));
|
|
uintptr_t a = pmm_alloc();
|
|
uintptr_t b = pmm_alloc();
|
|
ASSERT_NEQ_PTR(a, b);
|
|
}
|