Fix 'not enough arguments' during wasmtime run (#858)
* Fix 'not enough arguments' during wasmtime run * add simple cli smoke tests * autogenerate wasm
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1928,6 +1928,7 @@ dependencies = [
|
|||||||
"rayon",
|
"rayon",
|
||||||
"structopt",
|
"structopt",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
|
"tempfile",
|
||||||
"test-programs",
|
"test-programs",
|
||||||
"wasi-common",
|
"wasi-common",
|
||||||
"wasm-webidl-bindings",
|
"wasm-webidl-bindings",
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ more-asserts = "0.2.1"
|
|||||||
# wasm32-wasi integration tests. To enable, run
|
# wasm32-wasi integration tests. To enable, run
|
||||||
# `cargo test --features test-programs`.
|
# `cargo test --features test-programs`.
|
||||||
test-programs = { path = "crates/test-programs" }
|
test-programs = { path = "crates/test-programs" }
|
||||||
|
tempfile = "3.1.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
anyhow = "1.0.19"
|
anyhow = "1.0.19"
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ impl ExportBinding<'_> {
|
|||||||
ExportBindingKind::Raw(sig) => sig
|
ExportBindingKind::Raw(sig) => sig
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.skip(1) // skip the VMContext argument
|
.skip(2) // skip the VMContext arguments
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, param)| default_incoming(i, param))
|
.map(|(i, param)| default_incoming(i, param))
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -252,7 +252,7 @@ impl ExportBinding<'_> {
|
|||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
ExportBindingKind::Raw(sig) => sig.params.iter().skip(1).map(abi2ast).collect(),
|
ExportBindingKind::Raw(sig) => sig.params.iter().skip(2).map(abi2ast).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
66
tests/cli_tests.rs
Normal file
66
tests/cli_tests.rs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
use anyhow::{bail, Result};
|
||||||
|
use std::env;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
|
fn run_wasmtime(args: &[&str]) -> Result<()> {
|
||||||
|
let cargo = env::var("CARGO").unwrap_or("cargo".to_string());
|
||||||
|
let pkg_dir = env!("CARGO_MANIFEST_DIR");
|
||||||
|
let success = Command::new(cargo)
|
||||||
|
.current_dir(pkg_dir)
|
||||||
|
.stdout(Stdio::null())
|
||||||
|
.args(&["run", "-q", "--"])
|
||||||
|
.args(args)
|
||||||
|
.status()?
|
||||||
|
.success();
|
||||||
|
if !success {
|
||||||
|
bail!("Failed to execute wasmtime with: {:?}", args);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_wasm(wat_path: impl AsRef<Path>) -> Result<NamedTempFile> {
|
||||||
|
let mut wasm_file = NamedTempFile::new()?;
|
||||||
|
let wasm = wat::parse_file(wat_path)?;
|
||||||
|
wasm_file.write(&wasm)?;
|
||||||
|
Ok(wasm_file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Very basic use case: compile binary wasm file and run specific function with arguments.
|
||||||
|
#[test]
|
||||||
|
fn run_wasmtime_simple() -> Result<()> {
|
||||||
|
let wasm = build_wasm("tests/wasm/simple.wat")?;
|
||||||
|
run_wasmtime(&[
|
||||||
|
"run",
|
||||||
|
wasm.path().to_str().unwrap(),
|
||||||
|
"--invoke",
|
||||||
|
"simple",
|
||||||
|
"4",
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wasmtime shakk when not enough arguments were provided.
|
||||||
|
#[test]
|
||||||
|
fn run_wasmtime_simple_fail_no_args() -> Result<()> {
|
||||||
|
let wasm = build_wasm("tests/wasm/simple.wat")?;
|
||||||
|
assert!(
|
||||||
|
run_wasmtime(&["run", wasm.path().to_str().unwrap(), "--invoke", "simple"]).is_err(),
|
||||||
|
"shall fail"
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Running simple wat
|
||||||
|
#[test]
|
||||||
|
fn run_wasmtime_simple_wat() -> Result<()> {
|
||||||
|
let wasm = build_wasm("tests/wasm/simple.wat")?;
|
||||||
|
run_wasmtime(&[
|
||||||
|
"run",
|
||||||
|
wasm.path().to_str().unwrap(),
|
||||||
|
"--invoke",
|
||||||
|
"simple",
|
||||||
|
"4",
|
||||||
|
])
|
||||||
|
}
|
||||||
5
tests/wasm/simple.wat
Normal file
5
tests/wasm/simple.wat
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
(module
|
||||||
|
(func (export "simple") (param i32) (result i32)
|
||||||
|
local.get 0
|
||||||
|
)
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user