Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Grab FORK_MTX when unmounting or forking in the mount tests #2386

Merged
merged 4 commits into from Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/mount/test_mount.rs
Expand Up @@ -53,6 +53,8 @@ fn test_mount_tmpfs_without_flags_allows_rwx() {
.unwrap_or_else(|e| panic!("read failed: {e}"));
assert_eq!(buf, SCRIPT_CONTENTS);

// while forking and unmounting prevent other child processes
let _m = FORK_MTX.lock();
// Verify execute.
assert_eq!(
EXPECTED_STATUS,
Expand Down Expand Up @@ -129,6 +131,8 @@ fn test_mount_noexec_disallows_exec() {
&test_path
);

// while forking and unmounting prevent other child processes
let _m = FORK_MTX.lock();
// EACCES: Permission denied
assert_eq!(
EACCES,
Expand Down Expand Up @@ -168,6 +172,8 @@ fn test_mount_bind() {
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
.unwrap_or_else(|e| panic!("write failed: {e}"));

// wait for child processes to prevent EBUSY
let _m = FORK_MTX.lock();
umount(mount_point.path())
.unwrap_or_else(|e| panic!("umount failed: {e}"));
}
Expand Down
5 changes: 3 additions & 2 deletions test/test.rs
Expand Up @@ -57,8 +57,9 @@ fn read_exact<Fd: AsFd>(f: Fd, buf: &mut [u8]) {
}
}

/// Any test that creates child processes must grab this mutex, regardless
/// of what it does with those children.
/// Any test that creates child processes or can be affected by child processes must grab this mutex, regardless
/// of what it does with those children. It must hold the mutex until the
/// child processes are waited upon.
pub static FORK_MTX: Mutex<()> = Mutex::new(());
/// Any test that changes the process's current working directory must grab
/// the RwLock exclusively. Any process that cares about the current
Expand Down