tree: 2a12984d98fa0e9524278569c1ab4e0df380933f
  1. cargo_fuzztest/
  2. coverage/
  3. e2e_tests/
  4. engine/
  5. fuzztest_macro/
  6. src/
  7. tests/
  8. .rustfmt.toml
  9. BUILD
  10. Cargo.toml
  11. README.md
  12. rust-toolchain.toml
rust/README.md

FuzzTest Rust

A framework for fuzzing Rust projects using Google FuzzTest.

Prerequisites

  1. Clone the repository.

  2. Build the C++ Centipede static library engine using Bazel (from the repository root):

    cd /path/to/fuzztest
    bazel build //centipede:centipede_engine_static
    
  3. Copy the libcentipede_engine_static.a library to another location:

    mkdir -p $HOME/.local/lib
    cp /path/to/fuzztest/bazel-bin/centipede/libcentipede_engine_static.a \
        $HOME/.local/lib/
    

Setup a Project

  1. Create a new Rust project:

    cargo new my_fuzz_project --bin
    
  2. Add fuzztest as a dependency in your Cargo.toml:

    [dependencies]
    fuzztest = { path = "/path/to/fuzztest/rust" }
    googletest = "0.14.3"
    

Write a Fuzz Test

In src/main.rs:

#[cfg(test)]
mod tests {
    use fuzztest::domains::arbitrary::Arbitrary;
    use fuzztest::fuzztest;

    #[fuzztest(a = Arbitrary::<i32>::default(), b = Arbitrary::<i32>::default())]
    fn test_addition(a: i32, b: i32) {
        let _ = a.wrapping_add(b);
    }
}

Build and Run Fuzz Tests

To run the fuzz tests, you must specify:

RUSTFLAGS="-L $HOME/.local/lib" cargo test __fuzztest_mod__::test_addition