feat(kernel): per-process budgets (pages, endpoints, notifs, regions) carved from creator, returned on death; init owns pool
This commit is contained in:
35
crates/domain/src/budget_tests.rs
Normal file
35
crates/domain/src/budget_tests.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use super::{Budget, Limits};
|
||||
|
||||
const L: Limits = Limits {
|
||||
pages: 10,
|
||||
endpoints: 2,
|
||||
notifications: 2,
|
||||
regions: 1,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn a_carve_takes_all_parts_or_none() {
|
||||
let mut b = Budget::new(L);
|
||||
b.endpoints.charge(2);
|
||||
let child = Limits {
|
||||
pages: 1,
|
||||
endpoints: 1,
|
||||
..Limits::default()
|
||||
};
|
||||
assert!(!b.carve(child));
|
||||
assert_eq!(b.limits(), L);
|
||||
assert!(b.carve(Limits {
|
||||
endpoints: 0,
|
||||
..child
|
||||
}));
|
||||
assert_eq!(b.limits().pages, 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refund_restores_what_was_carved() {
|
||||
let mut b = Budget::new(L);
|
||||
assert!(b.carve(L));
|
||||
assert_eq!(b.limits(), Limits::default());
|
||||
b.refund(L);
|
||||
assert_eq!(b.limits(), L);
|
||||
}
|
||||
Reference in New Issue
Block a user