feat(domain): add ProcessTable with create, get, and destroy

This commit is contained in:
2026-10-17 23:27:28 +02:00
parent fe0fde7de1
commit 42ed5ade29
3 changed files with 109 additions and 3 deletions

View File

@@ -76,3 +76,55 @@ fn capabilities_mut_accessible() {
let mut p = test_process(0);
let _caps = p.capabilities_mut();
}
// --- ProcessTable tests ---
#[test]
fn table_create_and_lookup() {
let mut table = ProcessTable::new();
let id = table.create(CapabilityTable::new(), None).unwrap();
assert_eq!(table.get(id).unwrap().id(), id);
}
#[test]
fn table_create_returns_unique_ids() {
let mut table = ProcessTable::new();
let a = table.create(CapabilityTable::new(), None).unwrap();
let b = table.create(CapabilityTable::new(), None).unwrap();
assert_ne!(a, b);
}
#[test]
fn table_destroy_then_get_fails() {
let mut table = ProcessTable::new();
let id = table.create(CapabilityTable::new(), None).unwrap();
table.destroy(id).unwrap();
assert!(table.get(id).is_err());
}
#[test]
fn table_full_returns_error() {
let mut table = ProcessTable::new();
for _ in 0..MAX_PROCESSES {
table.create(CapabilityTable::new(), None).unwrap();
}
assert!(table.create(CapabilityTable::new(), None).is_err());
}
#[test]
fn table_destroy_reuses_slot() {
let mut table = ProcessTable::new();
let id = table.create(CapabilityTable::new(), None).unwrap();
table.destroy(id).unwrap();
let new_id = table.create(CapabilityTable::new(), None).unwrap();
assert_eq!(id, new_id);
}
#[test]
fn table_get_mut_allows_modification() {
let mut table = ProcessTable::new();
let id = table.create(CapabilityTable::new(), None).unwrap();
let p = table.get_mut(id).unwrap();
p.add_thread(thread(0)).unwrap();
assert_eq!(table.get(id).unwrap().thread_ids().count(), 1);
}