Whoops: add fuzzers code.
This commit is contained in:
parent
6f62f9c5dc
commit
5c92517245
|
@ -0,0 +1,4 @@
|
|||
|
||||
target
|
||||
corpus
|
||||
artifacts
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
[package]
|
||||
name = "tor-consdiff-fuzz"
|
||||
version = "0.0.0"
|
||||
authors = ["Automatically generated"]
|
||||
publish = false
|
||||
edition = "2018"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.3"
|
||||
|
||||
[dependencies.tor-consdiff]
|
||||
path = ".."
|
||||
|
||||
# Prevent this from interfering with workspaces
|
||||
[workspace]
|
||||
members = ["."]
|
||||
|
||||
[[bin]]
|
||||
name = "compare_diffs"
|
||||
path = "fuzz_targets/compare_diffs.rs"
|
||||
test = false
|
||||
doc = false
|
|
@ -0,0 +1,21 @@
|
|||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if let Ok(s) = std::str::from_utf8(data) {
|
||||
let parts:Vec<_> = s.splitn(2, "=====\n").collect();
|
||||
if parts.len() == 2 {
|
||||
let orig = parts[0];
|
||||
let diff = parts[1];
|
||||
let out1 = tor_consdiff::apply_diff_trivial(orig, diff);
|
||||
let out2 = tor_consdiff::apply_diff(orig, diff, None);
|
||||
// dbg!(&out1);
|
||||
// dbg!(&out2);
|
||||
assert_eq!(out1.is_err(), out2.is_err());
|
||||
match (out1, out2) {
|
||||
(Ok(a), Ok(b)) => assert_eq!(a.to_string(),b.to_string()),
|
||||
(_, _) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue