forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a compiler test to check for deterministic
This is to test wasmerio#2173, the empty test always pass while the table one fails sometimes.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters