Skip to content

Commit 694cec5

Browse files
authored
Merge pull request #119 from wingo/fdflags-sync
path_filestat: Dynamically allow fdflags_sync to fail
2 parents 1f9072f + 0bdb440 commit 694cec5

File tree

2 files changed

+21
-50
lines changed

2 files changed

+21
-50
lines changed

tests/rust/src/bin/path_filestat.rs

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{env, process};
2-
use wasi_tests::{assert_errno, create_tmp_dir, open_scratch_directory, TESTCONFIG};
2+
use wasi_tests::{assert_errno, create_tmp_dir, open_scratch_directory};
33

44
unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
55
let mut fdstat = wasi::fd_fdstat_get(dir_fd).expect("fd_fdstat_get");
@@ -9,69 +9,46 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
99
"the scratch directory should have RIGHT_PATH_FILESTAT_GET as base right",
1010
);
1111

12-
let fdflags = if TESTCONFIG.support_fdflags_sync() {
13-
wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC
14-
} else {
15-
wasi::FDFLAGS_APPEND
12+
// Create a file in the scratch directory.
13+
let open_file = |fdflags| -> Result<wasi::Fd, wasi::Errno> {
14+
let rights = wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE |
15+
wasi::RIGHTS_PATH_FILESTAT_GET;
16+
return wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, rights, 0,
17+
fdflags);
1618
};
1719

18-
// Create a file in the scratch directory.
19-
let file_fd = wasi::path_open(
20-
dir_fd,
21-
0,
22-
"file",
23-
wasi::OFLAGS_CREAT,
24-
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_PATH_FILESTAT_GET,
25-
0,
26-
// Pass some flags for later retrieval
27-
fdflags,
28-
)
29-
.expect("opening a file");
20+
let (file_fd, fdflags) =
21+
match open_file(wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC) {
22+
Ok(fd) => { (fd, wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC) }
23+
Err(wasi::ERRNO_NOTSUP) => {
24+
(open_file(wasi::FDFLAGS_APPEND).expect("opening file"),
25+
wasi::FDFLAGS_APPEND)
26+
}
27+
Err(err) => {
28+
eprintln!("error opening file: {}", err);
29+
process::exit(1);
30+
}
31+
};
32+
3033
assert!(
3134
file_fd > libc::STDERR_FILENO as wasi::Fd,
3235
"file descriptor range check",
3336
);
3437

3538
fdstat = wasi::fd_fdstat_get(file_fd).expect("fd_fdstat_get");
36-
assert_eq!(
37-
fdstat.fs_rights_base & wasi::RIGHTS_PATH_FILESTAT_GET,
38-
0,
39-
"files shouldn't have rights for path_* syscalls even if manually given",
40-
);
41-
assert_eq!(
42-
fdstat.fs_rights_inheriting & wasi::RIGHTS_PATH_FILESTAT_GET,
43-
0,
44-
"files shouldn't have rights for path_* syscalls even if manually given",
45-
);
4639
assert_eq!(
4740
fdstat.fs_flags & wasi::FDFLAGS_APPEND,
4841
wasi::FDFLAGS_APPEND,
4942
"file should have the APPEND fdflag used to create the file"
5043
);
51-
if TESTCONFIG.support_fdflags_sync() {
44+
if (fdflags & wasi::FDFLAGS_SYNC) != 0 {
5245
assert_eq!(
5346
fdstat.fs_flags & wasi::FDFLAGS_SYNC,
5447
wasi::FDFLAGS_SYNC,
5548
"file should have the SYNC fdflag used to create the file"
5649
);
5750
}
5851

59-
if !TESTCONFIG.support_fdflags_sync() {
60-
assert_errno!(
61-
wasi::path_open(
62-
dir_fd,
63-
0,
64-
"file",
65-
0,
66-
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_PATH_FILESTAT_GET,
67-
0,
68-
wasi::FDFLAGS_SYNC,
69-
)
70-
.expect_err("FDFLAGS_SYNC not supported by platform"),
71-
wasi::ERRNO_NOTSUP
72-
);
73-
}
74-
7552
// Check file size
7653
let file_stat = wasi::path_filestat_get(dir_fd, 0, "file").expect("reading file stats");
7754
assert_eq!(file_stat.size, 0, "file size should be 0");

tests/rust/src/config.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pub struct TestConfig {
22
errno_mode: ErrnoMode,
33
no_dangling_filesystem: bool,
44
no_rename_dir_to_empty_dir: bool,
5-
no_fdflags_sync_support: bool,
65
}
76

87
enum ErrnoMode {
@@ -25,13 +24,11 @@ impl TestConfig {
2524
};
2625
let no_dangling_filesystem = std::env::var("NO_DANGLING_FILESYSTEM").is_ok();
2726
let no_rename_dir_to_empty_dir = std::env::var("NO_RENAME_DIR_TO_EMPTY_DIR").is_ok();
28-
let no_fdflags_sync_support = std::env::var("NO_FDFLAGS_SYNC_SUPPORT").is_ok();
2927

3028
TestConfig {
3129
errno_mode,
3230
no_dangling_filesystem,
3331
no_rename_dir_to_empty_dir,
34-
no_fdflags_sync_support,
3532
}
3633
}
3734
pub fn errno_expect_unix(&self) -> bool {
@@ -58,7 +55,4 @@ impl TestConfig {
5855
pub fn support_rename_dir_to_empty_dir(&self) -> bool {
5956
!self.no_rename_dir_to_empty_dir
6057
}
61-
pub fn support_fdflags_sync(&self) -> bool {
62-
!self.no_fdflags_sync_support
63-
}
6458
}

0 commit comments

Comments
 (0)