WasmFuzz/src/lib.rs

58 lines
1.4 KiB
Rust

use wasmi::{ModuleInstance, ImportsBuilder, NopExternals, RuntimeValue};
fn init_population() -> Vec<u8> {
unimplemented!();
}
fn mutate() -> Vec<u8> {
unimplemented!();
}
fn asd() {
// Parse WAT (WebAssembly Text format) into wasm bytecode.
let wasm_binary: Vec<u8> =
wabt::wat2wasm(
r#"
(module
(func (export "test") (result i32)
i32.const 1337
)
)
"#,
)
.expect("failed to parse wat");
// Load wasm binary and prepare it for instantiation.
let module = wasmi::Module::from_buffer(&wasm_binary)
.expect("failed to load wasm");
// Instantiate a module with empty imports and
// assert that there is no `start` function.
let instance =
ModuleInstance::new(
&module,
&ImportsBuilder::default()
)
.expect("failed to instantiate wasm module")
.assert_no_start();
// Finally, invoke the exported function "test" with no parameters
// and empty external function executor.
assert_eq!(
instance.invoke_export(
"test",
&[],
&mut NopExternals,
).expect("failed to execute export"),
Some(RuntimeValue::I32(1337)),
);
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
super::asd();
}
}