Skip to content

Commit

Permalink
convert more tests in module
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Jan 16, 2025
1 parent e17c127 commit 008f6ad
Showing 1 changed file with 14 additions and 51 deletions.
65 changes: 14 additions & 51 deletions crates/wasmi/src/engine/translator/tests/fuzz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::*;
use crate::{
core::{TrapCode, F32},
core::TrapCode,
engine::EngineFunc,
ir::{index::Global, BranchOffset, BranchOffset16, RegSpan},
tests::{AssertResults, AssertTrap, ExecutionTest},
Expand Down Expand Up @@ -254,24 +254,11 @@ fn fuzz_regression_13_codegen() {
#[test]
#[cfg_attr(miri, ignore)]
fn fuzz_regression_13_execute() {
use crate::{Engine, Linker, Store};
let wasm = include_str!("wat/fuzz_13.wat");
let engine = Engine::default();
let mut store = <Store<()>>::new(&engine, ());
let linker = Linker::new(&engine);
let module = Module::new(&engine, wasm).unwrap();
let instance = linker
.instantiate(&mut store, &module)
.unwrap()
.ensure_no_start(&mut store)
.unwrap();
let func = instance
.get_func(&store, "")
.unwrap()
.typed::<(), (i32, i32, i32)>(&store)
.unwrap();
let (x, y, z) = func.call(&mut store, ()).unwrap();
assert!(x == 0 && y == 0 && z == 0);
ExecutionTest::default()
.wasm(wasm)
.call::<(), (i32, i32, i32)>("", ())
.assert_results((0, 0, 0));
}

#[test]
Expand Down Expand Up @@ -316,26 +303,11 @@ fn fuzz_regression_15_01_codegen() {
#[test]
#[cfg_attr(miri, ignore)]
fn fuzz_regression_15_01_execute() {
// Note: we can remove this test case once the bug is fixed
// since this is a codegen bug and not an executor bug.
use crate::{Engine, Linker, Store};
let wasm: &str = include_str!("wat/fuzz_15_01.wat");
let engine = Engine::default();
let mut store = <Store<()>>::new(&engine, ());
let linker = Linker::new(&engine);
let module = Module::new(&engine, wasm).unwrap();
let instance = linker
.instantiate(&mut store, &module)
.unwrap()
.ensure_no_start(&mut store)
.unwrap();
let func = instance
.get_func(&store, "")
.unwrap()
.typed::<i64, F32>(&store)
.unwrap();
let result = func.call(&mut store, 1).unwrap();
assert_eq!(result, 10.0);
let wasm = include_str!("wat/fuzz_15_01.wat");
ExecutionTest::default()
.wasm(wasm)
.call::<i64, f32>("", 1)
.assert_results(10.0);
}

#[test]
Expand Down Expand Up @@ -455,20 +427,11 @@ fn audit_0_codegen() {
#[test]
#[cfg_attr(miri, ignore)]
fn audit_0_execution() {
use crate::{Engine, Instance, Store};
let wasm = include_str!("wat/audit_0.wat");
let engine = Engine::default();
let mut store = <Store<()>>::new(&engine, ());
let module = Module::new(&engine, wasm).unwrap();
let instance = Instance::new(&mut store, &module, &[]).unwrap();
let func = instance
.get_func(&store, "")
.unwrap()
.typed::<(), (i32, i32, i32, i32)>(&store)
.unwrap();
let result = func.call(&mut store, ()).unwrap();
std::println!("result = {result:?}");
assert_eq!(result, (0, 1, 0, 1));
ExecutionTest::default()
.wasm(wasm)
.call::<(), (i32, i32, i32, i32)>("", ())
.assert_results((0, 1, 0, 1));
}

#[test]
Expand Down

0 comments on commit 008f6ad

Please sign in to comment.