fmt
This commit is contained in:
parent
68a72f583c
commit
944753c741
@ -9,7 +9,7 @@ use core::marker::PhantomData;
|
|||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
|
|
||||||
use crate::corpus::{Corpus, Testcase};
|
use crate::corpus::{Corpus, Testcase};
|
||||||
use crate::events::{EventManager, Event};
|
use crate::events::{Event, EventManager};
|
||||||
use crate::executors::Executor;
|
use crate::executors::Executor;
|
||||||
use crate::feedbacks::Feedback;
|
use crate::feedbacks::Feedback;
|
||||||
use crate::generators::Generator;
|
use crate::generators::Generator;
|
||||||
@ -177,7 +177,10 @@ where
|
|||||||
for _ in 0..num {
|
for _ in 0..num {
|
||||||
let input = generator.generate(rand)?;
|
let input = generator.generate(rand)?;
|
||||||
state.add_input(corpus, input)?;
|
state.add_input(corpus, input)?;
|
||||||
let event = Event::LoadInitial {sender_id: 0, _marker: PhantomData};
|
let event = Event::LoadInitial {
|
||||||
|
sender_id: 0,
|
||||||
|
_marker: PhantomData,
|
||||||
|
};
|
||||||
events.fire(event)?;
|
events.fire(event)?;
|
||||||
}
|
}
|
||||||
events.process(state, corpus)?;
|
events.process(state, corpus)?;
|
||||||
@ -332,7 +335,11 @@ where
|
|||||||
let cur = current_milliseconds();
|
let cur = current_milliseconds();
|
||||||
if cur - last > 60 * 100 {
|
if cur - last > 60 * 100 {
|
||||||
last = cur;
|
last = cur;
|
||||||
events.fire(Event::UpdateStats {sender_id: 0, new_execs: 1, _marker: PhantomData})?; // TODO self.new_execs});
|
events.fire(Event::UpdateStats {
|
||||||
|
sender_id: 0,
|
||||||
|
new_execs: 1,
|
||||||
|
_marker: PhantomData,
|
||||||
|
})?; // TODO self.new_execs});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ pub mod shmem_translated;
|
|||||||
pub use crate::events::llmp::LLMP;
|
pub use crate::events::llmp::LLMP;
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
use std::{marker::PhantomData, io::Write};
|
use std::{io::Write, marker::PhantomData};
|
||||||
|
|
||||||
use crate::corpus::{Corpus, Testcase};
|
use crate::corpus::{Corpus, Testcase};
|
||||||
use crate::engines::State;
|
use crate::engines::State;
|
||||||
@ -69,12 +69,37 @@ where
|
|||||||
R: Rand,
|
R: Rand,
|
||||||
// CE: CustomEvent<S, C, E, I, R>,
|
// CE: CustomEvent<S, C, E, I, R>,
|
||||||
{
|
{
|
||||||
LoadInitial {sender_id: u64, _marker: PhantomData<(S, C, E, I, R)>},
|
LoadInitial {
|
||||||
NewTestcase {sender_id: u64, input: I, fitness: u32, _marker: PhantomData<(S, C, E, I, R)>},
|
sender_id: u64,
|
||||||
UpdateStats {sender_id: u64, new_execs: usize, _marker: PhantomData<(S, C, E, I, R)>},
|
_marker: PhantomData<(S, C, E, I, R)>,
|
||||||
Crash {sender_id: u64, input: I, _marker: PhantomData<(S, C, E, I, R)>},
|
},
|
||||||
Timeout {sender_id: u64, input: I, _marker: PhantomData<(S, C, E, I, R)>},
|
NewTestcase {
|
||||||
Log {sender_id: u64, severity_level: u8, message: String, _marker: PhantomData<(S, C, E, I, R)>},
|
sender_id: u64,
|
||||||
|
input: I,
|
||||||
|
fitness: u32,
|
||||||
|
_marker: PhantomData<(S, C, E, I, R)>,
|
||||||
|
},
|
||||||
|
UpdateStats {
|
||||||
|
sender_id: u64,
|
||||||
|
new_execs: usize,
|
||||||
|
_marker: PhantomData<(S, C, E, I, R)>,
|
||||||
|
},
|
||||||
|
Crash {
|
||||||
|
sender_id: u64,
|
||||||
|
input: I,
|
||||||
|
_marker: PhantomData<(S, C, E, I, R)>,
|
||||||
|
},
|
||||||
|
Timeout {
|
||||||
|
sender_id: u64,
|
||||||
|
input: I,
|
||||||
|
_marker: PhantomData<(S, C, E, I, R)>,
|
||||||
|
},
|
||||||
|
Log {
|
||||||
|
sender_id: u64,
|
||||||
|
severity_level: u8,
|
||||||
|
message: String,
|
||||||
|
_marker: PhantomData<(S, C, E, I, R)>,
|
||||||
|
},
|
||||||
//Custom {sender_id: u64, custom_event: CE},
|
//Custom {sender_id: u64, custom_event: CE},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,54 +114,107 @@ where
|
|||||||
{
|
{
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
Event::LoadInitial {sender_id, _marker} => "Initial",
|
Event::LoadInitial { sender_id, _marker } => "Initial",
|
||||||
Event::NewTestcase {sender_id, input, fitness, _marker} => "New Testcase",
|
Event::NewTestcase {
|
||||||
Event::UpdateStats {sender_id, new_execs, _marker} => "Stats",
|
sender_id,
|
||||||
Event::Crash {sender_id, input, _marker} => "Crash",
|
input,
|
||||||
Event::Timeout {sender_id, input, _marker} => "Timeout",
|
fitness,
|
||||||
Event::Log {sender_id, severity_level, message, _marker} => "Log",
|
_marker,
|
||||||
|
} => "New Testcase",
|
||||||
|
Event::UpdateStats {
|
||||||
|
sender_id,
|
||||||
|
new_execs,
|
||||||
|
_marker,
|
||||||
|
} => "Stats",
|
||||||
|
Event::Crash {
|
||||||
|
sender_id,
|
||||||
|
input,
|
||||||
|
_marker,
|
||||||
|
} => "Crash",
|
||||||
|
Event::Timeout {
|
||||||
|
sender_id,
|
||||||
|
input,
|
||||||
|
_marker,
|
||||||
|
} => "Timeout",
|
||||||
|
Event::Log {
|
||||||
|
sender_id,
|
||||||
|
severity_level,
|
||||||
|
message,
|
||||||
|
_marker,
|
||||||
|
} => "Log",
|
||||||
//Event::Custom {sender_id, custom_event} => custom_event.name(),
|
//Event::Custom {sender_id, custom_event} => custom_event.name(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_in_broker(&self, /*broker: &dyn EventManager<S, C, E, I, R>,*/ state: &mut S, corpus: &mut C) -> Result<BrokerEventResult, AflError> {
|
fn handle_in_broker(
|
||||||
|
&self,
|
||||||
|
/*broker: &dyn EventManager<S, C, E, I, R>,*/ state: &mut S,
|
||||||
|
corpus: &mut C,
|
||||||
|
) -> Result<BrokerEventResult, AflError> {
|
||||||
match self {
|
match self {
|
||||||
Event::LoadInitial {sender_id, _marker} => {
|
Event::LoadInitial { sender_id, _marker } => Ok(BrokerEventResult::Handled),
|
||||||
Ok(BrokerEventResult::Handled)
|
Event::NewTestcase {
|
||||||
}
|
sender_id,
|
||||||
Event::NewTestcase {sender_id, input, fitness, _marker} => {
|
input,
|
||||||
Ok(BrokerEventResult::Forward)
|
fitness,
|
||||||
}
|
_marker,
|
||||||
Event::UpdateStats {sender_id, new_execs, _marker} => {
|
} => Ok(BrokerEventResult::Forward),
|
||||||
|
Event::UpdateStats {
|
||||||
|
sender_id,
|
||||||
|
new_execs,
|
||||||
|
_marker,
|
||||||
|
} => {
|
||||||
// TODO
|
// TODO
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
}
|
}
|
||||||
Event::Crash {sender_id, input, _marker} => {
|
Event::Crash {
|
||||||
Ok(BrokerEventResult::Handled)
|
sender_id,
|
||||||
}
|
input,
|
||||||
Event::Timeout {sender_id, input, _marker} => {
|
_marker,
|
||||||
|
} => Ok(BrokerEventResult::Handled),
|
||||||
|
Event::Timeout {
|
||||||
|
sender_id,
|
||||||
|
input,
|
||||||
|
_marker,
|
||||||
|
} => {
|
||||||
// TODO
|
// TODO
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
},
|
}
|
||||||
Event::Log {sender_id, severity_level, message, _marker} => {
|
Event::Log {
|
||||||
|
sender_id,
|
||||||
|
severity_level,
|
||||||
|
message,
|
||||||
|
_marker,
|
||||||
|
} => {
|
||||||
//TODO: broker.log()
|
//TODO: broker.log()
|
||||||
println!("{}[{}]: {}", sender_id, severity_level, message);
|
println!("{}[{}]: {}", sender_id, severity_level, message);
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
},
|
}
|
||||||
//Event::Custom {sender_id, custom_event} => custom_event.handle_in_broker(state, corpus),
|
//Event::Custom {sender_id, custom_event} => custom_event.handle_in_broker(state, corpus),
|
||||||
_ => Ok(BrokerEventResult::Forward)
|
_ => Ok(BrokerEventResult::Forward),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_in_client(&self, /*client: &dyn EventManager<S, C, E, I, R>,*/ state: &mut S, corpus: &mut C) -> Result<(), AflError> {
|
fn handle_in_client(
|
||||||
|
&self,
|
||||||
|
/*client: &dyn EventManager<S, C, E, I, R>,*/ state: &mut S,
|
||||||
|
corpus: &mut C,
|
||||||
|
) -> Result<(), AflError> {
|
||||||
match self {
|
match self {
|
||||||
Event::NewTestcase {sender_id, input, fitness, _marker} => {
|
Event::NewTestcase {
|
||||||
|
sender_id,
|
||||||
|
input,
|
||||||
|
fitness,
|
||||||
|
_marker,
|
||||||
|
} => {
|
||||||
let mut testcase = Testcase::new(input.to_owned());
|
let mut testcase = Testcase::new(input.to_owned());
|
||||||
testcase.set_fitness(*fitness);
|
testcase.set_fitness(*fitness);
|
||||||
corpus.add(testcase);
|
corpus.add(testcase);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(AflError::Unknown("Received illegal message that message should not have arrived.".into()))
|
_ => Err(AflError::Unknown(
|
||||||
|
"Received illegal message that message should not have arrived.".into(),
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +228,6 @@ where
|
|||||||
E: Executor<I>,
|
E: Executor<I>,
|
||||||
I: Input,
|
I: Input,
|
||||||
R: Rand,
|
R: Rand,
|
||||||
//CE: CustomEvent<S, C, E, I, R>,
|
|
||||||
{
|
{
|
||||||
/// Check if this EventaManager support a given Event type
|
/// Check if this EventaManager support a given Event type
|
||||||
/// To compare events, use Event::name().as_ptr()
|
/// To compare events, use Event::name().as_ptr()
|
||||||
@ -163,7 +240,6 @@ where
|
|||||||
/// Return the number of processes events or an error
|
/// Return the number of processes events or an error
|
||||||
fn process(&mut self, state: &mut S, corpus: &mut C) -> Result<usize, AflError>;
|
fn process(&mut self, state: &mut S, corpus: &mut C) -> Result<usize, AflError>;
|
||||||
|
|
||||||
|
|
||||||
fn on_recv(&self, _state: &mut S, corpus: &mut C) -> Result<(), AflError> {
|
fn on_recv(&self, _state: &mut S, corpus: &mut C) -> Result<(), AflError> {
|
||||||
// TODO: Better way to move out of testcase, or get ref
|
// TODO: Better way to move out of testcase, or get ref
|
||||||
//Ok(corpus.add(self.testcase.take().unwrap()))
|
//Ok(corpus.add(self.testcase.take().unwrap()))
|
||||||
@ -209,31 +285,30 @@ where
|
|||||||
W: Write,
|
W: Write,
|
||||||
//CE: CustomEvent<S, C, E, I, R>,
|
//CE: CustomEvent<S, C, E, I, R>,
|
||||||
{
|
{
|
||||||
fn enabled(&self) -> bool
|
fn enabled(&self) -> bool {
|
||||||
{
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fire(&mut self, event: Event<S, C, E, I, R>) -> Result<(), AflError>
|
fn fire(&mut self, event: Event<S, C, E, I, R>) -> Result<(), AflError> {
|
||||||
{
|
|
||||||
self.events.push(event);
|
self.events.push(event);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(&mut self, state: &mut S, corpus: &mut C) -> Result<usize, AflError> {
|
fn process(&mut self, state: &mut S, corpus: &mut C) -> Result<usize, AflError> {
|
||||||
// TODO: iterators
|
// TODO: iterators
|
||||||
let mut handled = vec!();
|
let mut handled = vec![];
|
||||||
for x in self.events.iter() {
|
for x in self.events.iter() {
|
||||||
handled.push(x.handle_in_broker(state, corpus)?);
|
handled.push(x.handle_in_broker(state, corpus)?);
|
||||||
}
|
}
|
||||||
handled.iter().zip(self.events.iter()).map(|(x, event)| match x {
|
handled
|
||||||
BrokerEventResult::Forward => {
|
.iter()
|
||||||
event.handle_in_client(state, corpus)
|
.zip(self.events.iter())
|
||||||
},
|
.map(|(x, event)| match x {
|
||||||
|
BrokerEventResult::Forward => event.handle_in_client(state, corpus),
|
||||||
// Ignore broker-only events
|
// Ignore broker-only events
|
||||||
BrokerEventResult::Handled => Ok(()),
|
BrokerEventResult::Handled => Ok(()),
|
||||||
}
|
})
|
||||||
).collect::<Result<(), AflError>>();
|
.collect::<Result<(), AflError>>();
|
||||||
let count = self.events.len();
|
let count = self.events.len();
|
||||||
dbg!("Handled {} events", count);
|
dbg!("Handled {} events", count);
|
||||||
self.events.clear();
|
self.events.clear();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use crate::{events::Event, engines::State};
|
|
||||||
use crate::events::EventManager;
|
use crate::events::EventManager;
|
||||||
use crate::executors::Executor;
|
use crate::executors::Executor;
|
||||||
use crate::inputs::Input;
|
use crate::inputs::Input;
|
||||||
@ -9,6 +8,7 @@ use crate::stages::Corpus;
|
|||||||
use crate::stages::Stage;
|
use crate::stages::Stage;
|
||||||
use crate::utils::Rand;
|
use crate::utils::Rand;
|
||||||
use crate::AflError;
|
use crate::AflError;
|
||||||
|
use crate::{engines::State, events::Event};
|
||||||
|
|
||||||
// TODO multi mutators stage
|
// TODO multi mutators stage
|
||||||
|
|
||||||
@ -56,7 +56,12 @@ where
|
|||||||
|
|
||||||
if interesting > 0 {
|
if interesting > 0 {
|
||||||
//let new_testcase = state.input_to_testcase(input_mut, interesting)?;
|
//let new_testcase = state.input_to_testcase(input_mut, interesting)?;
|
||||||
events.fire(Event::NewTestcase { sender_id: 0, input: input_mut, fitness: interesting , _marker: PhantomData})?;
|
events.fire(Event::NewTestcase {
|
||||||
|
sender_id: 0,
|
||||||
|
input: input_mut,
|
||||||
|
fitness: interesting,
|
||||||
|
_marker: PhantomData,
|
||||||
|
})?;
|
||||||
//state.corpus_mut().add(new_testcase); // TODO: Probably no longer needed, once events work
|
//state.corpus_mut().add(new_testcase); // TODO: Probably no longer needed, once events work
|
||||||
} else {
|
} else {
|
||||||
state.discard_input(&input_mut)?;
|
state.discard_input(&input_mut)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user