Update wasi-tests to wasi 0.11. (#5488)

This updates the tests to version 0.11 of the wasi bindings. There
aren't any fundamental changes here; this just syncs up with the latest
version so that it's consistent with other users of the wasi APIs.
This commit is contained in:
Dan Gohman
2023-01-03 09:43:04 -06:00
committed by GitHub
parent 0c615365c6
commit a71f679453
28 changed files with 89 additions and 149 deletions

View File

@@ -16,9 +16,9 @@ checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasi-tests"

View File

@@ -7,7 +7,7 @@ publish = false
[dependencies]
libc = "0.2.65"
wasi = "0.10.2"
wasi = "0.11.0"
once_cell = "1.12"
# This crate is built with the wasm32-wasi target, so it's separate

View File

@@ -8,17 +8,14 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
// Try to close a preopened directory handle.
assert_errno!(
wasi::fd_close(pre_fd)
.expect_err("closing a preopened file descriptor")
.raw_error(),
wasi::fd_close(pre_fd).expect_err("closing a preopened file descriptor"),
wasi::ERRNO_NOTSUP
);
// Try to renumber over a preopened directory handle.
assert_errno!(
wasi::fd_renumber(dir_fd, pre_fd)
.expect_err("renumbering over a preopened file descriptor")
.raw_error(),
.expect_err("renumbering over a preopened file descriptor"),
wasi::ERRNO_NOTSUP
);
@@ -33,8 +30,7 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
// Try to renumber a preopened directory handle.
assert_errno!(
wasi::fd_renumber(pre_fd, dir_fd)
.expect_err("renumbering over a preopened file descriptor")
.raw_error(),
.expect_err("renumbering over a preopened file descriptor"),
wasi::ERRNO_NOTSUP
);

View File

@@ -9,8 +9,7 @@ unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) {
// Try to open it as a directory with O_NOFOLLOW.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a dangling symlink as a directory")
.raw_error(),
.expect_err("opening a dangling symlink as a directory"),
wasi::ERRNO_NOTDIR,
wasi::ERRNO_LOOP
);
@@ -18,8 +17,7 @@ unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) {
// Try to open it as a file with O_NOFOLLOW.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
.expect_err("opening a dangling symlink as a file")
.raw_error(),
.expect_err("opening a dangling symlink as a file"),
wasi::ERRNO_LOOP
);

View File

@@ -23,9 +23,7 @@ unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
// Attempt to seek.
assert_errno!(
wasi::fd_seek(fd, 0, wasi::WHENCE_CUR)
.expect_err("seek on a directory")
.raw_error(),
wasi::fd_seek(fd, 0, wasi::WHENCE_CUR).expect_err("seek on a directory"),
wasi::ERRNO_BADF
);

View File

