Factored out test program and fuzzing features; core crate now only depends on smallvec and log.

This commit is contained in:
Chris Fallin
2021-04-18 13:38:05 -07:00
parent 34ab744f4f
commit 414f3f828d
6 changed files with 39 additions and 15 deletions

View File

@@ -1,50 +0,0 @@
/*
* Released under the terms of the Apache 2.0 license with LLVM
* exception. See `LICENSE` for details.
*/
use arbitrary::{Arbitrary, Unstructured};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;
use regalloc2::fuzzing::func::{machine_env, Func};
use regalloc2::ion;
use regalloc2::Function;
fn create_random_func(seed: u64, size: usize) -> Func {
let mut bytes: Vec<u8> = vec![];
bytes.resize(size, 0);
let mut rng = ChaCha8Rng::seed_from_u64(seed);
rng.fill(&mut bytes[..]);
loop {
let mut u = Unstructured::new(&bytes[..]);
match Func::arbitrary(&mut u) {
Ok(f) => {
return f;
}
Err(arbitrary::Error::NotEnoughData) => {
let len = bytes.len();
bytes.resize(len + 1024, 0);
rng.fill(&mut bytes[len..]);
}
Err(e) => panic!("unexpected error: {:?}", e),
}
}
}
fn main() {
const SIZE: usize = 1000 * 1000;
env_logger::init();
let env = machine_env();
for iter in 0..3 {
let func = create_random_func(iter, SIZE);
eprintln!("==== {} instructions", func.insts());
let mut stats: ion::Stats = ion::Stats::default();
for i in 0..1000 {
let out = ion::run(&func, &env).expect("regalloc did not succeed");
if i == 0 {
stats = out.stats;
}
}
eprintln!("Stats: {:?}", stats);
}
}

View File

@@ -25,6 +25,8 @@ pub mod index;
pub use index::{Block, Inst, InstRange, InstRangeIter};
pub mod checker;
#[cfg(feature = "fuzzing")]
pub mod fuzzing;
/// Register classes.