Bug 1888590 - Mark some subtests on trusted-types-event-handlers.html as failing...
[gecko.git] / third_party / rust / wasm-smith / README.md
blob489918aca4078bf0504bc6eff13f2b62b281a1f7
1 # `wasm-smith`
3 **A WebAssembly test case generator.**
5 [![](https://docs.rs/wasm-smith/badge.svg)](https://docs.rs/wasm-smith/)
6 [![](https://img.shields.io/crates/v/wasm-smith.svg)](https://crates.io/crates/wasm-smith)
7 [![](https://img.shields.io/crates/d/wasm-smith.svg)](https://crates.io/crates/wasm-smith)
9 * [Features](#features)
10 * [Usage](#usage)
11   * [With `cargo fuzz` and `libfuzzer-sys`](#with-cargo-fuzz-and-libfuzzer-sys)
12   * [As a Command Line Tool](#as-a-command-line-tool)
14 ## Features
16 * **Always valid:** All generated Wasm modules pass validation. `wasm-smith`
17   gets past your wasm parser and validator, exercising the guts of your Wasm
18   compiler, runtime, or tool.
20 * **Supports the full WebAssembly language:** Doesn't have blind spots or
21   unimplemented instructions.
23 * **Implements the
24   [`Arbitrary`](https://docs.rs/arbitrary/*/arbitrary/trait.Arbitrary.html)
25   trait**: Easy to use with [`cargo
26   fuzz`](https://github.com/rust-fuzz/cargo-fuzz) and
27   [`libfuzzer-sys`](https://github.com/rust-fuzz/libfuzzer)!
29 * **Deterministic:** Given the same input seed, always generates the same output
30   Wasm module, so you can always reproduce test failures.
32 * **Plays nice with mutation-based fuzzers:** Small changes to the input tend to
33   produce small changes to the output Wasm module. Larger inputs tend to
34   generate larger Wasm modules.
36 ## Usage
38 ### With `cargo fuzz` and `libfuzzer-sys`
40 First, use `cargo fuzz` to define a new fuzz target:
42 ```shell
43 $ cargo fuzz add my_wasm_smith_fuzz_target
44 ```
46 Next, add `wasm-smith` to your dependencies:
48 ```shell
49 $ cargo add wasm-smith
50 ```
52 Then, define your fuzz target so that it takes arbitrary `wasm_smith::Module`s
53 as an argument, convert the module into serialized Wasm bytes via the `to_bytes`
54 method, and then feed it into your system:
56 ```rust
57 // fuzz/fuzz_targets/my_wasm_smith_fuzz_target.rs
59 #![no_main]
61 use libfuzzer_sys::fuzz_target;
62 use wasm_smith::Module;
64 fuzz_target!(|module: Module| {
65     let wasm_bytes = module.to_bytes();
67     // Your code here...
68 });
69 ```
71 Finally, start fuzzing:
73 ```shell
74 $ cargo fuzz run my_wasm_smith_fuzz_target
75 ```
77 > **Note:** Also check out [the `validate` fuzz
78 > target](https://github.com/bytecodealliance/wasm-tools/blob/main/fuzz/src/validate.rs)
79 > defined in this repository. Using the `wasmparser` crate, it checks that every
80 > module generated by `wasm-smith` validates successfully.
82 ### As a Command Line Tool
84 Install the CLI tool via `cargo`:
86 ```shell
87 $ cargo install wasm-tools
88 ```
90 Convert some arbitrary input into a valid Wasm module:
92 ```shell
93 $ head -c 100 /dev/urandom | wasm-tools smith -o test.wasm
94 ```
96 Finally, run your tool on the generated Wasm module:
98 ```shell
99 $ my-wasm-tool test.wasm