@@ -1,5 +1,4 @@
unsafe fn test_fd_filestat_get() {
let stat = wasi::fd_filestat_get(libc::STDIN_FILENO as u32).expect("failed filestat 0");
assert_eq!(stat.size, 0, "stdio size should be 0");
assert_eq!(stat.atim, 0, "stdio atim should be 0");

View File

@@ -57,8 +57,7 @@ unsafe fn test_file_seek_tell(dir_fd: wasi::Fd) {
// Seek before byte 0 is an error though
assert_errno!(
wasi::fd_seek(file_fd, -2000, wasi::WHENCE_CUR)
.expect_err("seeking before byte 0 should be an error")
.raw_error(),
.expect_err("seeking before byte 0 should be an error"),
wasi::ERRNO_INVAL
);

View File

@@ -14,8 +14,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
// Now open it with an absolute path.
assert_errno!(
wasi::path_open(dir_fd, 0, "/dir/nested/file", 0, 0, 0, 0)
.expect_err("opening a file with an absolute path")
.raw_error(),
.expect_err("opening a file with an absolute path"),
wasi::ERRNO_PERM
);
@@ -39,8 +38,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
// Now open it with a trailing NUL.
assert_errno!(
wasi::path_open(dir_fd, 0, "dir/nested/file\0", 0, 0, 0, 0)
.expect_err("opening a file with a trailing NUL")
.raw_error(),
.expect_err("opening a file with a trailing NUL"),
wasi::ERRNO_INVAL,
wasi::ERRNO_ILSEQ
);
@@ -48,8 +46,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
// Now open it with a trailing slash.
assert_errno!(
wasi::path_open(dir_fd, 0, "dir/nested/file/", 0, 0, 0, 0)
.expect_err("opening a file with a trailing slash should fail")
.raw_error(),
.expect_err("opening a file with a trailing slash should fail"),
wasi::ERRNO_NOTDIR,
wasi::ERRNO_NOENT
);
@@ -57,8 +54,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
// Now open it with trailing slashes.
assert_errno!(
wasi::path_open(dir_fd, 0, "dir/nested/file///", 0, 0, 0, 0)
.expect_err("opening a file with trailing slashes should fail")
.raw_error(),
.expect_err("opening a file with trailing slashes should fail"),
wasi::ERRNO_NOTDIR,
wasi::ERRNO_NOENT
);
@@ -85,8 +81,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
let bad_path = format!("dir/nested/../../../{}/dir/nested/file", arg);
assert_errno!(
wasi::path_open(dir_fd, 0, &bad_path, 0, 0, 0, 0)
.expect_err("opening a file with too many \"..\"s in the path should fail")
.raw_error(),
.expect_err("opening a file with too many \"..\"s in the path should fail"),
wasi::ERRNO_PERM
);
wasi::path_unlink_file(dir_fd, "dir/nested/file")

View File

@@ -11,8 +11,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
// Try to open it as a directory with O_NOFOLLOW again.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a directory symlink as a directory should fail")
.raw_error(),
.expect_err("opening a directory symlink as a directory should fail"),
wasi::ERRNO_LOOP,
wasi::ERRNO_NOTDIR
);
@@ -20,8 +19,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
// Try to open it with just O_NOFOLLOW.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
.expect_err("opening a symlink with O_NOFOLLOW should fail")
.raw_error(),
.expect_err("opening a symlink with O_NOFOLLOW should fail"),
wasi::ERRNO_LOOP,
wasi::ERRNO_ACCES
);
@@ -56,8 +54,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
// Try to open it as a directory with O_NOFOLLOW again.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a directory symlink as a directory should fail")
.raw_error(),
.expect_err("opening a directory symlink as a directory should fail"),
wasi::ERRNO_LOOP,
wasi::ERRNO_NOTDIR
);
@@ -65,8 +62,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
// Try to open it with just O_NOFOLLOW.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
.expect_err("opening a symlink with NOFOLLOW should fail")
.raw_error(),
.expect_err("opening a symlink with NOFOLLOW should fail"),
wasi::ERRNO_LOOP
);
@@ -81,8 +77,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
0,
0,
)
.expect_err("opening a symlink to a file as a directory")
.raw_error(),
.expect_err("opening a symlink to a file as a directory"),
wasi::ERRNO_NOTDIR
);

View File

@@ -67,8 +67,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
0,
wasi::FDFLAGS_SYNC,
)
.expect_err("FDFLAGS_SYNC not supported by platform")
.raw_error(),
.expect_err("FDFLAGS_SYNC not supported by platform"),
wasi::ERRNO_NOTSUP
);
}
@@ -95,8 +94,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
new_mtim,
wasi::FSTFLAGS_MTIM | wasi::FSTFLAGS_MTIM_NOW,
)
.expect_err("MTIM and MTIM_NOW can't both be set")
.raw_error(),
.expect_err("MTIM and MTIM_NOW can't both be set"),
wasi::ERRNO_INVAL
);
@@ -118,8 +116,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
0,
wasi::FSTFLAGS_ATIM | wasi::FSTFLAGS_ATIM_NOW,
)
.expect_err("ATIM & ATIM_NOW can't both be set")
.raw_error(),
.expect_err("ATIM & ATIM_NOW can't both be set"),
wasi::ERRNO_INVAL
);

