Skip to content

Commit 790d54b

Browse files
committed
Add documentation for creating new fuzz test targets.
1 parent 132b072 commit 790d54b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

fuzz/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,36 @@ export RUSTFLAGS="--cfg=fuzzing"
8484
cargo test
8585
```
8686

87+
Note that if the fuzz test failed locally, moving the offending run's trace
88+
to the `test_cases` folder should also do the trick, simply replace the `echo $HEX |` line above
89+
with (the trace file name is of course a bit longer than in the example):
90+
91+
```shell
92+
mv hfuzz_workspace/fuzz_target/SIGABRT.PC.7ffff7e21ce1.STACK.[…].fuzz ./test_cases/$TARGET/
93+
```
94+
8795
This will reproduce the failing fuzz input and yield a usable stack trace.
96+
97+
98+
## How do I add a new fuzz test?
99+
100+
1. The easiest approach is to take one of the files in `fuzz/src/`, such as e. g.
101+
`process_network_graph.rs`, and duplicate it, renaming the new file to something more
102+
suitable. For the sake of example, let's call the new fuzz target we're creating
103+
`my_fuzzy_experiment`.
104+
105+
2. In the newly created file `fuzz/src/my_fuzzy_experiment.rs`, run a string substitution
106+
of `process_network_graph` to `my_fuzzy_experiment`, such that the three methods in the
107+
file are `do_test`, `my_fuzzy_experiment_test`, and `my_fuzzy_experiment_run`.
108+
109+
3. In `fuzz/src/bin/gen_target.sh`, add a line reading `GEN_TEST my_fuzzy_experiment` to the
110+
first group of `GEN_TEST` lines (starting in line 9).
111+
112+
4. If your test relies on a new local crate, add that crate to `fuzz/Cargo.toml`.
113+
114+
5. In `fuzz/src/lib.rs`, add the line `pub mod my_fuzzy_experiment`. Additionally, if
115+
you added a new crate dependency, add the `extern crate […]` import line.
116+
117+
6. Run `fuzz/src/bin/gen_target.sh`.
118+
119+
7. There is no step seven: happy fuzzing!

0 commit comments

Comments
 (0)