From b19d86268c35408fed0b23aa8a523e329e15a04e Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 6 May 2021 16:19:33 -0700 Subject: [PATCH] fix test harness stdio --- .../tests/wasm_tests/runtime/cap_std_sync.rs | 19 ++++++++++++------- .../tests/wasm_tests/runtime/tokio.rs | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs b/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs index 0d89518df1..32aa3cbedb 100644 --- a/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs +++ b/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs @@ -15,7 +15,12 @@ pub fn instantiate_inherit_stdio( run(data, bin_name, workspace, true) } -fn run(data: &[u8], bin_name: &str, workspace: Option<&Path>, stdio: bool) -> anyhow::Result<()> { +fn run( + data: &[u8], + bin_name: &str, + workspace: Option<&Path>, + inherit_stdio: bool, +) -> anyhow::Result<()> { let stdout = WritePipe::new_in_memory(); let stderr = WritePipe::new_in_memory(); @@ -26,15 +31,15 @@ fn run(data: &[u8], bin_name: &str, workspace: Option<&Path>, stdio: bool) -> an // Additionally register any preopened directories if we have them. let mut builder = WasiCtxBuilder::new(); - if stdio { + if inherit_stdio { builder = builder.inherit_stdio(); + } else { + builder = builder + .stdout(Box::new(stdout.clone())) + .stderr(Box::new(stderr.clone())); } - builder = builder - .arg(bin_name)? - .arg(".")? - .stdout(Box::new(stdout.clone())) - .stderr(Box::new(stderr.clone())); + builder = builder.arg(bin_name)?.arg(".")?; if let Some(workspace) = workspace { println!("preopen: {:?}", workspace); diff --git a/crates/test-programs/tests/wasm_tests/runtime/tokio.rs b/crates/test-programs/tests/wasm_tests/runtime/tokio.rs index ba5fcf16db..28577015bc 100644 --- a/crates/test-programs/tests/wasm_tests/runtime/tokio.rs +++ b/crates/test-programs/tests/wasm_tests/runtime/tokio.rs @@ -15,7 +15,12 @@ pub fn instantiate_inherit_stdio( run(data, bin_name, workspace, true) } -fn run(data: &[u8], bin_name: &str, workspace: Option<&Path>, stdio: bool) -> anyhow::Result<()> { +fn run( + data: &[u8], + bin_name: &str, + workspace: Option<&Path>, + inherit_stdio: bool, +) -> anyhow::Result<()> { let stdout = WritePipe::new_in_memory(); let stdout_ = stdout.clone(); let stderr = WritePipe::new_in_memory(); @@ -33,15 +38,15 @@ fn run(data: &[u8], bin_name: &str, workspace: Option<&Path>, stdio: bool) -> an // Create our wasi context. let mut builder = WasiCtxBuilder::new(); - if stdio { + if inherit_stdio { builder = builder.inherit_stdio(); + } else { + builder = builder + .stdout(Box::new(stdout_.clone())) + .stderr(Box::new(stderr_.clone())); } - builder = builder - .arg(bin_name)? - .arg(".")? - .stdout(Box::new(stdout_)) - .stderr(Box::new(stderr_)); + builder = builder.arg(bin_name)?.arg(".")?; if let Some(workspace) = workspace { println!("preopen: {:?}", workspace);