View File

@@ -101,8 +101,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_link(dir_fd, 0, "file", dir_fd, "link")
.expect_err("creating a link to existing path should fail")
.raw_error(),
.expect_err("creating a link to existing path should fail"),
wasi::ERRNO_EXIST
);
wasi::path_unlink_file(dir_fd, "link").expect("removing a file");
@@ -110,8 +109,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
// Create a link to itself
assert_errno!(
wasi::path_link(dir_fd, 0, "file", dir_fd, "file")
.expect_err("creating a link to itself should fail")
.raw_error(),
.expect_err("creating a link to itself should fail"),
wasi::ERRNO_EXIST
);
@@ -120,8 +118,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_link(dir_fd, 0, "file", dir_fd, "link")
.expect_err("creating a link where target is a directory should fail")
.raw_error(),
.expect_err("creating a link where target is a directory should fail"),
wasi::ERRNO_EXIST
);
wasi::path_remove_directory(dir_fd, "link").expect("removing a dir");
@@ -132,8 +129,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_link(dir_fd, 0, "subdir", dir_fd, "link")
.expect_err("creating a link to a directory should fail")
.raw_error(),
.expect_err("creating a link to a directory should fail"),
wasi::ERRNO_PERM,
wasi::ERRNO_ACCES
);
@@ -143,8 +139,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
// Create a link to a file with trailing slash
assert_errno!(
wasi::path_link(dir_fd, 0, "file", dir_fd, "link/")
.expect_err("creating a link to a file with trailing slash should fail")
.raw_error(),
.expect_err("creating a link to a file with trailing slash should fail"),
wasi::ERRNO_NOENT
);
@@ -171,8 +166,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_link(dir_fd, 0, "file", dir_fd, "symlink")
.expect_err("creating a link where target is a dangling symlink")
.raw_error(),
.expect_err("creating a link where target is a dangling symlink"),
wasi::ERRNO_EXIST
);
wasi::path_unlink_file(dir_fd, "symlink").expect("removing a symlink");
@@ -189,8 +183,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
dir_fd,
"link",
)
.expect_err("calling path_link with LOOKUPFLAGS_SYMLINK_FOLLOW should fail")
.raw_error(),
.expect_err("calling path_link with LOOKUPFLAGS_SYMLINK_FOLLOW should fail"),
wasi::ERRNO_INVAL
);

View File

@@ -13,8 +13,7 @@ unsafe fn test_path_open_create_existing(dir_fd: wasi::Fd) {
0,
0,
)
.expect_err("trying to create a file that already exists")
.raw_error(),
.expect_err("trying to create a file that already exists"),
wasi::ERRNO_EXIST
);
wasi::path_unlink_file(dir_fd, "file").expect("removing a file");

View File

@@ -8,8 +8,7 @@ unsafe fn test_dirfd_not_dir(dir_fd: wasi::Fd) {
// Now try to open a file underneath it as if it were a directory.
assert_errno!(
wasi::path_open(file_fd, 0, "foo", wasi::OFLAGS_CREAT, 0, 0, 0)
.expect_err("non-directory base fd should get ERRNO_NOTDIR")
.raw_error(),
.expect_err("non-directory base fd should get ERRNO_NOTDIR"),
wasi::ERRNO_NOTDIR
);
wasi::fd_close(file_fd).expect("closing a file");

View File

@@ -7,8 +7,7 @@ unsafe fn test_path_open_missing(dir_fd: wasi::Fd) {
dir_fd, 0, "file", 0, // not passing O_CREAT here
0, 0, 0,
)
.expect_err("trying to open a file that doesn't exist")
.raw_error(),
.expect_err("trying to open a file that doesn't exist"),
wasi::ERRNO_NOENT
);
}

View File

