Skip to content

Commit

Permalink
implement fuzzing for component types
Browse files Browse the repository at this point in the history
This addresses bytecodealliance#4307.

For the static API we generate 100 arbitrary test cases at build time, each of
which includes 0-5 parameter types, a result type, and a WAT fragment containing
an imported function and an exported function.  The exported function calls the
imported function, which is implemented by the host.  At runtime, the fuzz test
selects a test case at random and feeds it zero or more sets of arbitrary
parameters and results, checking that values which flow host-to-guest and
guest-to-host make the transition unchanged.

The fuzz test for the dynamic API follows a similar pattern, the only difference
being that test cases are generated at runtime.

Signed-off-by: Joel Dice <[email protected]>

fix build error and type name tracking

This fixes two issues:

- build.rs was failing to build when the component_model feature was not enabled

- Name assignments for types in component_types.rs were not being tracked
  properly because structurally identical types were being considered equal to
  each other.

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Jul 29, 2022
1 parent 46782b1 commit 6c412dc
Show file tree
Hide file tree
Showing 19 changed files with 1,765 additions and 117 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ wat = "1.0.47"
once_cell = "1.9.0"
rayon = "1.5.0"
component-macro-test = { path = "crates/misc/component-macro-test" }
component-test-util = { path = "crates/misc/component-test-util" }

[target.'cfg(windows)'.dev-dependencies]
windows-sys = { version = "0.36.0", features = ["Win32_System_Memory"] }
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() -> anyhow::Result<()> {
} else {
println!(
"cargo:warning=The spec testsuite is disabled. To enable, run `git submodule \
update --remote`."
update --remote`."
);
}
Ok(())
Expand Down
6 changes: 6 additions & 0 deletions crates/fuzzing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ license = "Apache-2.0 WITH LLVM-exception"
[dependencies]
anyhow = "1.0.22"
arbitrary = { version = "1.1.0", features = ["derive"] }
component-test-util = { path = "../misc/component-test-util" }
env_logger = "0.9.0"
log = "0.4.8"
proc-macro2 = "1.0"
quote = "1.0"
rayon = "1.2.1"
target-lexicon = "0.12.3"
tempfile = "3.3.0"
wasmparser = "0.88.0"
wasmprinter = "0.2.38"
wasmtime = { path = "../wasmtime" }
wasmtime-component-util = { path = "../component-util" }
wasmtime-wast = { path = "../wast" }
wasm-encoder = "0.15.0"
wasm-smith = "0.11.3"
Expand All @@ -43,4 +47,6 @@ rand = { version = "0.8.0", features = ["small_rng"] }
wasm-spec-interpreter = { path = "./wasm-spec-interpreter", optional = true, features = ['build-libinterpret'] }

[features]
default = ['fuzz-spec-interpreter']
fuzz-spec-interpreter = ['wasm-spec-interpreter']
component-model = ['wasmtime/component-model']
3 changes: 3 additions & 0 deletions crates/fuzzing/src/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ mod spec_test;
mod stacks;
pub mod table_ops;

#[cfg(feature = "component-model")]
pub mod component_types;

pub use codegen_settings::CodegenSettings;
pub use config::{Config, WasmtimeConfig};
pub use instance_allocation_strategy::InstanceAllocationStrategy;
Expand Down
Loading

0 comments on commit 6c412dc

Please sign in to comment.