TEMPORARY: inherit stdio for the wasi ctx

this is unfortunate but the poll_oneoff test insists on polling on stdio
handles. to undo this temporary fix later, lets rewrite the test to open
some regular files from the scratch directory and poll on them instead.
This commit is contained in:
Pat Hickey
2021-01-14 17:38:43 -08:00
parent 4b39a14163
commit 9a1ce1a272

View File

@@ -5,8 +5,10 @@ use wasi_c2::virt::pipe::{ReadPipe, WritePipe};
use wasmtime::{Linker, Module, Store}; use wasmtime::{Linker, Module, Store};
pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> anyhow::Result<()> { pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> anyhow::Result<()> {
/*
let stdout = WritePipe::new_in_memory(); let stdout = WritePipe::new_in_memory();
let stderr = WritePipe::new_in_memory(); let stderr = WritePipe::new_in_memory();
*/
let r = { let r = {
let store = Store::default(); let store = Store::default();
@@ -15,12 +17,7 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
// Additionally register any preopened directories if we have them. // Additionally register any preopened directories if we have them.
let mut builder = wasi_c2::WasiCtx::builder(); let mut builder = wasi_c2::WasiCtx::builder();
builder = builder builder = builder.arg(bin_name)?.arg(".")?.inherit_stdio();
.arg(bin_name)?
.arg(".")?
.stdin(Box::new(ReadPipe::from(Vec::new())))
.stdout(Box::new(stdout.clone()))
.stderr(Box::new(stderr.clone()));
if let Some(workspace) = workspace { if let Some(workspace) = workspace {
println!("preopen: {:?}", workspace); println!("preopen: {:?}", workspace);
@@ -46,6 +43,7 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
match r { match r {
Ok(()) => Ok(()), Ok(()) => Ok(()),
Err(trap) => { Err(trap) => {
/*
let stdout = stdout let stdout = stdout
.try_into_inner() .try_into_inner()
.expect("sole ref to stdout") .expect("sole ref to stdout")
@@ -60,6 +58,7 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
if !stderr.is_empty() { if !stderr.is_empty() {
println!("guest stderr:\n{}\n===", String::from_utf8_lossy(&stderr)); println!("guest stderr:\n{}\n===", String::from_utf8_lossy(&stderr));
} }
*/
Err(trap.context(format!("error while testing Wasm module '{}'", bin_name,))) Err(trap.context(format!("error while testing Wasm module '{}'", bin_name,)))
} }
} }