use super::*;
#[test]
fn windows_wait_decision_only_treats_signalled_as_exited() {
const WAIT_OBJECT_0_FIXTURE: u32 = 0;
const WAIT_TIMEOUT_FIXTURE: u32 = 258;
const WAIT_FAILED_FIXTURE: u32 = u32::MAX;
assert!(wait_probe_reports_live_or_unknown(
WAIT_TIMEOUT_FIXTURE,
WAIT_OBJECT_0_FIXTURE
));
assert!(!wait_probe_reports_live_or_unknown(
WAIT_OBJECT_0_FIXTURE,
WAIT_OBJECT_0_FIXTURE
));
assert!(wait_probe_reports_live_or_unknown(
WAIT_FAILED_FIXTURE,
WAIT_OBJECT_0_FIXTURE
));
assert!(wait_probe_reports_live_or_unknown(
123_456,
WAIT_OBJECT_0_FIXTURE
));
}
#[test]
fn windows_open_failure_only_treats_invalid_parameter_as_absent() {
const ERROR_ACCESS_DENIED_FIXTURE: i32 = 5;
const ERROR_INVALID_PARAMETER_FIXTURE: i32 = 87;
assert!(!open_process_failure_reports_live_or_unknown(
Some(ERROR_INVALID_PARAMETER_FIXTURE),
ERROR_INVALID_PARAMETER_FIXTURE
));
assert!(open_process_failure_reports_live_or_unknown(
Some(ERROR_ACCESS_DENIED_FIXTURE),
ERROR_INVALID_PARAMETER_FIXTURE
));
assert!(open_process_failure_reports_live_or_unknown(
Some(1_234_567),
ERROR_INVALID_PARAMETER_FIXTURE
));
assert!(open_process_failure_reports_live_or_unknown(
None,
ERROR_INVALID_PARAMETER_FIXTURE
));
}
#[test]
fn a_pid_reused_after_its_owner_died_is_not_the_owner() {
const HEARTBEAT: i64 = 1_000;
assert!(pid_identity_matches(Some(HEARTBEAT - 1), HEARTBEAT));
assert!(pid_identity_matches(Some(HEARTBEAT), HEARTBEAT));
assert!(!pid_identity_matches(Some(HEARTBEAT + 1), HEARTBEAT));
assert!(pid_identity_matches(None, HEARTBEAT));
}
#[cfg(target_os = "linux")]
#[test]
fn pid_start_time_is_unix_nanos_on_the_same_scale_as_the_claim_clock() {
let now = now_claim_nanos();
let started = pid_start_unix_nanos(i64::from(std::process::id()))
.expect("this process's own /proc/<pid>/stat is readable");
assert!(
started <= now,
"start {started} must not be after now {now}"
);
const ONE_DAY_NANOS: i64 = 24 * 3_600 * 1_000_000_000;
assert!(
now - started < ONE_DAY_NANOS,
"start {started} implausibly far before now {now}"
);
assert!(pid_identity_matches(Some(started), now));
}