From 4e42e774834683570b1c0ca59ce5bb1a11119fb5 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 27 Jan 2020 06:28:45 -0600 Subject: [PATCH] Add test for posix_fadvise --- tests/run-pass/fs.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/run-pass/fs.rs b/tests/run-pass/fs.rs index 81c56e4aafc7..43f394bd3274 100644 --- a/tests/run-pass/fs.rs +++ b/tests/run-pass/fs.rs @@ -1,8 +1,13 @@ // ignore-windows: File handling is not implemented yet // compile-flags: -Zmiri-disable-isolation +#![feature(rustc_private)] + +extern crate libc; + use std::fs::{File, remove_file}; use std::io::{Read, Write, ErrorKind, Result}; +use std::os::unix::io::AsRawFd; use std::path::{PathBuf, Path}; fn test_metadata(bytes: &[u8], path: &Path) -> Result<()> { @@ -40,6 +45,16 @@ fn main() { file.read_to_end(&mut contents).unwrap(); assert_eq!(bytes, contents.as_slice()); + // Test calling posix_fadvise on the file. + unsafe { + libc::posix_fadvise( + file.as_raw_fd(), + 0, + bytes.len() as i64, + libc::POSIX_FADV_DONTNEED, + ); + } + // Test that metadata of an absolute path is correct. test_metadata(bytes, &path).unwrap(); // Test that metadata of a relative path is correct.