use crate::identity::{HostKernel, ProcessId, Resolved};
use crate::test_child::live_exiting_member;
pub(super) fn begun(id: &ProcessId) -> Resolved<bool> {
#[cfg(target_os = "linux")]
{
let Ok(dir) = crate::identity::proc_view_with(&HostKernel).into_dir() else {
panic!("the host's /proc view is usable");
};
id.exit_begun_in(&HostKernel, &dir).0
}
#[cfg(not(target_os = "linux"))]
{
id.exit_begun_with(&HostKernel).0
}
}
#[track_caller]
fn await_exit_without_reaping(pid: u32) {
let mut info: libc::siginfo_t = unsafe { std::mem::zeroed() };
let waited = unsafe { libc::waitid(libc::P_PID, pid as libc::id_t, &mut info, libc::WEXITED | libc::WNOWAIT) };
assert_eq!(waited, 0, "waitid(WNOWAIT): {}", std::io::Error::last_os_error());
}
#[skuld::test]
fn a_running_process_has_not_begun_to_exit_a_zombie_has_and_a_reaped_one_is_gone() {
let (mut child, id) = live_exiting_member();
assert_eq!(begun(&id), Resolved::Found(false), "running");
drop(child.stdin.take());
await_exit_without_reaping(child.id());
assert_eq!(begun(&id), Resolved::Found(true), "a zombie");
child.wait().expect("reap the member");
assert_eq!(begun(&id), Resolved::Gone, "reaped");
}