Skip to content

Commit e64951d

Browse files
Adam ReicholdPaulGrandperrin
authored andcommitted
Extend example to include usage of arbitrary crate
Closes #17
1 parent 7c18a4f commit e64951d

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

example/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@ name = "example"
33
version = "0.0.0"
44
authors = ["Paul Grandperrin <[email protected]>"]
55

6+
[[bin]]
7+
name = "example"
8+
path = "src/main.rs"
9+
10+
[[bin]]
11+
name = "arbitrary-example"
12+
path = "src/arbitrary_main.rs"
13+
614
[dependencies]
715
honggfuzz = {path = ".."}

example/src/arbitrary_main.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#[macro_use] extern crate honggfuzz;
2+
3+
fn main() {
4+
// Here you can parse `std::env::args and
5+
// setup / initialize your project
6+
7+
// You have full control over the loop but
8+
// you're supposed to call `fuzz` ad vitam aeternam
9+
loop {
10+
// The fuzz macro gives an arbitrary object (see `arbitrary crate`)
11+
// to a closure-like block of code.
12+
// For performance, it is recommended that you use the native type
13+
// `&[u8]` when possible.
14+
// Here, this tuple will contain three "random" values of different type.
15+
fuzz!(|data: (bool, i32, f32)| {
16+
17+
if data.0 == false {return}
18+
if data.1 < 0 {return}
19+
if data.2 > 1.0 {return}
20+
panic!("BOOM")
21+
22+
});
23+
}
24+
}

example/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ RUSTFLAGS="" cargo build
8282

8383
# but when we run it, it should fail with a useful error message and status 17
8484
set +e
85-
RUSTFLAGS="" cargo run
85+
RUSTFLAGS="" cargo run --bin example
8686
status=$?
8787
set -e
8888
test $status -eq 17

0 commit comments

Comments
 (0)