Start to update the wasi crate in wasi tests (#675)
* Move `wasi` to `wasi_old` in wasi-tests Leave space for the new `wasi` crate but allow us to incrementally update tests. * Update the big_random_buf test * Update clock_time_get test * Update close_preopen test * Review comments * Update to latest Wasmtime API
This commit is contained in:
committed by
Jakub Konka
parent
51f880f625
commit
e13fabb276
@@ -1,60 +1,46 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, mem, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::wasi_wrappers::wasi_fd_fdstat_get;
|
||||
use std::{env, process};
|
||||
use wasi_tests::open_scratch_directory_new;
|
||||
|
||||
unsafe fn test_close_preopen(dir_fd: wasi_unstable::Fd) {
|
||||
let pre_fd: wasi_unstable::Fd = (libc::STDERR_FILENO + 1) as wasi_unstable::Fd;
|
||||
unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
|
||||
let pre_fd: wasi::Fd = (libc::STDERR_FILENO + 1) as wasi::Fd;
|
||||
|
||||
assert_gt!(dir_fd, pre_fd, "dir_fd number");
|
||||
|
||||
// Try to close a preopened directory handle.
|
||||
assert_eq!(
|
||||
wasi_unstable::fd_close(pre_fd),
|
||||
Err(wasi_unstable::ENOTSUP),
|
||||
wasi::fd_close(pre_fd).unwrap_err().raw_error(),
|
||||
wasi::ERRNO_NOTSUP,
|
||||
"closing a preopened file descriptor",
|
||||
);
|
||||
|
||||
// Try to renumber over a preopened directory handle.
|
||||
assert_eq!(
|
||||
wasi_unstable::fd_renumber(dir_fd, pre_fd),
|
||||
Err(wasi_unstable::ENOTSUP),
|
||||
wasi::fd_renumber(dir_fd, pre_fd).unwrap_err().raw_error(),
|
||||
wasi::ERRNO_NOTSUP,
|
||||
"renumbering over a preopened file descriptor",
|
||||
);
|
||||
|
||||
// Ensure that dir_fd is still open.
|
||||
let mut dir_fdstat: wasi_unstable::FdStat = mem::zeroed();
|
||||
let mut status = wasi_fd_fdstat_get(dir_fd, &mut dir_fdstat);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"calling fd_fdstat on the scratch directory"
|
||||
);
|
||||
let dir_fdstat = wasi::fd_fdstat_get(dir_fd).expect("failed fd_fdstat_get");
|
||||
assert_eq!(
|
||||
dir_fdstat.fs_filetype,
|
||||
wasi_unstable::FILETYPE_DIRECTORY,
|
||||
wasi::FILETYPE_DIRECTORY,
|
||||
"expected the scratch directory to be a directory",
|
||||
);
|
||||
|
||||
// Try to renumber a preopened directory handle.
|
||||
assert_eq!(
|
||||
wasi_unstable::fd_renumber(pre_fd, dir_fd),
|
||||
Err(wasi_unstable::ENOTSUP),
|
||||
wasi::fd_renumber(pre_fd, dir_fd).unwrap_err().raw_error(),
|
||||
wasi::ERRNO_NOTSUP,
|
||||
"renumbering over a preopened file descriptor",
|
||||
);
|
||||
|
||||
// Ensure that dir_fd is still open.
|
||||
status = wasi_fd_fdstat_get(dir_fd, &mut dir_fdstat);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"calling fd_fdstat on the scratch directory"
|
||||
);
|
||||
let dir_fdstat = wasi::fd_fdstat_get(dir_fd).expect("failed fd_fdstat_get");
|
||||
assert_eq!(
|
||||
dir_fdstat.fs_filetype,
|
||||
wasi_unstable::FILETYPE_DIRECTORY,
|
||||
wasi::FILETYPE_DIRECTORY,
|
||||
"expected the scratch directory to be a directory",
|
||||
);
|
||||
}
|
||||
@@ -70,7 +56,7 @@ fn main() {
|
||||
};
|
||||
|
||||
// Open scratch directory
|
||||
let dir_fd = match open_scratch_directory(&arg) {
|
||||
let dir_fd = match open_scratch_directory_new(&arg) {
|
||||
Ok(dir_fd) => dir_fd,
|
||||
Err(err) => {
|
||||
eprintln!("{}", err);
|
||||
|
||||
Reference in New Issue
Block a user