not compiling yet
This commit is contained in:
parent
44e56c56f9
commit
c6f5f79cca
@ -246,24 +246,6 @@ impl LlmpConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the next message, tag, buf, if avaliable, else None
|
|
||||||
#[inline]
|
|
||||||
pub fn recv_buf(&mut self) -> Result<Option<(u32, &[u8])>, AflError> {
|
|
||||||
match self {
|
|
||||||
LlmpConnection::IsBroker {
|
|
||||||
broker,
|
|
||||||
listener_thread: _,
|
|
||||||
} => broker.recv_buf(),
|
|
||||||
LlmpConnection::IsClient { client } => client.recv_buf(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A client blocks/spins until the next message gets posted to the page,
|
|
||||||
/// then returns that message.
|
|
||||||
#[inline]
|
|
||||||
pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, AflError> {
|
|
||||||
self.llmp_in.recv_blocking()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Contents of the share mem pages, used by llmp internally
|
/// Contents of the share mem pages, used by llmp internally
|
||||||
|
@ -22,7 +22,7 @@ use crate::executors::Executor;
|
|||||||
use crate::feedbacks::FeedbacksTuple;
|
use crate::feedbacks::FeedbacksTuple;
|
||||||
use crate::inputs::Input;
|
use crate::inputs::Input;
|
||||||
use crate::observers::ObserversTuple;
|
use crate::observers::ObserversTuple;
|
||||||
use crate::serde_anymap::{Ptr, PtrMut, SerdeAny};
|
use crate::serde_anymap::SerdeAny;
|
||||||
use crate::utils::Rand;
|
use crate::utils::Rand;
|
||||||
use crate::AflError;
|
use crate::AflError;
|
||||||
use crate::{engines::State, utils};
|
use crate::{engines::State, utils};
|
||||||
@ -59,10 +59,9 @@ where
|
|||||||
/// Events sent around in the library
|
/// Events sent around in the library
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(bound = "I: serde::de::DeserializeOwned")]
|
#[serde(bound = "I: serde::de::DeserializeOwned")]
|
||||||
pub enum Event<'a, I, OT>
|
pub enum Event<I>
|
||||||
where
|
where
|
||||||
I: Input,
|
I: Input,
|
||||||
OT: ObserversTuple,
|
|
||||||
{
|
{
|
||||||
LoadInitial {
|
LoadInitial {
|
||||||
sender_id: u64,
|
sender_id: u64,
|
||||||
@ -70,9 +69,9 @@ where
|
|||||||
},
|
},
|
||||||
NewTestcase {
|
NewTestcase {
|
||||||
sender_id: u64,
|
sender_id: u64,
|
||||||
input: Ptr<'a, I>,
|
input: I,
|
||||||
observers: PtrMut<'a, OT>,
|
observers_buf: Vec<u8>,
|
||||||
corpus_count: usize,
|
client_config: String,
|
||||||
},
|
},
|
||||||
UpdateStats {
|
UpdateStats {
|
||||||
sender_id: u64,
|
sender_id: u64,
|
||||||
@ -106,10 +105,9 @@ where
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I, OT> Event<'a, I, OT>
|
impl<I> Event<I>
|
||||||
where
|
where
|
||||||
I: Input,
|
I: Input,
|
||||||
OT: ObserversTuple, //CE: CustomEvent<I, OT>,
|
|
||||||
{
|
{
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
@ -120,8 +118,8 @@ where
|
|||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
input: _,
|
input: _,
|
||||||
observers: _,
|
client_config: _,
|
||||||
corpus_count: _,
|
observers_buf: _,
|
||||||
} => "New Testcase",
|
} => "New Testcase",
|
||||||
Event::UpdateStats {
|
Event::UpdateStats {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
@ -161,6 +159,19 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_testcase<Ot>(config: String, input: I, observers: Ot) -> Result<Self, AflError>
|
||||||
|
where
|
||||||
|
Ot: ObserversTuple,
|
||||||
|
{
|
||||||
|
let observers_buf = postcard::to_allocvec(&observers)?;
|
||||||
|
Ok(Self::NewTestcase {
|
||||||
|
sender_id: 0,
|
||||||
|
input: input,
|
||||||
|
client_config: config,
|
||||||
|
observers_buf: observers_buf,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_stats(executions: usize, execs_over_sec: u64) -> Self {
|
pub fn update_stats(executions: usize, execs_over_sec: u64) -> Self {
|
||||||
Event::UpdateStats {
|
Event::UpdateStats {
|
||||||
sender_id: 0,
|
sender_id: 0,
|
||||||
@ -181,7 +192,7 @@ where
|
|||||||
R: Rand,
|
R: Rand,
|
||||||
{
|
{
|
||||||
/// Fire an Event
|
/// Fire an Event
|
||||||
fn fire<'a>(&mut self, event: Event<'a, I, OT>) -> Result<(), AflError>;
|
fn fire<'a>(&mut self, event: Event<I>) -> Result<(), AflError>;
|
||||||
|
|
||||||
/// Lookup for incoming events and process them.
|
/// Lookup for incoming events and process them.
|
||||||
/// Return the number of processes events or an error
|
/// Return the number of processes events or an error
|
||||||
@ -221,13 +232,13 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Broker fun
|
/// Broker fun
|
||||||
fn handle_in_broker(&mut self, event: &Event<I, OT>) -> Result<BrokerEventResult, AflError> {
|
fn handle_in_broker(&mut self, event: &Event<I>) -> Result<BrokerEventResult, AflError> {
|
||||||
match event {
|
match event {
|
||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
input: _,
|
input: _,
|
||||||
observers: _,
|
observers_buf: _,
|
||||||
corpus_count,
|
client_config: _,
|
||||||
} => {
|
} => {
|
||||||
self.corpus_size_inc();
|
self.corpus_size_inc();
|
||||||
println!(
|
println!(
|
||||||
@ -293,7 +304,7 @@ where
|
|||||||
/// Client fun
|
/// Client fun
|
||||||
fn handle_in_client(
|
fn handle_in_client(
|
||||||
&mut self,
|
&mut self,
|
||||||
event: Event<I, OT>,
|
event: Event<I>,
|
||||||
state: &mut State<I, R, FT>,
|
state: &mut State<I, R, FT>,
|
||||||
corpus: &mut C,
|
corpus: &mut C,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), AflError> {
|
||||||
@ -301,14 +312,16 @@ where
|
|||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
input,
|
input,
|
||||||
observers,
|
observers_buf,
|
||||||
corpus_count: _,
|
client_config: _,
|
||||||
} => {
|
} => {
|
||||||
// here u should match sender_id, if equal to the current one do not re-execute
|
|
||||||
|
// TODO: here u should match client_config, if equal to the current one do not re-execute
|
||||||
// we need to pass engine to process() too, TODO
|
// we need to pass engine to process() too, TODO
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
println!("Received new Testcase");
|
println!("Received new Testcase");
|
||||||
let interestingness = state.is_interesting(input, observers)?;
|
let observers = postcard::from_bytes(&observers_buf)?;
|
||||||
|
let interestingness = state.is_interesting(&input, observers)?;
|
||||||
state.add_if_interesting(corpus, input, interestingness);
|
state.add_if_interesting(corpus, input, interestingness);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -357,7 +370,7 @@ where
|
|||||||
//CE: CustomEvent<I, OT>,
|
//CE: CustomEvent<I, OT>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fire<'a>(&mut self, event: Event<'a, I, OT>) -> Result<(), AflError> {
|
fn fire<'a>(&mut self, event: Event<I>) -> Result<(), AflError> {
|
||||||
match self.handle_in_broker(&event)? {
|
match self.handle_in_broker(&event)? {
|
||||||
BrokerEventResult::Forward => (), //self.handle_in_client(event, state, corpus)?,
|
BrokerEventResult::Forward => (), //self.handle_in_client(event, state, corpus)?,
|
||||||
// Ignore broker-only events
|
// Ignore broker-only events
|
||||||
@ -420,7 +433,7 @@ where
|
|||||||
execs_over_sec: 0,
|
execs_over_sec: 0,
|
||||||
corpus_size: 0,
|
corpus_size: 0,
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,7 +479,7 @@ where
|
|||||||
//CE: CustomEvent<I>,
|
//CE: CustomEvent<I>,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fire<'a>(&mut self, event: Event<'a, I, OT>) -> Result<(), AflError> {
|
fn fire<'a>(&mut self, event: Event<I>) -> Result<(), AflError> {
|
||||||
let serialized = postcard::to_allocvec(&event)?;
|
let serialized = postcard::to_allocvec(&event)?;
|
||||||
self.send_buf(LLMP_TAG_EVENT_TO_CLIENT, &serialized)?;
|
self.send_buf(LLMP_TAG_EVENT_TO_CLIENT, &serialized)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -520,13 +533,14 @@ mod tests {
|
|||||||
fn test_event_serde() {
|
fn test_event_serde() {
|
||||||
let obv = StdMapObserver::new("test", unsafe { &mut MAP });
|
let obv = StdMapObserver::new("test", unsafe { &mut MAP });
|
||||||
let mut map = tuple_list!(obv);
|
let mut map = tuple_list!(obv);
|
||||||
|
let observers_buf = postcard::to_allocvec(&map).unwrap();
|
||||||
|
|
||||||
let i = BytesInput::new(vec![0]);
|
let i = BytesInput::new(vec![0]);
|
||||||
let e = Event::NewTestcase {
|
let e = Event::NewTestcase {
|
||||||
sender_id: 0,
|
sender_id: 0,
|
||||||
input: Ptr::Ref(&i),
|
input: &i,
|
||||||
observers: PtrMut::Ref(&mut map),
|
observers_buf: observers_buf,
|
||||||
corpus_count: 1,
|
client_config: "conf".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let j = serde_json::to_string(&e).unwrap();
|
let j = serde_json::to_string(&e).unwrap();
|
||||||
@ -537,10 +551,10 @@ mod tests {
|
|||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
input: _,
|
input: _,
|
||||||
observers,
|
observers_buf,
|
||||||
corpus_count: _,
|
client_config: String,
|
||||||
} => {
|
} => {
|
||||||
let o = observers
|
let o = postcard::from_bytes(&observers_buf).unwrap()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.match_name_type::<StdMapObserver<u32>>("test")
|
.match_name_type::<StdMapObserver<u32>>("test")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -76,8 +76,8 @@ where
|
|||||||
// TODO decouple events manager and engine
|
// TODO decouple events manager and engine
|
||||||
manager.fire(Event::NewTestcase {
|
manager.fire(Event::NewTestcase {
|
||||||
sender_id: 0,
|
sender_id: 0,
|
||||||
input: Ptr::Ref(testcase.load_input()?),
|
input: testcase.load_input()?,
|
||||||
observers: PtrMut::Ref(engine.executor_mut().observers_mut()),
|
observers_buf: PtrMut::Ref(engine.executor_mut().observers_mut()),
|
||||||
corpus_count: corpus.count() + 1,
|
corpus_count: corpus.count() + 1,
|
||||||
})?;
|
})?;
|
||||||
// let _ = corpus.add(testcase);
|
// let _ = corpus.add(testcase);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user