Reactor support. (#1565)

* Reactor support.

This implements the new WASI ABI described here:

https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md

It adds APIs to `Instance` and `Linker` with support for running
WASI programs, and also simplifies the process of instantiating
WASI API modules.

This currently only includes Rust API support.

* Add comments and fix a typo in a comment.

* Fix a rustdoc warning.

* Tidy an unneeded `mut`.

* Factor out instance initialization with `NewInstance`.

This also separates instantiation from initialization in a manner
similar to https://github.com/bytecodealliance/lucet/pull/506.

* Update fuzzing oracles for the API changes.

* Remove `wasi_linker` and clarify that Commands/Reactors aren't connected to WASI.

* Move Command/Reactor semantics into the Linker.

* C API support.

* Fix fuzzer build.

* Update usage syntax from "::" to "=".

* Remove `NewInstance` and `start()`.

* Elaborate on Commands and Reactors and add a spec link.

* Add more comments.

* Fix wat syntax.

* Fix wat.

* Use the `Debug` formatter to format an anyhow::Error.

* Fix wat.
This commit is contained in:
Dan Gohman
2020-05-26 08:39:40 -07:00
committed by GitHub
parent c619136752
commit 3715e19c67
19 changed files with 724 additions and 245 deletions

View File

@@ -256,3 +256,97 @@ fn exit126_wasi_snapshot1() -> Result<()> {
assert!(String::from_utf8_lossy(&output.stderr).contains("invalid exit status"));
Ok(())
}
// Run a minimal command program.
#[test]
fn minimal_command() -> Result<()> {
let wasm = build_wasm("tests/wasm/minimal-command.wat")?;
let stdout = run_wasmtime(&[wasm.path().to_str().unwrap(), "--disable-cache"])?;
assert_eq!(stdout, "");
Ok(())
}
// Run a minimal reactor program.
#[test]
fn minimal_reactor() -> Result<()> {
let wasm = build_wasm("tests/wasm/minimal-reactor.wat")?;
let stdout = run_wasmtime(&[wasm.path().to_str().unwrap(), "--disable-cache"])?;
assert_eq!(stdout, "");
Ok(())
}
// Attempt to call invoke on a command.
#[test]
fn command_invoke() -> Result<()> {
let wasm = build_wasm("tests/wasm/minimal-command.wat")?;
run_wasmtime(&[
"run",
wasm.path().to_str().unwrap(),
"--invoke",
"_start",
"--disable-cache",
])?;
Ok(())
}
// Attempt to call invoke on a command.
#[test]
fn reactor_invoke() -> Result<()> {
let wasm = build_wasm("tests/wasm/minimal-reactor.wat")?;
run_wasmtime(&[
"run",
wasm.path().to_str().unwrap(),
"--invoke",
"_initialize",
"--disable-cache",
])?;
Ok(())
}
// Run the greeter test, which runs a preloaded reactor and a command.
#[test]
fn greeter() -> Result<()> {
let wasm = build_wasm("tests/wasm/greeter_command.wat")?;
let stdout = run_wasmtime(&[
"run",
wasm.path().to_str().unwrap(),
"--disable-cache",
"--preload",
"reactor=tests/wasm/greeter_reactor.wat",
])?;
assert_eq!(
stdout,
"Hello _initialize\nHello _start\nHello greet\nHello done\n"
);
Ok(())
}
// Run the greeter test, but this time preload a command.
#[test]
fn greeter_preload_command() -> Result<()> {
let wasm = build_wasm("tests/wasm/greeter_reactor.wat")?;
let stdout = run_wasmtime(&[
"run",
wasm.path().to_str().unwrap(),
"--disable-cache",
"--preload",
"reactor=tests/wasm/hello_wasi_snapshot1.wat",
])?;
assert_eq!(stdout, "Hello _initialize\n");
Ok(())
}
// Run the greeter test, which runs a preloaded reactor and a command.
#[test]
fn greeter_preload_callable_command() -> Result<()> {
let wasm = build_wasm("tests/wasm/greeter_command.wat")?;
let stdout = run_wasmtime(&[
"run",
wasm.path().to_str().unwrap(),
"--disable-cache",
"--preload",
"reactor=tests/wasm/greeter_callable_command.wat",
])?;
assert_eq!(stdout, "Hello _start\nHello callable greet\nHello done\n");
Ok(())
}