fuzz: add threads flag

This commit is contained in:
Richard Patel 2022-04-07 06:11:03 +02:00
parent 9c433919fc
commit fd94a6c493
4 changed files with 27 additions and 13 deletions

1
Cargo.lock generated
View File

@ -300,6 +300,7 @@ dependencies = [
name = "ppc750cl-fuzz" name = "ppc750cl-fuzz"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"clap",
"num_cpus", "num_cpus",
"ppc750cl", "ppc750cl",
] ]

View File

@ -8,5 +8,6 @@ description = "Complete fuzzer for ppc750cl"
repository = "https://github.com/terorie/ppc750cl" repository = "https://github.com/terorie/ppc750cl"
[dependencies] [dependencies]
clap = "3"
num_cpus = "1.13" num_cpus = "1.13"
ppc750cl = { path = "../disasm", version = "0.2.0" } ppc750cl = { path = "../disasm", version = "0.2.0" }

View File

@ -1,5 +1,6 @@
use std::io::Write; use std::io::Write;
use std::ops::Range; use std::ops::Range;
use std::str::FromStr;
use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
@ -8,8 +9,24 @@ use ppc750cl::formatter::FormattedIns;
use ppc750cl::Ins; use ppc750cl::Ins;
fn main() { fn main() {
let matches = clap::Command::new("ppc750cl-fuzz")
.version("0.2.0")
.about("Complete \"fuzzer\" for ppc750cl disassembler")
.arg(
clap::Arg::new("threads")
.short('t')
.long("--threads")
.takes_value(true)
.help("Number of threads to use (default num CPUs)"),
)
.get_matches();
let threads = match matches.value_of("threads") {
Some(t) => u32::from_str(t).expect("invalid threads flag"),
None => num_cpus::get() as u32,
};
let start = Instant::now(); let start = Instant::now();
let fuzzer = MultiFuzzer::new(num_cpus::get() as u32); let fuzzer = MultiFuzzer::new(threads);
fuzzer.run(); fuzzer.run();
println!("Finished in {:.2}s", start.elapsed().as_secs_f32()); println!("Finished in {:.2}s", start.elapsed().as_secs_f32());
} }

View File

@ -534,18 +534,13 @@ impl Isa {
let use_match_arms = token_stream!(use_match_arms); let use_match_arms = token_stream!(use_match_arms);
let suffix_match_arms = token_stream!(suffix_match_arms); let suffix_match_arms = token_stream!(suffix_match_arms);
let simplified_ins_match_arms = token_stream!(simplified_ins_match_arms); let simplified_ins_match_arms = token_stream!(simplified_ins_match_arms);
let field_accessors = self let field_accessors =
.fields TokenStream::from_iter(self.fields.iter().map(|field| field.construct_accessor()));
.iter() let modifier_accessors = TokenStream::from_iter(
.map(|field| field.construct_accessor()) self.modifiers
.collect::<Vec<_>>(); .iter()
let field_accessors = token_stream!(field_accessors); .map(|modifier| modifier.construct_accessor()),
let modifier_accessors = self );
.modifiers
.iter()
.map(|modifier| modifier.construct_accessor())
.collect::<Vec<_>>();
let modifier_accessors = token_stream!(modifier_accessors);
// Generate final fields function. // Generate final fields function.
let ins_impl = quote! { let ins_impl = quote! {
#[allow(clippy::all, unused_mut)] #[allow(clippy::all, unused_mut)]