feat(server-framework): add Server trait, Encode/Decode, async executor, syscall wrappers, and mock arch for host testing

This commit is contained in:
2026-10-18 02:55:22 +02:00
parent 5c29c0845d
commit c14fe50c23
12 changed files with 303 additions and 23 deletions

View File

@@ -0,0 +1,35 @@
#[cfg(test)]
mod tests;
use core::future::Future;
use core::pin::Pin;
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
fn noop_raw_waker() -> RawWaker {
fn no_op(_: *const ()) {}
fn clone(_: *const ()) -> RawWaker { noop_raw_waker() }
RawWaker::new(
core::ptr::null(),
&RawWakerVTable::new(clone, no_op, no_op, no_op),
)
}
fn noop_waker() -> Waker {
unsafe { Waker::from_raw(noop_raw_waker()) }
}
pub fn block_on<F: Future>(future: F) -> F::Output {
let waker = noop_waker();
let mut cx = Context::from_waker(&waker);
let mut future = core::pin::pin!(future);
loop {
match future.as_mut().poll(&mut cx) {
Poll::Ready(output) => return output,
Poll::Pending => {
#[cfg(not(test))]
userspace::syscall::yield_now();
}
}
}
}

View File

@@ -0,0 +1,17 @@
use super::*;
#[test]
fn block_on_ready_future() {
let result = block_on(async { 42 });
assert_eq!(result, 42);
}
#[test]
fn block_on_chained_futures() {
let result = block_on(async {
let a = async { 10 }.await;
let b = async { 20 }.await;
a + b
});
assert_eq!(result, 30);
}