Fix WASI test program running.

PR #585 moved the execution of a `_start` function to the CLI rather than have
it automatically invoked by module instantiation.

Unfortunately, this broke the WASI test programs that were relying on this
behavior from instantiation.

This fixes it by adding an invocation of the `_start` function in the test
runner.

Fixes #698.
This commit is contained in:
Peter Huene
2019-12-11 16:09:30 -08:00
parent ddd2300010
commit 4e67ccfbc3

View File

@@ -100,11 +100,27 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
}
})
.collect::<Result<Vec<_>, _>>()?;
let _ = HostRef::new(Instance::new(&store, &module, &imports).context(format!(
let instance = HostRef::new(Instance::new(&store, &module, &imports).context(format!(
"error while instantiating Wasm module '{}'",
bin_name,
))?);
let export = instance
.borrow()
.find_export_by_name("_start")
.context("expected a _start export")?
.clone();
if let Err(trap) = export
.func()
.context("expected export to be a func")?
.borrow()
.call(&[])
{
bail!("trapped: {:?}", trap.borrow());
}
Ok(())
}