summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/sys/test_ptrace.rs2
-rw-r--r--test/sys/test_socket.rs115
-rw-r--r--test/sys/test_sockopt.rs2
-rw-r--r--test/test_fcntl.rs1
-rw-r--r--test/test_mount.rs2
-rw-r--r--test/test_stat.rs6
6 files changed, 123 insertions, 5 deletions
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs
index 83fff9a5..89c4e2dd 100644
--- a/test/sys/test_ptrace.rs
+++ b/test/sys/test_ptrace.rs
@@ -72,7 +72,7 @@ fn test_ptrace_cont() {
let _m = crate::FORK_MTX.lock();
// FIXME: qemu-user doesn't implement ptrace on all architectures
- // and retunrs ENOSYS in this case.
+ // and returns ENOSYS in this case.
// We (ab)use this behavior to detect the affected platforms
// and skip the test then.
// On valid platforms the ptrace call should return Errno::EPERM, this
diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs
index 0f6fac66..5262d3b8 100644
--- a/test/sys/test_socket.rs
+++ b/test/sys/test_socket.rs
@@ -57,6 +57,64 @@ pub fn test_inetv4_addr_roundtrip_sockaddr_storage_to_addr() {
assert_eq!(from_storage, sockaddr);
}
+#[cfg(any(target_os = "linux"))]
+#[cfg_attr(qemu, ignore)]
+#[test]
+pub fn test_timestamping() {
+ use nix::sys::socket::{
+ recvmsg, sendmsg, setsockopt, socket, sockopt::Timestamping, ControlMessageOwned, MsgFlags,
+ SockFlag, SockType, TimestampingFlag,
+ };
+ use nix::sys::uio::IoVec;
+
+ let std_sa = SocketAddr::from_str("127.0.0.1:6790").unwrap();
+ let inet_addr = InetAddr::from_std(&std_sa);
+ let sock_addr = SockAddr::new_inet(inet_addr);
+
+ let ssock = socket(
+ AddressFamily::Inet,
+ SockType::Datagram,
+ SockFlag::empty(),
+ None,
+ )
+ .expect("send socket failed");
+
+ let rsock = socket(
+ AddressFamily::Inet,
+ SockType::Datagram,
+ SockFlag::empty(),
+ None,
+ )
+ .unwrap();
+ nix::sys::socket::bind(rsock, &sock_addr).unwrap();
+
+ setsockopt(rsock, Timestamping, &TimestampingFlag::all()).unwrap();
+
+ let sbuf = [0u8; 2048];
+ let mut rbuf = [0u8; 2048];
+ let flags = MsgFlags::empty();
+ let iov1 = [IoVec::from_slice(&sbuf)];
+ let iov2 = [IoVec::from_mut_slice(&mut rbuf)];
+ let mut cmsg = cmsg_space!(nix::sys::socket::Timestamps);
+ sendmsg(ssock, &iov1, &[], flags, Some(&sock_addr)).unwrap();
+ let recv = recvmsg(rsock, &iov2, Some(&mut cmsg), flags).unwrap();
+
+ let mut ts = None;
+ for c in recv.cmsgs() {
+ if let ControlMessageOwned::ScmTimestampsns(timestamps) = c {
+ ts = Some(timestamps.system);
+ }
+ }
+ let ts = ts.expect("ScmTimestampns is present");
+ let sys_time = ::nix::time::clock_gettime(::nix::time::ClockId::CLOCK_REALTIME).unwrap();
+ let diff = if ts > sys_time {
+ ts - sys_time
+ } else {
+ sys_time - ts
+ };
+ assert!(std::time::Duration::from(diff).as_secs() < 60);
+}
+
#[test]
pub fn test_inetv6_addr_to_sock_addr() {
let port: u16 = 3000;
@@ -1939,3 +1997,60 @@ mod linux_errqueue {
assert_eq!(ext_err.ee_info, 0);
}
}
+
+// Disable the test on emulated platforms because it fails in Cirrus-CI. Lack
+// of QEMU support is suspected.
+#[cfg_attr(qemu, ignore)]
+#[cfg(target_os = "linux")]
+#[test]
+pub fn test_txtime() {
+ use nix::sys::socket::{
+ bind, recvmsg, sendmsg, setsockopt, socket, sockopt, ControlMessage,
+ MsgFlags, SockFlag, SockType,
+ };
+ use nix::sys::time::TimeValLike;
+ use nix::time::{ClockId, clock_gettime};
+
+ require_kernel_version!(test_txtime, ">= 5.8");
+
+ let std_sa = SocketAddr::from_str("127.0.0.1:6790").unwrap();
+ let inet_addr = InetAddr::from_std(&std_sa);
+ let sock_addr = SockAddr::new_inet(inet_addr);
+
+ let ssock = socket(
+ AddressFamily::Inet,
+ SockType::Datagram,
+ SockFlag::empty(),
+ None,
+ )
+ .expect("send socket failed");
+
+ let txtime_cfg = libc::sock_txtime {
+ clockid: libc::CLOCK_MONOTONIC,
+ flags: 0,
+ };
+ setsockopt(ssock, sockopt::TxTime, &txtime_cfg).unwrap();
+
+ let rsock = socket(
+ AddressFamily::Inet,
+ SockType::Datagram,
+ SockFlag::empty(),
+ None,
+ )
+ .unwrap();
+ bind(rsock, &sock_addr).unwrap();
+
+ let sbuf = [0u8; 2048];
+ let iov1 = [nix::sys::uio::IoVec::from_slice(&sbuf)];
+
+ let now = clock_gettime(ClockId::CLOCK_MONOTONIC).unwrap();
+ let delay = std::time::Duration::from_secs(1).into();
+ let txtime = (now + delay).num_nanoseconds() as u64;
+
+ let cmsg = ControlMessage::TxTime(&txtime);
+ sendmsg(ssock, &iov1, &[cmsg], MsgFlags::empty(), Some(&sock_addr)).unwrap();
+
+ let mut rbuf = [0u8; 2048];
+ let iov2 = [nix::sys::uio::IoVec::from_mut_slice(&mut rbuf)];
+ recvmsg(rsock, &iov2, None, MsgFlags::empty()).unwrap();
+}
diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs
index 01920fd4..59b97c8b 100644
--- a/test/sys/test_sockopt.rs
+++ b/test/sys/test_sockopt.rs
@@ -122,7 +122,7 @@ fn test_so_tcp_maxseg() {
}
// The CI doesn't supported getsockopt and setsockopt on emulated processors.
-// It's beleived that a QEMU issue, the tests run ok on a fully emulated system.
+// It's believed that a QEMU issue, the tests run ok on a fully emulated system.
// Current CI just run the binary with QEMU but the Kernel remains the same as the host.
// So the syscall doesn't work properly unless the kernel is also emulated.
#[test]
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs
index db2acfbf..b24a49ee 100644
--- a/test/test_fcntl.rs
+++ b/test/test_fcntl.rs
@@ -488,6 +488,7 @@ mod test_posix_fadvise {
#[cfg(any(target_os = "linux",
target_os = "android",
+ target_os = "dragonfly",
target_os = "emscripten",
target_os = "fuchsia",
any(target_os = "wasi", target_env = "wasi"),
diff --git a/test/test_mount.rs b/test/test_mount.rs
index 44287f97..1ddfcfe9 100644
--- a/test/test_mount.rs
+++ b/test/test_mount.rs
@@ -1,6 +1,6 @@
mod common;
-// Impelmentation note: to allow unprivileged users to run it, this test makes
+// Implementation note: to allow unprivileged users to run it, this test makes
// use of user and mount namespaces. On systems that allow unprivileged user
// namespaces (Linux >= 3.8 compiled with CONFIG_USER_NS), the test should run
// without root.
diff --git a/test/test_stat.rs b/test/test_stat.rs
index 33cf748d..8baa6555 100644
--- a/test/test_stat.rs
+++ b/test/test_stat.rs
@@ -308,7 +308,8 @@ fn test_mkdirat_fail() {
}
#[test]
-#[cfg(not(any(target_os = "freebsd",
+#[cfg(not(any(target_os = "dragonfly",
+ target_os = "freebsd",
target_os = "ios",
target_os = "macos",
target_os = "redox")))]
@@ -325,7 +326,8 @@ fn test_mknod() {
}
#[test]
-#[cfg(not(any(target_os = "freebsd",
+#[cfg(not(any(target_os = "dragonfly",
+ target_os = "freebsd",
target_os = "illumos",
target_os = "ios",
target_os = "macos",