Move posix_fadvise test to new libc test file
This commit is contained in:
parent
4e42e77483
commit
b2d404d19a
2 changed files with 35 additions and 15 deletions
|
|
@ -1,13 +1,8 @@
|
|||
// 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<()> {
|
||||
|
|
@ -45,16 +40,6 @@ 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.
|
||||
|
|
|
|||
35
tests/run-pass/libc.rs
Normal file
35
tests/run-pass/libc.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// ignore-windows: No libc on Windows
|
||||
// compile-flags: -Zmiri-disable-isolation
|
||||
|
||||
#![feature(rustc_private)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use std::env::temp_dir;
|
||||
use std::fs::{File, remove_file};
|
||||
use std::io::Write;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
fn main() {
|
||||
let path = temp_dir().join("miri_test_libc.txt");
|
||||
// Cleanup before test
|
||||
remove_file(&path).ok();
|
||||
|
||||
// Set up an open file
|
||||
let mut file = File::create(&path).unwrap();
|
||||
let bytes = b"Hello, World!\n";
|
||||
file.write(bytes).unwrap();
|
||||
|
||||
// Test calling posix_fadvise on a file.
|
||||
let result = unsafe {
|
||||
libc::posix_fadvise(
|
||||
file.as_raw_fd(),
|
||||
0,
|
||||
bytes.len() as i64,
|
||||
libc::POSIX_FADV_DONTNEED,
|
||||
)
|
||||
};
|
||||
drop(file);
|
||||
remove_file(&path).unwrap();
|
||||
assert_eq!(result, 0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue