File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,11 +81,21 @@ hardware floating-point behavior) is to employ *fuzzing*.
8181The fuzzing infrastructure lives in ` fuzz/ ` and requires ` cargo-afl ` , but also
8282involves an automated build of the original C++ ` llvm::APFloat ` code with ` clang `
8383(to be able to instrument it via LLVM, in the same way ` cargo-afl ` does for the
84- Rust code), and has been prototyped and tested on Linux (and is unlikely to work
85- on other platforms, or even some Linux distros, though it mostly assumes UNIX) .
84+ Rust code), and has been prototyped and tested on Linux. It is unlikely to work
85+ on other platforms, or even some Linux distros, though it mostly assumes UNIX.
8686
87- Example usage:
88- <sub >(** TODO** : maybe move this to ` fuzz/README.md ` and/or expand on it)</sub >
87+ There is a justfile that makes this easy:
88+
89+ ``` sh
90+ # Build and run fuzzing
91+ just fuzz
92+ # Do the same thing but use more cores
93+ just fuzz-parallel
94+ # Print crashes. Can be run while fuzzing is ongoing.
95+ just decode
96+ ```
97+
98+ Longer version:
8999
90100``` sh
91101# Install `cargo-afl` (used below to build/run the fuzzing binary).
Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ set -euxo pipefail
99# Detect cores
1010all_cores=" $( nproc) "
1111used_cores=" $(( all_cores - 2 )) "
12- in_dir=" fuzz/runs/fuzz-in "
13- sync_dir=" fuzz/runs/fuzz- out"
12+ in_dir=" ${FUZZ_IN :- fuzz/ runs/ in} "
13+ sync_dir=" ${FUZZ_OUT :- fuzz/ runs/ out} "
1414tmux_window=afl
1515
1616if [[ " $used_cores " -lt 2 ]]; then
Original file line number Diff line number Diff line change @@ -576,7 +576,8 @@ fn run_decode_subcmd(files: &[PathBuf], cli_args: &Args) {
576576 match decode_eval_check ( & buf, cli_args, true ) {
577577 Ok ( ( ) ) => ( ) ,
578578 Err ( Error :: Decode ( e) ) => println ! ( "error decoding file: {e}" ) ,
579- Err ( Error :: Check ( e) ) => println ! ( "check error: {e:?}" ) ,
579+ // No need to print anything extra, we already get the mismatch messages.
580+ Err ( Error :: Check ( _e) ) => ( ) ,
580581 }
581582 }
582583}
Original file line number Diff line number Diff line change 1+ # Allow overriding the fuzz directories
2+ fuzz_in := env (" FUZZ_IN" , " fuzz/runs/in" )
3+ fuzz_out := env (" FUZZ_OUT" , " fuzz/runs/out" )
4+
5+ alias f := fuzz
6+ alias fp := fuzz-parallel
7+ alias fa := fuzz-attach
8+ alias fq := fuzz-parallel-quit
9+ alias d := decode
10+ alias t := test
11+
12+ _ default :
13+ {{ just_executable () }} --list
14+
15+ # Run non-fuzzing tests
16+ test :
17+ cargo test --workspace
18+
19+ # Create directories and build the executable, but don't start fuzzing.
20+ _ fuzz-setup :
21+ mkdir -p " {{ fuzz_in }} "
22+ echo > " {{ fuzz_in }} /empty"
23+ cargo afl build -p rustc_apfloat-fuzz --release
24+
25+ # Build the instrumented executable and fuzz it. See also: `fuzz-parallel`.
26+ fuzz : _fuzz-setup
27+ cargo afl fuzz -i " {{ fuzz_in }} " -o " {{ fuzz_out }} " target/ release/ rustc_apfloat-fuzz
28+
29+ # Start fuzzing in parallel. Note this must be stopped with fuzz-parallel-quit (see fuzz-parallel.sh).
30+ fuzz-parallel * args : _fuzz-setup
31+ etc/ fuzz-parallel.sh {{ args }}
32+
33+ # Attach to a running parallel fuzz session
34+ fuzz-attach :
35+ tmux attach -t afl01
36+
37+ # Stop parallel fuzzing
38+ fuzz-parallel-quit :
39+ tmux list-sessions | cut -d' :' -f1 | grep afl | xargs -iSESS tmux kill-session -t SESS
40+
41+ all-crashes := ' "' + fuzz_out + ' "/*/crashes/*'
42+
43+ # Print the result of crashes in the fuzz output directory
44+ decode * paths = all-crashes :
45+ ls {{ all-crashes }}
46+ cargo run -p rustc_apfloat-fuzz -- decode {{ paths }}
You can’t perform that action at this time.
0 commit comments