use std::os::fd::OwnedFd;
use super::super::child::Spawned;
use super::super::log::Log;
fn not_a_process() -> Spawned {
let not_a_pidfd: OwnedFd = std::fs::File::open("/dev/null").unwrap().into();
Spawned {
pid: 0,
pidfd: not_a_pidfd,
}
}
fn collected_process() -> Spawned {
let mut command = std::process::Command::new("true");
let mut child = crate::test_spawn::spawn(&mut command).expect("true starts");
let pid = rustix::process::Pid::from_raw(child.id() as i32).unwrap();
let pidfd = rustix::process::pidfd_open(pid, rustix::process::PidfdFlags::empty()).unwrap();
child.wait().unwrap();
Spawned {
pid: pid.as_raw_nonzero().get(),
pidfd,
}
}
#[skuld::test]
fn a_kill_of_a_collected_process_is_expected() {
collected_process().kill(&Log::new(None));
}
#[cfg(debug_assertions)]
#[skuld::test]
#[should_panic(expected = "pidfd_send_signal(SIGKILL)")]
fn a_kill_that_fails_otherwise_is_a_bug() {
not_a_process().kill(&Log::new(None));
}
#[cfg(not(debug_assertions))]
#[skuld::test]
fn a_kill_that_fails_otherwise_is_logged_and_goes_on() {
not_a_process().kill(&Log::new(None));
}
#[skuld::test]
fn a_status_collected_by_someone_else_is_lost_not_a_bug() {
assert_eq!(collected_process().reap(false, &Log::new(None)), None);
}
#[cfg(debug_assertions)]
#[skuld::test]
#[should_panic(expected = "waitid on the program's pidfd")]
fn a_wait_that_fails_other_than_echild_is_a_bug() {
not_a_process().reap(false, &Log::new(None));
}
#[cfg(not(debug_assertions))]
#[skuld::test]
fn a_wait_that_fails_other_than_echild_is_logged_and_lost() {
assert_eq!(not_a_process().reap(false, &Log::new(None)), None);
}