Skip to content

Commit

Permalink
add fuzzing to the CI + dev tools
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Apr 8, 2024
1 parent 62eda41 commit 60959c5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: CI
env:
CARGO_TERM_COLOR: always
RUST_TOOLCHAIN: stable
RUST_TOOLCHAIN_NIGHTLY: nightly
RUST_TOOLCHAIN_MSRV: 1.75.0
RUST_TOOLCHAIN_BETA: beta

Expand Down Expand Up @@ -328,15 +329,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v1

# semver-checks:
# needs: [check, check-msrv]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - name: Check semver
# uses: obi1kenobi/cargo-semver-checks-action@v2
# with:
# rust-toolchain: ${{env.RUST_TOOLCHAIN}}
- uses: dtolnay/rust-toolchain@nightly
with:
toolchain: ${{env.RUST_TOOLCHAIN_NIGHTLY}}
- name: Install cargo-fuzz
run: |
cargo install cargo-fuzz
- name: cargo fuzz check
run: |
cargo fuzz run -max-total-time=30 fuzz_employee_db
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [".", "venndb-macros", "venndb-usage"]
members = [".", "fuzz", "venndb-macros", "venndb-usage"]

[package]
description = "an in-memory database in Rust for rows queried using bit (flag) columns"
Expand Down
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
21 changes: 21 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "venndb-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] }

[dependencies.venndb]
path = ".."

[[bin]]
name = "fuzz_employee_db"
path = "fuzz_targets/fuzz_employee_db.rs"
test = false
doc = false
bench = false
25 changes: 25 additions & 0 deletions fuzz/fuzz_targets/fuzz_employee_db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![no_main]

use libfuzzer_sys::arbitrary::{self, Arbitrary};
use libfuzzer_sys::fuzz_target;
use venndb::VennDB;

#[derive(Clone, Debug, Arbitrary, VennDB)]
pub struct Employee {
#[venndb(key)]
id: u16,
_name: String,
earth: bool,
#[venndb(filter)]
faction: Faction,
}

#[derive(Clone, Debug, Arbitrary, PartialEq, Eq, Hash)]
pub enum Faction {
Rebel,
Empire,
}

fuzz_target!(|rows: Vec<Employee>| {
let _ = EmployeeDB::from_rows(rows);
});
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ watch-docs:

watch-check:
cargo watch -x check -x test

fuzz:
cargo +nightly fuzz run fuzz_employee_db

fuzz-30s:
cargo +nightly fuzz run fuzz_employee_db -- -max_total_time=30

0 comments on commit 60959c5

Please sign in to comment.