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
@@ -4,8 +4,12 @@ pub mod wasi_wrappers;
|
||||
use libc;
|
||||
use std::ffi::CString;
|
||||
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> {
|
||||
// Open the scratch directory.
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
/// 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"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user