Skip to content

Commit b2d404d

Browse files
committed
Move posix_fadvise test to new libc test file
1 parent 4e42e77 commit b2d404d

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

tests/run-pass/fs.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
// ignore-windows: File handling is not implemented yet
22
// compile-flags: -Zmiri-disable-isolation
33

4-
#![feature(rustc_private)]
5-
6-
extern crate libc;
7-
84
use std::fs::{File, remove_file};
95
use std::io::{Read, Write, ErrorKind, Result};
10-
use std::os::unix::io::AsRawFd;
116
use std::path::{PathBuf, Path};
127

138
fn test_metadata(bytes: &[u8], path: &Path) -> Result<()> {
@@ -45,16 +40,6 @@ fn main() {
4540
file.read_to_end(&mut contents).unwrap();
4641
assert_eq!(bytes, contents.as_slice());
4742

48-
// Test calling posix_fadvise on the file.
49-
unsafe {
50-
libc::posix_fadvise(
51-
file.as_raw_fd(),
52-
0,
53-
bytes.len() as i64,
54-
libc::POSIX_FADV_DONTNEED,
55-
);
56-
}
57-
5843
// Test that metadata of an absolute path is correct.
5944
test_metadata(bytes, &path).unwrap();
6045
// Test that metadata of a relative path is correct.

tests/run-pass/libc.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ignore-windows: No libc on Windows
2+
// compile-flags: -Zmiri-disable-isolation
3+
4+
#![feature(rustc_private)]
5+
6+
extern crate libc;
7+
8+
use std::env::temp_dir;
9+
use std::fs::{File, remove_file};
10+
use std::io::Write;
11+
use std::os::unix::io::AsRawFd;
12+
13+
fn main() {
14+
let path = temp_dir().join("miri_test_libc.txt");
15+
// Cleanup before test
16+
remove_file(&path).ok();
17+
18+
// Set up an open file
19+
let mut file = File::create(&path).unwrap();
20+
let bytes = b"Hello, World!\n";
21+
file.write(bytes).unwrap();
22+
23+
// Test calling posix_fadvise on a file.
24+
let result = unsafe {
25+
libc::posix_fadvise(
26+
file.as_raw_fd(),
27+
0,
28+
bytes.len() as i64,
29+
libc::POSIX_FADV_DONTNEED,
30+
)
31+
};
32+
drop(file);
33+
remove_file(&path).unwrap();
34+
assert_eq!(result, 0);
35+
}

0 commit comments

Comments
 (0)