diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/sys/mod.rs | 3 | ||||
-rw-r--r-- | test/sys/test_epoll.rs | 24 | ||||
-rw-r--r-- | test/test_unistd.rs | 19 |
3 files changed, 46 insertions, 0 deletions
diff --git a/test/sys/mod.rs b/test/sys/mod.rs index 25c9a92f..5e5eed41 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -9,3 +9,6 @@ mod test_ioctl; mod test_wait; mod test_select; mod test_uio; + +#[cfg(target_os = "linux")] +mod test_epoll; diff --git a/test/sys/test_epoll.rs b/test/sys/test_epoll.rs new file mode 100644 index 00000000..a73fea6d --- /dev/null +++ b/test/sys/test_epoll.rs @@ -0,0 +1,24 @@ +use nix::sys::epoll::{EpollCreateFlags, EpollOp, EpollEvent}; +use nix::sys::epoll::{EPOLLIN, EPOLLERR}; +use nix::sys::epoll::{epoll_create1, epoll_ctl}; +use nix::{Error, Errno}; + +#[test] +pub fn test_epoll_errno() { + let efd = epoll_create1(EpollCreateFlags::empty()).unwrap(); + let result = epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None); + assert!(result.is_err()); + assert_eq!(result.unwrap_err(), Error::Sys(Errno::ENOENT)); + + let result = epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, None); + assert!(result.is_err()); + assert_eq!(result.unwrap_err(), Error::Sys(Errno::EINVAL)); +} + +#[test] +pub fn test_epoll_ctl() { + let efd = epoll_create1(EpollCreateFlags::empty()).unwrap(); + let mut event = EpollEvent::new(EPOLLIN | EPOLLERR, 1); + epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, &mut event).unwrap(); + epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None).unwrap(); +} diff --git a/test/test_unistd.rs b/test/test_unistd.rs index d281f9b2..76ab442a 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -6,6 +6,7 @@ use nix::sys::wait::*; use nix::sys::stat; use std::iter; use std::ffi::CString; +use std::fs::File; use std::io::{Write, Read}; use std::os::unix::prelude::*; use std::env::current_dir; @@ -142,6 +143,24 @@ macro_rules! execve_test_factory( ); #[test] +fn test_fchdir() { + let tmpdir = TempDir::new("test_fchdir").unwrap(); + let tmpdir_path = tmpdir.path().canonicalize().unwrap(); + let tmpdir_fd = File::open(&tmpdir_path).unwrap().into_raw_fd(); + let olddir_path = getcwd().unwrap(); + let olddir_fd = File::open(&olddir_path).unwrap().into_raw_fd(); + + assert!(fchdir(tmpdir_fd).is_ok()); + assert_eq!(getcwd().unwrap(), tmpdir_path); + + assert!(fchdir(olddir_fd).is_ok()); + assert_eq!(getcwd().unwrap(), olddir_path); + + assert!(close(olddir_fd).is_ok()); + assert!(close(tmpdir_fd).is_ok()); +} + +#[test] fn test_getcwd() { let tmp_dir = TempDir::new("test_getcwd").unwrap(); assert!(chdir(tmp_dir.path()).is_ok()); |