More test fixes

This commit is contained in:
Arshia Ghafoori
2025-05-07 14:23:12 +00:00
parent af87c1b7a3
commit 822a626c52
3 changed files with 57 additions and 24 deletions

View File

@@ -45,6 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut wasi_env = WasiEnv::builder("hello") let mut wasi_env = WasiEnv::builder("hello")
// .args(&["world"]) // .args(&["world"])
// .env("KEY", "Value") // .env("KEY", "Value")
.engine(store.engine().clone())
.finalize(&mut store)?; .finalize(&mut store)?;
println!("Instantiating module with WASI imports..."); println!("Instantiating module with WASI imports...");

View File

@@ -1215,15 +1215,6 @@ mod test {
"nul in key must be invalid" "nul in key must be invalid"
); );
// `=` in the value is valid.
assert!(
WasiEnvBuilder::new("test_prog")
.env("HOME", "/home/home=home")
.build_init()
.is_ok(),
"equal sign in the value must be valid"
);
// `\0` in the value is invalid. // `\0` in the value is invalid.
assert!( assert!(
WasiEnvBuilder::new("test_prog") WasiEnvBuilder::new("test_prog")
@@ -1232,6 +1223,16 @@ mod test {
.is_err(), .is_err(),
"nul in value must be invalid" "nul in value must be invalid"
); );
// `=` in the value is valid.
assert!(
WasiEnvBuilder::new("test_prog")
.env("HOME", "/home/home=home")
.engine(Engine::default())
.build_init()
.is_ok(),
"equal sign in the value must be valid"
);
} }
#[test] #[test]

View File

@@ -1,4 +1,5 @@
use virtual_fs::{AsyncReadExt, AsyncWriteExt}; use virtual_fs::{AsyncReadExt, AsyncWriteExt};
use virtual_mio::InlineWaker;
use wasmer::Module; use wasmer::Module;
use wasmer_types::ModuleHash; use wasmer_types::ModuleHash;
use wasmer_wasix::{ use wasmer_wasix::{
@@ -7,19 +8,19 @@ use wasmer_wasix::{
}; };
mod sys { mod sys {
#[tokio::test] #[test]
async fn test_stdout() { fn test_stdout() {
super::test_stdout().await; super::test_stdout();
} }
#[tokio::test] #[test]
async fn test_stdin() { fn test_stdin() {
super::test_stdin().await; super::test_stdin();
} }
#[tokio::test] #[test]
async fn test_env() { fn test_env() {
super::test_env().await; super::test_env();
} }
} }
@@ -43,7 +44,17 @@ mod sys {
// } // }
// } // }
async fn test_stdout() { fn test_stdout() {
#[cfg(not(target_arch = "wasm32"))]
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
#[cfg(not(target_arch = "wasm32"))]
let handle = runtime.handle().clone();
#[cfg(not(target_arch = "wasm32"))]
let _guard = handle.enter();
let engine = wasmer::Engine::default(); let engine = wasmer::Engine::default();
let module = Module::new(&engine, br#" let module = Module::new(&engine, br#"
(module (module
@@ -95,12 +106,22 @@ async fn test_stdout() {
} }
let mut stdout_str = String::new(); let mut stdout_str = String::new();
stdout_rx.read_to_string(&mut stdout_str).await.unwrap(); InlineWaker::block_on(stdout_rx.read_to_string(&mut stdout_str)).unwrap();
let stdout_as_str = stdout_str.as_str(); let stdout_as_str = stdout_str.as_str();
assert_eq!(stdout_as_str, "hello world"); assert_eq!(stdout_as_str, "hello world");
} }
async fn test_env() { fn test_env() {
#[cfg(not(target_arch = "wasm32"))]
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
#[cfg(not(target_arch = "wasm32"))]
let handle = runtime.handle().clone();
#[cfg(not(target_arch = "wasm32"))]
let _guard = handle.enter();
let engine = wasmer::Engine::default(); let engine = wasmer::Engine::default();
let module = Module::new(&engine, include_bytes!("envvar.wasm")).unwrap(); let module = Module::new(&engine, include_bytes!("envvar.wasm")).unwrap();
@@ -132,12 +153,22 @@ async fn test_env() {
} }
let mut stdout_str = String::new(); let mut stdout_str = String::new();
pipe_rx.read_to_string(&mut stdout_str).await.unwrap(); InlineWaker::block_on(pipe_rx.read_to_string(&mut stdout_str)).unwrap();
let stdout_as_str = stdout_str.as_str(); let stdout_as_str = stdout_str.as_str();
assert_eq!(stdout_as_str, "Env vars:\nDOG=X\nTEST2=VALUE2\nTEST=VALUE\nDOG Ok(\"X\")\nDOG_TYPE Err(NotPresent)\nSET VAR Ok(\"HELLO\")\n"); assert_eq!(stdout_as_str, "Env vars:\nDOG=X\nTEST2=VALUE2\nTEST=VALUE\nDOG Ok(\"X\")\nDOG_TYPE Err(NotPresent)\nSET VAR Ok(\"HELLO\")\n");
} }
async fn test_stdin() { fn test_stdin() {
#[cfg(not(target_arch = "wasm32"))]
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
#[cfg(not(target_arch = "wasm32"))]
let handle = runtime.handle().clone();
#[cfg(not(target_arch = "wasm32"))]
let _guard = handle.enter();
let engine = wasmer::Engine::default(); let engine = wasmer::Engine::default();
let module = Module::new(&engine, include_bytes!("stdin-hello.wasm")).unwrap(); let module = Module::new(&engine, include_bytes!("stdin-hello.wasm")).unwrap();
@@ -146,7 +177,7 @@ async fn test_stdin() {
// Write to STDIN // Write to STDIN
let buf = "Hello, stdin!\n".as_bytes().to_owned(); let buf = "Hello, stdin!\n".as_bytes().to_owned();
pipe_tx.write_all(&buf[..]).await.unwrap(); InlineWaker::block_on(pipe_tx.write_all(&buf[..])).unwrap();
{ {
let mut runner = WasiRunner::new(); let mut runner = WasiRunner::new();