Skip to content

Commit

Permalink
dir_fd_op_failures.rs: accept more reasonable error numbers
Browse files Browse the repository at this point in the history
it makes more sense to align posix than wasmtime.
  • Loading branch information
yamt authored and loganek committed Jan 2, 2024
1 parent ec55cdc commit 7ec16c2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/rust/src/bin/dir_fd_op_failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ unsafe fn test_fd_dir_ops(dir_fd: wasi::Fd) {
// On posix, this fails with ERRNO_ISDIR
assert_errno!(
wasi::fd_read(dir_fd, &[iovec]).expect_err("fd_read error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);

// On posix, this fails with ERRNO_ISDIR
assert_errno!(
wasi::fd_pread(dir_fd, &[iovec], 0).expect_err("fd_pread error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);
Expand All @@ -51,42 +53,50 @@ unsafe fn test_fd_dir_ops(dir_fd: wasi::Fd) {
buf_len: write_buf.len(),
};

// On posix, this fails with ERRNO_ISDIR
assert_errno!(
wasi::fd_write(dir_fd, &[ciovec]).expect_err("fd_write error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);

// On posix, this fails with ERRNO_ISDIR
assert_errno!(
wasi::fd_pwrite(dir_fd, &[ciovec], 0).expect_err("fd_pwrite error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);

// Divergence from posix: lseek(dirfd) will return 0
assert_errno!(
wasi::fd_seek(dir_fd, 0, wasi::WHENCE_CUR).expect_err("fd_seek WHENCE_CUR error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);

// Divergence from posix: lseek(dirfd) will return 0
assert_errno!(
wasi::fd_seek(dir_fd, 0, wasi::WHENCE_SET).expect_err("fd_seek WHENCE_SET error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);

// Divergence from posix: lseek(dirfd) will return 0
assert_errno!(
wasi::fd_seek(dir_fd, 0, wasi::WHENCE_END).expect_err("fd_seek WHENCE_END error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);

// Tell isnt in posix, its basically lseek with WHENCE_CUR above
assert_errno!(
wasi::fd_tell(dir_fd).expect_err("fd_tell error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);
Expand All @@ -95,13 +105,16 @@ unsafe fn test_fd_dir_ops(dir_fd: wasi::Fd) {
// not available on mac os.
assert_errno!(
wasi::fd_allocate(dir_fd, 0, 0).expect_err("fd_allocate error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);

// ftruncate(dirfd, 1) will fail with errno EINVAL on posix.
assert_errno!(
wasi::fd_filestat_set_size(dir_fd, 0).expect_err("fd_filestat_set_size error"),
wasi::ERRNO_ISDIR,
wasi::ERRNO_INVAL,
wasi::ERRNO_BADF,
wasi::ERRNO_NOTCAPABLE
);
Expand Down

0 comments on commit 7ec16c2

Please sign in to comment.