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,12 +1,9 @@
|
||||
use wasi::wasi_unstable;
|
||||
|
||||
fn test_big_random_buf() {
|
||||
let mut buf = Vec::new();
|
||||
buf.resize(1024, 0);
|
||||
assert!(
|
||||
wasi_unstable::random_get(&mut buf).is_ok(),
|
||||
"calling get_random on a large buffer"
|
||||
);
|
||||
unsafe {
|
||||
wasi::random_get(buf.as_mut_ptr(), 1024).expect("failed to call random_get");
|
||||
}
|
||||
// Chances are pretty good that at least *one* byte will be non-zero in
|
||||
// any meaningful random function producing 1024 u8 values.
|
||||
assert!(buf.iter().any(|x| *x != 0), "random_get returned all zeros");
|
||||
|
||||
@@ -1,33 +1,15 @@
|
||||
use more_asserts::assert_le;
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_tests::wasi_wrappers::wasi_clock_time_get;
|
||||
|
||||
unsafe fn test_clock_time_get() {
|
||||
// Test that clock_time_get succeeds. Even in environments where it's not
|
||||
// desirable to expose high-precision timers, it should still succeed.
|
||||
// clock_res_get is where information about precision can be provided.
|
||||
let mut time: wasi_unstable::Timestamp = 0;
|
||||
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 1, &mut time);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"clock_time_get with a precision of 1"
|
||||
);
|
||||
wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 1).expect("precision 1 should work");
|
||||
|
||||
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 0, &mut time);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"clock_time_get with a precision of 0"
|
||||
);
|
||||
let first_time = time;
|
||||
let first_time =
|
||||
wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 0).expect("precision 0 should work");
|
||||
|
||||
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 0, &mut time);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"clock_time_get with a precision of 0"
|
||||
);
|
||||
let time = wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 0).expect("re-fetch time should work");
|
||||
assert_le!(first_time, time, "CLOCK_MONOTONIC should be monotonic");
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::wasi_path_open;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::cleanup_file;
|
||||
use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, mem, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_dir, close_fd, create_dir};
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_fd_seek, wasi_path_open};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd};
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_advise, wasi_fd_filestat_get, wasi_path_open};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd};
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{cmp::min, env, mem, process, slice, str};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_fd_readdir, wasi_path_open};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd};
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd};
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_pread, wasi_fd_pwrite, wasi_path_open};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd};
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_seek, wasi_fd_tell, wasi_fd_write, wasi_path_open};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd, create_file};
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_read, wasi_fd_write, wasi_path_open};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{close_fd, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd};
|
||||
use wasi_tests::wasi_wrappers::wasi_path_open;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_remove_directory, wasi_path_symlink};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd};
|
||||
use wasi_tests::wasi_wrappers::{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd};
|
||||
use wasi_tests::wasi_wrappers::wasi_path_open;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::close_fd;
|
||||
use wasi_tests::wasi_wrappers::wasi_path_open;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_dir, cleanup_file, close_fd, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_rename};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::wasi_path_rename;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::wasi_path_symlink;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, mem::MaybeUninit, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::{
|
||||
open_scratch_directory,
|
||||
utils::{cleanup_file, close_fd},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, create_file};
|
||||
use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::cleanup_file;
|
||||
use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::wasi_path_remove_directory;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_dir, create_dir};
|
||||
use wasi_tests::wasi_wrappers::wasi_path_remove_directory;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use libc;
|
||||
use more_asserts::assert_gt;
|
||||
use std::{env, mem, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::close_fd;
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
|
||||
fn test_sched_yield() {
|
||||
assert!(wasi_unstable::sched_yield().is_ok(), "sched_yield");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::mem::MaybeUninit;
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::wasi_wrappers::wasi_fd_fdstat_get;
|
||||
|
||||
unsafe fn test_stdio() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::cleanup_file;
|
||||
use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, mem, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, close_fd, create_file};
|
||||
use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use std::{env, process};
|
||||
use wasi::wasi_unstable;
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_dir, create_dir, create_file};
|
||||
use wasi_tests::wasi_wrappers::wasi_path_unlink_file;
|
||||
|
||||
Reference in New Issue
Block a user