From 4c8d4289e9ef7d7d78915c5a5371aa3d5ca806d8 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Wed, 18 Dec 2024 12:34:59 +0000 Subject: [PATCH] Introduce tests.extra/hardware_revoker_IRQs --- tests.extra/hardware_revoker_IRQs/README.md | 1 + tests.extra/hardware_revoker_IRQs/top.cc | 53 +++++++++++++++++++++ tests.extra/hardware_revoker_IRQs/xmake.lua | 26 ++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tests.extra/hardware_revoker_IRQs/README.md create mode 100644 tests.extra/hardware_revoker_IRQs/top.cc create mode 100644 tests.extra/hardware_revoker_IRQs/xmake.lua diff --git a/tests.extra/hardware_revoker_IRQs/README.md b/tests.extra/hardware_revoker_IRQs/README.md new file mode 100644 index 00000000..bc8925cf --- /dev/null +++ b/tests.extra/hardware_revoker_IRQs/README.md @@ -0,0 +1 @@ +This is a minimal "the clock is ticking" test for a hardware revoker. diff --git a/tests.extra/hardware_revoker_IRQs/top.cc b/tests.extra/hardware_revoker_IRQs/top.cc new file mode 100644 index 00000000..f3e50d3b --- /dev/null +++ b/tests.extra/hardware_revoker_IRQs/top.cc @@ -0,0 +1,53 @@ +#include +#include + +using Debug = ConditionalDebug; + +#if __has_include() +# include +#else +# error No platform-hardware_revoker.hh found, are you building for the right platform? +#endif + +using Revoker = HardwareRevoker; +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(); + } + } +} diff --git a/tests.extra/hardware_revoker_IRQs/xmake.lua b/tests.extra/hardware_revoker_IRQs/xmake.lua new file mode 100644 index 00000000..a8c713f8 --- /dev/null +++ b/tests.extra/hardware_revoker_IRQs/xmake.lua @@ -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)