/src/wasmer/fuzz/fuzz_targets/deterministic.rs
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | #![no_main] | 
| 2 |  |  | 
| 3 |  | use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target}; | 
| 4 |  | use wasm_smith::{Config, ConfiguredModule}; | 
| 5 |  | use wasmer::{CompilerConfig, EngineBuilder, Module, Store}; | 
| 6 |  | use wasmer_compiler::Engine; | 
| 7 |  | use wasmer_compiler_cranelift::Cranelift; | 
| 8 |  | use wasmer_compiler_llvm::LLVM; | 
| 9 |  | use wasmer_compiler_singlepass::Singlepass; | 
| 10 |  |  | 
| 11 | 0 | #[derive(Arbitrary, Debug, Default, Copy, Clone)] <deterministic::NoImportsConfig as arbitrary::Arbitrary>::arbitrary::{closure#1}| Line | Count | Source |  | 11 | 5.00k | #[derive(Arbitrary, Debug, Default, Copy, Clone)] | 
Unexecuted instantiation: <deterministic::NoImportsConfig as arbitrary::Arbitrary>::arbitrary::{closure#0}Unexecuted instantiation: <deterministic::NoImportsConfig as arbitrary::Arbitrary>::arbitrary::{closure#2}Unexecuted instantiation: <deterministic::NoImportsConfig as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#1}Unexecuted instantiation: <deterministic::NoImportsConfig as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#0}Unexecuted instantiation: <deterministic::NoImportsConfig as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#2}Unexecuted instantiation: <deterministic::NoImportsConfig as arbitrary::Arbitrary>::size_hint::{closure#0} | 
| 12 |  | struct NoImportsConfig; | 
| 13 |  | impl Config for NoImportsConfig { | 
| 14 | 5.00k |     fn max_imports(&self) -> usize { | 
| 15 | 5.00k |         0 | 
| 16 | 5.00k |     } | 
| 17 | 2.50k |     fn max_memory_pages(&self) -> u32 { | 
| 18 | 2.50k |         // https://github.com/wasmerio/wasmer/issues/2187 | 
| 19 | 2.50k |         65535 | 
| 20 | 2.50k |     } | 
| 21 | 5.00k |     fn allow_start_export(&self) -> bool { | 
| 22 | 5.00k |         false | 
| 23 | 5.00k |     } | 
| 24 |  | } | 
| 25 |  |  | 
| 26 | 15.0k | fn compile_and_compare(name: &str, engine: Engine, wasm: &[u8]) { | 
| 27 | 15.0k |     let store = Store::new(engine); | 
| 28 | 15.0k |  | 
| 29 | 15.0k |     // compile for first time | 
| 30 | 15.0k |     let module = Module::new(&store, wasm).unwrap(); | 
| 31 | 15.0k |     let first = module.serialize().unwrap(); | 
| 32 | 15.0k |  | 
| 33 | 15.0k |     // compile for second time | 
| 34 | 15.0k |     let module = Module::new(&store, wasm).unwrap(); | 
| 35 | 15.0k |     let second = module.serialize().unwrap(); | 
| 36 | 15.0k |  | 
| 37 | 15.0k |     if first != second { | 
| 38 | 0 |         panic!("non-deterministic compilation from {}", name); | 
| 39 | 15.0k |     } | 
| 40 | 15.0k | } | 
| 41 |  |  | 
| 42 |  | fuzz_target!(|module: ConfiguredModule<NoImportsConfig>| { | 
| 43 |  |     let wasm_bytes = module.to_bytes(); | 
| 44 |  |  | 
| 45 |  |     let mut compiler = Cranelift::default(); | 
| 46 |  |     compiler.canonicalize_nans(true); | 
| 47 |  |     compiler.enable_verifier(); | 
| 48 |  |     compile_and_compare( | 
| 49 |  |         "universal-cranelift", | 
| 50 |  |         EngineBuilder::new(compiler.clone()).engine(), | 
| 51 |  |         &wasm_bytes, | 
| 52 |  |     ); | 
| 53 |  |  | 
| 54 |  |     let mut compiler = LLVM::default(); | 
| 55 |  |     compiler.canonicalize_nans(true); | 
| 56 |  |     compiler.enable_verifier(); | 
| 57 |  |     compile_and_compare( | 
| 58 |  |         "universal-llvm", | 
| 59 |  |         EngineBuilder::new(compiler.clone()).engine(), | 
| 60 |  |         &wasm_bytes, | 
| 61 |  |     ); | 
| 62 |  |  | 
| 63 |  |     let compiler = Singlepass::default(); | 
| 64 |  |     compile_and_compare( | 
| 65 |  |         "universal-singlepass", | 
| 66 |  |         EngineBuilder::new(compiler.clone()).engine(), | 
| 67 |  |         &wasm_bytes, | 
| 68 |  |     ); | 
| 69 |  | }); |