Skip to content

Commit

Permalink
cranelift: Build a runtest case from fuzzer TestCase's
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Aug 3, 2022
1 parent 55215bb commit d11dce8
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion cranelift/fuzzgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,55 @@ use cranelift::codegen::ir::Function;
use cranelift::codegen::Context;
use cranelift::prelude::*;
use cranelift_native::builder_with_options;
use std::fmt;

mod config;
mod function_generator;

pub type TestCaseInput = Vec<DataValue>;

#[derive(Debug)]
pub struct TestCase {
pub func: Function,
/// Generate multiple test inputs for each test case.
/// This allows us to get more coverage per compilation, which may be somewhat expensive.
pub inputs: Vec<TestCaseInput>,
}

impl fmt::Debug for TestCase {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
r#";; Fuzzgen test case
test interpret
test run
set enable_llvm_abi_extensions
target aarch64
target s390x
target x86_64
"#
)?;

writeln!(f, "{}", self.func)?;

for input in self.inputs.iter() {
let args = input
.iter()
.map(|val| format!("{}", val))
.collect::<Vec<_>>()
.join(", ");

// TODO: We don't know the expected outputs, maybe we can run the interpreter
// here to figure them out? Should work, however we need to be careful to catch
// panics in case its the interpreter that is failing.
writeln!(f, "; run: {}({}) == TODO", self.func.name, args)?;
}

Ok(())
}
}

impl<'a> Arbitrary<'a> for TestCase {
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
FuzzGen::new(u)
Expand Down

0 comments on commit d11dce8

Please sign in to comment.