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:
Alex Crichton
2019-12-09 04:08:47 -08:00
committed by Jakub Konka
parent 51f880f625
commit e13fabb276
40 changed files with 137 additions and 120 deletions

View File

@@ -30,6 +30,8 @@ mod wasi_tests {
println!("cargo:rerun-if-changed={}", test_file_path); println!("cargo:rerun-if-changed={}", test_file_path);
} }
} }
println!("cargo:rerun-if-changed=wasi-tests/Cargo.toml");
println!("cargo:rerun-if-changed=wasi-tests/src/lib.rs");
// Build tests to OUT_DIR (target/*/build/wasi-common-*/out/wasm32-wasi/release/*.wasm) // Build tests to OUT_DIR (target/*/build/wasi-common-*/out/wasm32-wasi/release/*.wasm)
let out_dir = PathBuf::from( let out_dir = PathBuf::from(
env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"), env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"),

View File

@@ -1,6 +1,6 @@
use anyhow::{bail, Context}; use anyhow::{bail, Context};
use std::fs::File; use std::fs::File;
use std::{collections::HashMap, path::Path}; use std::path::Path;
use wasmtime::{Config, Engine, HostRef, Instance, Module, Store}; use wasmtime::{Config, Engine, HostRef, Instance, Module, Store};
use wasmtime_environ::settings::{self, Configurable}; use wasmtime_environ::settings::{self, Configurable};
@@ -18,7 +18,6 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
let engine = HostRef::new(Engine::new(&config)); let engine = HostRef::new(Engine::new(&config));
let store = HostRef::new(Store::new(&engine)); let store = HostRef::new(Store::new(&engine));
let mut module_registry = HashMap::new();
let global_exports = store.borrow().global_exports().clone(); let global_exports = store.borrow().global_exports().clone();
let get_preopens = |workspace: Option<&Path>| -> anyhow::Result<Vec<_>> { let get_preopens = |workspace: Option<&Path>| -> anyhow::Result<Vec<_>> {
if let Some(workspace) = workspace { if let Some(workspace) = workspace {
@@ -33,7 +32,7 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
// Create our wasi context with pretty standard arguments/inheritance/etc. // Create our wasi context with pretty standard arguments/inheritance/etc.
// Additionally register andy preopened directories if we have them. // Additionally register andy preopened directories if we have them.
let mut builder = wasi_common::old::snapshot_0::WasiCtxBuilder::new() let mut builder = wasi_common::WasiCtxBuilder::new()
.arg(bin_name) .arg(bin_name)
.arg(".") .arg(".")
.inherit_stdio(); .inherit_stdio();
@@ -47,19 +46,33 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
// stdin is closed which causes tests to fail. // stdin is closed which causes tests to fail.
let (reader, _writer) = os_pipe::pipe()?; let (reader, _writer) = os_pipe::pipe()?;
builder = builder.stdin(reader_to_file(reader)); builder = builder.stdin(reader_to_file(reader));
let snapshot1 = Instance::from_handle(
&store,
wasmtime_wasi::instantiate_wasi_with_context(
global_exports.clone(),
builder.build().context("failed to build wasi context")?,
)
.context("failed to instantiate wasi")?,
);
// The current stable Rust toolchain uses the old `wasi_unstable` ABI, // ... and then do the same as above but for the old snapshot of wasi, since
// aka `snapshot_0`. // a few tests still test that
module_registry.insert( let mut builder = wasi_common::old::snapshot_0::WasiCtxBuilder::new()
"wasi_unstable".to_owned(), .arg(bin_name)
Instance::from_handle( .arg(".")
&store, .inherit_stdio();
wasmtime_wasi::old::snapshot_0::instantiate_wasi_with_context( for (dir, file) in get_preopens(workspace)? {
global_exports.clone(), builder = builder.preopened_dir(file, dir);
builder.build().context("failed to build wasi context")?, }
) let (reader, _writer) = os_pipe::pipe()?;
.context("failed to instantiate wasi")?, builder = builder.stdin(reader_to_file(reader));
), let snapshot0 = Instance::from_handle(
&store,
wasmtime_wasi::old::snapshot_0::instantiate_wasi_with_context(
global_exports.clone(),
builder.build().context("failed to build wasi context")?,
)
.context("failed to instantiate wasi")?,
); );
let module = HostRef::new(Module::new(&store, &data).context("failed to create wasm module")?); let module = HostRef::new(Module::new(&store, &data).context("failed to create wasm module")?);
@@ -68,20 +81,22 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
.imports() .imports()
.iter() .iter()
.map(|i| { .map(|i| {
let module_name = i.module(); let instance = if i.module() == "wasi_unstable" {
if let Some(instance) = module_registry.get(module_name) { &snapshot0
let field_name = i.name(); } else if i.module() == "wasi_snapshot_preview1" {
if let Some(export) = instance.find_export_by_name(field_name) { &snapshot1
Ok(export.clone())
} else {
bail!(
"import {} was not found in module {}",
field_name,
module_name
)
}
} else { } else {
bail!("import module {} was not found", module_name) bail!("import module {} was not found", i.module())
};
let field_name = i.name();
if let Some(export) = instance.find_export_by_name(field_name) {
Ok(export.clone())
} else {
bail!(
"import {} was not found in module {}",
field_name,
i.module(),
)
} }
}) })
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;

View File

@@ -8,7 +8,8 @@ publish = false
[dependencies] [dependencies]
libc = "0.2.65" libc = "0.2.65"
wasi = "0.7.0" wasi = "0.9.0"
wasi-old = { version = "0.7.0", package = "wasi" }
more-asserts = "0.2.1" more-asserts = "0.2.1"
# This crate is built with the wasm32-wasi target, so it's separate # This crate is built with the wasm32-wasi target, so it's separate

View File

@@ -1,12 +1,9 @@
use wasi::wasi_unstable;
fn test_big_random_buf() { fn test_big_random_buf() {
let mut buf = Vec::new(); let mut buf = Vec::new();
buf.resize(1024, 0); buf.resize(1024, 0);
assert!( unsafe {
wasi_unstable::random_get(&mut buf).is_ok(), wasi::random_get(buf.as_mut_ptr(), 1024).expect("failed to call random_get");
"calling get_random on a large buffer" }
);
// Chances are pretty good that at least *one* byte will be non-zero in // Chances are pretty good that at least *one* byte will be non-zero in
// any meaningful random function producing 1024 u8 values. // any meaningful random function producing 1024 u8 values.
assert!(buf.iter().any(|x| *x != 0), "random_get returned all zeros"); assert!(buf.iter().any(|x| *x != 0), "random_get returned all zeros");

View File

@@ -1,33 +1,15 @@
use more_asserts::assert_le; use more_asserts::assert_le;
use wasi::wasi_unstable;
use wasi_tests::wasi_wrappers::wasi_clock_time_get;
unsafe fn test_clock_time_get() { unsafe fn test_clock_time_get() {
// Test that clock_time_get succeeds. Even in environments where it's not // Test that clock_time_get succeeds. Even in environments where it's not
// desirable to expose high-precision timers, it should still succeed. // desirable to expose high-precision timers, it should still succeed.
// clock_res_get is where information about precision can be provided. // clock_res_get is where information about precision can be provided.
let mut time: wasi_unstable::Timestamp = 0; wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 1).expect("precision 1 should work");
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"
);
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 0, &mut time); let first_time =
assert_eq!( wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 0).expect("precision 0 should work");
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"clock_time_get with a precision of 0"
);
let first_time = time;
let status = wasi_clock_time_get(wasi_unstable::CLOCK_MONOTONIC, 0, &mut time); let time = wasi::clock_time_get(wasi::CLOCKID_MONOTONIC, 0).expect("re-fetch time should work");
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"clock_time_get with a precision of 0"
);
assert_le!(first_time, time, "CLOCK_MONOTONIC should be monotonic"); assert_le!(first_time, time, "CLOCK_MONOTONIC should be monotonic");
} }

View File

@@ -1,60 +1,46 @@
use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, mem, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_tests::open_scratch_directory_new;
use wasi_tests::open_scratch_directory;
use wasi_tests::wasi_wrappers::wasi_fd_fdstat_get;
unsafe fn test_close_preopen(dir_fd: wasi_unstable::Fd) { unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
let pre_fd: wasi_unstable::Fd = (libc::STDERR_FILENO + 1) as wasi_unstable::Fd; let pre_fd: wasi::Fd = (libc::STDERR_FILENO + 1) as wasi::Fd;
assert_gt!(dir_fd, pre_fd, "dir_fd number"); assert_gt!(dir_fd, pre_fd, "dir_fd number");
// Try to close a preopened directory handle. // Try to close a preopened directory handle.
assert_eq!( assert_eq!(
wasi_unstable::fd_close(pre_fd), wasi::fd_close(pre_fd).unwrap_err().raw_error(),
Err(wasi_unstable::ENOTSUP), wasi::ERRNO_NOTSUP,
"closing a preopened file descriptor", "closing a preopened file descriptor",
); );
// Try to renumber over a preopened directory handle. // Try to renumber over a preopened directory handle.
assert_eq!( assert_eq!(
wasi_unstable::fd_renumber(dir_fd, pre_fd), wasi::fd_renumber(dir_fd, pre_fd).unwrap_err().raw_error(),
Err(wasi_unstable::ENOTSUP), wasi::ERRNO_NOTSUP,
"renumbering over a preopened file descriptor", "renumbering over a preopened file descriptor",
); );
// Ensure that dir_fd is still open. // Ensure that dir_fd is still open.
let mut dir_fdstat: wasi_unstable::FdStat = mem::zeroed(); let dir_fdstat = wasi::fd_fdstat_get(dir_fd).expect("failed fd_fdstat_get");
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"
);
assert_eq!( assert_eq!(
dir_fdstat.fs_filetype, dir_fdstat.fs_filetype,
wasi_unstable::FILETYPE_DIRECTORY, wasi::FILETYPE_DIRECTORY,
"expected the scratch directory to be a directory", "expected the scratch directory to be a directory",
); );
// Try to renumber a preopened directory handle. // Try to renumber a preopened directory handle.
assert_eq!( assert_eq!(
wasi_unstable::fd_renumber(pre_fd, dir_fd), wasi::fd_renumber(pre_fd, dir_fd).unwrap_err().raw_error(),
Err(wasi_unstable::ENOTSUP), wasi::ERRNO_NOTSUP,
"renumbering over a preopened file descriptor", "renumbering over a preopened file descriptor",
); );
// Ensure that dir_fd is still open. // Ensure that dir_fd is still open.
status = wasi_fd_fdstat_get(dir_fd, &mut dir_fdstat); let dir_fdstat = wasi::fd_fdstat_get(dir_fd).expect("failed fd_fdstat_get");
assert_eq!(
status,
wasi_unstable::raw::__WASI_ESUCCESS,
"calling fd_fdstat on the scratch directory"
);
assert_eq!( assert_eq!(
dir_fdstat.fs_filetype, dir_fdstat.fs_filetype,
wasi_unstable::FILETYPE_DIRECTORY, wasi::FILETYPE_DIRECTORY,
"expected the scratch directory to be a directory", "expected the scratch directory to be a directory",
); );
} }
@@ -70,7 +56,7 @@ fn main() {
}; };
// Open scratch directory // 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, Ok(dir_fd) => dir_fd,
Err(err) => { Err(err) => {
eprintln!("{}", err); eprintln!("{}", err);

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
use wasi_tests::wasi_wrappers::wasi_path_open; use wasi_tests::wasi_wrappers::wasi_path_open;

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::cleanup_file; use wasi_tests::utils::cleanup_file;
use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink}; use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink};

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, mem, process}; use std::{env, mem, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, close_fd, create_dir}; 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}; use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_fd_seek, wasi_path_open};

