Skip to content

Commit

Permalink
Fix fuzz tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sthiele committed Apr 12, 2024
1 parent 483bc46 commit b45e5c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Cargo.lock
.directory
Notes.md
fuzz/coverage
13 changes: 13 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# How to run fuzz tests

1. Install [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz)

```sh
cargo install cargo-fuzz
```

2. Run a fuzzing target and find bugs! (needs nighly toolchain)

```sh
cargo +nightly fuzz run fuzz_target_1`
```
10 changes: 5 additions & 5 deletions fuzz/fuzz_targets/fuzz_target_1.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![no_main]
extern crate winnow;
use flatzinc::Stmt;
use libfuzzer_sys::fuzz_target;
pub use winnow::error::ContextError;

fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
if let Ok(mut utf8_str) = std::str::from_utf8(data) {
match flatzinc::statement::<ContextError>(&mut utf8_str) {
Ok(result) => println!("{:#?}", result),
Err(e) => print!("Failed to parse flatzinc: {:?}", e),
if let Ok(utf8_str) = std::str::from_utf8(data) {
match <Stmt as std::str::FromStr>::from_str(utf8_str) {
Ok(result) => println!("{}\n{:#?}", utf8_str, result),
Err(_) => print!(" Failed to parse test data."),
}
} else {
// print!("No valid utf8!")
Expand Down

0 comments on commit b45e5c6

Please sign in to comment.