@@ -27,9 +27,7 @@ unsafe fn try_read_file(dir_fd: wasi::Fd) {
// Since we no longer have the right to fd_read, trying to read a file
// should be an error.
assert_errno!(
wasi::fd_read(fd, &[iovec])
.expect_err("reading bytes from file should fail")
.raw_error(),
wasi::fd_read(fd, &[iovec]).expect_err("reading bytes from file should fail"),
wasi::ERRNO_BADF
);
}

View File

@@ -12,8 +12,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
// Check that source directory doesn't exist anymore
assert_errno!(
wasi::path_open(dir_fd, 0, "source", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a nonexistent path as a directory should fail")
.raw_error(),
.expect_err("opening a nonexistent path as a directory should fail"),
wasi::ERRNO_NOENT
);
@@ -41,8 +40,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
// Check that source directory doesn't exist anymore
assert_errno!(
wasi::path_open(dir_fd, 0, "source", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a nonexistent path as a directory")
.raw_error(),
.expect_err("opening a nonexistent path as a directory"),
wasi::ERRNO_NOENT
);
@@ -72,8 +70,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_rename(dir_fd, "source", dir_fd, "target")
.expect_err("renaming directory to a nonempty directory")
.raw_error(),
.expect_err("renaming directory to a nonempty directory"),
windows => wasi::ERRNO_ACCES,
unix => wasi::ERRNO_NOTEMPTY
);
@@ -85,8 +82,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
// Try renaming dir to a file
assert_errno!(
wasi::path_rename(dir_fd, "source", dir_fd, "target/file")
.expect_err("renaming a directory to a file")
.raw_error(),
.expect_err("renaming a directory to a file"),
wasi::ERRNO_NOTDIR
);
wasi::path_unlink_file(dir_fd, "target/file").expect("removing a file");
@@ -107,8 +103,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
// Check that source file doesn't exist anymore
assert_errno!(
wasi::path_open(dir_fd, 0, "source", 0, 0, 0, 0)
.expect_err("opening a nonexistent path should fail")
.raw_error(),
.expect_err("opening a nonexistent path should fail"),
wasi::ERRNO_NOENT
);
@@ -131,9 +126,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
// Check that source file doesn't exist anymore
assert_errno!(
wasi::path_open(dir_fd, 0, "source", 0, 0, 0, 0)
.expect_err("opening a nonexistent path")
.raw_error(),
wasi::path_open(dir_fd, 0, "source", 0, 0, 0, 0).expect_err("opening a nonexistent path"),
wasi::ERRNO_NOENT
);
@@ -153,8 +146,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_rename(dir_fd, "source", dir_fd, "target")
.expect_err("renaming a file to existing directory should fail")
.raw_error(),
.expect_err("renaming a file to existing directory should fail"),
windows => wasi::ERRNO_ACCES,
unix => wasi::ERRNO_ISDIR
);

View File

@@ -11,20 +11,19 @@ unsafe fn test_path_rename_trailing_slashes(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_rename(dir_fd, "source/", dir_fd, "target")
.expect_err("renaming a file with a trailing slash in the source name should fail")
.raw_error(),
.expect_err("renaming a file with a trailing slash in the source name should fail"),
wasi::ERRNO_NOTDIR
);
assert_errno!(
wasi::path_rename(dir_fd, "source", dir_fd, "target/")
.expect_err("renaming a file with a trailing slash in the destination name should fail")
.raw_error(),
wasi::path_rename(dir_fd, "source", dir_fd, "target/").expect_err(
"renaming a file with a trailing slash in the destination name should fail"
),
wasi::ERRNO_NOTDIR
);
assert_errno!(
wasi::path_rename(dir_fd, "source/", dir_fd, "target/")
.expect_err("renaming a file with a trailing slash in the source and destination names should fail")
.raw_error(),
wasi::path_rename(dir_fd, "source/", dir_fd, "target/").expect_err(
"renaming a file with a trailing slash in the source and destination names should fail"
),
wasi::ERRNO_NOTDIR
);
wasi::path_unlink_file(dir_fd, "source").expect("removing a file");

View File

