Files
wasmtime/cranelift/peepmatic/crates/fuzzing/src/parser.rs
Nick Fitzgerald 1a7670f964 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.
2020-05-14 07:50:58 -07:00

30 lines
613 B
Rust

//! 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()));
}
}