Skip to content

Commit abefc0b

Browse files
committed
test: testing support of fstat in linux
1 parent a785689 commit abefc0b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/pass-dep/libc/libc-fs.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ fn main() {
3838
test_posix_fadvise();
3939
#[cfg(target_os = "linux")]
4040
test_sync_file_range();
41+
#[cfg(target_os = "linux")]
42+
test_fstat();
4143
test_isatty();
4244
test_read_and_uninit();
4345
test_nofollow_not_symlink();
@@ -380,6 +382,25 @@ fn test_sync_file_range() {
380382
assert_eq!(result_2, 0);
381383
}
382384

385+
#[cfg(target_os = "linux")]
386+
fn test_fstat() {
387+
use std::mem::MaybeUninit;
388+
use std::os::unix::io::AsRawFd;
389+
390+
let path = utils::prepare_with_content("miri_test_libc_fstat.txt", b"hello");
391+
let file = File::open(&path).unwrap();
392+
let fd = file.as_raw_fd();
393+
394+
let mut stat: libc::stat = unsafe { MaybeUninit::zeroed().assume_init() };
395+
let res = unsafe { libc::fstat(fd, &mut stat) };
396+
assert_eq!(res, 0);
397+
398+
assert_eq!(stat.st_size, 5);
399+
assert_eq!(stat.st_mode & libc::S_IFMT, libc::S_IFREG);
400+
401+
remove_file(&path).unwrap();
402+
}
403+
383404
fn test_isatty() {
384405
// Testing whether our isatty shim returns the right value would require controlling whether
385406
// these streams are actually TTYs, which is hard.

0 commit comments

Comments
 (0)