Objective event

This commit is contained in:
Andrea Fioraldi 2021-02-15 14:27:54 +01:00
parent 8059a765ed
commit 4b1c8e283b
6 changed files with 59 additions and 45 deletions

View File

@ -228,14 +228,10 @@ where
stats.display(event.name().to_string() + " #" + &sender_id.to_string()); stats.display(event.name().to_string() + " #" + &sender_id.to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::Crash { input: _ } => { Event::Objective { objective_size } => {
#[cfg(feature = "std")] let client = stats.client_stats_mut_for(sender_id);
println!("Event::Crash"); client.update_objective_size(*objective_size as u64);
Ok(BrokerEventResult::Handled) stats.display(event.name().to_string() + " #" + &sender_id.to_string());
}
Event::Timeout { input: _ } => {
#[cfg(feature = "std")]
println!("Event::Timeout");
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::Log { Event::Log {

View File

@ -112,11 +112,10 @@ where
stats.display(event.name().to_string()); stats.display(event.name().to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::Crash { input: _ } => { Event::Objective { objective_size } => {
panic!("LoggerEventManager cannot handle Event::Crash"); stats.client_stats_mut()[0].update_objective_size(*objective_size as u64);
} stats.display(event.name().to_string());
Event::Timeout { input: _ } => { Ok(BrokerEventResult::Handled)
panic!("LoggerEventManager cannot handle Event::Timeout");
} }
Event::Log { Event::Log {
severity_level, severity_level,

View File

@ -93,15 +93,10 @@ where
executions: usize, executions: usize,
phantom: PhantomData<I>, phantom: PhantomData<I>,
}, },
/// A crash was found /// A new objective was found
Crash { Objective {
/// Crashing input /// Objective corpus size
input: I, objective_size: usize,
},
/// A timeout was found
Timeout {
/// Timeouting input
input: I,
}, },
/// Write a new log /// Write a new log
Log { Log {
@ -137,8 +132,7 @@ where
executions: _, executions: _,
phantom: _, phantom: _,
} => "Stats", } => "Stats",
Event::Crash { input: _ } => "Crash", Event::Objective { objective_size: _ } => "Objective",
Event::Timeout { input: _ } => "Timeout",
Event::Log { Event::Log {
severity_level: _, severity_level: _,
message: _, message: _,

View File

@ -291,19 +291,18 @@ pub mod unix_signals {
.is_interesting_all(&input, observers, ExitKind::Crash) .is_interesting_all(&input, observers, ExitKind::Crash)
.expect("In crash handler objective feedbacks failure.".into()); .expect("In crash handler objective feedbacks failure.".into());
if obj_fitness > 0 { if obj_fitness > 0 {
state if !state
.add_if_objective(input.clone(), obj_fitness) .add_if_objective(input.clone(), obj_fitness)
.expect("In crash handler objective corpus add failure.".into()); .expect("In crash handler objective corpus add failure.".into()).is_none() {
mgr.fire(
state,
Event::Objective {
objective_size: state.objective_corpus().count(),
},
) .expect(&format!("Could not send timeouting input {:?}", input));
}
} }
mgr.fire(
state,
Event::Crash {
input: input.to_owned(),
},
)
.expect(&format!("Could not send crashing input {:?}", input));
mgr.on_restart(state).unwrap(); mgr.on_restart(state).unwrap();
println!("Waiting for broker..."); println!("Waiting for broker...");
@ -350,19 +349,18 @@ pub mod unix_signals {
.is_interesting_all(&input, observers, ExitKind::Timeout) .is_interesting_all(&input, observers, ExitKind::Timeout)
.expect("In timeout handler objective feedbacks failure.".into()); .expect("In timeout handler objective feedbacks failure.".into());
if obj_fitness > 0 { if obj_fitness > 0 {
state if !state
.add_if_objective(input.clone(), obj_fitness) .add_if_objective(input.clone(), obj_fitness)
.expect("In timeout handler objective corpus add failure.".into()); .expect("In timeout handler objective corpus add failure.".into()).is_none() {
mgr.fire(
state,
Event::Objective {
objective_size: state.objective_corpus().count(),
},
) .expect(&format!("Could not send timeouting input {:?}", input));
}
} }
mgr.fire(
state,
Event::Timeout {
input: input.to_owned(),
},
)
.expect(&format!("Could not send timeouting input {:?}", input));
mgr.on_restart(state).unwrap(); mgr.on_restart(state).unwrap();
mgr.await_restart_safe(); mgr.await_restart_safe();

View File

@ -260,6 +260,18 @@ where
pub fn objective_feedbacks_mut(&mut self) -> &mut OFT { pub fn objective_feedbacks_mut(&mut self) -> &mut OFT {
&mut self.objective_feedbacks &mut self.objective_feedbacks
} }
/// Returns the objective corpus
#[inline]
pub fn objective_corpus(&self) -> &OC {
&self.objective_corpus
}
/// Returns the mutable objective corpus
#[inline]
pub fn objective_corpus_mut(&mut self) -> &mut OC {
&mut self.objective_corpus
}
// TODO move some of these, like evaluate_input, to FuzzingEngine // TODO move some of these, like evaluate_input, to FuzzingEngine
#[inline] #[inline]

View File

@ -15,6 +15,8 @@ pub struct ClientStats {
pub corpus_size: u64, pub corpus_size: u64,
/// The total executions for this client /// The total executions for this client
pub executions: u64, pub executions: u64,
/// The size of the objectives corpus for this client
pub objective_size: u64,
/// The last reported executions for this client /// The last reported executions for this client
pub last_window_executions: u64, pub last_window_executions: u64,
/// The last time we got this information /// The last time we got this information
@ -41,6 +43,11 @@ impl ClientStats {
pub fn update_corpus_size(&mut self, corpus_size: u64) { pub fn update_corpus_size(&mut self, corpus_size: u64) {
self.corpus_size = corpus_size; self.corpus_size = corpus_size;
} }
/// We got a new information about objective corpus size for this client, insert them.
pub fn update_objective_size(&mut self, objective_size: u64) {
self.objective_size = objective_size;
}
/// Get the calculated executions per second for this client /// Get the calculated executions per second for this client
pub fn execs_per_sec(&mut self, cur_time: time::Duration) -> u64 { pub fn execs_per_sec(&mut self, cur_time: time::Duration) -> u64 {
@ -93,6 +100,13 @@ pub trait Stats {
.fold(0u64, |acc, x| acc + x.corpus_size) .fold(0u64, |acc, x| acc + x.corpus_size)
} }
/// Amount of elements in the objectives (combined for all children)
fn objective_size(&self) -> u64 {
self.client_stats()
.iter()
.fold(0u64, |acc, x| acc + x.objective_size)
}
/// Total executions /// Total executions
#[inline] #[inline]
fn total_execs(&mut self) -> u64 { fn total_execs(&mut self) -> u64 {
@ -155,10 +169,11 @@ where
fn display(&mut self, event_msg: String) { fn display(&mut self, event_msg: String) {
let fmt = format!( let fmt = format!(
"[{}] clients: {}, corpus: {}, executions: {}, exec/sec: {}", "[{}] clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}",
event_msg, event_msg,
self.client_stats().len(), self.client_stats().len(),
self.corpus_size(), self.corpus_size(),
self.objective_size(),
self.total_execs(), self.total_execs(),
self.execs_per_sec() self.execs_per_sec()
); );