Skip to content

Commit

Permalink
Initial test files
Browse files Browse the repository at this point in the history
  • Loading branch information
HAKarlsson committed May 16, 2024
1 parent ea04c31 commit 25a16cb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
19 changes: 19 additions & 0 deletions kernel/test/cap/test_cap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <cap.h>

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));
}
34 changes: 34 additions & 0 deletions kernel/test/hal_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Here we implement an emulation of the hardware.

#include <stdint.h>
#include <stdbool.h>

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];
}

0 comments on commit 25a16cb

Please sign in to comment.