diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/nix/test/test.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/nix/test/test.rs')
-rw-r--r-- | third_party/rust/nix/test/test.rs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/third_party/rust/nix/test/test.rs b/third_party/rust/nix/test/test.rs new file mode 100644 index 0000000000..a91b6348e0 --- /dev/null +++ b/third_party/rust/nix/test/test.rs @@ -0,0 +1,80 @@ +extern crate bytes; +#[macro_use] +extern crate cfg_if; +#[macro_use] +extern crate nix; +#[macro_use] +extern crate lazy_static; +extern crate libc; +extern crate rand; +extern crate tempfile; + +macro_rules! skip_if_not_root { + ($name:expr) => { + use nix::unistd::Uid; + use std; + use std::io::Write; + + if !Uid::current().is_root() { + let stderr = std::io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, "{} requires root privileges. Skipping test.", $name).unwrap(); + return; + } + }; +} + +mod sys; +mod test_dir; +mod test_fcntl; +#[cfg(any(target_os = "android", + target_os = "linux"))] +mod test_kmod; +#[cfg(any(target_os = "dragonfly", + target_os = "freebsd", + target_os = "fushsia", + target_os = "linux", + target_os = "netbsd"))] +mod test_mq; +mod test_net; +mod test_nix_path; +mod test_poll; +mod test_pty; +#[cfg(any(target_os = "android", + target_os = "freebsd", + target_os = "ios", + target_os = "linux", + target_os = "macos"))] +mod test_sendfile; +mod test_stat; +mod test_unistd; + +use std::os::unix::io::RawFd; +use std::sync::Mutex; +use nix::unistd::read; + +/// Helper function analogous to `std::io::Read::read_exact`, but for `RawFD`s +fn read_exact(f: RawFd, buf: &mut [u8]) { + let mut len = 0; + while len < buf.len() { + // get_mut would be better than split_at_mut, but it requires nightly + let (_, remaining) = buf.split_at_mut(len); + len += read(f, remaining).unwrap(); + } +} + +lazy_static! { + /// Any test that changes the process's current working directory must grab + /// this mutex + pub static ref CWD_MTX: Mutex<()> = Mutex::new(()); + /// Any test that changes the process's supplementary groups must grab this + /// mutex + pub static ref GROUPS_MTX: Mutex<()> = Mutex::new(()); + /// Any test that creates child processes must grab this mutex, regardless + /// of what it does with those children. + pub static ref FORK_MTX: Mutex<()> = Mutex::new(()); + /// Any test that calls ptsname(3) must grab this mutex. + pub static ref PTSNAME_MTX: Mutex<()> = Mutex::new(()); + /// Any test that alters signal handling must grab this mutex. + pub static ref SIGNAL_MTX: Mutex<()> = Mutex::new(()); +} |