Skip to content

Commit

Permalink
remove TranslationTest::from_wat
Browse files Browse the repository at this point in the history
This is now just the same as TranslationTest::new, so use that instead.
  • Loading branch information
Robbepop committed Dec 1, 2024
1 parent 25de56f commit 76140bc
Show file tree
Hide file tree
Showing 42 changed files with 457 additions and 475 deletions.
14 changes: 3 additions & 11 deletions crates/wasmi/src/engine/translator/tests/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ impl ExpectedFunc {
impl TranslationTest {
/// Creates a new [`TranslationTest`] for the given Webassembly `bytes`.
///
/// The `bytes` can either be Wasm binary (`.wasm`) or Wasm text format (`.wat`).
///
/// # Panics
///
/// If the WebAssembly `bytes` is not valid WebAssembly.
#[must_use]
fn new(bytes: impl AsRef<[u8]>) -> Self {
pub fn new(bytes: impl AsRef<[u8]>) -> Self {
let config = {
let mut cfg = Config::default();
cfg.wasm_tail_call(true);
Expand All @@ -180,16 +182,6 @@ impl TranslationTest {
}
}

/// Creates a new [`TranslationTest`] for the given Webassembly `source`.
///
/// # Panics
///
/// If the WebAssembly `source` is not valid WebAssembly Text Format (WAT).
#[must_use]
pub fn from_wat(wasm: &str) -> Self {
Self::new(wasm)
}

/// Returns the [`Config`] used for the test case.
fn config(&self) -> &Config {
&self.config
Expand Down
48 changes: 24 additions & 24 deletions crates/wasmi/src/engine/translator/tests/fuzz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
#[cfg_attr(miri, ignore)]
fn fuzz_regression_0() {
let wasm = include_str!("wat/fuzz_0.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(1, 0),
Instruction::copy_imm32(Reg::from(0), 13.0_f32),
Expand All @@ -25,7 +25,7 @@ fn fuzz_regression_0() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_1() {
let wasm = include_str!("wat/fuzz_1.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(1, 0),
Instruction::copy_f64imm32(Reg::from(0), 13.0_f32),
Expand All @@ -38,7 +38,7 @@ fn fuzz_regression_1() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_2() {
let wasm = include_str!("wat/fuzz_2.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(1, 0),
Instruction::branch_i32_eq_imm16(Reg::from(0), 0, BranchOffset16::from(2)),
Expand All @@ -52,7 +52,7 @@ fn fuzz_regression_2() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_3() {
let wasm = include_str!("wat/fuzz_3.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::call_internal_0(RegSpan::new(Reg::from(0)), EngineFunc::from_u32(0)),
Instruction::call_internal_0(RegSpan::new(Reg::from(3)), EngineFunc::from_u32(0)),
Expand All @@ -65,7 +65,7 @@ fn fuzz_regression_3() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_4() {
let wasm = include_str!("wat/fuzz_4.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(2, 1),
Instruction::copy(1, 0),
Expand All @@ -80,7 +80,7 @@ fn fuzz_regression_4() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_5() {
let wasm = include_str!("wat/fuzz_5.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::call_internal(RegSpan::new(Reg::from(1)), EngineFunc::from_u32(0)),
Instruction::register(Reg::from(0)),
Expand All @@ -99,7 +99,7 @@ fn fuzz_regression_5() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_6() {
let wasm = include_str!("wat/fuzz_6.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(2, 0),
Instruction::branch_i32_eq_imm16(Reg::from(0), 0, BranchOffset16::from(4)),
Expand All @@ -116,7 +116,7 @@ fn fuzz_regression_6() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_7() {
let wasm = include_str!("wat/fuzz_7.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(1, 0),
Instruction::copy_imm32(Reg::from(0), 1),
Expand All @@ -129,7 +129,7 @@ fn fuzz_regression_7() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_8() {
let wasm = include_str!("wat/fuzz_8.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(4, 1),
Instruction::copy_imm32(Reg::from(1), 10),
Expand All @@ -145,7 +145,7 @@ fn fuzz_regression_8() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_9() {
let wasm = include_str!("wat/fuzz_9.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(6, 1),
Instruction::copy_imm32(Reg::from(1), 10),
Expand All @@ -166,7 +166,7 @@ fn fuzz_regression_9() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_10() {
let wasm = include_str!("wat/fuzz_10.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::branch_i32_eq_imm16(Reg::from(0), 0, BranchOffset16::from(3)),
Instruction::copy_imm32(Reg::from(1), 10),
Expand All @@ -181,7 +181,7 @@ fn fuzz_regression_10() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_11() {
let wasm = include_str!("wat/fuzz_11.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::i32_and_imm16(Reg::from(1), Reg::from(0), 2),
Instruction::i32_eq_imm16(Reg::from(0), Reg::from(0), 0),
Expand All @@ -196,7 +196,7 @@ fn fuzz_regression_11() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_12_f32() {
let wasm = include_str!("wat/fuzz_12_f32.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func(ExpectedFunc::new([
Instruction::copy_imm32(Reg::from(0), u32::MAX),
Instruction::f32_le(Reg::from(1), Reg::from(0), Reg::from(0)),
Expand All @@ -216,7 +216,7 @@ fn fuzz_regression_12_f32() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_12_f64() {
let wasm = include_str!("wat/fuzz_12_f64.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func(
ExpectedFunc::new([
Instruction::copy(0, -1),
Expand All @@ -242,7 +242,7 @@ fn fuzz_regression_12_f64() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_13_codegen() {
let wasm = include_str!("wat/fuzz_13.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::return_nez_many_ext(0, 0, 0),
Instruction::register(0),
Expand Down Expand Up @@ -278,7 +278,7 @@ fn fuzz_regression_13_execute() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_14() {
let wasm = include_str!("wat/fuzz_14.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func(
ExpectedFunc::new([
Instruction::i32_and(Reg::from(2), Reg::from(0), Reg::from(1)),
Expand All @@ -293,7 +293,7 @@ fn fuzz_regression_14() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_15_01_codegen() {
let wasm = include_str!("wat/fuzz_15_01.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func(
// Note:
//
Expand Down Expand Up @@ -342,7 +342,7 @@ fn fuzz_regression_15_01_execute() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_15_02() {
let wasm = include_str!("wat/fuzz_15_02.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func(
// Note: The bug is that `copy2` overwrites `i32_wrap_i64` which is the `index` of the `br_table`.
ExpectedFunc::new([
Expand All @@ -363,7 +363,7 @@ fn fuzz_regression_15_02() {
#[cfg_attr(miri, ignore)]
fn fuzz_regression_15_03() {
let wasm = include_str!("wat/fuzz_15_03.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func(
// Note: The bug is that `copy2` overwrites `i32_wrap_i64` which is the `index` of the `br_table`.
ExpectedFunc::new([
Expand Down Expand Up @@ -395,7 +395,7 @@ fn fuzz_regression_16() {
// for the preserved local value causing the `value` register
// of the `i64_store_at` instruction to be 32676 instead of 2.
let wasm = include_str!("wat/fuzz_16.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(2, 0),
Instruction::global_get(Reg::from(0), Global::from(0)),
Expand All @@ -413,7 +413,7 @@ fn fuzz_regression_17() {
// for the preserved local value causing the `value` register
// of the `i64_store_at` instruction to be 32676 instead of 2.
let wasm = include_str!("wat/fuzz_17.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(2, 0),
Instruction::copy_i64imm32(Reg::from(0), 2),
Expand All @@ -428,7 +428,7 @@ fn fuzz_regression_17() {
#[cfg_attr(miri, ignore)]
fn audit_0_codegen() {
let wasm = include_str!("wat/audit_0.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func(
ExpectedFunc::new([
Instruction::return_many_ext(-1, -2, -1),
Expand Down Expand Up @@ -475,7 +475,7 @@ fn audit_0_execution() {
#[cfg_attr(miri, ignore)]
fn audit_1_codegen() {
let wasm = include_str!("wat/audit_1.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy_span_non_overlapping(
RegSpan::new(Reg::from(6)),
Expand Down Expand Up @@ -509,7 +509,7 @@ fn audit_1_execution() {
#[cfg_attr(miri, ignore)]
fn audit_2_codegen() {
let wasm = include_str!("wat/audit_2.wat");
TranslationTest::from_wat(wasm)
TranslationTest::new(wasm)
.expect_func_instrs([
Instruction::copy(2, 0),
Instruction::copy(0, 2),
Expand Down
8 changes: 4 additions & 4 deletions crates/wasmi/src/engine/translator/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
T: IntoIterator<Item = Instruction>,
<T as IntoIterator>::IntoIter: ExactSizeIterator,
{
let mut testcase = TranslationTest::from_wat(wasm);
let mut testcase = TranslationTest::new(wasm);
for instrs in expected {
testcase.expect_func_instrs(instrs);
}
Expand Down Expand Up @@ -227,7 +227,7 @@ where
)
"#,
);
TranslationTest::from_wat(&wasm)
TranslationTest::new(&wasm)
}

fn testcase_binary_imm_reg<T>(wasm_op: WasmOp, value: T) -> TranslationTest
Expand All @@ -249,7 +249,7 @@ where
)
"#,
);
TranslationTest::from_wat(&wasm)
TranslationTest::new(&wasm)
}

/// Variant of [`test_binary_reg_imm16`] where the `rhs` operand is an immediate value.
Expand Down Expand Up @@ -387,7 +387,7 @@ where
)
"#,
);
TranslationTest::from_wat(&wasm)
TranslationTest::new(&wasm)
}

fn test_binary_consteval<T, E>(wasm_op: WasmOp, lhs: T, rhs: T, expected: E)
Expand Down
Loading

0 comments on commit 76140bc

Please sign in to comment.