use super::kernel::HostKernel;
use super::proc_view::{proc_view_with, ProcView};
use crate::identity::{Existence, Liveness, ProcessId, Resolved};
use crate::test_child::fixture_path;
use crate::test_child::namespaces as ns;
use crate::test_child::Console;
use crate::test_groups::{namespaces, pidfd_group_signal, Group};
#[skuld::test]
fn namespaces_an_outer_procfs_does_not_matter_to_a_pidfs_identity(
#[fixture(namespaces)] _group: &Group,
#[fixture(pidfd_group_signal)] _pidfs: &Group,
) {
ns::run(fixture_path!(fixture_outer_procfs_outer));
}
#[skuld::test]
fn fixture_outer_procfs_outer() {
if !ns::is_child() {
return;
}
ns::enter_new_pid_ns_for_children();
ns::run(fixture_path!(fixture_outer_procfs_inner));
}
#[skuld::test]
fn fixture_outer_procfs_inner() {
if !ns::is_child_in_new_pid_ns() {
return;
}
assert_eq!(
std::process::id(),
1,
"the fixture must be pid 1 of its own pid namespace"
);
let view = proc_view_with(&HostKernel);
assert!(matches!(view, ProcView::Diverged), "got {view:?}");
let current = ProcessId::current();
assert_eq!(current.pid(), 1);
assert!(
current.pidfs_ino().is_some(),
"a pidfs host gives current() its pidfd's inode"
);
assert_eq!(
ProcessId::of(1),
Resolved::Found(current),
"pid 1 is this process, whatever /proc shows"
);
assert_eq!(current.exists(), Existence::Present);
assert_eq!(current.is_alive(), Liveness::Alive);
let mut child = crate::test_child::blocker();
let got = ProcessId::of(child.id());
let Resolved::Found(id) = got else {
panic!("an inner-namespace child: got {got:?}")
};
assert_eq!(id.exists(), Existence::Present);
assert_eq!(id.is_alive(), Liveness::Alive);
child.kill().expect("kill the child");
child.wait().expect("reap the child");
assert_eq!(id.exists(), Existence::Gone);
assert!(matches!(
ProcessId::of(super::read_tests::NO_PROCESS_CAN_HOLD),
Resolved::Gone
));
let mut cmd = crate::test_child::command(Console::Hidden);
cmd.args(crate::test_child::BLOCKER_ARGV.iter().copied());
let (stdin, writer) = crate::test_child::held_writer_stdin();
cmd.stdin(stdin).expect("set stdin pipe");
let spawned = cmd.spawn().expect("a spawn needs no /proc view on pidfs");
let teardown = crate::child::spawn::fault::release_at_drop_kill(writer);
drop(spawned);
teardown.assert_killed();
}