diff options
author | Andreas Fuchs <asf@boinkor.net> | 2018-04-28 21:08:39 +0200 |
---|---|---|
committer | Andreas Fuchs <asf@boinkor.net> | 2018-04-28 23:54:54 +0200 |
commit | 492903ba6c89b3f042cd9336b321020b23b98f5f (patch) | |
tree | f3306f88bcd69295e7618b83affda42f62c95ba4 /test | |
parent | c2fb79e2fd6ecc15589f532459db06a506696efa (diff) | |
download | nix-492903ba6c89b3f042cd9336b321020b23b98f5f.zip |
select: add pselect syscall
This is a straight port of @abbradar's work in #276, with
two (somewhat weak) tests and a bit of documentation.
Diffstat (limited to 'test')
-rw-r--r-- | test/sys/mod.rs | 1 | ||||
-rw-r--r-- | test/sys/test_select.rs | 55 |
2 files changed, 56 insertions, 0 deletions
diff --git a/test/sys/mod.rs b/test/sys/mod.rs index 31cf73b1..1b3e67aa 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -15,6 +15,7 @@ mod test_aio; mod test_signalfd; mod test_socket; mod test_sockopt; +mod test_select; mod test_termios; mod test_ioctl; mod test_wait; diff --git a/test/sys/test_select.rs b/test/sys/test_select.rs new file mode 100644 index 00000000..19d12fba --- /dev/null +++ b/test/sys/test_select.rs @@ -0,0 +1,55 @@ +use nix::sys::select::*; +use nix::unistd::{pipe, write}; +use nix::sys::signal::SigSet; +use nix::sys::time::{TimeSpec, TimeValLike}; +use std::os::unix::io::RawFd; + +#[test] +pub fn test_pselect() { + let _mtx = ::SIGNAL_MTX + .lock() + .expect("Mutex got poisoned by another test"); + + let (r1, w1) = pipe().unwrap(); + write(w1, b"hi!").unwrap(); + let (r2, _w2) = pipe().unwrap(); + + let mut fd_set = FdSet::new(); + fd_set.insert(r1); + fd_set.insert(r2); + + let timeout = TimeSpec::seconds(10); + let sigmask = SigSet::empty(); + assert_eq!( + 1, + pselect(None, &mut fd_set, None, None, &timeout, &sigmask).unwrap() + ); + assert!(fd_set.contains(r1)); + assert!(!fd_set.contains(r2)); +} + +#[test] +pub fn test_pselect_nfds2() { + let (r1, w1) = pipe().unwrap(); + write(w1, b"hi!").unwrap(); + let (r2, _w2) = pipe().unwrap(); + + let mut fd_set = FdSet::new(); + fd_set.insert(r1); + fd_set.insert(r2); + + let timeout = TimeSpec::seconds(10); + assert_eq!( + 1, + pselect( + ::std::cmp::max(r1, r2) + 1, + &mut fd_set, + None, + None, + &timeout, + None + ).unwrap() + ); + assert!(fd_set.contains(r1)); + assert!(!fd_set.contains(r2)); +} |