summaryrefslogtreecommitdiff
path: root/test/test_poll.rs
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2017-10-11 19:11:12 -0600
committerAlan Somers <asomers@gmail.com>2017-10-14 17:42:51 -0600
commit5810b9424dc2b1845dd318b0d3b082883f64069b (patch)
tree4b8e491ba96f9b94bd7ea86160d21a52f633c3d5 /test/test_poll.rs
parent9f4db8a494398226d4feda72ea2c4ed25fa03364 (diff)
downloadnix-5810b9424dc2b1845dd318b0d3b082883f64069b.zip
Add a test for ppoll
Diffstat (limited to 'test/test_poll.rs')
-rw-r--r--test/test_poll.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/test_poll.rs b/test/test_poll.rs
index 6d30f265..a48604f9 100644
--- a/test/test_poll.rs
+++ b/test/test_poll.rs
@@ -1,4 +1,6 @@
use nix::poll::*;
+use nix::sys::signal::SigSet;
+use nix::sys::time::{TimeSpec, TimeValLike};
use nix::unistd::{write, pipe};
#[test]
@@ -6,13 +8,41 @@ fn test_poll() {
let (r, w) = pipe().unwrap();
let mut fds = [PollFd::new(r, POLLIN)];
+ // Poll an idle pipe. Should timeout
let nfds = poll(&mut fds, 100).unwrap();
assert_eq!(nfds, 0);
assert!(!fds[0].revents().unwrap().contains(POLLIN));
write(w, b".").unwrap();
+ // Poll a readable pipe. Should return an event.
let nfds = poll(&mut fds, 100).unwrap();
assert_eq!(nfds, 1);
assert!(fds[0].revents().unwrap().contains(POLLIN));
}
+
+// ppoll(2) is the same as poll except for how it handles timeouts and signals.
+// Repeating the test for poll(2) should be sufficient to check that our
+// bindings are correct.
+#[cfg(any(target_os = "android",
+ target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "linux"))]
+#[test]
+fn test_ppoll() {
+ let timeout = TimeSpec::milliseconds(1);
+ let (r, w) = pipe().unwrap();
+ let mut fds = [PollFd::new(r, POLLIN)];
+
+ // Poll an idle pipe. Should timeout
+ let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap();
+ assert_eq!(nfds, 0);
+ assert!(!fds[0].revents().unwrap().contains(POLLIN));
+
+ write(w, b".").unwrap();
+
+ // Poll a readable pipe. Should return an event.
+ let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap();
+ assert_eq!(nfds, 1);
+ assert!(fds[0].revents().unwrap().contains(POLLIN));
+}