diff options
author | Kevin Wern <kevin.m.wern@gmail.com> | 2019-06-21 00:13:02 -0400 |
---|---|---|
committer | Kevin Wern <kevin.m.wern@gmail.com> | 2019-07-09 01:02:39 -0400 |
commit | f723b1822de9bd446cc6d038f4e78f7b0f58a48b (patch) | |
tree | d23c66450a960e66645ba792606a8d860578a992 /test | |
parent | 112438b1e954c1266a76f8c53fd084f9019ebc99 (diff) | |
download | nix-f723b1822de9bd446cc6d038f4e78f7b0f58a48b.zip |
implement posix_fadvise
Diffstat (limited to 'test')
-rw-r--r-- | test/test_fcntl.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/test_fcntl.rs b/test/test_fcntl.rs index 8d02f147..05851828 100644 --- a/test/test_fcntl.rs +++ b/test/test_fcntl.rs @@ -180,3 +180,36 @@ mod linux_android { assert_eq!(100, read(fd, &mut buf).unwrap()); } } + +#[cfg(any(target_os = "linux", + target_os = "android", + target_os = "emscripten", + target_os = "fuchsia", + any(target_os = "wasi", target_env = "wasi"), + target_env = "uclibc", + target_env = "freebsd"))] +mod test_posix_fadvise { + + use tempfile::NamedTempFile; + use std::os::unix::io::{RawFd, AsRawFd}; + use nix::errno::Errno; + use nix::fcntl::*; + use nix::unistd::pipe; + + #[test] + fn test_success() { + let tmp = NamedTempFile::new().unwrap(); + let fd = tmp.as_raw_fd(); + let res = posix_fadvise(fd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED).unwrap(); + + assert_eq!(res, 0); + } + + #[test] + fn test_errno() { + let (rd, _wr) = pipe().unwrap(); + let errno = posix_fadvise(rd as RawFd, 0, 100, PosixFadviseAdvice::POSIX_FADV_WILLNEED) + .unwrap(); + assert_eq!(errno, Errno::ESPIPE as i32); + } +} |