Skip to content

Commit

Permalink
wasm-smith: Deduplicate and devirtualize configuration (#1351)
Browse files Browse the repository at this point in the history
* wasm-smith: Deduplicate and devirtualize configuration

This makes it so that we don't have three or four places where each config
option needs to be enumerated anymore and also removes the `Config` trait and
replaces it with a `Config` struct (what used to be the `SwarmConfig`
struct). This struct implements `Arbitrary` and therefore you can still do swarm
testing by generating an arbitrary config and then using that to generate a
module. There is also no difference between `Module` and `ConfiguredModule`
anymore.

Overall, I feel like this is a big clean up, and also should in theory make
module generation a little faster since there won't be so many indirect calls.

* Fix some compile errors

* Fix fuzz target compilation

* Fix some warnings and errors in the doc build

* Fix more fuzz target compilation errors
  • Loading branch information
fitzgen authored Jan 3, 2024
1 parent 9de484b commit 4d1f503
Show file tree
Hide file tree
Showing 18 changed files with 1,020 additions and 1,466 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/c-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]

use arbitrary::{Error, Unstructured};
use wasm_smith::{DefaultConfig, Module};
use wasm_smith::{Config, Module};

#[repr(C)]
pub struct wasm_tools_byte_vec_t {
Expand Down Expand Up @@ -50,7 +50,7 @@ pub unsafe extern "C" fn wasm_smith_create(

bytes.data = std::ptr::null_mut();
let mut u = Unstructured::new(seed_bytes);
match Module::new(DefaultConfig::default(), &mut u) {
match Module::new(Config::default(), &mut u) {
Ok(module) => {
let mut wasm_buffer = module.to_bytes().into_boxed_slice();
bytes.data = wasm_buffer.as_mut_ptr();
Expand Down
5 changes: 2 additions & 3 deletions crates/fuzz-stats/src/bin/failed-instantiations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use arbitrary::{Arbitrary, Error, Unstructured};
use rand::RngCore;
use std::sync::atomic::{AtomicIsize, AtomicUsize, Ordering::SeqCst};
use std::sync::Arc;
use wasm_smith::SwarmConfig;
use wasmtime::*;

struct State {
Expand Down Expand Up @@ -95,12 +94,12 @@ impl State {
/// Records when instantiation fails and why it fails.
fn run_once(&self, data: &[u8]) -> Result<(), Error> {
let mut u = Unstructured::new(data);
// Here `SwarmConfig` is used to get hopefully a bit more coverage of
// Here swarm testing is used to get hopefully a bit more coverage of
// interesting states, and we also forcibly disable all `start`
// functions for now. Not much work has gone into minimizing the traps
// generated from wasm functions themselves, and this shouldn't be
// enabled until that's been worked on.
let mut config = SwarmConfig::arbitrary(&mut u)?;
let mut config = wasm_smith::Config::arbitrary(&mut u)?;
config.allow_start_export = false;

// Wasmtime doesn't support this proposal yet.
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-shrink/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Shrink a Wasm file while maintaining a property of interest (such as
//! triggering a compiler bug).
//!
//! See the [`WasmShrink`][WasmShrink] type for details.
//! See the [`WasmShrink`] type for details.
use std::collections::HashSet;

Expand Down
5 changes: 4 additions & 1 deletion crates/wasm-smith/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ name = "corpus"
harness = false

[dependencies]
anyhow = { workspace = true, optional = true }
arbitrary = { workspace = true, features = ["derive"] }
clap = { workspace = true, optional = true }
flagset = "0.4"
indexmap = { workspace = true }
leb128 = { workspace = true }
serde = { workspace = true, optional = true }
serde_derive = { workspace = true, optional = true }
wasm-encoder = { workspace = true, features = ['wasmparser'] }
wasmparser = { workspace = true, optional = true }
wat = { workspace = true, optional = true }

[dev-dependencies]
criterion = { workspace = true }
Expand All @@ -36,4 +39,4 @@ wat = { path = "../wat" }
libfuzzer-sys = { workspace = true }

[features]
_internal_cli = ["serde", "serde_derive", "wasmparser"]
_internal_cli = ["anyhow", "clap", "flagset/serde", "serde", "serde_derive", "wasmparser", "wat"]
Loading

0 comments on commit 4d1f503

Please sign in to comment.