Skip to content

Commit

Permalink
Update to the latest close_preopen.rs
Browse files Browse the repository at this point in the history
This updates the close_preopens test to the latest upstream version,
which implements WebAssembly/WASI#522. Preopens
may now be closed.
  • Loading branch information
sunfishcode committed Mar 20, 2023
1 parent 3719f9a commit 117dc95
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions tests/rust/src/bin/close_preopen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
assert!(dir_fd > pre_fd, "dir_fd number");

// Try to close a preopened directory handle.
assert_errno!(
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"),
wasi::ERRNO_NOTSUP
);
wasi::fd_close(pre_fd).expect("closing a preopened file descriptor");

// Ensure that dir_fd is still open.
let dir_fdstat = wasi::fd_fdstat_get(dir_fd).expect("failed fd_fdstat_get");
Expand All @@ -27,19 +17,10 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
"expected the scratch directory to be a directory",
);

// Try to renumber a preopened directory handle.
// Ensure that pre_fd is closed.
assert_errno!(
wasi::fd_renumber(pre_fd, dir_fd)
.expect_err("renumbering over a preopened file descriptor"),
wasi::ERRNO_NOTSUP
);

// Ensure that dir_fd is still open.
let dir_fdstat = wasi::fd_fdstat_get(dir_fd).expect("failed fd_fdstat_get");
assert_eq!(
dir_fdstat.fs_filetype,
wasi::FILETYPE_DIRECTORY,
"expected the scratch directory to be a directory",
wasi::fd_fdstat_get(pre_fd).expect_err("failed fd_fdstat_get"),
wasi::ERRNO_BADF
);
}

Expand Down

0 comments on commit 117dc95

Please sign in to comment.