1 extern crate bytes; 2 #[macro_use] 3 extern crate cfg_if; 4 #[macro_use] 5 extern crate nix; 6 #[macro_use] 7 extern crate lazy_static; 8 extern crate libc; 9 extern crate rand; 10 extern crate tempfile; 11 12 macro_rules! skip_if_not_root { 13 ($name:expr) => { 14 use nix::unistd::Uid; 15 use std; 16 use std::io::Write; 17 18 if !Uid::current().is_root() { 19 let stderr = std::io::stderr(); 20 let mut handle = stderr.lock(); 21 writeln!(handle, "{} requires root privileges. Skipping test.", $name).unwrap(); 22 return; 23 } 24 }; 25 } 26 27 mod sys; 28 mod test_dir; 29 mod test_fcntl; 30 #[cfg(any(target_os = "android", 31 target_os = "linux"))] 32 mod test_kmod; 33 #[cfg(any(target_os = "dragonfly", 34 target_os = "freebsd", 35 target_os = "fushsia", 36 target_os = "linux", 37 target_os = "netbsd"))] 38 mod test_mq; 39 mod test_net; 40 mod test_nix_path; 41 mod test_poll; 42 mod test_pty; 43 #[cfg(any(target_os = "android", 44 target_os = "freebsd", 45 target_os = "ios", 46 target_os = "linux", 47 target_os = "macos"))] 48 mod test_sendfile; 49 mod test_stat; 50 mod test_unistd; 51 52 use std::os::unix::io::RawFd; 53 use std::sync::Mutex; 54 use nix::unistd::read; 55 56 /// Helper function analogous to `std::io::Read::read_exact`, but for `RawFD`s 57 fn read_exact(f: RawFd, buf: &mut [u8]) { 58 let mut len = 0; 59 while len < buf.len() { 60 // get_mut would be better than split_at_mut, but it requires nightly 61 let (_, remaining) = buf.split_at_mut(len); 62 len += read(f, remaining).unwrap(); 63 } 64 } 65 66 lazy_static! { 67 /// Any test that changes the process's current working directory must grab 68 /// this mutex 69 pub static ref CWD_MTX: Mutex<()> = Mutex::new(()); 70 /// Any test that changes the process's supplementary groups must grab this 71 /// mutex 72 pub static ref GROUPS_MTX: Mutex<()> = Mutex::new(()); 73 /// Any test that creates child processes must grab this mutex, regardless 74 /// of what it does with those children. 75 pub static ref FORK_MTX: Mutex<()> = Mutex::new(()); 76 /// Any test that calls ptsname(3) must grab this mutex. 77 pub static ref PTSNAME_MTX: Mutex<()> = Mutex::new(()); 78 /// Any test that alters signal handling must grab this mutex. 79 pub static ref SIGNAL_MTX: Mutex<()> = Mutex::new(()); 80 } 81