use super::is_nested;
#[skuld::test]
fn is_nested_without_marker_is_false() {
assert!(!is_nested(false));
}
#[skuld::test]
fn is_nested_with_marker_is_true() {
assert!(is_nested(true));
}
#[cfg(unix)]
#[skuld::test]
fn unix_setup_for_session_selects_setsid() {
use super::{unix_setup_for, UnixSetup};
use crate::containment::ContainMode;
assert_eq!(unix_setup_for(Some(ContainMode::Session)), UnixSetup::Session);
}
#[cfg(unix)]
#[skuld::test]
fn unix_setup_for_strongest_selects_process_group() {
use super::{unix_setup_for, UnixSetup};
use crate::containment::ContainMode;
assert_eq!(unix_setup_for(Some(ContainMode::Strongest)), UnixSetup::ProcessGroup);
}
#[cfg(unix)]
#[skuld::test]
fn unix_setup_for_treewalk_selects_none() {
use super::{unix_setup_for, UnixSetup};
use crate::containment::ContainMode;
assert_eq!(unix_setup_for(Some(ContainMode::TreeWalk)), UnixSetup::None);
}
#[cfg(unix)]
#[skuld::test]
fn unix_setup_for_none_mode_selects_process_group() {
use super::{unix_setup_for, UnixSetup};
assert_eq!(unix_setup_for(None), UnixSetup::ProcessGroup);
}
#[skuld::test]
fn attached_is_actionable() {
use super::Attached;
assert!(!Attached::None.is_actionable()); assert!(!Attached::Delegated.is_actionable());
assert!(Attached::TreeWalk(crate::identity::ProcessId::current()).is_actionable());
#[cfg(unix)]
assert!(Attached::ProcessGroup(0).is_actionable());
#[cfg(target_os = "linux")]
assert!(Attached::Cgroup(crate::containment::cgroup::CgroupLeaf::placeholder_for_test()).is_actionable());
#[cfg(windows)]
assert!(Attached::JobObject(crate::containment::windows::JobHandle::create_empty_for_test()).is_actionable());
}
#[cfg(unix)]
#[skuld::test]
fn attached_carries_recyclable_pgid() {
use super::Attached;
assert!(!Attached::None.carries_recyclable_pgid());
assert!(!Attached::Delegated.carries_recyclable_pgid());
assert!(!Attached::TreeWalk(crate::identity::ProcessId::current()).carries_recyclable_pgid());
assert!(Attached::ProcessGroup(0).carries_recyclable_pgid());
#[cfg(target_os = "linux")]
assert!(
!Attached::Cgroup(crate::containment::cgroup::CgroupLeaf::placeholder_for_test()).carries_recyclable_pgid()
);
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn attached_fd_marker_carries_recyclable_pgid_tracks_its_own_pgid() {
use std::os::fd::{AsFd, AsRawFd};
use super::Attached;
fn marker_with_pgid(pgid: Option<i32>) -> crate::containment::fdmarker::Marker {
let (read, write) = std::io::pipe().expect("pipe");
let handle = crate::containment::fdmarker::pipe_handle_of(write.as_fd()).expect("handle");
let read_handle = crate::containment::fdmarker::pipe_handle_of(read.as_fd()).expect("read handle");
let prepared = crate::containment::fdmarker::PreparedMarker {
read: std::os::fd::OwnedFd::from(read),
handle,
read_handle,
fd: write.as_fd().as_raw_fd(),
};
crate::containment::fdmarker::Marker::new(
prepared,
crate::containment::fdmarker::fdmarker_tests::inert_root(),
pgid,
)
}
assert!(Attached::FdMarker(marker_with_pgid(Some(1234))).carries_recyclable_pgid());
assert!(!Attached::FdMarker(marker_with_pgid(None)).carries_recyclable_pgid());
}
#[skuld::test]
fn nested_attach_is_delegated() {
use super::{attach, Attached, Prepared};
use crate::containment::{ContainMode, Containment};
fn spawn_trivial() -> std::process::Child {
#[cfg(unix)]
return crate::test_spawn::spawn(&mut std::process::Command::new("true")).expect("spawn true");
#[cfg(windows)]
return crate::test_spawn::spawn(std::process::Command::new("cmd").args(["/C", "exit"])).expect("spawn cmd");
}
for mode in [ContainMode::Strongest, ContainMode::TreeWalk] {
let mut child = spawn_trivial();
let prepared = Prepared {
mode: Some(mode),
is_root: false, #[cfg(target_os = "linux")]
cgroup_leaf: None,
#[cfg(target_os = "macos")]
marker: None,
#[cfg(windows)]
graceful: crate::containment::windows::mechanism_from_flags(crate::containment::windows::group_flags()),
#[cfg(windows)]
frozen: false,
};
#[cfg(windows)]
let proc_handle = {
use std::os::windows::io::AsRawHandle;
child.as_raw_handle()
};
let crate::identity::Resolved::Found(id) = crate::identity::ProcessId::of(child.id()) else {
panic!("the helper child must be readable");
};
let attachment = attach(
id,
#[cfg(target_os = "linux")]
crate::containment::cgroup::test_support::handle_of(
child.id(),
&crate::containment::cgroup::test_support::pidfd_of(child.id()),
),
#[cfg(windows)]
proc_handle,
prepared,
)
.expect("attach nested");
let (containment, attached) = (attachment.containment, attachment.attached);
_ = child.kill();
_ = child.wait();
assert_eq!(
containment,
Containment::Delegated,
"nested member ({mode:?}) must report Containment::Delegated, got {containment:?}"
);
assert!(
matches!(attached, Attached::Delegated),
"nested member ({mode:?}) must be Attached::Delegated, got {attached:?}"
);
}
}
#[skuld::test]
fn sync_kill_tree_backstop_is_load_bearing() {
#[cfg(not(target_os = "macos"))]
use super::super::treewalk::fault;
#[cfg(target_os = "macos")]
use crate::containment::fdmarker::fault;
let mut cmd = crate::Command::new();
#[cfg(unix)]
cmd.args(["cat"]);
#[cfg(windows)]
cmd.args([crate::test_child::windows_more()]);
cmd.stdin(crate::Stdio::pipe()).expect("set stdin pipe");
#[cfg(windows)]
cmd.stdout(crate::Stdio::null()).expect("set stdout null");
cmd.contain_with(crate::ContainMode::TreeWalk);
let mut child = cmd.spawn().expect("spawn");
let stdin = child.stdin().expect("piped stdin");
fault::set_force_root_kill_noop(true);
let result = child.kill_tree();
assert!(
!fault::armed(),
"seam not consumed — hard_kill did not run on the arming thread"
);
result.expect("kill_tree via backstop");
drop(stdin);
let status = child.wait().expect("reap");
assert!(
!status.success(),
"the handle backstop must be what killed the root, got {status:?}"
);
}
#[cfg(feature = "tokio")]
#[skuld::test]
async fn async_kill_tree_backstop_is_load_bearing() {
#[cfg(not(target_os = "macos"))]
use super::super::treewalk::fault;
#[cfg(target_os = "macos")]
use crate::containment::fdmarker::fault;
let mut cmd = crate::tokio::Command::new();
#[cfg(unix)]
cmd.args(["cat"]);
#[cfg(windows)]
cmd.args([crate::test_child::windows_more()]);
cmd.stdin(crate::Stdio::pipe()).expect("set stdin pipe");
#[cfg(windows)]
cmd.stdout(crate::Stdio::null()).expect("set stdout null");
cmd.contain_with(crate::ContainMode::TreeWalk);
let mut child = cmd.spawn().expect("spawn");
let stdin = child.stdin().expect("piped stdin");
fault::set_force_root_kill_noop(true);
let result = child.kill_tree();
assert!(
!fault::armed(),
"seam not consumed — hard_kill did not run on the arming thread"
);
result.expect("kill_tree via backstop");
drop(stdin);
let status = child.wait().await.expect("reap");
assert!(
!status.success(),
"the handle backstop must be what killed the root, got {status:?}"
);
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn marker_wanted_installs_for_every_contained_root_and_nothing_else() {
use crate::containment::fdmarker::marker_wanted;
use crate::containment::ContainMode;
for mode in [ContainMode::Strongest, ContainMode::Session, ContainMode::TreeWalk] {
assert!(
marker_wanted(Some(mode), true, false),
"{mode:?} root installs a marker"
);
assert!(
!marker_wanted(Some(mode), false, false),
"{mode:?} nested inherits, never installs"
);
assert!(
!marker_wanted(Some(mode), true, true),
"{mode:?} elevated root must not install"
);
}
assert!(
!marker_wanted(None, true, false),
"an uncontained spawn installs no marker"
);
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn attached_fd_marker_is_actionable() {
use std::os::fd::{AsFd, AsRawFd};
use super::Attached;
let (read, write) = std::io::pipe().expect("pipe");
let handle = crate::containment::fdmarker::pipe_handle_of(write.as_fd()).expect("handle");
let read_handle = crate::containment::fdmarker::pipe_handle_of(read.as_fd()).expect("read handle");
let prepared = crate::containment::fdmarker::PreparedMarker {
read: std::os::fd::OwnedFd::from(read),
handle,
read_handle,
fd: write.as_fd().as_raw_fd(),
};
let marker = crate::containment::fdmarker::Marker::new(
prepared,
crate::containment::fdmarker::fdmarker_tests::inert_root(),
None,
);
assert!(Attached::FdMarker(marker).is_actionable());
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn prepare_places_the_marker_above_the_callers_reserved_fds() {
use crate::containment::{ContainMode, ContainRequest, Nesting};
let mut cmd = std::process::Command::new("/usr/bin/true");
let prepared = super::prepare(
&mut cmd,
&ContainRequest {
mode: Some(ContainMode::Strongest),
nesting: Nesting::Mark,
},
&crate::command::flags::FlagsRequest::default(),
&[3, 4, 5, 6, 7, 8, 9, 10],
false,
&[],
)
.expect("prepare is infallible off Windows");
let marker = prepared.marker.as_ref().expect("a contained macOS root gets a marker");
assert!(
marker.fd > 10,
"prepare placed the marker on fd {}, which a user mapping would dup2 over",
marker.fd
);
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn a_failed_marker_install_leaves_prepare_without_one() {
use crate::containment::fdmarker::fault::{lock_for_log_assertion, set_fault, Fault};
use crate::containment::{ContainMode, ContainRequest, Nesting};
let _serialize = lock_for_log_assertion();
let mut cmd = std::process::Command::new("/usr/bin/true");
set_fault(Some(Fault::Pipe));
let prepared = super::prepare(
&mut cmd,
&ContainRequest {
mode: Some(ContainMode::Strongest),
nesting: Nesting::Mark,
},
&crate::command::flags::FlagsRequest::default(),
&[],
false,
&[],
)
.expect("prepare is infallible off Windows");
assert!(prepared.marker.is_none(), "the forced failure must yield no marker");
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn prepare_installs_no_marker_for_an_elevation_derived_spawn() {
use crate::containment::{ContainMode, ContainRequest, Nesting};
let mut cmd = std::process::Command::new("/usr/bin/true");
let prepared = super::prepare(
&mut cmd,
&ContainRequest {
mode: Some(ContainMode::Strongest),
nesting: Nesting::Mark,
},
&crate::command::flags::FlagsRequest::default(),
&[],
true,
&[],
)
.expect("prepare is infallible off Windows");
assert!(
prepared.marker.is_none(),
"an elevated spawn must not claim marker containment"
);
}
#[cfg(windows)]
#[skuld::test]
fn spawn_identity_distinguishes_a_denied_pid_from_a_vanished_one() {
use crate::child::spawn::{resolve_identity_unchecked, spawn_identity_error};
use windows::Win32::System::Threading::PROCESS_SYNCHRONIZE;
let child = crate::identity::windows_fixture::spawn_restricted(PROCESS_SYNCHRONIZE.0);
assert!(child.is_running(), "precondition: the subject must be live");
let denied = spawn_identity_error(resolve_identity_unchecked(child.pid()));
assert!(
matches!(denied, crate::error::Error::Unassessable { .. }),
"a pid we may not query must not read as vanished: {denied:?}"
);
let absent = spawn_identity_error(resolve_identity_unchecked(0xFFFF_FFF0));
assert!(
matches!(&absent, crate::error::Error::Io(e) if e.to_string().contains("reaped by another party")),
"absence must not read as denial: {absent:?}"
);
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn wait_drained_is_unsupported_without_a_marker() {
use super::Attached;
for attached in [Attached::None, Attached::Delegated] {
let err = attached
.wait_drained(Some(Some(std::time::Instant::now())))
.expect_err("a mechanism with no drain edge must be Unsupported");
assert!(matches!(err, crate::error::Error::Unsupported { .. }), "got {err:?}");
}
}
#[cfg(target_os = "macos")]
#[skuld::test]
fn wait_drained_reports_members_remain_then_all_markers_closed() {
use super::Attached;
use crate::containment::fdmarker::{pipe_handle_of, Marker, PreparedMarker};
use crate::containment::TreeDrain;
use std::os::fd::{AsFd, OwnedFd};
let mut cmd = crate::Command::new();
cmd.executable("/bin/sh").args(["sh", "-c", "exec cat >/dev/null"]);
cmd.fd(0, crate::Stdio::pipe_in()).expect("stdin pipe");
cmd.fd(3, crate::Stdio::pipe_out()).expect("marker pipe");
let mut child = cmd.spawn().expect("spawn /bin/sh");
let marker = child.fd_read_end(3.into()).expect("marker read end");
let stdin = child.fd_write_end(crate::Fd::STDIN).expect("stdin write end");
let handle = pipe_handle_of(marker.as_fd()).expect("handle");
let prepared = PreparedMarker {
read: OwnedFd::from(marker),
handle,
read_handle: handle,
fd: 3,
};
let attached = Attached::FdMarker(Marker::new(
prepared,
crate::containment::fdmarker::fdmarker_tests::inert_root(),
None,
));
assert_eq!(
attached
.wait_drained(Some(Some(std::time::Instant::now())))
.expect("bounded wait while the holder is alive"),
TreeDrain::MembersRemain
);
drop(stdin); child.wait().expect("reap");
assert_eq!(
attached
.wait_drained(None)
.expect("unbounded wait after the holder exits"),
TreeDrain::AllMarkersClosed
);
}
#[cfg(windows)]
#[skuld::test]
fn uac_elevated_attachment_has_no_in_process_route() {
use super::{Attached, Attachment};
use crate::containment::Containment;
use crate::graceful::GracefulMechanism;
let a = Attachment::uac_elevated();
assert_eq!(a.containment, Containment::None);
assert!(matches!(a.attached, Attached::None), "got {:?}", a.attached);
assert_eq!(a.graceful, GracefulMechanism::Unknown);
}
#[cfg(target_os = "linux")]
#[derive(Clone, Copy)]
enum ChildReport {
Placed,
WriteFailed,
NotReported,
}
#[cfg(target_os = "linux")]
fn decide(leaf_path: &std::path::Path, report: ChildReport) -> (crate::containment::Containment, super::Attached) {
use crate::containment::cgroup::{place_self_in_cgroup_pre_exec, CgroupLeaf};
let leaf = CgroupLeaf::for_test_at(leaf_path.to_path_buf());
match report {
ChildReport::Placed => unsafe { leaf.placement_slot().report_placed_for_test() },
ChildReport::WriteFailed => {
_ = unsafe { place_self_in_cgroup_pre_exec(-1, leaf.placement_slot()) };
}
ChildReport::NotReported => {}
}
let prepared = super::Prepared {
mode: Some(crate::containment::ContainMode::Strongest),
is_root: true,
cgroup_leaf: Some(leaf),
};
super::attach_tree(
crate::identity::ProcessId::current(),
crate::containment::cgroup::test_support::handle_of(
std::process::id(),
&crate::containment::cgroup::test_support::pidfd_of(std::process::id()),
),
prepared,
)
.expect("attach_tree")
}
#[cfg(target_os = "linux")]
fn leaf_listing_another_pid(dir: &std::path::Path) -> std::path::PathBuf {
let leaf_path = dir.join("cosca-decision-leaf");
std::fs::create_dir(&leaf_path).expect("create the leaf");
let other = std::process::id().wrapping_add(1);
std::fs::write(leaf_path.join("cgroup.procs"), format!("{other}\n")).expect("write cgroup.procs");
leaf_path
}
#[cfg(target_os = "linux")]
#[skuld::test(labels = [crate::test_harness::CGROUP])]
fn a_placed_report_outranks_a_cgroup_procs_that_omits_the_child() {
let dir = tempfile::tempdir().expect("tempdir");
let leaf_path = leaf_listing_another_pid(dir.path());
let (containment, attached) = decide(&leaf_path, ChildReport::Placed);
assert_eq!(containment, crate::containment::Containment::CgroupV2);
let super::Attached::Cgroup(leaf) = &attached else {
panic!("got {attached:?}");
};
assert!(
!leaf.holds_spawn_resources(),
"a live child's leaf must not hold its cgroup.procs fd or report pipe past the verdict"
);
assert!(
!leaf_path.join("cgroup.kill").exists(),
"the leaf owns a live tree; nothing may kill it at spawn time"
);
}
#[cfg(target_os = "linux")]
#[skuld::test(labels = [crate::test_harness::CGROUP])]
fn a_placed_report_outranks_an_unreadable_cgroup_procs() {
let dir = tempfile::tempdir().expect("tempdir");
let leaf_path = dir.path().join("cosca-decision-leaf");
std::fs::create_dir(&leaf_path).expect("create the leaf (no cgroup.procs inside)");
let (containment, attached) = decide(&leaf_path, ChildReport::Placed);
assert_eq!(containment, crate::containment::Containment::CgroupV2);
assert!(matches!(attached, super::Attached::Cgroup(_)), "got {attached:?}");
}
#[cfg(target_os = "linux")]
#[skuld::test]
fn a_failed_write_degrades_and_removes_the_leaf() {
let dir = tempfile::tempdir().expect("tempdir");
let leaf_path = dir.path().join("cosca-decision-leaf");
std::fs::create_dir(&leaf_path).expect("create the leaf");
let (containment, attached) = decide(&leaf_path, ChildReport::WriteFailed);
assert_eq!(containment, crate::containment::Containment::ProcessGroup);
assert!(matches!(attached, super::Attached::ProcessGroup(_)), "got {attached:?}");
assert!(!leaf_path.exists(), "the degrade must remove the leaf it created");
}
#[cfg(target_os = "linux")]
#[skuld::test]
fn a_degrade_never_kills_through_the_leaf() {
crate::log_capture::install();
for report in [ChildReport::WriteFailed, ChildReport::NotReported] {
let dir = tempfile::tempdir().expect("tempdir");
let leaf_path = leaf_listing_another_pid(dir.path());
let mark = crate::log_capture::mark();
let (containment, _attached) = decide(&leaf_path, report);
assert_eq!(containment, crate::containment::Containment::ProcessGroup);
assert!(
!leaf_path.join("cgroup.kill").exists(),
"a degrade wrote cgroup.kill: it would kill a tree cosca had just been asked to contain"
);
let left_behind: Vec<String> = crate::log_capture::records_since(mark, &leaf_path.to_string_lossy())
.into_iter()
.filter(|record| record.contains("was not removed"))
.collect();
assert_eq!(
left_behind.len(),
1,
"the unremoved leaf is reported once: {left_behind:?}"
);
}
}
#[cfg(target_os = "linux")]
fn occupied_leaf_for_test(dir: &std::path::Path, name: &str) -> std::path::PathBuf {
let leaf_path = dir.join(name);
std::fs::create_dir(&leaf_path).expect("create the leaf");
std::fs::write(leaf_path.join("occupant"), "").expect("stand in for the live tree");
std::fs::write(leaf_path.join("cgroup.kill"), b"").expect("create cgroup.kill");
leaf_path
}
#[cfg(target_os = "linux")]
fn cgroup_attachment_for_test(leaf_path: &std::path::Path) -> super::Attachment {
super::Attachment {
containment: crate::containment::Containment::CgroupV2,
attached: super::Attached::Cgroup(crate::containment::cgroup::test_support::entered_leaf_at(
leaf_path.to_path_buf(),
)),
graceful: crate::graceful::GracefulMechanism::Process,
}
}
#[cfg(target_os = "linux")]
#[skuld::test(labels = [crate::test_harness::CGROUP])]
fn kill_on_drop_false_disarms_a_cgroup_leaf() {
let dir = tempfile::tempdir().expect("tempdir");
let leaf_path = occupied_leaf_for_test(dir.path(), "cosca-kill-on-drop-false-leaf");
let attachment = cgroup_attachment_for_test(&leaf_path);
attachment.attached.honor_kill_on_drop(false);
drop(attachment);
assert_eq!(
std::fs::read(leaf_path.join("cgroup.kill")).expect("read cgroup.kill"),
b"",
"kill_on_drop(false) opts out of the teardown; a tree it killed anyway is the opposite"
);
}
#[cfg(target_os = "linux")]
#[skuld::test(labels = [crate::test_harness::CGROUP])]
fn kill_on_drop_true_leaves_a_cgroup_leaf_armed() {
let dir = tempfile::tempdir().expect("tempdir");
let leaf_path = occupied_leaf_for_test(dir.path(), "cosca-kill-on-drop-true-leaf");
let attachment = cgroup_attachment_for_test(&leaf_path);
attachment.attached.honor_kill_on_drop(true);
drop(attachment);
assert_eq!(
std::fs::read(leaf_path.join("cgroup.kill")).expect("read cgroup.kill"),
b"1",
"the default is still a kill-on-drop teardown"
);
}
#[cfg(windows)]
mod frozen_attach {
use crate::containment::dispatch::{attach, Attached, Attachment, Prepared};
use crate::containment::windows::fault::{force_next, Step};
use crate::containment::{ContainMode, Containment};
use crate::error::Error;
use crate::test_frozen::{raw, spawn_suspended_blocker, InitialThread};
const ERROR_ACCESS_DENIED: u32 = 5;
fn prepared(mode: Option<ContainMode>, is_root: bool, frozen: bool) -> Prepared {
Prepared {
mode,
is_root,
graceful: crate::graceful::GracefulMechanism::None,
frozen,
}
}
fn attach_suspended(child: &std::process::Child, prepared: Prepared) -> Result<Attachment, Error> {
let crate::identity::Resolved::Found(id) = crate::identity::ProcessId::of(child.id()) else {
panic!("the suspended child must be readable");
};
attach(id, raw(child), prepared)
}
fn dispose(mut child: std::process::Child) {
child.kill().expect("kill the test child");
child.wait().expect("reap the test child");
}
#[skuld::test]
fn death_watch_attach_frozen_assigns_a_strongest_roots_job_and_leaves_the_thread_suspended() {
let child = spawn_suspended_blocker();
let thread = InitialThread::of(child.id());
let attachment = attach_suspended(&child, prepared(Some(ContainMode::Strongest), true, true)).expect("attach");
assert_eq!(attachment.containment, Containment::JobObject);
assert!(matches!(attachment.attached, Attached::JobObject(_)));
assert_eq!(thread.suspend_count(), 1, "a frozen attach must not resume");
drop(attachment);
child
.wait_with_output()
.expect("the job's close killed the frozen child");
}
#[skuld::test]
fn attach_frozen_fails_when_the_strongest_assignment_fails_instead_of_falling_back_to_treewalk() {
let child = spawn_suspended_blocker();
let _forced = force_next(Step::Assign, ERROR_ACCESS_DENIED);
let err = attach_suspended(&child, prepared(Some(ContainMode::Strongest), true, true))
.err()
.expect("a frozen attach with no job must fail");
assert!(matches!(err, Error::Containment { .. }), "got {err:?}");
dispose(child);
}
#[skuld::test]
fn attach_without_hold_still_resumes_and_still_falls_back_to_treewalk() {
let child = spawn_suspended_blocker();
let thread = InitialThread::of(child.id());
let _forced = force_next(Step::Assign, ERROR_ACCESS_DENIED);
let attachment = attach_suspended(&child, prepared(Some(ContainMode::Strongest), true, false)).expect("attach");
assert_eq!(attachment.containment, Containment::TreeWalk);
assert_eq!(thread.suspend_count(), 0, "the ordinary attach resumes the child");
dispose(child);
}
#[skuld::test]
fn attach_frozen_gives_treewalk_nested_and_uncontained_shapes_no_job_and_leaves_them_suspended() {
let shapes = [
(
"treewalk root",
Some(ContainMode::TreeWalk),
true,
Containment::TreeWalk,
),
(
"nested strongest member",
Some(ContainMode::Strongest),
false,
Containment::Delegated,
),
(
"nested treewalk member",
Some(ContainMode::TreeWalk),
false,
Containment::Delegated,
),
("uncontained", None, false, Containment::None),
];
for (name, mode, is_root, expected) in shapes {
let child = spawn_suspended_blocker();
let thread = InitialThread::of(child.id());
let attachment = attach_suspended(&child, prepared(mode, is_root, true)).expect(name);
assert_eq!(attachment.containment, expected, "{name}");
assert!(
!matches!(attachment.attached, Attached::JobObject(_)),
"{name}: no job of its own"
);
assert_eq!(thread.suspend_count(), 1, "{name}: a frozen attach must not resume");
drop(attachment);
dispose(child);
}
}
}