View File

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd}; use wasi_tests::utils::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::{wasi_fd_advise, wasi_fd_filestat_get, wasi_path_open}; use wasi_tests::wasi_wrappers::{wasi_fd_advise, wasi_fd_filestat_get, wasi_path_open};

View File

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd}; use wasi_tests::utils::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open}; use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open};

View File

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{cmp::min, env, mem, process, slice, str}; 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::open_scratch_directory;
use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_fd_readdir, wasi_path_open}; use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_fd_readdir, wasi_path_open};

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd}; use wasi_tests::utils::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open}; use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open};

View File

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd}; use wasi_tests::utils::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::{wasi_fd_pread, wasi_fd_pwrite, wasi_path_open}; use wasi_tests::wasi_wrappers::{wasi_fd_pread, wasi_fd_pwrite, wasi_path_open};

View File

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd}; 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}; use wasi_tests::wasi_wrappers::{wasi_fd_seek, wasi_fd_tell, wasi_fd_write, wasi_path_open};

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd, create_file}; use wasi_tests::utils::{cleanup_file, close_fd, create_file};
use wasi_tests::wasi_wrappers::{wasi_fd_read, wasi_fd_write, wasi_path_open}; use wasi_tests::wasi_wrappers::{wasi_fd_read, wasi_fd_write, wasi_path_open};