@@ -6,8 +6,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
// Dangling symlink: Link destination shouldn't end with a slash.
assert_errno!(
wasi::path_symlink("source", dir_fd, "target/")
.expect_err("link destination ending with a slash should fail")
.raw_error(),
.expect_err("link destination ending with a slash should fail"),
wasi::ERRNO_NOENT
);
@@ -21,8 +20,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_create_directory(dir_fd, "target").expect("creating a directory");
assert_errno!(
wasi::path_symlink("source", dir_fd, "target/")
.expect_err("link destination already exists")
.raw_error(),
.expect_err("link destination already exists"),
unix => wasi::ERRNO_EXIST,
windows => wasi::ERRNO_NOENT
);
@@ -32,8 +30,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_create_directory(dir_fd, "target").expect("creating a directory");
assert_errno!(
wasi::path_symlink("source", dir_fd, "target")
.expect_err("link destination already exists")
.raw_error(),
.expect_err("link destination already exists"),
unix => wasi::ERRNO_EXIST,
windows => wasi::ERRNO_NOENT
);
@@ -44,8 +41,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_symlink("source", dir_fd, "target/")
.expect_err("link destination already exists")
.raw_error(),
.expect_err("link destination already exists"),
unix => wasi::ERRNO_NOTDIR,
windows => wasi::ERRNO_NOENT
);
@@ -56,8 +52,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
assert_errno!(
wasi::path_symlink("source", dir_fd, "target")
.expect_err("link destination already exists")
.raw_error(),
.expect_err("link destination already exists"),
unix => wasi::ERRNO_EXIST,
windows => wasi::ERRNO_NOENT
);

View File

