MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / serialize_deterministic

Function serialize_deterministic

tests/all/module.rs:98–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96#[test]
97#[cfg_attr(miri, ignore)]
98fn 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

Callers

nothing calls this directly

Calls 5

precompile_moduleMethod · 0.80
as_bytesMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
serializeMethod · 0.45

Tested by

no test coverage detected