diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/sys/test_aio.rs | 24 | ||||
-rw-r--r-- | test/test_fcntl.rs | 15 | ||||
-rw-r--r-- | test/test_unistd.rs | 18 |
3 files changed, 54 insertions, 3 deletions
diff --git a/test/sys/test_aio.rs b/test/sys/test_aio.rs index 67fd0850..630dff9a 100644 --- a/test/sys/test_aio.rs +++ b/test/sys/test_aio.rs @@ -13,7 +13,7 @@ use std::{thread, time}; use tempfile::tempfile; // Helper that polls an AioCb for completion or error -fn poll_aio(mut aiocb: &mut AioCb) -> Result<()> { +fn poll_aio(aiocb: &mut AioCb) -> Result<()> { loop { let err = aiocb.error(); if err != Err(Error::from(Errno::EINPROGRESS)) { return err; }; @@ -21,6 +21,28 @@ fn poll_aio(mut aiocb: &mut AioCb) -> Result<()> { } } +#[test] +fn test_accessors() { + let mut rbuf = vec![0; 4]; + let aiocb = AioCb::from_mut_slice( 1001, + 2, //offset + &mut rbuf, + 42, //priority + SigevNotify::SigevSignal { + signal: Signal::SIGUSR2, + si_value: 99 + }, + LioOpcode::LIO_NOP); + assert_eq!(1001, aiocb.fd()); + assert_eq!(Some(LioOpcode::LIO_NOP), aiocb.lio_opcode()); + assert_eq!(4, aiocb.nbytes()); + assert_eq!(2, aiocb.offset()); + assert_eq!(42, aiocb.priority()); + let sev = aiocb.sigevent().sigevent(); + assert_eq!(Signal::SIGUSR2 as i32, sev.sigev_signo); + assert_eq!(99, sev.sigev_value.sival_ptr as i64); +} + // Tests AioCb.cancel. We aren't trying to test the OS's implementation, only our // bindings. So it's sufficient to check that AioCb.cancel returned any // AioCancelStat value. diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 43bfc091..d171b91d 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -54,11 +54,11 @@ mod linux_android { use libc::loff_t; - use nix::fcntl::{SpliceFFlags, splice, tee, vmsplice}; + use nix::fcntl::{SpliceFFlags, FallocateFlags, fallocate, splice, tee, vmsplice}; use nix::sys::uio::IoVec; use nix::unistd::{close, pipe, read, write}; - use tempfile::tempfile; + use tempfile::{tempfile, NamedTempFile}; #[test] fn test_splice() { @@ -131,4 +131,15 @@ mod linux_android { close(wr).unwrap(); } + #[test] + fn test_fallocate() { + let tmp = NamedTempFile::new().unwrap(); + + let fd = tmp.as_raw_fd(); + fallocate(fd, FallocateFlags::empty(), 0, 100).unwrap(); + + // Check if we read exactly 100 bytes + let mut buf = [0u8; 200]; + assert_eq!(100, read(fd, &mut buf).unwrap()); + } } diff --git a/test/test_unistd.rs b/test/test_unistd.rs index adf73579..627eb09b 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -86,6 +86,24 @@ fn test_mkstemp_directory() { } #[test] +fn test_mkfifo() { + let tempdir = TempDir::new("nix-test_mkfifo").unwrap(); + let mkfifo_fifo = tempdir.path().join("mkfifo_fifo"); + + mkfifo(&mkfifo_fifo, stat::S_IRUSR).unwrap(); + + let stats = stat::stat(&mkfifo_fifo).unwrap(); + let typ = stat::SFlag::from_bits_truncate(stats.st_mode); + assert!(typ == stat::S_IFIFO); +} + +#[test] +fn test_mkfifo_directory() { + // mkfifo should fail if a directory is given + assert!(mkfifo(&env::temp_dir(), stat::S_IRUSR).is_err()); +} + +#[test] fn test_getpid() { let pid: ::libc::pid_t = getpid().into(); let ppid: ::libc::pid_t = getppid().into(); |