Skip to content

Commit 93d22fc

Browse files
authored
Migrate fuzzing to wasmtime::error (#12263)
* Migrate fuzzing to `wasmtime::error` * fix
1 parent f237539 commit 93d22fc

File tree

14 files changed

+22
-27
lines changed

14 files changed

+22
-27
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/fuzzing/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ workspace = true
1515
wasmtime-test-util = { workspace = true, features = ['wast'] }
1616

1717
[dependencies]
18-
anyhow = { workspace = true }
1918
backtrace = { workspace = true }
2019
arbitrary = { workspace = true, features = ["derive"] }
2120
env_logger = { workspace = true }

crates/fuzzing/src/generators/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
33
use super::{AsyncConfig, CodegenSettings, InstanceAllocationStrategy, MemoryConfig, ModuleConfig};
44
use crate::oracles::{StoreLimits, Timeout};
5-
use anyhow::Result;
65
use arbitrary::{Arbitrary, Unstructured};
76
use std::time::Duration;
7+
use wasmtime::Result;
88
use wasmtime::{Enabled, Engine, Module, Store};
99
use wasmtime_test_util::wast::{WastConfig, WastTest, limits};
1010

crates/fuzzing/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ mod test {
9090
use rand::prelude::*;
9191

9292
pub fn gen_until_pass<T: for<'a> Arbitrary<'a>>(
93-
mut f: impl FnMut(T, &mut Unstructured<'_>) -> anyhow::Result<bool>,
93+
mut f: impl FnMut(T, &mut Unstructured<'_>) -> wasmtime::Result<bool>,
9494
) -> bool {
9595
let mut rng = SmallRng::seed_from_u64(0);
9696
let mut buf = vec![0; 2048];

crates/fuzzing/src/oracles.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn compile_module(
321321
) -> Option<Module> {
322322
log_wasm(bytes);
323323

324-
fn is_pcc_error(e: &anyhow::Error) -> bool {
324+
fn is_pcc_error(e: &wasmtime::Error) -> bool {
325325
// NOTE: please keep this predicate in sync with the display format of CodegenError,
326326
// defined in `wasmtime/cranelift/codegen/src/result.rs`
327327
e.to_string().to_lowercase().contains("proof-carrying-code")
@@ -400,7 +400,7 @@ pub fn instantiate_with_dummy(store: &mut Store<StoreLimits>, module: &Module) -
400400

401401
fn unwrap_instance(
402402
store: &Store<StoreLimits>,
403-
instance: anyhow::Result<Instance>,
403+
instance: wasmtime::Result<Instance>,
404404
) -> Option<Instance> {
405405
let e = match instance {
406406
Ok(i) => return Some(i),
@@ -460,7 +460,7 @@ pub fn differential(
460460
name: &str,
461461
args: &[DiffValue],
462462
result_tys: &[DiffValueType],
463-
) -> anyhow::Result<bool> {
463+
) -> wasmtime::Result<bool> {
464464
log::debug!("Evaluating: `{name}` with {args:?}");
465465
let lhs_results = match lhs.evaluate(name, args, result_tys) {
466466
Ok(Some(results)) => Ok(results),
@@ -1324,7 +1324,7 @@ mod tests {
13241324
let ok =
13251325
Validator::new_with_features(WasmFeatures::all() ^ feature).validate_all(&wasm);
13261326
if ok.is_err() {
1327-
anyhow::bail!("generated a module with {feature:?} but that wasn't expected");
1327+
wasmtime::bail!("generated a module with {feature:?} but that wasn't expected");
13281328
}
13291329
}
13301330

crates/fuzzing/src/oracles/component_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ where
226226
fn host_function<P, R>(
227227
cx: StoreContextMut<'_, Box<dyn Any + Send>>,
228228
params: P,
229-
) -> anyhow::Result<R>
229+
) -> wasmtime::Result<R>
230230
where
231231
P: Debug + PartialEq + 'static,
232232
R: Debug + Clone + 'static,

crates/fuzzing/src/oracles/diff_spec.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
44
use crate::generators::{Config, DiffValue, DiffValueType};
55
use crate::oracles::engine::{DiffEngine, DiffInstance};
6-
use anyhow::{Error, Result, anyhow};
76
use wasm_spec_interpreter::SpecValue;
8-
use wasmtime::Trap;
7+
use wasmtime::{Error, Result, Trap, format_err};
98

109
/// A wrapper for `wasm-spec-interpreter` as a [`DiffEngine`].
1110
pub struct SpecInterpreter;
@@ -41,7 +40,7 @@ impl DiffEngine for SpecInterpreter {
4140

4241
fn instantiate(&mut self, wasm: &[u8]) -> Result<Box<dyn DiffInstance>> {
4342
let instance = wasm_spec_interpreter::instantiate(wasm)
44-
.map_err(|e| anyhow!("failed to instantiate in spec interpreter: {e}"))?;
43+
.map_err(|e| format_err!("failed to instantiate in spec interpreter: {e}"))?;
4544
Ok(Box::new(SpecInstance { instance }))
4645
}
4746

@@ -73,7 +72,7 @@ impl DiffInstance for SpecInstance {
7372
let arguments = arguments.iter().map(SpecValue::from).collect();
7473
match wasm_spec_interpreter::interpret(&self.instance, function_name, Some(arguments)) {
7574
Ok(results) => Ok(Some(results.into_iter().map(SpecValue::into).collect())),
76-
Err(err) => Err(anyhow!(err)),
75+
Err(err) => Err(format_err!(err)),
7776
}
7877
}
7978

crates/fuzzing/src/oracles/diff_v8.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::generators::{Config, DiffValue, DiffValueType};
22
use crate::oracles::engine::{DiffEngine, DiffInstance};
3-
use anyhow::{Error, Result, bail};
43
use std::cell::RefCell;
54
use std::rc::Rc;
65
use std::sync::Once;
7-
use wasmtime::Trap;
6+
use wasmtime::{Error, Result, Trap, bail};
87

98
pub struct V8Engine {
109
isolate: Rc<RefCell<v8::OwnedIsolate>>,

crates/fuzzing/src/oracles/diff_wasmi.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
use crate::generators::{Config, DiffValue, DiffValueType};
44
use crate::oracles::engine::{DiffEngine, DiffInstance};
5-
use anyhow::{Context, Error, Result};
6-
use wasmtime::Trap;
5+
use wasmtime::{Error, Result, Trap, error::Context as _};
76

87
/// A wrapper for `wasmi` as a [`DiffEngine`].
98
pub struct WasmiEngine {

crates/fuzzing/src/oracles/diff_wasmtime.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use crate::oracles::dummy;
55
use crate::oracles::engine::DiffInstance;
66
use crate::oracles::{StoreLimits, compile_module, engine::DiffEngine};
77
use crate::single_module_fuzzer::KnownValid;
8-
use anyhow::{Context, Error, Result};
98
use arbitrary::Unstructured;
10-
use wasmtime::{Extern, FuncType, Instance, Module, Store, Trap, Val};
9+
use wasmtime::{
10+
Error, Extern, FuncType, Instance, Module, Result, Store, Trap, Val, error::Context as _,
11+
};
1112

1213
/// A wrapper for using Wasmtime as a [`DiffEngine`].
1314
pub struct WasmtimeEngine {

0 commit comments

Comments
 (0)