Ensure wasi-common tests always have an unreadable stdin
Some wasi-common tests assume that stdin is never ready to be read, but on CI stdin is closed so it's always ready to be read. Work around this by guaranteeing that wasi-common tests always have an unreadable stdin pipe by creating our own pipe.
This commit is contained in:
@@ -8,7 +8,7 @@ use cranelift_wasm::DefinedFuncIndex;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use target_lexicon::HOST;
|
||||
use wasi_common::WasiCtxBuilder;
|
||||
use wasi_common::{WasiCtx, WasiCtxBuilder};
|
||||
use wasmtime_environ::{translate_signature, Export, Module};
|
||||
use wasmtime_runtime::{Imports, InstanceHandle, InstantiationError, VMFunctionBody};
|
||||
|
||||
@@ -19,6 +19,37 @@ pub fn instantiate_wasi(
|
||||
preopened_dirs: &[(String, File)],
|
||||
argv: &[String],
|
||||
environ: &[(String, String)],
|
||||
) -> Result<InstanceHandle, InstantiationError> {
|
||||
let mut wasi_ctx_builder = WasiCtxBuilder::new()
|
||||
.inherit_stdio()
|
||||
.args(argv)
|
||||
.envs(environ);
|
||||
|
||||
for (dir, f) in preopened_dirs {
|
||||
wasi_ctx_builder = wasi_ctx_builder.preopened_dir(
|
||||
f.try_clone().map_err(|err| {
|
||||
InstantiationError::Resource(format!(
|
||||
"couldn't clone an instance handle to pre-opened dir: {}",
|
||||
err
|
||||
))
|
||||
})?,
|
||||
dir,
|
||||
);
|
||||
}
|
||||
|
||||
let wasi_ctx = wasi_ctx_builder.build().map_err(|err| {
|
||||
InstantiationError::Resource(format!("couldn't assemble WASI context object: {}", err))
|
||||
})?;
|
||||
instantiate_wasi_with_context(prefix, global_exports, wasi_ctx)
|
||||
}
|
||||
|
||||
/// Return an instance implementing the "wasi" interface.
|
||||
///
|
||||
/// The wasi context is configured by
|
||||
pub fn instantiate_wasi_with_context(
|
||||
prefix: &str,
|
||||
global_exports: Rc<RefCell<HashMap<String, Option<wasmtime_runtime::Export>>>>,
|
||||
wasi_ctx: WasiCtx,
|
||||
) -> Result<InstanceHandle, InstantiationError> {
|
||||
let pointer_type = types::Type::triple_pointer_type(&HOST);
|
||||
let mut module = Module::new();
|
||||
@@ -101,27 +132,6 @@ pub fn instantiate_wasi(
|
||||
let data_initializers = Vec::new();
|
||||
let signatures = PrimaryMap::new();
|
||||
|
||||
let mut wasi_ctx_builder = WasiCtxBuilder::new()
|
||||
.inherit_stdio()
|
||||
.args(argv)
|
||||
.envs(environ);
|
||||
|
||||
for (dir, f) in preopened_dirs {
|
||||
wasi_ctx_builder = wasi_ctx_builder.preopened_dir(
|
||||
f.try_clone().map_err(|err| {
|
||||
InstantiationError::Resource(format!(
|
||||
"couldn't clone an instance handle to pre-opened dir: {}",
|
||||
err
|
||||
))
|
||||
})?,
|
||||
dir,
|
||||
);
|
||||
}
|
||||
|
||||
let wasi_ctx = wasi_ctx_builder.build().map_err(|err| {
|
||||
InstantiationError::Resource(format!("couldn't assemble WASI context object: {}", err))
|
||||
})?;
|
||||
|
||||
InstanceHandle::new(
|
||||
Rc::new(module),
|
||||
global_exports,
|
||||
|
||||
@@ -3,4 +3,4 @@ extern crate alloc;
|
||||
mod instantiate;
|
||||
mod syscalls;
|
||||
|
||||
pub use instantiate::instantiate_wasi;
|
||||
pub use instantiate::{instantiate_wasi, instantiate_wasi_with_context};
|
||||
|
||||
Reference in New Issue
Block a user