summaryrefslogtreecommitdiff
path: root/test/common/mod.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2020-12-02 17:47:35 -0700
committerAlan Somers <asomers@gmail.com>2020-12-06 22:35:30 -0700
commitbf7a5fd606ba48c789bdaf95da2779e46e5f83c6 (patch)
tree5ff9c603b744eff0c5d1763df5220a661087bb5f /test/common/mod.rs
parenta1eb89568e50132339b5e8a1d5166fb5b5f9b0e8 (diff)
downloadnix-bf7a5fd606ba48c789bdaf95da2779e46e5f83c6.zip
Switch all builds from Travis to Cirrus
Travis has been super-slow lately (> 6 hours per build). Cirrus is much faster: about 20 minutes. Cirrus also has slightly better test coverage, mainly because it doesn't use SECCOMP. Also, * Fix the Redox CI build. The old Travis configuration didn't actually build for Redox, so we never noticed that Redox can't be built with a stable compiler. Thanks to @coolreader18 for finding this. * Disable the udp_offload tests on cross-tested platforms. These tests are failing with ENOPROTOOPT in Cirrus-CI. I suspect it's due to a lack of support in QEMU. These tests were skipped on Travis because its kernel was too old. * Fix require_kernel_version on Cirrus-CI. Cirrus reports the Linux kernel version as 4.19.112+, which the semver crate can't handle. * Fix test_setfsuid on Cirrus. When run on Cirrus, it seems like the file in /tmp gets deleted as soon as it's closed. Probably an overzealous temporary file cleaner. Use /var/tmp, because no temporary file cleaner should run in there. * Skip mount tests on Cirrus. They fail for an unknown reason. Issue #1351 * Skip the AF_ALG tests on Cirrus-CI Issue #1352
Diffstat (limited to 'test/common/mod.rs')
-rw-r--r--test/common/mod.rs127
1 files changed, 127 insertions, 0 deletions
diff --git a/test/common/mod.rs b/test/common/mod.rs
new file mode 100644
index 00000000..ace03fc6
--- /dev/null
+++ b/test/common/mod.rs
@@ -0,0 +1,127 @@
+use cfg_if::cfg_if;
+
+#[macro_export] 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_export] macro_rules! require_capability {
+ ($capname:ident) => {
+ use ::caps::{Capability, CapSet, has_cap};
+
+ if !has_cap(None, CapSet::Effective, Capability::$capname)
+ .unwrap()
+ {
+ skip!("Insufficient capabilities. Skipping test.");
+ }
+ }
+ }
+ } else if #[cfg(not(target_os = "redox"))] {
+ #[macro_export] macro_rules! require_capability {
+ ($capname:ident) => {}
+ }
+ }
+}
+
+#[cfg(any(target_os = "linux", target_os= "android"))]
+#[macro_export] macro_rules! skip_if_cirrus {
+ ($reason:expr) => {
+ if std::env::var_os("CIRRUS_CI").is_some() {
+ skip!("{}", $reason);
+ }
+ }
+}
+
+#[cfg(target_os = "freebsd")]
+#[macro_export] macro_rules! skip_if_jailed {
+ ($name:expr) => {
+ use ::sysctl::CtlValue;
+
+ if let CtlValue::Int(1) = ::sysctl::value("security.jail.jailed")
+ .unwrap()
+ {
+ skip!("{} cannot run in a jail. Skipping test.", $name);
+ }
+ }
+}
+
+#[cfg(not(target_os = "redox"))]
+#[macro_export] macro_rules! skip_if_not_root {
+ ($name:expr) => {
+ use nix::unistd::Uid;
+
+ if !Uid::current().is_root() {
+ skip!("{} requires root privileges. Skipping test.", $name);
+ }
+ };
+}
+
+cfg_if! {
+ if #[cfg(any(target_os = "android", target_os = "linux"))] {
+ #[macro_export] macro_rules! skip_if_seccomp {
+ ($name:expr) => {
+ if let Ok(s) = std::fs::read_to_string("/proc/self/status") {
+ for l in s.lines() {
+ let mut fields = l.split_whitespace();
+ if fields.next() == Some("Seccomp:") &&
+ fields.next() != Some("0")
+ {
+ skip!("{} cannot be run in Seccomp mode. Skipping test.",
+ stringify!($name));
+ }
+ }
+ }
+ }
+ }
+ } else if #[cfg(not(target_os = "redox"))] {
+ #[macro_export] macro_rules! skip_if_seccomp {
+ ($name:expr) => {}
+ }
+ }
+}
+
+cfg_if! {
+ if #[cfg(target_os = "linux")] {
+ #[macro_export] macro_rules! require_kernel_version {
+ ($name:expr, $version_requirement:expr) => {
+ use semver::{Version, VersionReq};
+
+ let version_requirement = VersionReq::parse($version_requirement)
+ .expect("Bad match_version provided");
+
+ let uname = nix::sys::utsname::uname();
+ println!("{}", uname.sysname());
+ println!("{}", uname.nodename());
+ println!("{}", uname.release());
+ println!("{}", uname.version());
+ println!("{}", uname.machine());
+
+ // Fix stuff that the semver parser can't handle
+ let fixed_release = &uname.release().to_string()
+ // Fedora 33 reports version as 4.18.el8_2.x86_64 or
+ // 5.18.200-fc33.x86_64. Remove the underscore.
+ .replace("_", "-")
+ // Cirrus-CI reports version as 4.19.112+ . Remove the +
+ .replace("+", "");
+ let mut version = Version::parse(fixed_release).unwrap();
+
+ //Keep only numeric parts
+ version.pre.clear();
+ version.build.clear();
+
+ if !version_requirement.matches(&version) {
+ skip!("Skip {} because kernel version `{}` doesn't match the requirement `{}`",
+ stringify!($name), version, version_requirement);
+ }
+ }
+ }
+ }
+}