feat(domain): add Process constructor, accessors, and thread slot management
This commit is contained in:
78
crates/domain/src/process/tests.rs
Normal file
78
crates/domain/src/process/tests.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
use super::*;
|
||||
use crate::capability::CapabilityTable;
|
||||
use types::bounded::CapSlot;
|
||||
use types::id::{ProcessId, ThreadId};
|
||||
|
||||
fn thread(id: u16) -> ThreadId {
|
||||
ThreadId::from_raw(id)
|
||||
}
|
||||
|
||||
fn test_process(id: u16) -> Process {
|
||||
Process::new(ProcessId::from_raw(id), CapabilityTable::new(), None)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_process_has_no_threads() {
|
||||
let p = test_process(0);
|
||||
assert_eq!(p.thread_ids().count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn id_matches_construction() {
|
||||
let p = test_process(42);
|
||||
assert_eq!(p.id(), ProcessId::from_raw(42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fault_handler_none_by_default() {
|
||||
let p = test_process(0);
|
||||
assert!(p.fault_handler().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fault_handler_preserved() {
|
||||
let slot = CapSlot::new(5).unwrap();
|
||||
let p = Process::new(ProcessId::from_raw(0), CapabilityTable::new(), Some(slot));
|
||||
assert_eq!(p.fault_handler(), Some(slot));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_and_iterate_threads() {
|
||||
let mut p = test_process(0);
|
||||
p.add_thread(thread(0)).unwrap();
|
||||
p.add_thread(thread(1)).unwrap();
|
||||
assert_eq!(p.thread_ids().count(), 2);
|
||||
assert!(p.thread_ids().any(|t| t == thread(0)));
|
||||
assert!(p.thread_ids().any(|t| t == thread(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_thread_beyond_max_fails() {
|
||||
let mut p = test_process(0);
|
||||
for i in 0..MAX_THREADS_PER_PROCESS {
|
||||
p.add_thread(thread(i as u16)).unwrap();
|
||||
}
|
||||
assert!(p.add_thread(thread(99)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_thread_frees_slot() {
|
||||
let mut p = test_process(0);
|
||||
p.add_thread(thread(0)).unwrap();
|
||||
p.remove_thread(thread(0));
|
||||
assert_eq!(p.thread_ids().count(), 0);
|
||||
p.add_thread(thread(1)).unwrap();
|
||||
assert_eq!(p.thread_ids().count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capabilities_accessible() {
|
||||
let p = test_process(0);
|
||||
let _caps = p.capabilities();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capabilities_mut_accessible() {
|
||||
let mut p = test_process(0);
|
||||
let _caps = p.capabilities_mut();
|
||||
}
|
||||
Reference in New Issue
Block a user