Skip to content

Commit

Permalink
add a compiler test to check for deterministic
Browse files Browse the repository at this point in the history
This is to test wasmerio#2173, the empty test always pass while the table one
fails sometimes.
  • Loading branch information
Anbang Wen committed Mar 18, 2021
1 parent 031afdf commit 7ca93dd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/compilers/deterministic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use anyhow::Result;
use wasmer::{wat2wasm, Module};

fn compile_and_compare(wasm: &[u8]) -> Result<()> {
let store = Default::default();

// compile for first time
let module = Module::new(&store, wasm)?;
let first = module.serialize()?;

// compile for second time
let module = Module::new(&store, wasm)?;
let second = module.serialize()?;

assert!(first == second);

Ok(())
}

#[test]
fn deterministic_empty() -> Result<()> {
let wasm_bytes = wat2wasm(
br#"
(module)
"#,
)?;

compile_and_compare(&wasm_bytes)
}

#[test]
fn deterministic_table() -> Result<()> {
let wasm_bytes = wat2wasm(
br#"
(module
(table 2 funcref)
(func $f1)
(func $f2)
(elem (i32.const 0) $f1 $f2))
"#,
)?;

compile_and_compare(&wasm_bytes)
}
1 change: 1 addition & 0 deletions tests/compilers/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! implementation, such as: singlepass, cranelift or llvm depending
//! on what's available on the target.

mod deterministic;
mod imports;
mod metering;
mod middlewares;
Expand Down

0 comments on commit 7ca93dd

Please sign in to comment.