Skip to content

Commit

Permalink
Merge pull request #81 from kdarkhan/fuzz-tests
Browse files Browse the repository at this point in the history
Implement  fuzzer for normalize
  • Loading branch information
mgeisler authored Sep 16, 2023
2 parents 057547e + c77777c commit 742a6f2
Show file tree
Hide file tree
Showing 7 changed files with 604 additions and 558 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ jobs:
restore-keys: |
fuzz-corpus
- name: Run fuzz test
run: cargo fuzz run group_events -- -only_ascii=1 -max_total_time=30

- name: Minimize fuzz corpus
run: cargo fuzz cmin group_events
- name: Run group_events fuzzer and minimize corpus
run: |
cargo fuzz run group_events -- -only_ascii=1 -max_total_time=30
cargo fuzz cmin group_events
- name: Run normalize fuzzer and minimize corpus
run: |
cargo fuzz run normalize -- -only_ascii=1 -max_total_time=30
cargo fuzz cmin normalize
clippy:
name: Clippy
Expand Down
22 changes: 12 additions & 10 deletions fuzz/Cargo.lock

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

7 changes: 7 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
polib = "0.2.0"
pretty_assertions = "1.3.0"

[dependencies.mdbook-i18n-helpers]
Expand All @@ -26,3 +27,9 @@ name = "group_events"
path = "fuzz_targets/group_events.rs"
test = false
doc = false

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

use libfuzzer_sys::fuzz_target;
use mdbook_i18n_helpers::normalize::normalize;
use polib::catalog::Catalog;
use polib::message::Message;
use polib::metadata::CatalogMetadata;

fuzz_target!(|translations: Vec<(&str, &str)>| {
let catalog = create_catalog(translations);
let _ = normalize(catalog);
});

fn create_catalog(translations: Vec<(&str, &str)>) -> Catalog {
let mut catalog = Catalog::new(CatalogMetadata::new());
for (idx, (msgid, msgstr)) in translations.iter().enumerate() {
let message = Message::build_singular()
.with_source(format!("foo.md:{idx}"))
.with_msgid(String::from(*msgid))
.with_msgstr(String::from(*msgstr))
.done();
catalog.append_or_update(message);
}
catalog
}
Loading

0 comments on commit 742a6f2

Please sign in to comment.