View File

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{close_fd, create_dir, create_file}; use wasi_tests::utils::{close_fd, create_dir, create_file};
use wasi_tests::wasi_wrappers::{ use wasi_tests::wasi_wrappers::{

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd}; use wasi_tests::utils::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::wasi_path_open; use wasi_tests::wasi_wrappers::wasi_path_open;

View File

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd, create_dir, create_file}; 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}; use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_remove_directory, wasi_path_symlink};

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd}; use wasi_tests::utils::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::{ use wasi_tests::wasi_wrappers::{

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
use wasi_tests::wasi_wrappers::{ use wasi_tests::wasi_wrappers::{

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd}; use wasi_tests::utils::{cleanup_file, close_fd};
use wasi_tests::wasi_wrappers::wasi_path_open; use wasi_tests::wasi_wrappers::wasi_path_open;

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::close_fd; use wasi_tests::utils::close_fd;
use wasi_tests::wasi_wrappers::wasi_path_open; use wasi_tests::wasi_wrappers::wasi_path_open;

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, cleanup_file, close_fd, create_dir, create_file}; 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}; use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_rename};

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
use wasi_tests::wasi_wrappers::wasi_path_rename; use wasi_tests::wasi_wrappers::wasi_path_rename;

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file};
use wasi_tests::wasi_wrappers::wasi_path_symlink; use wasi_tests::wasi_wrappers::wasi_path_symlink;

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, mem::MaybeUninit, process}; use std::{env, mem::MaybeUninit, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::{ use wasi_tests::{
open_scratch_directory, open_scratch_directory,
utils::{cleanup_file, close_fd}, utils::{cleanup_file, close_fd},

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, create_file}; use wasi_tests::utils::{cleanup_file, create_file};
use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink}; use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink};

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::cleanup_file; use wasi_tests::utils::cleanup_file;
use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink}; use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink};

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, create_dir, create_file}; use wasi_tests::utils::{cleanup_file, create_dir, create_file};
use wasi_tests::wasi_wrappers::wasi_path_remove_directory; use wasi_tests::wasi_wrappers::wasi_path_remove_directory;

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, create_dir}; use wasi_tests::utils::{cleanup_dir, create_dir};
use wasi_tests::wasi_wrappers::wasi_path_remove_directory; use wasi_tests::wasi_wrappers::wasi_path_remove_directory;

