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

Function smoke_test_engine

crates/fuzzing/src/oracles/engine.rs:179–234  ·  view source on GitHub ↗
(
    mk_engine: impl Fn(&mut arbitrary::Unstructured<'_>, &mut Config) -> arbitrary::Result<T>,
)

Source from the content-addressed store, hash-verified

177/// Smoke test an engine with a given config.
178#[cfg(test)]
179pub fn smoke_test_engine<T>(
180 mk_engine: impl Fn(&mut arbitrary::Unstructured<'_>, &mut Config) -> arbitrary::Result<T>,
181) where
182 T: DiffEngine,
183{
184 crate::test::test_n_times(5, |mut config: Config, u| {
185 // This will ensure that wasmtime, which uses this configuration
186 // settings, can guaranteed instantiate a module.
187 config.set_differential_config();
188
189 let mut engine = match mk_engine(u, &mut config) {
190 Ok(engine) => engine,
191 Err(e) => {
192 println!("skip {e:?}");
193 return Ok(());
194 }
195 };
196
197 let wasm = wat::parse_str(
198 r#"
199 (module
200 (func (export "add") (param i32 i32) (result i32)
201 local.get 0
202 local.get 1
203 i32.add)
204
205 (global (export "global") i32 i32.const 1)
206 (memory (export "memory") 1)
207 )
208 "#,
209 )
210 .unwrap();
211 let mut instance = engine.instantiate(&wasm).unwrap();
212 let results = instance
213 .evaluate(
214 "add",
215 &[DiffValue::I32(1), DiffValue::I32(2)],
216 &[DiffValueType::I32],
217 )
218 .unwrap();
219 assert_eq!(results, Some(vec![DiffValue::I32(3)]));
220
221 if let Some(val) = instance.get_global("global", DiffValueType::I32) {
222 assert_eq!(val, DiffValue::I32(1));
223 }
224
225 if let Some(val) = instance.get_memory("memory", false) {
226 assert_eq!(val.len(), 65536);
227 for i in val.iter() {
228 assert_eq!(*i, 0);
229 }
230 }
231
232 Ok(())
233 })
234}

Callers 6

smokeFunction · 0.85
smoke_cranelift_nativeFunction · 0.85
smoke_cranelift_pulleyFunction · 0.85
smoke_winchFunction · 0.85
smokeFunction · 0.85
smokeFunction · 0.85

Calls 9

test_n_timesFunction · 0.85
OkFunction · 0.85
unwrapMethod · 0.45
instantiateMethod · 0.45
evaluateMethod · 0.45
get_globalMethod · 0.45
get_memoryMethod · 0.45
iterMethod · 0.45

Tested by 6

smokeFunction · 0.68
smoke_cranelift_nativeFunction · 0.68
smoke_cranelift_pulleyFunction · 0.68
smoke_winchFunction · 0.68
smokeFunction · 0.68
smokeFunction · 0.68