Skip to content

Commit

Permalink
Add tests locals can be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Feb 7, 2024
1 parent 403f943 commit 2b0a035
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crates/wasm-mutate/src/mutators/peephole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,24 @@ mod tests {
);
}

#[test]
fn remove_local_set() {
test_default_peephole_mutator(
"(module (func (local i32) (local.set 0 (i32.const 0))))",
"(module (func (local i32) nop))",
4,
);
}

#[test]
fn remove_local_tee() {
test_default_peephole_mutator(
"(module (func (local i32) (local.tee 0 (i32.const 0)) drop))",
"(module (func (local i32) (i32.const 0) drop))",
4,
);
}

fn test_peephole_mutator(
original: &str,
rules: &[Rewrite<super::Lang, PeepholeMutationAnalysis>],
Expand All @@ -1599,4 +1617,17 @@ mod tests {
let mutator = PeepholeMutator::new_with_rules(3, rules.to_vec());
config.match_mutation(original, mutator, expected);
}

fn test_default_peephole_mutator(original: &str, expected: &str, seed: u64) {
let original_wasm = wat::parse_str(original).unwrap();
let mut config = WasmMutate::default();
config.fuel(10000);
config.seed(seed);
config.info = Some(ModuleInfo::new(&original_wasm).unwrap());

let mut mutator = PeepholeMutator::new(3);
let rules = mutator.get_rules(&config);
mutator.rules = Some(rules);
config.match_mutation(original, mutator, expected);
}
}

0 comments on commit 2b0a035

Please sign in to comment.