View File

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, mem, process}; use std::{env, mem, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::close_fd; use wasi_tests::utils::close_fd;
use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open}; use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open};

View File

@@ -1,4 +1,4 @@
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
fn test_sched_yield() { fn test_sched_yield() {
assert!(wasi_unstable::sched_yield().is_ok(), "sched_yield"); assert!(wasi_unstable::sched_yield().is_ok(), "sched_yield");

View File

@@ -1,5 +1,5 @@
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::wasi_wrappers::wasi_fd_fdstat_get; use wasi_tests::wasi_wrappers::wasi_fd_fdstat_get;
unsafe fn test_stdio() { unsafe fn test_stdio() {

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::cleanup_file; use wasi_tests::utils::cleanup_file;
use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink}; use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink};

View File

@@ -1,5 +1,5 @@
use std::{env, mem, process}; use std::{env, mem, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_file, close_fd, create_file}; use wasi_tests::utils::{cleanup_file, close_fd, create_file};
use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open}; use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open};

View File

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
use wasi_tests::utils::{cleanup_dir, create_dir, create_file}; use wasi_tests::utils::{cleanup_dir, create_dir, create_file};
use wasi_tests::wasi_wrappers::wasi_path_unlink_file; use wasi_tests::wasi_wrappers::wasi_path_unlink_file;

