From 25a16cbdd7d3b49c00a1f304af8210c62ca0aeb2 Mon Sep 17 00:00:00 2001 From: Henrik Karlsson Date: Thu, 16 May 2024 10:10:54 +0200 Subject: [PATCH] Initial test files --- kernel/test/cap/test_cap.c | 19 +++++++++++++++++++ kernel/test/hal_test.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 kernel/test/cap/test_cap.c create mode 100644 kernel/test/hal_test.c diff --git a/kernel/test/cap/test_cap.c b/kernel/test/cap/test_cap.c new file mode 100644 index 0000000..77a2435 --- /dev/null +++ b/kernel/test/cap/test_cap.c @@ -0,0 +1,19 @@ +#include + +void test_mem_valid1 (void) +{ + cap_t mem = mk_memory(0x10, 0x2000, 0x3); + assert(cap_is_valid(parent)); +} + +void test_mem_valid2 (void) +{ + cap_t mem = mk_memory(0x1000, 0x2000, 0x7); + assert(cap_is_valid(parent)); +} + +void test_mem_invalid1 (void) +{ + cap_t mem = mk_memory(0x2000, 0x2000, 0x7); + assert(!cap_is_valid(parent)); +} diff --git a/kernel/test/hal_test.c b/kernel/test/hal_test.c new file mode 100644 index 0000000..6c8da7c --- /dev/null +++ b/kernel/test/hal_test.c @@ -0,0 +1,34 @@ +// Here we implement an emulation of the hardware. + +#include +#include + +static uint64_t mtime; +static uint64_t mtimecmp[4]; + +uint64_t time_get(void) +{ + mtime += 10; + return mtime; +} + +void time_set(uint64_t val) +{ + mtime = val; +} + +uint64_t timeout_get(uint64_t hartid) +{ + return mtimecmp[hartid]; +} + +uint64_t timeout_set(uint64_t hartid, uint64_t val) +{ + mtimecmp[hartid] = val; +} + +bool timeout_check(uint64_t hartid) +{ + mtime += 10; + return mtime >= mtimecmp[hartid]; +}