Skip to content

Commit 352cdca

Browse files
authored
Merge pull request #124 from alexcrichton/support-no-rights
Disable some tests if rights aren't supported
2 parents d4383b4 + 92c0545 commit 352cdca

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

tests/rust/wasm32-wasip1/src/bin/fd_fdstat_set_rights.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
use std::{env, process};
22
use wasi_tests::{
33
assert_errno, create_tmp_dir, drop_rights, fd_get_rights, open_scratch_directory,
4+
supports_rights,
45
};
56

67
const TEST_FILENAME: &'static str = "file.cleanup";
78

89
unsafe fn test_fd_fdstat_set_rights(dir_fd: wasi::Fd) {
10+
// For hosts that don't support rights at all skip this test.
11+
if !supports_rights(dir_fd) {
12+
return;
13+
}
14+
915
let fd = wasi::path_open(
1016
dir_fd,
1117
0,

tests/rust/wasm32-wasip1/src/bin/path_link.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::{env, process};
2-
use wasi_tests::{assert_errno, create_file, create_tmp_dir, open_scratch_directory, TESTCONFIG};
2+
use wasi_tests::{
3+
assert_errno, create_file, create_tmp_dir, open_scratch_directory, supports_rights, TESTCONFIG,
4+
};
35

46
const TEST_RIGHTS: wasi::Rights = wasi::RIGHTS_FD_READ
57
| wasi::RIGHTS_PATH_LINK_SOURCE
@@ -43,20 +45,24 @@ fn filestats_assert_eq(left: wasi::Filestat, right: wasi::Filestat) {
4345

4446
// This is temporary until `wasi` implements `Debug` and `PartialEq` for
4547
// `wasi::Fdstat`.
46-
fn fdstats_assert_eq(left: wasi::Fdstat, right: wasi::Fdstat) {
48+
fn fdstats_assert_eq(left: wasi::Fdstat, right: wasi::Fdstat, supports_rights: bool) {
4749
assert_eq!(left.fs_flags, right.fs_flags, "fs_flags should be equal");
4850
assert_eq!(
4951
left.fs_filetype, right.fs_filetype,
5052
"fs_filetype should be equal"
5153
);
52-
assert_eq!(
53-
left.fs_rights_base, right.fs_rights_base,
54-
"fs_rights_base should be equal"
55-
);
56-
assert_eq!(
57-
left.fs_rights_inheriting, right.fs_rights_inheriting,
58-
"fs_rights_inheriting should be equal"
59-
);
54+
55+
// Only tests rights if the host in general supports rights.
56+
if supports_rights {
57+
assert_eq!(
58+
left.fs_rights_base, right.fs_rights_base,
59+
"fs_rights_base should be equal"
60+
);
61+
assert_eq!(
62+
left.fs_rights_inheriting, right.fs_rights_inheriting,
63+
"fs_rights_inheriting should be equal"
64+
);
65+
}
6066
}
6167

6268
unsafe fn check_rights(orig_fd: wasi::Fd, link_fd: wasi::Fd) {
@@ -68,7 +74,7 @@ unsafe fn check_rights(orig_fd: wasi::Fd, link_fd: wasi::Fd) {
6874
// Compare Fdstats
6975
let orig_fdstat = wasi::fd_fdstat_get(orig_fd).expect("reading fdstat of the source");
7076
let link_fdstat = wasi::fd_fdstat_get(link_fd).expect("reading fdstat of the link");
71-
fdstats_assert_eq(orig_fdstat, link_fdstat);
77+
fdstats_assert_eq(orig_fdstat, link_fdstat, supports_rights(orig_fd));
7278
}
7379

7480
// Extra calls of fd_close are needed for Windows, which will not remove

tests/rust/wasm32-wasip1/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,11 @@ macro_rules! assert_errno {
175175
}
176176
};
177177
}
178+
179+
pub unsafe fn supports_rights(fd: wasi::Fd) -> bool {
180+
let fd_stat = wasi::fd_fdstat_get(fd).expect("fd_fdstat_get failed");
181+
match wasi::fd_fdstat_set_rights(fd, fd_stat.fs_rights_base, fd_stat.fs_rights_inheriting) {
182+
Err(wasi::ERRNO_NOTSUP) => false,
183+
_ => true,
184+
}
185+
}

0 commit comments

Comments
 (0)