feat(kernel): WatchDeath + SetTimer events as notification signals; adapter wakes at earliest deadline
This commit is contained in:
37
crates/domain/src/timer_tests.rs
Normal file
37
crates/domain/src/timer_tests.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use super::{Target, Timers};
|
||||
use types::{badge::Badge, generation::Generation, id::NotificationId, id::ProcessId, time::Ticks};
|
||||
|
||||
fn target(n: u16) -> Target {
|
||||
Target {
|
||||
notification: NotificationId::from_raw(n),
|
||||
generation: Generation::initial(),
|
||||
badge: Badge::NONE,
|
||||
}
|
||||
}
|
||||
|
||||
fn pid(n: u16) -> ProcessId {
|
||||
ProcessId::from_raw(n)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_expired_timers_fire_and_each_fires_once() {
|
||||
let mut t = Timers::new();
|
||||
t.set(pid(0), Ticks::from_raw(10), target(0));
|
||||
t.set(pid(1), Ticks::from_raw(30), target(1));
|
||||
assert_eq!(t.earliest(), Some(Ticks::from_raw(10)));
|
||||
assert_eq!(t.take_expired(Ticks::from_raw(9)), None);
|
||||
assert_eq!(t.take_expired(Ticks::from_raw(10)), Some(target(0)));
|
||||
assert_eq!(t.take_expired(Ticks::from_raw(29)), None);
|
||||
assert_eq!(t.earliest(), Some(Ticks::from_raw(30)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn setting_again_replaces_and_clear_cancels() {
|
||||
let mut t = Timers::new();
|
||||
t.set(pid(2), Ticks::from_raw(10), target(0));
|
||||
t.set(pid(2), Ticks::from_raw(50), target(1));
|
||||
assert_eq!(t.take_expired(Ticks::from_raw(20)), None);
|
||||
t.clear(pid(2));
|
||||
assert_eq!(t.earliest(), None);
|
||||
assert!(!t.set(pid(500), Ticks::from_raw(1), target(0)));
|
||||
}
|
||||
Reference in New Issue
Block a user