feat(kernel): add SpawnThread, CreateProcess, and Kill syscalls
This commit is contained in:
65
crates/kernel/src/tests/lifecycle.rs
Normal file
65
crates/kernel/src/tests/lifecycle.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use super::*;
|
||||
use crate::{SyscallOutcome, SyscallResult};
|
||||
use domain::syscall::Syscall;
|
||||
use types::address::{DataRef, EntryPoint, StackPointer};
|
||||
use types::bounded::CapSlot;
|
||||
|
||||
#[test]
|
||||
fn spawn_thread_creates_ready_thread() {
|
||||
let (mut k, _) = kernel_with_process();
|
||||
let outcome = k.handle_syscall(Syscall::SpawnThread {
|
||||
entry: EntryPoint::from_raw(0x1000),
|
||||
stack: StackPointer::from_raw(0x2000),
|
||||
});
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Value(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_process_with_cap_succeeds() {
|
||||
let (mut k, _) = kernel_with_process();
|
||||
// boot() grants ProcessCreate cap at slot 0
|
||||
let outcome = k.handle_syscall(Syscall::CreateProcess {
|
||||
create_cap: CapSlot::new(0).unwrap(),
|
||||
image: DataRef::empty(),
|
||||
});
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Slot(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_process_without_cap_fails() {
|
||||
let (mut k, _) = kernel_with_process();
|
||||
// slot 5 doesn't exist
|
||||
let outcome = k.handle_syscall(Syscall::CreateProcess {
|
||||
create_cap: CapSlot::new(5).unwrap(),
|
||||
image: DataRef::empty(),
|
||||
});
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Error(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kill_removes_process() {
|
||||
let (mut k, _pid) = kernel_with_process();
|
||||
// Create a second process, get cap for it
|
||||
let slot = match k.handle_syscall(Syscall::CreateProcess {
|
||||
create_cap: CapSlot::new(0).unwrap(),
|
||||
image: DataRef::empty(),
|
||||
}) {
|
||||
SyscallOutcome::Complete(SyscallResult::Slot(s)) => s,
|
||||
_ => panic!("expected slot"),
|
||||
};
|
||||
|
||||
let outcome = k.handle_syscall(Syscall::Kill { process: slot });
|
||||
assert!(matches!(
|
||||
outcome,
|
||||
SyscallOutcome::Complete(SyscallResult::Ok)
|
||||
));
|
||||
}
|
||||
Reference in New Issue
Block a user