os_test_framework/
platform.rs1use core::fmt::Arguments;
2
3use alloc::boxed::Box;
4use spin::{Mutex, Once};
5
6static PLATFORM: Once<Mutex<Box<dyn Platform>>> = Once::new();
7
8pub fn init_platform(platform: impl Platform + 'static) {
9 PLATFORM.call_once(|| Mutex::new(Box::new(platform)));
10}
11
12pub fn platform() -> &'static Mutex<Box<dyn Platform>> {
13 try_platform().expect("os-test-framework platform not initialized")
14}
15
16pub fn try_platform() -> Option<&'static Mutex<Box<dyn Platform>>> {
17 PLATFORM.get()
18}
19
20pub enum ExitState {
21 Success,
22 Failed,
23}
24
25pub trait Platform: Send + Sync {
26 fn print(&mut self, args: Arguments);
27 fn exit(&self, state: ExitState) -> !;
28}