Skip to content

Commit

Permalink
Introduce tests.extra/hardware_revoker_IRQs
Browse files Browse the repository at this point in the history
  • Loading branch information
nwf authored and rmn30 committed Dec 20, 2024
1 parent 1a4b9b4 commit 4c8d428
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests.extra/hardware_revoker_IRQs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a minimal "the clock is ticking" test for a hardware revoker.
53 changes: 53 additions & 0 deletions tests.extra/hardware_revoker_IRQs/top.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <debug.hh>
#include <fail-simulator-on-error.h>

using Debug = ConditionalDebug<true, "top">;

#if __has_include(<platform-hardware_revoker.hh>)
# include <platform-hardware_revoker.hh>
#else
# error No platform-hardware_revoker.hh found, are you building for the right platform?
#endif

using Revoker = HardwareRevoker<uint32_t, REVOKABLE_MEMORY_START>;
static_assert(Revoker::IsAsynchronous, "This test is for async revokers");

void __cheri_compartment("top") entry()
{
Revoker r{};
r.init();

uint32_t epoch = r.system_epoch_get();
Debug::log("At startup, revocation epoch is {}; waiting...", epoch);

// Just in case a revocation is somehow active...
epoch &= ~1;
r.system_bg_revoker_kick();

for (int i = 0; i < 10; i++)
{
bool res;
uint32_t newepoch;
Timeout t{50};

res = r.wait_for_completion(&t, (epoch & ~1) + 2);
newepoch = r.system_epoch_get();

Debug::log("After wait: for {}, result {}, epoch now is {}, "
"wait elapsed {} remaining {}",
epoch,
res,
newepoch,
t.elapsed,
t.remaining);

Debug::Assert(t.remaining > 0,
"Timed out waiting for revoker to advance");

if (res)
{
epoch = newepoch;
r.system_bg_revoker_kick();
}
}
}
26 changes: 26 additions & 0 deletions tests.extra/hardware_revoker_IRQs/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set_project("Hardware Revoker IRQ Basic Functionality Test")
sdkdir = "../../sdk"
includes(sdkdir)
set_toolchains("cheriot-clang")

option("board")
set_default("ibex-safe-simulator")

compartment("top")
add_files("top.cc")

firmware("top_compartment")
add_deps("freestanding", "debug")
add_deps("top")
on_load(function(target)
target:values_set("board", "$(board)")
target:values_set("threads", {
{
compartment = "top",
priority = 1,
entry_point = "entry",
stack_size = 0x300,
trusted_stack_frames = 1
}
}, {expand = false})
end)

0 comments on commit 4c8d428

Please sign in to comment.