peepmatic: Introduce the peepmatic-fuzzing crate
This crate contains oracles, generators, and fuzz targets for use with fuzzing engines (e.g. libFuzzer). This doesn't contain the actual `libfuzzer_sys::fuzz_target!` definitions (those are in the `peepmatic-fuzz` crate) but does those definitions are one liners calling out to functions defined in this crate.
This commit is contained in:
29
cranelift/peepmatic/crates/fuzzing/src/parser.rs
Normal file
29
cranelift/peepmatic/crates/fuzzing/src/parser.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
//! Utilities for fuzzing our DSL's parser.
|
||||
|
||||
use peepmatic::Optimizations;
|
||||
use std::str;
|
||||
|
||||
/// Attempt to parse the given string as if it were a snippet of our DSL.
|
||||
pub fn parse(data: &[u8]) {
|
||||
let source = match str::from_utf8(data) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
let buf = match wast::parser::ParseBuffer::new(&source) {
|
||||
Ok(buf) => buf,
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
let _ = wast::parser::parse::<Optimizations>(&buf);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn check_parse() {
|
||||
crate::check(|s: String| parse(s.as_bytes()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user