Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
wasi-tests: pull in all changes from upstream which remove support fo…
Browse files Browse the repository at this point in the history
…r rights

bytecodealliance/wasmtime#6265

note, im leaving out upstream changes to fd_readdir which are from bytecodealliance/wasmtime#6163, which requires porting the rest of that PR into this repo
  • Loading branch information
Pat Hickey committed Apr 24, 2023
1 parent 915f562 commit e2ca0f6
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 106 deletions.
25 changes: 2 additions & 23 deletions test-programs/wasi-tests/src/bin/directory_seek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@ unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
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,19 +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",
);
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
3 changes: 2 additions & 1 deletion test-programs/wasi-tests/src/bin/overwrite_preopen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ unsafe fn test_overwrite_preopen(dir_fd: wasi::Fd) {
let old_dir_filestat = wasi::fd_filestat_get(dir_fd).expect("failed fd_filestat_get");

// Try to renumber over a preopened directory handle.
wasi::fd_renumber(dir_fd, pre_fd).expect("renumbering over a preopened file descriptor");
wasi::fd_renumber(dir_fd, pre_fd)
.expect("renumbering over a preopened file descriptor");

// Ensure that pre_fd is still open.
let new_dir_filestat = wasi::fd_filestat_get(pre_fd).expect("failed fd_filestat_get");
Expand Down
23 changes: 3 additions & 20 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,17 +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");
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 @@ -63,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
13 changes: 3 additions & 10 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 @@ -91,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
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
4 changes: 1 addition & 3 deletions test-programs/wasi-tests/src/bin/readlink.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{env, process};
use wasi_tests::{create_file, open_scratch_directory};
use wasi_tests::{assert_errno, create_file, open_scratch_directory};

unsafe fn test_readlink(dir_fd: wasi::Fd) {
// Create a file in the scratch directory.
Expand All @@ -21,8 +21,6 @@ unsafe fn test_readlink(dir_fd: wasi::Fd) {
);

// Read link into smaller buffer than the actual link's length
// FIXME: the adapter will actually truncate in this case. we could instead
// return an error in the adapter?
let buf = &mut [0u8; 4];
let bufused = wasi::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len())
.expect("readlink with too-small buffer should silently truncate");
Expand Down
9 changes: 1 addition & 8 deletions test-programs/wasi-tests/src/bin/symlink_filestat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ use std::{env, process};
use wasi_tests::open_scratch_directory;

unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
let 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",
);

// Create a file in the scratch directory.
let file_fd = wasi::path_open(
dir_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,
0,
)
Expand Down

0 comments on commit e2ca0f6

Please sign in to comment.