View File

@@ -4,8 +4,12 @@ pub mod wasi_wrappers;
use libc; use libc;
use std::ffi::CString; use std::ffi::CString;
use std::io; use std::io;
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
/// Opens a fresh file descriptor for `path` where `path` should be a preopened
/// directory. This is intended to be used with `wasi_unstable`, not with
/// `wasi_snapshot_preview1`. This is getting phased out and will likely be
/// deleted soon.
pub fn open_scratch_directory(path: &str) -> Result<wasi_unstable::Fd, String> { pub fn open_scratch_directory(path: &str) -> Result<wasi_unstable::Fd, String> {
// Open the scratch directory. // Open the scratch directory.
let dir_fd: wasi_unstable::Fd = unsafe { let dir_fd: wasi_unstable::Fd = unsafe {
@@ -23,3 +27,33 @@ pub fn open_scratch_directory(path: &str) -> Result<wasi_unstable::Fd, String> {
Ok(dir_fd) Ok(dir_fd)
} }
} }
/// Same as `open_scratch_directory` above, except uses `wasi_snapshot_preview1`
/// APIs instead of `wasi_unstable` ones.
///
/// This is intended to replace `open_scratch_directory` once all the tests are
/// updated.
pub fn open_scratch_directory_new(path: &str) -> Result<wasi::Fd, String> {
unsafe {
for i in 3.. {
let stat = match wasi::fd_prestat_get(i) {
Ok(s) => s,
Err(_) => break,
};
if stat.pr_type != wasi::PREOPENTYPE_DIR {
continue;
}
let mut dst = Vec::with_capacity(stat.u.dir.pr_name_len);
if wasi::fd_prestat_dir_name(i, dst.as_mut_ptr(), dst.capacity()).is_err() {
continue;
}
dst.set_len(stat.u.dir.pr_name_len);
if dst == path.as_bytes() {
return Ok(wasi::path_open(i, 0, ".", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect("failed to open dir"));
}
}
Err(format!("failed to find scratch dir"))
}
}

View File

@@ -1,6 +1,6 @@
use crate::wasi_wrappers::*; use crate::wasi_wrappers::*;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
pub unsafe fn create_dir(dir_fd: wasi_unstable::Fd, dir_name: &str) { pub unsafe fn create_dir(dir_fd: wasi_unstable::Fd, dir_name: &str) {
assert!( assert!(

View File

@@ -6,7 +6,7 @@
//! interfaces so that we can test whether they are stored to. In the future, //! interfaces so that we can test whether they are stored to. In the future,
//! WASI should switch to multi-value and eliminate out parameters altogether. //! WASI should switch to multi-value and eliminate out parameters altogether.
use wasi::wasi_unstable; use wasi_old::wasi_unstable;
pub unsafe fn wasi_path_create_directory( pub unsafe fn wasi_path_create_directory(
dir_fd: wasi_unstable::Fd, dir_fd: wasi_unstable::Fd,