Skip to content

Commit 917cd15

Browse files
yagehuloganek
authored andcommitted
Assert error on ambiguous fstflags
This commit adds a Rust test case that asserts an ambiguous `fstflags` input to `fd_filestat_set_times` should result in `inval` errno. An `fstflags` argument is ambiguous if: 1. both `atim` and `atim_now` are set, or 2. both `mtim` and `mtim_now` are set.
1 parent 047a002 commit 917cd15

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use std::{env, process};
2+
use wasi_tests::open_scratch_directory;
3+
4+
unsafe fn test_fstflags_validate(dir_fd: wasi::Fd) {
5+
const FILE_NAME: &str = "fstflags_validate.cleanup";
6+
7+
let file_fd = wasi::path_open(
8+
dir_fd,
9+
0,
10+
FILE_NAME,
11+
wasi::OFLAGS_CREAT,
12+
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_FILESTAT_SET_TIMES,
13+
0,
14+
0,
15+
)
16+
.expect("failed to create file");
17+
18+
let result = wasi::fd_filestat_set_times(
19+
file_fd,
20+
100,
21+
200,
22+
wasi::FSTFLAGS_MTIM | wasi::FSTFLAGS_MTIM_NOW,
23+
);
24+
assert!(matches!(result, Err(wasi::ERRNO_INVAL)));
25+
26+
let result = wasi::fd_filestat_set_times(
27+
file_fd,
28+
100,
29+
200,
30+
wasi::FSTFLAGS_ATIM | wasi::FSTFLAGS_ATIM_NOW,
31+
);
32+
assert!(matches!(result, Err(wasi::ERRNO_INVAL)));
33+
34+
wasi::fd_close(file_fd).expect("failed to close fd");
35+
}
36+
fn main() {
37+
let mut args = env::args();
38+
let prog = args.next().unwrap();
39+
let arg = if let Some(arg) = args.next() {
40+
arg
41+
} else {
42+
eprintln!("usage: {} <scratch directory>", prog);
43+
process::exit(1);
44+
};
45+
46+
// Open scratch directory
47+
let dir_fd = match open_scratch_directory(&arg) {
48+
Ok(dir_fd) => dir_fd,
49+
Err(err) => {
50+
eprintln!("{}", err);
51+
process::exit(1)
52+
}
53+
};
54+
55+
// Run the tests.
56+
unsafe { test_fstflags_validate(dir_fd) }
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"dirs": ["fs-tests.dir"],
3+
"args": ["fs-tests.dir"]
4+
}

0 commit comments

Comments
 (0)