Skip to content

Commit

Permalink
remove test expectations around rights (bytecodealliance#153)
Browse files Browse the repository at this point in the history
* Revert "wasi-tests: add configuration to ignore rights readback (bytecodealliance#81)"

This reverts commit d006b1b.

* wasi-tests: pull in all changes from upstream which remove support for rights

bytecodealliance#6265

note, im leaving out upstream changes to fd_readdir which are from bytecodealliance#6163, which requires porting the rest of that PR into this repo

* remove rights readback variable from test runner

* rustfmt

* delete path_open_read_without_rights test

which was deleted upstream
  • Loading branch information
pchickey authored Apr 24, 2023
1 parent 6f44c91 commit fa859ea
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 232 deletions.
8 changes: 0 additions & 8 deletions host/tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ async fn run_default_clocks(mut store: Store<WasiCtx>, wasi: Command) -> Result<
async fn run_with_temp_dir(mut store: Store<WasiCtx>, wasi: Command) -> Result<()> {
let dir = tempfile::tempdir()?;

store.data_mut().push_env("NO_RIGHTS_READBACK_SUPPORT", "1");

if cfg!(windows) {
store.data_mut().push_env("ERRNO_MODE_WINDOWS", "1");
store.data_mut().push_env("NO_FDFLAGS_SYNC_SUPPORT", "1");
Expand Down Expand Up @@ -442,12 +440,6 @@ async fn run_path_open_missing(store: Store<WasiCtx>, wasi: Command) -> Result<(
run_with_temp_dir(store, wasi).await
}

async fn run_path_open_read_without_rights(store: Store<WasiCtx>, wasi: Command) -> Result<()> {
// unreachable in adapter line 557, inside fd_fdstat_set_rights, when test program is trying to
// drop the RIGHTS_FD_READ right
expect_fail(run_with_temp_dir(store, wasi).await)
}

async fn run_path_rename(store: Store<WasiCtx>, wasi: Command) -> Result<()> {
run_with_temp_dir(store, wasi).await
}
Expand Down
29 changes: 3 additions & 26 deletions test-programs/wasi-tests/src/bin/directory_seek.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use std::{env, process};
use wasi_tests::{assert_errno, open_scratch_directory, TESTCONFIG};
use wasi_tests::{assert_errno, open_scratch_directory};

unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
// Create a directory in the scratch directory.
wasi::path_create_directory(dir_fd, "dir").expect("failed to make directory");

// Open the directory and attempt to request rights for seeking.
let fd = wasi::path_open(
dir_fd,
0,
"dir",
wasi::OFLAGS_DIRECTORY,
wasi::RIGHTS_FD_SEEK,
0,
0,
)
.expect("failed to open file");
let fd = wasi::path_open(dir_fd, 0, "dir", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect("failed to open file");
assert!(
fd > libc::STDERR_FILENO as wasi::Fd,
"file descriptor range check",
Expand All @@ -27,21 +19,6 @@ unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
wasi::ERRNO_BADF
);

// Check if we obtained the right to seek.
let fdstat = wasi::fd_fdstat_get(fd).expect("failed to fdstat");
assert_eq!(
fdstat.fs_filetype,
wasi::FILETYPE_DIRECTORY,
"expected the scratch directory to be a directory",
);
if TESTCONFIG.support_rights_readback() {
assert_eq!(
(fdstat.fs_rights_base & wasi::RIGHTS_FD_SEEK),
0,
"directory does NOT have the seek right",
);
}

// Clean up.
wasi::fd_close(fd).expect("failed to close fd");
wasi::path_remove_directory(dir_fd, "dir").expect("failed to remove dir");
Expand Down
7 changes: 1 addition & 6 deletions test-programs/wasi-tests/src/bin/fd_advise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ unsafe fn test_fd_advise(dir_fd: wasi::Fd) {
0,
"file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ
| wasi::RIGHTS_FD_WRITE
| wasi::RIGHTS_FD_ADVISE
| wasi::RIGHTS_FD_FILESTAT_GET
| wasi::RIGHTS_FD_FILESTAT_SET_SIZE
| wasi::RIGHTS_FD_ALLOCATE,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
)
Expand Down
6 changes: 1 addition & 5 deletions test-programs/wasi-tests/src/bin/fd_filestat_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ unsafe fn test_fd_filestat_set(dir_fd: wasi::Fd) {
0,
"file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ
| wasi::RIGHTS_FD_WRITE
| wasi::RIGHTS_FD_FILESTAT_GET
| wasi::RIGHTS_FD_FILESTAT_SET_SIZE
| wasi::RIGHTS_FD_FILESTAT_SET_TIMES,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
)
Expand Down
6 changes: 1 addition & 5 deletions test-programs/wasi-tests/src/bin/fd_flags_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ unsafe fn test_fd_fdstat_set_flags(dir_fd: wasi::Fd) {
0,
FILE_NAME,
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ
| wasi::RIGHTS_FD_WRITE
| wasi::RIGHTS_FD_SEEK
| wasi::RIGHTS_FD_TELL
| wasi::RIGHTS_FD_FDSTAT_SET_FLAGS,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
wasi::FDFLAGS_APPEND,
)
Expand Down
10 changes: 2 additions & 8 deletions test-programs/wasi-tests/src/bin/fd_readdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ unsafe fn test_fd_readdir(dir_fd: wasi::Fd) {
0,
"file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ
| wasi::RIGHTS_FD_WRITE
| wasi::RIGHTS_FD_READDIR
| wasi::RIGHTS_FD_FILESTAT_GET,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
)
Expand Down Expand Up @@ -155,10 +152,7 @@ unsafe fn test_fd_readdir_lots(dir_fd: wasi::Fd) {
0,
&format!("file.{}", count),
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ
| wasi::RIGHTS_FD_WRITE
| wasi::RIGHTS_FD_READDIR
| wasi::RIGHTS_FD_FILESTAT_GET,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
)
Expand Down
5 changes: 1 addition & 4 deletions test-programs/wasi-tests/src/bin/file_allocate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ unsafe fn test_file_allocate(dir_fd: wasi::Fd) {
0,
"file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ
| wasi::RIGHTS_FD_WRITE
| wasi::RIGHTS_FD_ALLOCATE
| wasi::RIGHTS_FD_FILESTAT_GET,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
)
Expand Down
2 changes: 1 addition & 1 deletion test-programs/wasi-tests/src/bin/file_pread_pwrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ unsafe fn test_file_pread_pwrite(dir_fd: wasi::Fd) {
0,
"file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_SEEK | wasi::RIGHTS_FD_WRITE,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
)
Expand Down
2 changes: 1 addition & 1 deletion test-programs/wasi-tests/src/bin/file_seek_tell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ unsafe fn test_file_seek_tell(dir_fd: wasi::Fd) {
0,
"file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_FD_SEEK | wasi::RIGHTS_FD_TELL,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
0,
)
Expand Down
26 changes: 3 additions & 23 deletions test-programs/wasi-tests/src/bin/path_filestat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ use std::{env, process};
use wasi_tests::{assert_errno, open_scratch_directory, TESTCONFIG};

unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
let mut fdstat = wasi::fd_fdstat_get(dir_fd).expect("fd_fdstat_get");
assert_ne!(
fdstat.fs_rights_base & wasi::RIGHTS_PATH_FILESTAT_GET,
0,
"the scratch directory should have RIGHT_PATH_FILESTAT_GET as base right",
);

let fdflags = if TESTCONFIG.support_fdflags_sync() {
wasi::FDFLAGS_APPEND | wasi::FDFLAGS_SYNC
} else {
Expand All @@ -21,7 +14,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
0,
"file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_PATH_FILESTAT_GET,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
// Pass some flags for later retrieval
fdflags,
Expand All @@ -32,20 +25,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
"file descriptor range check",
);

fdstat = wasi::fd_fdstat_get(file_fd).expect("fd_fdstat_get");

if TESTCONFIG.support_rights_readback() {
assert_eq!(
fdstat.fs_rights_base & wasi::RIGHTS_PATH_FILESTAT_GET,
0,
"files shouldn't have rights for path_* syscalls even if manually given",
);
assert_eq!(
fdstat.fs_rights_inheriting & wasi::RIGHTS_PATH_FILESTAT_GET,
0,
"files shouldn't have rights for path_* syscalls even if manually given",
);
}
let fdstat = wasi::fd_fdstat_get(file_fd).expect("fd_fdstat_get");
assert_eq!(
fdstat.fs_flags & wasi::FDFLAGS_APPEND,
wasi::FDFLAGS_APPEND,
Expand All @@ -66,7 +46,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
0,
"file",
0,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_PATH_FILESTAT_GET,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_FD_WRITE,
0,
wasi::FDFLAGS_SYNC,
)
Expand Down
31 changes: 11 additions & 20 deletions test-programs/wasi-tests/src/bin/path_link.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
use std::{env, process};
use wasi_tests::{assert_errno, create_file, open_scratch_directory, TESTCONFIG};

const TEST_RIGHTS: wasi::Rights = wasi::RIGHTS_FD_READ
| wasi::RIGHTS_PATH_LINK_SOURCE
| wasi::RIGHTS_PATH_LINK_TARGET
| wasi::RIGHTS_FD_FILESTAT_GET
| wasi::RIGHTS_PATH_OPEN
| wasi::RIGHTS_PATH_UNLINK_FILE;

unsafe fn create_or_open(dir_fd: wasi::Fd, name: &str, flags: wasi::Oflags) -> wasi::Fd {
let file_fd = wasi::path_open(dir_fd, 0, name, flags, TEST_RIGHTS, TEST_RIGHTS, 0)
let file_fd = wasi::path_open(dir_fd, 0, name, flags, 0, 0, 0)
.unwrap_or_else(|_| panic!("opening '{}'", name));
assert!(
file_fd > libc::STDERR_FILENO as wasi::Fd,
Expand All @@ -19,7 +12,7 @@ unsafe fn create_or_open(dir_fd: wasi::Fd, name: &str, flags: wasi::Oflags) -> w
}

unsafe fn open_link(dir_fd: wasi::Fd, name: &str) -> wasi::Fd {
let file_fd = wasi::path_open(dir_fd, 0, name, 0, TEST_RIGHTS, TEST_RIGHTS, 0)
let file_fd = wasi::path_open(dir_fd, 0, name, 0, 0, 0, 0)
.unwrap_or_else(|_| panic!("opening a link '{}'", name));
assert!(
file_fd > libc::STDERR_FILENO as wasi::Fd,
Expand Down Expand Up @@ -49,16 +42,14 @@ fn fdstats_assert_eq(left: wasi::Fdstat, right: wasi::Fdstat) {
left.fs_filetype, right.fs_filetype,
"fs_filetype should be equal"
);
if TESTCONFIG.support_rights_readback() {
assert_eq!(
left.fs_rights_base, right.fs_rights_base,
"fs_rights_base should be equal"
);
assert_eq!(
left.fs_rights_inheriting, right.fs_rights_inheriting,
"fs_rights_inheriting should be equal"
);
}
assert_eq!(
left.fs_rights_base, right.fs_rights_base,
"fs_rights_base should be equal"
);
assert_eq!(
left.fs_rights_inheriting, right.fs_rights_inheriting,
"fs_rights_inheriting should be equal"
);
}

unsafe fn check_rights(orig_fd: wasi::Fd, link_fd: wasi::Fd) {
Expand Down Expand Up @@ -93,9 +84,9 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
wasi::path_link(dir_fd, 0, "file", subdir_fd, "link").expect("creating a link in subdirectory");
let link_fd = open_link(subdir_fd, "link");
check_rights(file_fd, link_fd);
wasi::fd_close(link_fd).expect("Closing link_fd"); // needed for Windows
wasi::path_unlink_file(subdir_fd, "link").expect("removing a link");
wasi::fd_close(subdir_fd).expect("Closing subdir_fd"); // needed for Windows
wasi::fd_close(link_fd).expect("Closing link_fd"); // needed for Windows
wasi::path_remove_directory(dir_fd, "subdir").expect("removing a subdirectory");

// Create a link to a path that already exists
Expand Down
79 changes: 0 additions & 79 deletions test-programs/wasi-tests/src/bin/path_open_read_without_rights.rs

This file was deleted.

15 changes: 4 additions & 11 deletions test-programs/wasi-tests/src/bin/poll_oneoff_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,8 @@ unsafe fn test_fd_readwrite_valid_fd(dir_fd: wasi::Fd) {
wasi::fd_close(nonempty_file).expect("close");

// Now open the file for reading
let readable_fd = wasi::path_open(
dir_fd,
0,
"readable_file",
0,
wasi::RIGHTS_FD_READ | wasi::RIGHTS_POLL_FD_READWRITE,
0,
0,
)
.expect("opening a readable file");
let readable_fd = wasi::path_open(dir_fd, 0, "readable_file", 0, wasi::RIGHTS_FD_READ, 0, 0)
.expect("opening a readable file");

assert!(
readable_fd > libc::STDERR_FILENO as wasi::Fd,
Expand All @@ -218,7 +210,7 @@ unsafe fn test_fd_readwrite_valid_fd(dir_fd: wasi::Fd) {
0,
"writable_file",
wasi::OFLAGS_CREAT,
wasi::RIGHTS_FD_WRITE | wasi::RIGHTS_POLL_FD_READWRITE,
wasi::RIGHTS_FD_WRITE,
0,
0,
)
Expand All @@ -231,6 +223,7 @@ unsafe fn test_fd_readwrite_valid_fd(dir_fd: wasi::Fd) {
test_fd_readwrite(readable_fd, writable_fd, wasi::ERRNO_SUCCESS);

wasi::fd_close(readable_fd).expect("closing readable_file");
wasi::fd_close(writable_fd).expect("closing writable_file");
wasi::path_unlink_file(dir_fd, "readable_file").expect("removing readable_file");
wasi::path_unlink_file(dir_fd, "writable_file").expect("removing writable_file");
}
Expand Down
Loading

0 comments on commit fa859ea

Please sign in to comment.