use usize for worker_id (#755)

This commit is contained in:
bmc-msft
2021-03-30 22:27:10 -04:00
committed by GitHub
parent 522ae4c5d9
commit 6aca32ed9c
3 changed files with 13 additions and 13 deletions

View File

@ -25,7 +25,7 @@ pub fn build_fuzz_config(args: &clap::ArgMatches<'_>, common: CommonConfig) -> R
let target_env = get_cmd_env(CmdType::Target, args)?; let target_env = get_cmd_env(CmdType::Target, args)?;
let target_options = get_cmd_arg(CmdType::Target, args); let target_options = get_cmd_arg(CmdType::Target, args);
let target_workers = value_t!(args, "target_workers", u64).unwrap_or_default(); let target_workers = value_t!(args, "target_workers", usize).unwrap_or_default();
let readonly_inputs = None; let readonly_inputs = None;
let check_fuzzer_help = args.is_present(CHECK_FUZZER_HELP); let check_fuzzer_help = args.is_present(CHECK_FUZZER_HELP);
let expect_crash_on_failure = !args.is_present(DISABLE_EXPECT_CRASH_ON_FAILURE); let expect_crash_on_failure = !args.is_present(DISABLE_EXPECT_CRASH_ON_FAILURE);

View File

@ -35,9 +35,9 @@ const PROC_INFO_PERIOD: Duration = Duration::from_secs(30);
// Period of reporting fuzzer-generated runtime stats. // Period of reporting fuzzer-generated runtime stats.
const RUNTIME_STATS_PERIOD: Duration = Duration::from_secs(60); const RUNTIME_STATS_PERIOD: Duration = Duration::from_secs(60);
pub fn default_workers() -> u64 { pub fn default_workers() -> usize {
let cpus = num_cpus::get() as u64; let cpus = num_cpus::get();
u64::max(1, cpus - 1) usize::max(1, cpus - 1)
} }
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
@ -50,7 +50,7 @@ pub struct Config {
pub target_options: Vec<String>, pub target_options: Vec<String>,
#[serde(default = "default_workers")] #[serde(default = "default_workers")]
pub target_workers: u64, pub target_workers: usize,
pub ensemble_sync_delay: Option<u64>, pub ensemble_sync_delay: Option<u64>,
#[serde(default = "default_bool_true")] #[serde(default = "default_bool_true")]
@ -72,7 +72,7 @@ impl LibFuzzerFuzzTask {
Ok(Self { config }) Ok(Self { config })
} }
fn workers(&self) -> u64 { fn workers(&self) -> usize {
match self.config.target_workers { match self.config.target_workers {
0 => default_workers(), 0 => default_workers(),
x => x, x => x,
@ -95,7 +95,7 @@ impl LibFuzzerFuzzTask {
let new_crashes = self.config.crashes.monitor_results(new_result, true); let new_crashes = self.config.crashes.monitor_results(new_result, true);
let (stats_sender, stats_receiver) = mpsc::unbounded_channel(); let (stats_sender, stats_receiver) = mpsc::unbounded_channel();
let report_stats = report_runtime_stats(self.workers() as usize, stats_receiver, hb_client); let report_stats = report_runtime_stats(self.workers(), stats_receiver, hb_client);
let fuzzers = self.run_fuzzers(Some(&stats_sender)); let fuzzers = self.run_fuzzers(Some(&stats_sender));
futures::try_join!(resync, new_inputs, new_crashes, fuzzers, report_stats)?; futures::try_join!(resync, new_inputs, new_crashes, fuzzers, report_stats)?;
@ -145,7 +145,7 @@ impl LibFuzzerFuzzTask {
// or discovered fault. The monitor restarts the libFuzzer when it exits. // or discovered fault. The monitor restarts the libFuzzer when it exits.
pub async fn start_fuzzer_monitor( pub async fn start_fuzzer_monitor(
&self, &self,
worker_id: u64, worker_id: usize,
stats_sender: Option<&StatsSender>, stats_sender: Option<&StatsSender>,
) -> Result<()> { ) -> Result<()> {
let local_input_dir = self.create_local_temp_dir().await?; let local_input_dir = self.create_local_temp_dir().await?;
@ -175,7 +175,7 @@ impl LibFuzzerFuzzTask {
async fn run_fuzzer( async fn run_fuzzer(
&self, &self,
local_inputs: impl AsRef<std::path::Path>, local_inputs: impl AsRef<std::path::Path>,
worker_id: u64, worker_id: usize,
stats_sender: Option<&StatsSender>, stats_sender: Option<&StatsSender>,
) -> Result<()> { ) -> Result<()> {
let crash_dir = self.create_local_temp_dir().await?; let crash_dir = self.create_local_temp_dir().await?;
@ -278,7 +278,7 @@ impl LibFuzzerFuzzTask {
fn try_report_iter_update( fn try_report_iter_update(
stats_sender: &StatsSender, stats_sender: &StatsSender,
worker_id: u64, worker_id: usize,
run_id: Uuid, run_id: Uuid,
line: &str, line: &str,
) -> Result<()> { ) -> Result<()> {
@ -294,7 +294,7 @@ fn try_report_iter_update(
Ok(()) Ok(())
} }
async fn report_fuzzer_sys_info(worker_id: u64, run_id: Uuid, fuzzer_pid: u32) -> Result<()> { async fn report_fuzzer_sys_info(worker_id: usize, run_id: Uuid, fuzzer_pid: u32) -> Result<()> {
loop { loop {
system::refresh()?; system::refresh()?;
@ -325,7 +325,7 @@ async fn report_fuzzer_sys_info(worker_id: u64, run_id: Uuid, fuzzer_pid: u32) -
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct RuntimeStats { pub struct RuntimeStats {
worker_id: u64, worker_id: usize,
run_id: Uuid, run_id: Uuid,
count: u64, count: u64,
execs_sec: f64, execs_sec: f64,

View File

@ -119,7 +119,7 @@ impl Event {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum EventData { pub enum EventData {
WorkerId(u64), WorkerId(usize),
InstanceId(Uuid), InstanceId(Uuid),
JobId(Uuid), JobId(Uuid),
TaskId(Uuid), TaskId(Uuid),