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 PLATFORM.get().unwrap()
14}
15
16pub enum ExitState {
17 Success,
18 Failed,
19}
20
21pub trait Platform: Send + Sync {
22 fn print(&mut self, args: Arguments);
23 fn exit(&self, state: ExitState) -> !;
24}