@@ -3,7 +3,7 @@ use wasi_tests::{assert_errno, open_scratch_directory};
const CLOCK_ID: wasi::Userdata = 0x0123_45678;
unsafe fn poll_oneoff_impl(r#in: &[wasi::Subscription]) -> Result<Vec<wasi::Event>, wasi::Error> {
unsafe fn poll_oneoff_impl(r#in: &[wasi::Subscription]) -> Result<Vec<wasi::Event>, wasi::Errno> {
let mut out: Vec<wasi::Event> = Vec::new();
out.resize_with(r#in.len(), || {
MaybeUninit::<wasi::Event>::zeroed().assume_init()
@@ -17,7 +17,7 @@ unsafe fn poll_oneoff_impl(r#in: &[wasi::Subscription]) -> Result<Vec<wasi::Even
/// seen their events occur.
unsafe fn poll_oneoff_with_retry(
r#in: &[wasi::Subscription],
) -> Result<Vec<wasi::Event>, wasi::Error> {
) -> Result<Vec<wasi::Event>, wasi::Errno> {
let mut subscriptions = r#in.to_vec();
let mut events = Vec::new();
while !subscriptions.is_empty() {
@@ -47,8 +47,7 @@ unsafe fn test_empty_poll() {
let mut out: Vec<wasi::Event> = Vec::new();
assert_errno!(
wasi::poll_oneoff(r#in.as_ptr(), out.as_mut_ptr(), r#in.len())
.expect_err("empty poll_oneoff should fail")
.raw_error(),
.expect_err("empty poll_oneoff should fail"),
wasi::ERRNO_INVAL
);
}
@@ -64,7 +63,7 @@ unsafe fn test_timeout() {
let r#in = [wasi::Subscription {
userdata: CLOCK_ID,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_CLOCK,
tag: wasi::EVENTTYPE_CLOCK.raw(),
u: wasi::SubscriptionUU { clock },
},
}];
@@ -75,7 +74,7 @@ unsafe fn test_timeout() {
let event = &out[0];
assert_errno!(event.error, wasi::ERRNO_SUCCESS);
assert_eq!(
event.r#type,
event.type_,
wasi::EVENTTYPE_CLOCK,
"the event.type should equal clock"
);
@@ -102,7 +101,7 @@ unsafe fn test_sleep() {
let r#in = [wasi::Subscription {
userdata: CLOCK_ID,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_CLOCK,
tag: wasi::EVENTTYPE_CLOCK.raw(),
u: wasi::SubscriptionUU { clock },
},
}];
@@ -113,7 +112,7 @@ unsafe fn test_sleep() {
let event = &out[0];
assert_errno!(event.error, wasi::ERRNO_SUCCESS);
assert_eq!(
event.r#type,
event.type_,
wasi::EVENTTYPE_CLOCK,
"the event.type should equal clock"
);
@@ -132,7 +131,7 @@ unsafe fn test_fd_readwrite(readable_fd: wasi::Fd, writable_fd: wasi::Fd, error_
wasi::Subscription {
userdata: 1,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_FD_READ,
tag: wasi::EVENTTYPE_FD_READ.raw(),
u: wasi::SubscriptionUU {
fd_read: wasi::SubscriptionFdReadwrite {
file_descriptor: readable_fd,
@@ -143,7 +142,7 @@ unsafe fn test_fd_readwrite(readable_fd: wasi::Fd, writable_fd: wasi::Fd, error_
wasi::Subscription {
userdata: 2,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_FD_WRITE,
tag: wasi::EVENTTYPE_FD_WRITE.raw(),
u: wasi::SubscriptionUU {
fd_write: wasi::SubscriptionFdReadwrite {
file_descriptor: writable_fd,
@@ -160,7 +159,7 @@ unsafe fn test_fd_readwrite(readable_fd: wasi::Fd, writable_fd: wasi::Fd, error_
);
assert_errno!(out[0].error, error_code);
assert_eq!(
out[0].r#type,
out[0].type_,
wasi::EVENTTYPE_FD_READ,
"the event.type_ should equal FD_READ"
);
@@ -170,7 +169,7 @@ unsafe fn test_fd_readwrite(readable_fd: wasi::Fd, writable_fd: wasi::Fd, error_
);
assert_errno!(out[1].error, error_code);
assert_eq!(
out[1].r#type,
out[1].type_,
wasi::EVENTTYPE_FD_WRITE,
"the event.type_ should equal FD_WRITE"
);
@@ -244,7 +243,7 @@ unsafe fn test_fd_readwrite_invalid_fd() {
wasi::Subscription {
userdata: 1,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_FD_READ,
tag: wasi::EVENTTYPE_FD_READ.raw(),
u: wasi::SubscriptionUU {
fd_read: fd_readwrite,
},
@@ -253,7 +252,7 @@ unsafe fn test_fd_readwrite_invalid_fd() {
wasi::Subscription {
userdata: 2,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_FD_WRITE,
tag: wasi::EVENTTYPE_FD_WRITE.raw(),
u: wasi::SubscriptionUU {
fd_write: fd_readwrite,
},
@@ -261,7 +260,7 @@ unsafe fn test_fd_readwrite_invalid_fd() {
},
];
let err = poll_oneoff_impl(&r#in).unwrap_err();
assert_eq!(err.raw_error(), wasi::ERRNO_BADF)
assert_eq!(err, wasi::ERRNO_BADF)
}
unsafe fn test_poll_oneoff(dir_fd: wasi::Fd) {

View File

@@ -6,7 +6,7 @@ const TIMEOUT: u64 = 200_000_000u64; // 200 milliseconds, required to satisfy sl
const CLOCK_ID: wasi::Userdata = 0x0123_45678;
const STDIN_ID: wasi::Userdata = 0x8765_43210;
unsafe fn poll_oneoff_impl(r#in: &[wasi::Subscription]) -> Result<Vec<wasi::Event>, wasi::Error> {
unsafe fn poll_oneoff_impl(r#in: &[wasi::Subscription]) -> Result<Vec<wasi::Event>, wasi::Errno> {
let mut out: Vec<wasi::Event> = Vec::new();
out.resize_with(r#in.len(), || {
MaybeUninit::<wasi::Event>::zeroed().assume_init()
@@ -31,14 +31,14 @@ unsafe fn test_stdin_read() {
wasi::Subscription {
userdata: CLOCK_ID,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_CLOCK,
tag: wasi::EVENTTYPE_CLOCK.raw(),
u: wasi::SubscriptionUU { clock },
},
},
wasi::Subscription {
userdata: STDIN_ID,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_FD_READ,
tag: wasi::EVENTTYPE_FD_READ.raw(),
u: wasi::SubscriptionUU {
fd_read: fd_readwrite,
},
@@ -50,20 +50,20 @@ unsafe fn test_stdin_read() {
// Both are valid behaviors that depend on the test environment.
assert!(out.len() >= 1, "stdin read should return at least 1 event");
for event in out {
if event.r#type == wasi::EVENTTYPE_CLOCK {
if event.type_ == wasi::EVENTTYPE_CLOCK {
assert_errno!(event.error, wasi::ERRNO_SUCCESS);
assert_eq!(
event.userdata, CLOCK_ID,
"the event.userdata should contain CLOCK_ID",
);
} else if event.r#type == wasi::EVENTTYPE_FD_READ {
} else if event.type_ == wasi::EVENTTYPE_FD_READ {
assert_errno!(event.error, wasi::ERRNO_SUCCESS);
assert_eq!(
event.userdata, STDIN_ID,
"the event.userdata should contain STDIN_ID",
);
} else {
panic!("unexpected event type {}", event.r#type);
panic!("unexpected event type {}", event.type_.raw());
}
}
}
@@ -74,7 +74,7 @@ fn writable_subs(h: &HashMap<u64, wasi::Fd>) -> Vec<wasi::Subscription> {
.map(|(ud, fd)| wasi::Subscription {
userdata: *ud,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_FD_WRITE,
tag: wasi::EVENTTYPE_FD_WRITE.raw(),
u: wasi::SubscriptionUU {
fd_write: wasi::SubscriptionFdReadwrite {
file_descriptor: *fd,
@@ -92,7 +92,7 @@ unsafe fn test_stdout_stderr_write() {
let clock = wasi::Subscription {
userdata: CLOCK_ID,
u: wasi::SubscriptionU {
tag: wasi::EVENTTYPE_CLOCK,
tag: wasi::EVENTTYPE_CLOCK.raw(),
u: wasi::SubscriptionUU {
clock: wasi::SubscriptionClock {
id: wasi::CLOCKID_MONOTONIC,
@@ -114,7 +114,7 @@ unsafe fn test_stdout_stderr_write() {
}
ud => {
if let Some(_) = writable.remove(&ud) {
assert_eq!(event.r#type, wasi::EVENTTYPE_FD_WRITE);
assert_eq!(event.type_, wasi::EVENTTYPE_FD_WRITE);
assert_errno!(event.error, wasi::ERRNO_SUCCESS);
} else {
panic!("Unknown userdata {}, pending sub: {:?}", ud, writable)

View File

@@ -25,7 +25,7 @@ unsafe fn test_readlink(dir_fd: wasi::Fd) {
let err = wasi::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len())
.err()
.expect("readlink with too-small buffer should fail");
assert_errno!(err.raw_error(), wasi::ERRNO_RANGE);
assert_errno!(err, wasi::ERRNO_RANGE);
// Clean up.
wasi::path_unlink_file(dir_fd, "target").expect("removing a file");

View File

@@ -21,16 +21,14 @@ unsafe fn test_remove_directory_trailing_slashes(dir_fd: wasi::Fd) {
// Test that removing it with no trailing slash fails.
assert_errno!(
wasi::path_remove_directory(dir_fd, "file")
.expect_err("remove_directory without a trailing slash on a file should fail")
.raw_error(),
.expect_err("remove_directory without a trailing slash on a file should fail"),
wasi::ERRNO_NOTDIR
);
// Test that removing it with a trailing slash fails.
assert_errno!(
wasi::path_remove_directory(dir_fd, "file/")
.expect_err("remove_directory with a trailing slash on a file should fail")
.raw_error(),
.expect_err("remove_directory with a trailing slash on a file should fail"),
unix => wasi::ERRNO_NOTDIR,
windows => wasi::ERRNO_NOENT
);

View File

@@ -11,8 +11,7 @@ unsafe fn test_remove_nonempty_directory(dir_fd: wasi::Fd) {
// Test that attempting to unlink the first directory returns the expected error code.
assert_errno!(
wasi::path_remove_directory(dir_fd, "dir")
.expect_err("remove_directory on a directory should return ENOTEMPTY")
.raw_error(),
.expect_err("remove_directory on a directory should return ENOTEMPTY"),
wasi::ERRNO_NOTEMPTY
);

View File

@@ -47,9 +47,7 @@ unsafe fn test_renumber(dir_fd: wasi::Fd) {
// Ensure that fd_from is closed
assert_errno!(
wasi::fd_close(fd_from)
.expect_err("closing already closed file descriptor")
.raw_error(),
wasi::fd_close(fd_from).expect_err("closing already closed file descriptor"),
wasi::ERRNO_BADF
);

View File

@@ -9,8 +9,7 @@ unsafe fn test_symlink_loop(dir_fd: wasi::Fd) {
// Try to open it.
assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
.expect_err("opening a self-referencing symlink")
.raw_error(),
.expect_err("opening a self-referencing symlink"),
wasi::ERRNO_LOOP
);

View File

@@ -66,8 +66,7 @@ unsafe fn test_truncation_rights(dir_fd: wasi::Fd) {
// wasi_unstable::RIGHT_PATH_FILESTAT_SET_SIZE right.
assert_errno!(
wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_TRUNC, 0, 0, 0)
.expect_err("truncating a file without path_filestat_set_size right")
.raw_error(),
.expect_err("truncating a file without path_filestat_set_size right"),
wasi::ERRNO_PERM
);
}

View File

@@ -8,8 +8,7 @@ unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
// Test that unlinking it fails.
assert_errno!(
wasi::path_unlink_file(dir_fd, "dir")
.expect_err("unlink_file on a directory should fail")
.raw_error(),
.expect_err("unlink_file on a directory should fail"),
macos => wasi::ERRNO_PERM,
unix => wasi::ERRNO_ISDIR,
windows => wasi::ERRNO_ACCES
@@ -18,8 +17,7 @@ unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
// Test that unlinking it with a trailing flash fails.
assert_errno!(
wasi::path_unlink_file(dir_fd, "dir/")
.expect_err("unlink_file on a directory should fail")
.raw_error(),
.expect_err("unlink_file on a directory should fail"),
macos => wasi::ERRNO_PERM,
unix => wasi::ERRNO_ISDIR,
windows => wasi::ERRNO_ACCES
@@ -34,8 +32,7 @@ unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
// Test that unlinking it with a trailing flash fails.
assert_errno!(
wasi::path_unlink_file(dir_fd, "file/")
.expect_err("unlink_file with a trailing slash should fail")
.raw_error(),
.expect_err("unlink_file with a trailing slash should fail"),
unix => wasi::ERRNO_NOTDIR,
windows => wasi::ERRNO_NOENT
);

View File

@@ -18,7 +18,7 @@ pub fn open_scratch_directory(path: &str) -> Result<wasi::Fd, String> {
Ok(s) => s,
Err(_) => break,
};
if stat.tag != wasi::PREOPENTYPE_DIR {
if stat.tag != wasi::PREOPENTYPE_DIR.raw() {
continue;
}
let mut dst = Vec::with_capacity(stat.u.dir.pr_name_len);
@@ -122,8 +122,8 @@ macro_rules! assert_errno {
}
assert!( $( e == $i || )+ false,
"expected errno {}; got {}",
Alt(&[ $( wasi::errno_name($i) ),+ ]),
wasi::errno_name(e),
Alt(&[ $( $i.name() ),+ ]),
e.name()
)
}
};