refactor(kernel): extract MockPlatform and test helpers into separate modules
This commit is contained in:
49
crates/kernel/src/tests/mock_platform.rs
Normal file
49
crates/kernel/src/tests/mock_platform.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use domain::memory::MemoryRegion;
|
||||
use domain::thread::SavedContext;
|
||||
use platform::Platform;
|
||||
use types::{
|
||||
address::{EntryPoint, StackPointer},
|
||||
id::{CoreId, IrqId, ProcessId},
|
||||
time::{Ticks, TimerDuration},
|
||||
};
|
||||
|
||||
pub struct MockPlatform {
|
||||
ticks: Ticks,
|
||||
core: CoreId,
|
||||
cores: u8,
|
||||
}
|
||||
|
||||
impl MockPlatform {
|
||||
pub fn new(num_cores: u8) -> Self {
|
||||
Self {
|
||||
ticks: Ticks::from_raw(0),
|
||||
core: CoreId::from_raw(0),
|
||||
cores: num_cores,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_ticks(&mut self, ticks: Ticks) {
|
||||
self.ticks = ticks;
|
||||
}
|
||||
}
|
||||
|
||||
impl Platform for MockPlatform {
|
||||
fn configure_protection(&mut self, _process: ProcessId, _regions: &[MemoryRegion]) {}
|
||||
fn context_switch(&mut self, _from: &mut SavedContext, _to: &SavedContext) {}
|
||||
fn enable_user_mode(&mut self, _entry: EntryPoint, _stack: StackPointer) -> ! {
|
||||
loop {}
|
||||
}
|
||||
fn set_timer(&mut self, _duration: TimerDuration) {}
|
||||
fn current_ticks(&self) -> Ticks {
|
||||
self.ticks
|
||||
}
|
||||
fn mask_irq(&mut self, _irq: IrqId) {}
|
||||
fn unmask_irq(&mut self, _irq: IrqId) {}
|
||||
fn send_ipi(&mut self, _target: CoreId) {}
|
||||
fn core_id(&self) -> CoreId {
|
||||
self.core
|
||||
}
|
||||
fn num_cores(&self) -> u8 {
|
||||
self.cores
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user