]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/libc.rs
Disable posix_fadvise test on macOS, not in libc
[rust.git] / tests / run-pass / libc.rs
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 #[cfg(not(target_os = "macos"))]
9 fn test_posix_fadvise() {
10     use std::convert::TryInto;
11     use std::env::temp_dir;
12     use std::fs::{File, remove_file};
13     use std::io::Write;
14     use std::os::unix::io::AsRawFd;
15
16     let path = temp_dir().join("miri_test_libc.txt");
17     // Cleanup before test
18     remove_file(&path).ok();
19
20     // Set up an open file
21     let mut file = File::create(&path).unwrap();
22     let bytes = b"Hello, World!\n";
23     file.write(bytes).unwrap();
24
25     // Test calling posix_fadvise on a file.
26     let result = unsafe {
27         libc::posix_fadvise(
28             file.as_raw_fd(),
29             0,
30             bytes.len().try_into().unwrap(),
31             libc::POSIX_FADV_DONTNEED,
32         )
33     };
34     drop(file);
35     remove_file(&path).unwrap();
36     assert_eq!(result, 0);
37 }
38
39 fn main() {
40     #[cfg(not(target_os = "macos"))]
41     test_posix_fadvise();
42 }