Skip to content

Commit

Permalink
Merge pull request #9 from stusmall/add-fuzzing
Browse files Browse the repository at this point in the history
Add fuzzing for the rust parser
  • Loading branch information
Zheoni authored Feb 1, 2024
2 parents 0402305 + 4aff3f4 commit 281f52d
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
deploy-playground:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup wasm-pack
uses: jetli/wasm-pack-action@v0.4.0
Expand Down
35 changes: 32 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,41 @@ env:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-stable-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose

fuzz:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-nightly-${{ hashFiles('**/Cargo.lock') }}
- name: Use nightly toolchain
run: rustup default nightly
- name: Install cargo fuzz
run: cargo fuzz --version || cargo install --locked cargo-fuzz
- name: Fuzz parser
run: cargo fuzz run --release fuzz_parser -- -max_total_time=120 -jobs=2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
.DS_Store
out/
.idea
25 changes: 25 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ name = "convert"
harness = false

[workspace]
members = [".", "playground", "bindings"]
members = [".", "playground", "bindings", "fuzz"]
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 = "cooklang-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.cooklang]
path = ".."

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

use libfuzzer_sys::fuzz_target;

use cooklang::{CooklangParser, Extensions, Converter};

fuzz_target!(|contents: &str| {
let parser = CooklangParser::new(Extensions::all(), Converter::default());
let _ = parser.parse(&contents);
});

0 comments on commit 281f52d

Please sign in to comment.