(data: &[u8])
| 55 | }); |
| 56 | |
| 57 | fn execute_one(data: &[u8]) -> Result<()> { |
| 58 | wasmtime_fuzzing::init_fuzzing(); |
| 59 | STATS.bump_attempts(); |
| 60 | |
| 61 | let mut u = Unstructured::new(data); |
| 62 | |
| 63 | // Generate a Wasmtime and module configuration and update its settings |
| 64 | // initially to be suitable for differential execution where the generated |
| 65 | // wasm will behave the same in two different engines. This will get further |
| 66 | // refined below. |
| 67 | let mut config: Config = u.arbitrary()?; |
| 68 | config.set_differential_config(); |
| 69 | |
| 70 | let allowed_engines = ALLOWED_ENGINES.lock().unwrap(); |
| 71 | let allowed_modules = ALLOWED_MODULES.lock().unwrap(); |
| 72 | |
| 73 | // Choose an engine that Wasmtime will be differentially executed against. |
| 74 | // The chosen engine is then created, which might update `config`, and |
| 75 | // returned as a trait object. |
| 76 | let lhs = match *u.choose(&allowed_engines)? { |
| 77 | Some(engine) => engine, |
| 78 | None => { |
| 79 | log::debug!("test case uses a runtime-disabled engine"); |
| 80 | return Ok(()); |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | log::trace!("Building LHS engine"); |
| 85 | let mut lhs = match engine::build(&mut u, lhs, &mut config)? { |
| 86 | Some(engine) => engine, |
| 87 | // The chosen engine does not have support compiled into the fuzzer, |
| 88 | // discard this test case. |
| 89 | None => return Ok(()), |
| 90 | }; |
| 91 | log::debug!("lhs engine: {}", lhs.name()); |
| 92 | |
| 93 | // Using the now-legalized module configuration generate the Wasm module; |
| 94 | // this is specified by either the ALLOWED_MODULES environment variable or a |
| 95 | // random selection between wasm-smith and single-inst. |
| 96 | let build_wasm_smith_module = |u: &mut Unstructured, config: &Config| -> Result<_> { |
| 97 | log::debug!("build wasm-smith with {config:?}"); |
| 98 | STATS.wasm_smith_modules.fetch_add(1, SeqCst); |
| 99 | let module = config.generate(u, Some(1000))?; |
| 100 | Ok(module.to_bytes()) |
| 101 | }; |
| 102 | let build_single_inst_module = |u: &mut Unstructured, config: &Config| -> Result<_> { |
| 103 | log::debug!("build single-inst with {config:?}"); |
| 104 | STATS.single_instruction_modules.fetch_add(1, SeqCst); |
| 105 | let module = SingleInstModule::new(u, &config.module_config)?; |
| 106 | Ok(module.to_bytes()) |
| 107 | }; |
| 108 | if allowed_modules.is_empty() { |
| 109 | panic!("unable to generate a module to fuzz against; check `ALLOWED_MODULES`") |
| 110 | } |
| 111 | let wasm = match *u.choose(&allowed_modules)? { |
| 112 | Some("wasm-smith") => build_wasm_smith_module(&mut u, &config)?, |
| 113 | Some("single-inst") => build_single_inst_module(&mut u, &config)?, |
| 114 | None => { |
nothing calls this directly
no test coverage detected