From d970e8e4b2825c4474ca92e7af85b8f54388b10d Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 2 May 2020 14:03:28 -0600 Subject: [PATCH 1/4] Factor out common code from the various skip macros --- test/test.rs | 51 ++++++++++++++++----------------------------- test/test_unistd.rs | 2 +- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/test/test.rs b/test/test.rs index ac842b1134..2d43196c87 100644 --- a/test/test.rs +++ b/test/test.rs @@ -5,22 +5,27 @@ extern crate nix; #[macro_use] extern crate lazy_static; +macro_rules! skip { + ($($reason: expr),+) => { + use ::std::io::{self, Write}; + + let stderr = io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, $($reason),+).unwrap(); + return; + } +} + cfg_if! { if #[cfg(any(target_os = "android", target_os = "linux"))] { macro_rules! require_capability { ($capname:ident) => { use ::caps::{Capability, CapSet, has_cap}; - use ::std::io::{self, Write}; if !has_cap(None, CapSet::Effective, Capability::$capname) .unwrap() { - let stderr = io::stderr(); - let mut handle = stderr.lock(); - writeln!(handle, - "Insufficient capabilities. Skipping test.") - .unwrap(); - return; + skip!("Insufficient capabilities. Skipping test."); } } } @@ -39,12 +44,7 @@ macro_rules! skip_if_jailed { if let CtlValue::Int(1) = ::sysctl::value("security.jail.jailed") .unwrap() { - use ::std::io::Write; - let stderr = ::std::io::stderr(); - let mut handle = stderr.lock(); - writeln!(handle, "{} cannot run in a jail. Skipping test.", $name) - .unwrap(); - return; + skip!("{} cannot run in a jail. Skipping test.", $name); } } } @@ -55,11 +55,7 @@ macro_rules! skip_if_not_root { use nix::unistd::Uid; if !Uid::current().is_root() { - use ::std::io::Write; - let stderr = ::std::io::stderr(); - let mut handle = stderr.lock(); - writeln!(handle, "{} requires root privileges. Skipping test.", $name).unwrap(); - return; + skip!("{} requires root privileges. Skipping test.", $name); } }; } @@ -74,13 +70,8 @@ cfg_if! { if fields.next() == Some("Seccomp:") && fields.next() != Some("0") { - use ::std::io::Write; - let stderr = ::std::io::stderr(); - let mut handle = stderr.lock(); - writeln!(handle, - "{} cannot be run in Seccomp mode. Skipping test.", - stringify!($name)).unwrap(); - return; + skip!("{} cannot be run in Seccomp mode. Skipping test.", + stringify!($name)); } } } @@ -97,7 +88,6 @@ cfg_if! { if #[cfg(target_os = "linux")] { macro_rules! require_kernel_version { ($name:expr, $version_requirement:expr) => { - use ::std::io::Write; use semver::{Version, VersionReq}; let version_requirement = VersionReq::parse($version_requirement) @@ -112,13 +102,8 @@ cfg_if! { version.build.clear(); if !version_requirement.matches(&version) { - let stderr = ::std::io::stderr(); - let mut handle = stderr.lock(); - - writeln!(handle, - "Skip {} because kernel version `{}` doesn't match the requirement `{}`", - stringify!($name), version, version_requirement).unwrap(); - return; + skip!("Skip {} because kernel version `{}` doesn't match the requirement `{}`", + stringify!($name), version, version_requirement); } } } diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 24ed2e564e..d44cb067d8 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -932,7 +932,7 @@ fn test_access_file_exists() { #[test] fn test_setfsuid() { use std::os::unix::fs::PermissionsExt; - use std::{fs, thread}; + use std::{fs, io, thread}; require_capability!(CAP_SETUID); // get the UID of the "nobody" user From d57326e5922de28e2fcaa26e80a71f84a3518be3 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 2 May 2020 10:15:51 -0600 Subject: [PATCH 2/4] Add a missing require_capability! to a test --- test/sys/test_ptrace.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index 05f407cc48..46ea3d6a14 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -128,6 +128,8 @@ fn test_ptrace_syscall() { use nix::unistd::getpid; use nix::unistd::ForkResult::*; + require_capability!(CAP_SYS_PTRACE); + let _m = crate::FORK_MTX.lock().expect("Mutex got poisoned by another test"); match fork().expect("Error: Fork Failed") { From f4698ea3faf35026f951271c45d4e854f5603a8a Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sat, 2 May 2020 10:17:00 -0600 Subject: [PATCH 3/4] Skip the OFD locks tests on OverlayFS and musl OFD lock functions don't work as expected on overlayfs, which is a type of union file system. And OVERLAYFS_SUPER_MAGIC isn't defined on musl, at least not yet. --- Cargo.toml | 2 +- src/sys/statfs.rs | 2 ++ test/test_fcntl.rs | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b5c017f7fe..abb6953083 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ exclude = [ ] [dependencies] -libc = { git = "https://github.com/rust-lang/libc/", features = [ "extra_traits" ] } +libc = { git = "https://github.com/rust-lang/libc/", rev = "fdc5cf4a1ba362aec989bd3dc7ec88bcd371a23a", features = [ "extra_traits" ] } bitflags = "1.1" cfg-if = "0.1.10" diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs index 3d46be9cad..e2b9e6b924 100644 --- a/src/sys/statfs.rs +++ b/src/sys/statfs.rs @@ -72,6 +72,8 @@ pub const NFS_SUPER_MAGIC: FsType = FsType(libc::NFS_SUPER_MAGIC); #[cfg(all(target_os = "linux", not(target_env = "musl"), not(target_arch = "s390x")))] pub const OPENPROM_SUPER_MAGIC: FsType = FsType(libc::OPENPROM_SUPER_MAGIC); #[cfg(all(target_os = "linux", not(target_env = "musl"), not(target_arch = "s390x")))] +pub const OVERLAYFS_SUPER_MAGIC: FsType = FsType(libc::OVERLAYFS_SUPER_MAGIC); +#[cfg(all(target_os = "linux", not(target_env = "musl"), not(target_arch = "s390x")))] pub const PROC_SUPER_MAGIC: FsType = FsType(libc::PROC_SUPER_MAGIC); #[cfg(all(target_os = "linux", not(target_env = "musl"), not(target_arch = "s390x")))] pub const QNX4_SUPER_MAGIC: FsType = FsType(libc::QNX4_SUPER_MAGIC); diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index c9f382bc9b..2971907224 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -228,11 +228,19 @@ mod linux_android { target_arch = "mips64", target_arch = "mips64el", target_arch = "powerpc64", - target_arch = "powerpc64le")))] + target_arch = "powerpc64le", + target_env = "musl")))] fn test_ofd_write_lock() { let tmp = NamedTempFile::new().unwrap(); let fd = tmp.as_raw_fd(); + let statfs = nix::sys::statfs::fstatfs(&tmp).unwrap(); + if statfs.filesystem_type() == nix::sys::statfs::OVERLAYFS_SUPER_MAGIC { + // OverlayFS is a union file system. It returns one inode value in + // stat(2), but a different one shows up in /proc/locks. So we must + // skip the test. + skip!("/proc/locks does not work on overlayfs"); + } let inode = fstat(fd).expect("fstat failed").st_ino as usize; let mut flock = libc::flock { @@ -262,11 +270,19 @@ mod linux_android { target_arch = "mips64", target_arch = "mips64el", target_arch = "powerpc64", - target_arch = "powerpc64le")))] + target_arch = "powerpc64le", + target_env = "musl")))] fn test_ofd_read_lock() { let tmp = NamedTempFile::new().unwrap(); let fd = tmp.as_raw_fd(); + let statfs = nix::sys::statfs::fstatfs(&tmp).unwrap(); + if statfs.filesystem_type() == nix::sys::statfs::OVERLAYFS_SUPER_MAGIC { + // OverlayFS is a union file system. It returns one inode value in + // stat(2), but a different one shows up in /proc/locks. So we must + // skip the test. + skip!("/proc/locks does not work on overlayfs"); + } let inode = fstat(fd).expect("fstat failed").st_ino as usize; let mut flock = libc::flock { From ec05dd7f5aaffb9a8d807ccfc8bff6f376923e95 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Tue, 28 Apr 2020 19:08:47 -0600 Subject: [PATCH 4/4] Update the Linux CI environment to Ubuntu Bionic --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e05c8fe19f..fcef85e9c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ # Based on the "trust" template v0.1.1 # https://github.com/japaric/trust/tree/v0.1.1 -dist: trusty +dist: bionic language: rust services: docker