use dope_sys::{
Timer as _,
thread::{Thread, timer::Error},
};
use dope_uring::Backend;
use o3::base::time::Positive;
pub mod common;
use common::ring::seccomp::Filter;
#[test]
fn rejects_range() {
let input = Positive::from_secs::<{ u64::MAX }>();
assert!(matches!(
<Backend as Thread>::Timer::try_new(input),
Err(Error::Range { deadline }) if deadline == input
));
}
#[test]
fn retains_handle() {
let timer = <Backend as Thread>::Timer::try_new(Positive::from_secs::<3600>())
.expect("kernel watchdog creation");
timer.try_refresh().expect("kernel watchdog refresh");
timer.try_disarm().expect("kernel watchdog disarm");
timer.try_refresh().expect("kernel watchdog rearm");
}
#[test]
fn rejects_arming() {
use dope::{core::platform::thread::Join, runtime::process};
let result = Join::scope(
|| {
Filter::Timer
.install()
.expect("thread-local timer-settime filter");
<Backend as Thread>::Timer::try_new(Positive::from_secs::<3600>()).map(drop)
},
process::STACK,
|join| join.finish(),
)
.expect("watchdog rejection on the filtered thread");
assert!(matches!(result, Err(Error::Arm(code)) if code.code().get() == libc::EPERM));
}