#[path = "../tests/support/mod.rs"]
mod support;
use std::path::PathBuf;
use std::process::ExitCode;
fn main() -> ExitCode {
let mut pos = Vec::new();
let mut include = Vec::new();
let (mut jobs, mut stride, mut samples, mut verbose) = (
std::thread::available_parallelism()
.map_or(4, |n| n.get())
.min(support::mutate::MAX_JOBS),
1usize,
400u64,
false,
);
let mut it = std::env::args().skip(1);
while let Some(a) = it.next() {
let mut num = |what: &str| -> usize {
it.next()
.and_then(|v| v.parse().ok())
.unwrap_or_else(|| panic!("{what} needs a number"))
};
match a.as_str() {
"--jobs" => jobs = num("--jobs"),
"--stride" => stride = num("--stride"),
"--samples" => samples = num("--samples") as u64,
"-I" => include.push(PathBuf::from(it.next().expect("-I needs a directory"))),
"-v" => verbose = true,
_ => pos.push(PathBuf::from(a)),
}
}
if pos.len() != 2 {
eprintln!("usage: mutate <object.o> <source.c> [--jobs N] [--stride N] [--samples N] [-I DIR] [-v]");
return ExitCode::from(2);
}
let elf = std::fs::read(&pos[0]).expect("read object");
if std::env::var_os("CVERIF_MUTATE_TRACE").is_none() {
std::panic::set_hook(Box::new(|_| {}));
}
let s = support::mutate::campaign(&elf, &pos[1], &include, stride, jobs, samples);
let suspects = s.suspects();
println!(
"{}: {} mutants, {} killed ({:.1}%), {} not vouched for, {} survived ({} seen to differ)",
pos[0].display(),
s.mutants,
s.killed,
100.0 * s.killed as f64 / s.mutants.max(1) as f64,
s.lost(),
s.survivors.len(),
suspects.len()
);
println!(" of which {} retargeted relocations", s.relocations);
for (why, n) in &s.not_vouched {
println!(" not vouched {n:6} {why}");
}
for p in &s.panics {
println!(" PANIC {p}");
}
for v in &s.survivors {
match &v.difference {
Some(d) if v.bounded => println!(" beyond-bound {} {}\n {d}", v.func, v.what),
Some(d) => println!(" DIFFERS {} {}\n {d}", v.func, v.what),
None if verbose => println!(" neutral? {} {}", v.func, v.what),
None => {}
}
}
if suspects.is_empty() {
ExitCode::SUCCESS
} else {
ExitCode::from(1)
}
}