style: cargo fmt kernel crates
This commit is contained in:
@@ -2,9 +2,9 @@ use super::*;
|
||||
use crate::{SyscallOutcome, SyscallResult};
|
||||
use domain::resource::Resource;
|
||||
use domain::syscall::Syscall;
|
||||
use types::address::DataRef;
|
||||
use types::bounded::CapSlot;
|
||||
use types::permission::{Permission, PermissionSet};
|
||||
use types::address::DataRef;
|
||||
|
||||
#[test]
|
||||
fn delegate_without_delegate_permission_fails() {
|
||||
@@ -75,7 +75,9 @@ fn revoke_resource_invalidates_all_caps() {
|
||||
let outcome = k.handle_syscall(Syscall::Receive { endpoint: cap_slot });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Error(domain::error::KernelError::RevokedCapability(_)))
|
||||
SyscallOutcome::Complete(SyscallResult::Error(
|
||||
domain::error::KernelError::RevokedCapability(_)
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -97,7 +99,9 @@ fn new_cap_after_revoke_uses_current_generation() {
|
||||
let outcome = k.handle_syscall(Syscall::Receive { endpoint: old_slot });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Error(domain::error::KernelError::RevokedCapability(_)))
|
||||
SyscallOutcome::Complete(SyscallResult::Error(
|
||||
domain::error::KernelError::RevokedCapability(_)
|
||||
))
|
||||
));
|
||||
|
||||
// New cap with current generation works
|
||||
@@ -136,7 +140,9 @@ fn revoke_does_not_affect_other_resources() {
|
||||
let outcome = k.handle_syscall(Syscall::Receive { endpoint: slot1 });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Error(domain::error::KernelError::RevokedCapability(_)))
|
||||
SyscallOutcome::Complete(SyscallResult::Error(
|
||||
domain::error::KernelError::RevokedCapability(_)
|
||||
))
|
||||
));
|
||||
|
||||
// ep2 cap still works
|
||||
@@ -159,13 +165,18 @@ fn revoke_syscall_invalidates_via_generation() {
|
||||
|
||||
// Revoke via syscall
|
||||
let outcome = k.handle_syscall(Syscall::Revoke { slot: cap_slot });
|
||||
assert!(matches!(outcome, SyscallOutcome::Complete(SyscallResult::Ok)));
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Ok)
|
||||
));
|
||||
|
||||
// The cap itself is now revoked (generation mismatch)
|
||||
let outcome = k.handle_syscall(Syscall::Receive { endpoint: cap_slot });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Error(domain::error::KernelError::RevokedCapability(_)))
|
||||
SyscallOutcome::Complete(SyscallResult::Error(
|
||||
domain::error::KernelError::RevokedCapability(_)
|
||||
))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ use types::{
|
||||
time::TimeSlice,
|
||||
};
|
||||
|
||||
use crate::Kernel;
|
||||
use super::mock_platform::MockPlatform;
|
||||
use crate::Kernel;
|
||||
|
||||
pub fn test_kernel() -> Kernel<MockPlatform> {
|
||||
let mock = MockPlatform::new(1);
|
||||
@@ -22,9 +22,7 @@ pub fn test_kernel() -> Kernel<MockPlatform> {
|
||||
|
||||
pub fn kernel_with_process() -> (Kernel<MockPlatform>, ProcessId) {
|
||||
let mut kernel = test_kernel();
|
||||
let (pid, _tid) = kernel
|
||||
.boot(Priority::DEFAULT, TimeSlice::DEFAULT)
|
||||
.unwrap();
|
||||
let (pid, _tid) = kernel.boot(Priority::DEFAULT, TimeSlice::DEFAULT).unwrap();
|
||||
(kernel, pid)
|
||||
}
|
||||
|
||||
@@ -35,7 +33,10 @@ impl Kernel<MockPlatform> {
|
||||
priority: Priority,
|
||||
time_slice: TimeSlice,
|
||||
) -> ThreadId {
|
||||
let tid = self.threads.spawn(pid, priority, time_slice, None).expect("spawn");
|
||||
let tid = self
|
||||
.threads
|
||||
.spawn(pid, priority, time_slice, None)
|
||||
.expect("spawn");
|
||||
let _ = self.processes.get_mut(pid).map(|p| p.add_thread(tid));
|
||||
let core = self.platform.core_id();
|
||||
self.scheduler.add(tid, priority, core);
|
||||
@@ -46,11 +47,7 @@ impl Kernel<MockPlatform> {
|
||||
let _ = self.irqs.register(irq, thread);
|
||||
}
|
||||
|
||||
pub fn block_thread_for_test(
|
||||
&mut self,
|
||||
tid: ThreadId,
|
||||
reason: domain::thread::BlockReason,
|
||||
) {
|
||||
pub fn block_thread_for_test(&mut self, tid: ThreadId, reason: domain::thread::BlockReason) {
|
||||
let core = self.platform.core_id();
|
||||
if let Ok(t) = self.threads.get_mut(tid) {
|
||||
if matches!(t.state(), ThreadState::Ready) {
|
||||
@@ -95,6 +92,7 @@ impl Kernel<MockPlatform> {
|
||||
resource: Resource,
|
||||
permissions: PermissionSet,
|
||||
) -> CapSlot {
|
||||
self.grant_cap(pid, resource, permissions).expect("grant cap")
|
||||
self.grant_cap(pid, resource, permissions)
|
||||
.expect("grant cap")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ use types::permission::{Permission, PermissionSet};
|
||||
|
||||
fn setup_ipc_kernel() -> (
|
||||
crate::Kernel<MockPlatform>,
|
||||
ProcessId, // process A
|
||||
ProcessId, // process B
|
||||
CapSlot, // endpoint cap for A (Execute perm)
|
||||
CapSlot, // endpoint cap for B (Read perm)
|
||||
ThreadId, // thread B id
|
||||
ProcessId, // process A
|
||||
ProcessId, // process B
|
||||
CapSlot, // endpoint cap for A (Execute perm)
|
||||
CapSlot, // endpoint cap for B (Read perm)
|
||||
ThreadId, // thread B id
|
||||
) {
|
||||
let (mut k, pid_a) = kernel_with_process();
|
||||
|
||||
@@ -27,11 +27,7 @@ fn setup_ipc_kernel() -> (
|
||||
};
|
||||
|
||||
let pid_b = ProcessId::from_raw(1);
|
||||
let tid_b = k.spawn_thread_for_test(
|
||||
pid_b,
|
||||
Priority::DEFAULT,
|
||||
TimeSlice::DEFAULT,
|
||||
);
|
||||
let tid_b = k.spawn_thread_for_test(pid_b, Priority::DEFAULT, TimeSlice::DEFAULT);
|
||||
|
||||
// Create an endpoint
|
||||
let ep_id = k.create_endpoint_for_test();
|
||||
@@ -65,7 +61,10 @@ fn send_without_receiver_blocks_caller() {
|
||||
endpoint: cap_a,
|
||||
message: msg,
|
||||
});
|
||||
assert!(matches!(outcome, SyscallOutcome::BlockCaller(BlockReason::Sending(_))));
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::BlockCaller(BlockReason::Sending(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -75,10 +74,11 @@ fn receive_without_sender_blocks_caller() {
|
||||
// Switch to thread B to call Receive
|
||||
k.switch_to_thread_for_test(tid_b);
|
||||
|
||||
let outcome = k.handle_syscall(Syscall::Receive {
|
||||
endpoint: cap_b,
|
||||
});
|
||||
assert!(matches!(outcome, SyscallOutcome::BlockCaller(BlockReason::Receiving(_))));
|
||||
let outcome = k.handle_syscall(Syscall::Receive { endpoint: cap_b });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::BlockCaller(BlockReason::Receiving(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -196,10 +196,7 @@ fn wait_any_with_ready_source_returns_immediately() {
|
||||
|
||||
// Thread A does WaitAny on the endpoint
|
||||
k.switch_to_thread_for_test(tid_a);
|
||||
let wait_set = WaitSet::new(
|
||||
[Some(cap_a), None, None, None],
|
||||
[None, None, None, None],
|
||||
);
|
||||
let wait_set = WaitSet::new([Some(cap_a), None, None, None], [None, None, None, None]);
|
||||
let outcome = k.handle_syscall(Syscall::WaitAny { sources: wait_set });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
@@ -210,10 +207,7 @@ fn wait_any_with_ready_source_returns_immediately() {
|
||||
#[test]
|
||||
fn wait_any_with_no_ready_source_blocks() {
|
||||
let (mut k, pid_a, _, cap_a, _, _) = setup_ipc_kernel();
|
||||
let wait_set = WaitSet::new(
|
||||
[Some(cap_a), None, None, None],
|
||||
[None, None, None, None],
|
||||
);
|
||||
let wait_set = WaitSet::new([Some(cap_a), None, None, None], [None, None, None, None]);
|
||||
let outcome = k.handle_syscall(Syscall::WaitAny { sources: wait_set });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
@@ -224,10 +218,7 @@ fn wait_any_with_no_ready_source_blocks() {
|
||||
#[test]
|
||||
fn wait_any_empty_sources_returns_error() {
|
||||
let (mut k, _, _, _, _, _) = setup_ipc_kernel();
|
||||
let wait_set = WaitSet::new(
|
||||
[None, None, None, None],
|
||||
[None, None, None, None],
|
||||
);
|
||||
let wait_set = WaitSet::new([None, None, None, None], [None, None, None, None]);
|
||||
let outcome = k.handle_syscall(Syscall::WaitAny { sources: wait_set });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use super::*;
|
||||
use crate::{SyscallOutcome, SyscallResult};
|
||||
use domain::syscall::Syscall;
|
||||
use types::bounded::PageCount;
|
||||
use types::address::VirtualAddress;
|
||||
use types::bounded::PageCount;
|
||||
|
||||
#[test]
|
||||
fn request_pages_returns_user_va() {
|
||||
|
||||
@@ -44,14 +44,29 @@ impl Platform for MockPlatform {
|
||||
loop {}
|
||||
}
|
||||
fn set_timer(&mut self, _duration: TimerDuration) {}
|
||||
fn current_ticks(&self) -> Ticks { self.ticks }
|
||||
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 }
|
||||
fn map_shared(&mut self, _process: ProcessId, _base: PhysicalAddress, _size: PageCount, _permissions: PermissionSet) {}
|
||||
fn halt(&self) -> ! { loop {} }
|
||||
fn core_id(&self) -> CoreId {
|
||||
self.core
|
||||
}
|
||||
fn num_cores(&self) -> u8 {
|
||||
self.cores
|
||||
}
|
||||
fn map_shared(
|
||||
&mut self,
|
||||
_process: ProcessId,
|
||||
_base: PhysicalAddress,
|
||||
_size: PageCount,
|
||||
_permissions: PermissionSet,
|
||||
) {
|
||||
}
|
||||
fn halt(&self) -> ! {
|
||||
loop {}
|
||||
}
|
||||
fn debug_putchar(&self, _byte: u8) {}
|
||||
|
||||
fn translate_va(&self, process: ProcessId, va: VirtualAddress) -> Option<PhysicalAddress> {
|
||||
@@ -65,10 +80,21 @@ impl Platform for MockPlatform {
|
||||
None
|
||||
}
|
||||
|
||||
fn map_user_page(&mut self, process: ProcessId, va: VirtualAddress, pa: PhysicalAddress, _writable: bool, _executable: bool) {
|
||||
fn map_user_page(
|
||||
&mut self,
|
||||
process: ProcessId,
|
||||
va: VirtualAddress,
|
||||
pa: PhysicalAddress,
|
||||
_writable: bool,
|
||||
_executable: bool,
|
||||
) {
|
||||
for slot in &mut self.mappings {
|
||||
if slot.is_none() {
|
||||
*slot = Some(PageMapping { process, va: va.raw(), pa: pa.raw() });
|
||||
*slot = Some(PageMapping {
|
||||
process,
|
||||
va: va.raw(),
|
||||
pa: pa.raw(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod mock_platform;
|
||||
mod helpers;
|
||||
mod mock_platform;
|
||||
|
||||
mod capability;
|
||||
mod exit;
|
||||
@@ -9,12 +9,12 @@ mod memory;
|
||||
mod simple;
|
||||
mod tick;
|
||||
|
||||
pub use helpers::{kernel_with_process, test_kernel};
|
||||
pub use mock_platform::MockPlatform;
|
||||
pub use helpers::{test_kernel, kernel_with_process};
|
||||
|
||||
pub use crate::Kernel;
|
||||
pub use domain::memory::page_pool::PagePool;
|
||||
pub use types::address::PhysicalAddress;
|
||||
pub use types::bounded::Priority;
|
||||
pub use types::id::ProcessId;
|
||||
pub use types::time::TimeSlice;
|
||||
pub use domain::memory::page_pool::PagePool;
|
||||
|
||||
@@ -46,9 +46,10 @@ fn interrupt_unblocks_registered_thread() {
|
||||
|
||||
// Register and block the thread on this IRQ
|
||||
k.register_irq_for_test(irq, tid);
|
||||
k.block_thread_for_test(tid, domain::thread::BlockReason::WaitingForInterrupt(
|
||||
types::bounded::CapSlot::new(0).unwrap()
|
||||
));
|
||||
k.block_thread_for_test(
|
||||
tid,
|
||||
domain::thread::BlockReason::WaitingForInterrupt(types::bounded::CapSlot::new(0).unwrap()),
|
||||
);
|
||||
|
||||
let result = k.handle_interrupt(irq);
|
||||
assert_eq!(result, Some(tid));
|
||||
|
||||
Reference in New Issue
Block a user