()
| 96 | #[test] |
| 97 | #[cfg_attr(miri, ignore)] |
| 98 | fn serialize_deterministic() { |
| 99 | let engine = Engine::default(); |
| 100 | |
| 101 | let assert_deterministic = |wasm: &str| { |
| 102 | let p1 = engine.precompile_module(wasm.as_bytes()).unwrap(); |
| 103 | let p2 = engine.precompile_module(wasm.as_bytes()).unwrap(); |
| 104 | if p1 != p2 { |
| 105 | panic!("precompile_module not deterministic for:\n{wasm}"); |
| 106 | } |
| 107 | |
| 108 | let module1 = Module::new(&engine, wasm).unwrap(); |
| 109 | let a1 = module1.serialize().unwrap(); |
| 110 | let a2 = module1.serialize().unwrap(); |
| 111 | if a1 != a2 { |
| 112 | panic!("Module::serialize not deterministic for:\n{wasm}"); |
| 113 | } |
| 114 | |
| 115 | let module2 = Module::new(&engine, wasm).unwrap(); |
| 116 | let b1 = module2.serialize().unwrap(); |
| 117 | let b2 = module2.serialize().unwrap(); |
| 118 | if b1 != b2 { |
| 119 | panic!("Module::serialize not deterministic for:\n{wasm}"); |
| 120 | } |
| 121 | |
| 122 | if a1 != b2 { |
| 123 | panic!("not matching across modules:\n{wasm}"); |
| 124 | } |
| 125 | if b1 != p2 { |
| 126 | panic!("not matching across engine/module:\n{wasm}"); |
| 127 | } |
| 128 | }; |
| 129 | |
| 130 | assert_deterministic("(module)"); |
| 131 | assert_deterministic("(module (func))"); |
| 132 | assert_deterministic("(module (func nop))"); |
| 133 | assert_deterministic("(module (func) (func (param i32)))"); |
| 134 | assert_deterministic("(module (func (export \"f\")) (func (export \"y\")))"); |
| 135 | assert_deterministic("(module (func $f) (func $g))"); |
| 136 | assert_deterministic("(module (data \"\") (data \"\"))"); |
| 137 | assert_deterministic("(module (elem func) (elem func))"); |
| 138 | } |
| 139 | |
| 140 | // This test asserts that the optimization to transform separate data segments |
| 141 | // into an initialization image doesn't unnecessarily create a massive module by |
nothing calls this directly
no test coverage detected