implement fuzzing for component types (#4537)
This addresses #4307. For the static API we generate 100 arbitrary test cases at build time, each of which includes 0-5 parameter types, a result type, and a WAT fragment containing an imported function and an exported function. The exported function calls the imported function, which is implemented by the host. At runtime, the fuzz test selects a test case at random and feeds it zero or more sets of arbitrary parameters and results, checking that values which flow host-to-guest and guest-to-host make the transition unchanged. The fuzz test for the dynamic API follows a similar pattern, the only difference being that test cases are generated at runtime. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
This commit is contained in:
@@ -1,19 +1,8 @@
|
||||
use super::{make_echo_component, make_echo_component_with_params, Param, Type};
|
||||
use anyhow::Result;
|
||||
use wasmtime::component::{self, Component, Func, Linker, Val};
|
||||
use wasmtime::{AsContextMut, Store};
|
||||
|
||||
trait FuncExt {
|
||||
fn call_and_post_return(&self, store: impl AsContextMut, args: &[Val]) -> Result<Val>;
|
||||
}
|
||||
|
||||
impl FuncExt for Func {
|
||||
fn call_and_post_return(&self, mut store: impl AsContextMut, args: &[Val]) -> Result<Val> {
|
||||
let result = self.call(&mut store, args)?;
|
||||
self.post_return(&mut store)?;
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
use component_test_util::FuncExt;
|
||||
use wasmtime::component::{self, Component, Linker, Val};
|
||||
use wasmtime::Store;
|
||||
|
||||
#[test]
|
||||
fn primitives() -> Result<()> {
|
||||
|
||||
Reference in New Issue
Block a user