expose client id to event
This commit is contained in:
parent
2b271aa5aa
commit
123e8a0fa1
@ -434,7 +434,9 @@ mod tests {
|
|||||||
let executor = InMemoryExecutor::<BytesInput, _>::new("main", harness, tuple_list!());
|
let executor = InMemoryExecutor::<BytesInput, _>::new("main", harness, tuple_list!());
|
||||||
let mut state = State::new(tuple_list!());
|
let mut state = State::new(tuple_list!());
|
||||||
|
|
||||||
let mut events_manager = LoggerEventManager::new(SimpleStats::new(|s| { println!("{}", s); }));
|
let mut events_manager = LoggerEventManager::new(SimpleStats::new(|s| {
|
||||||
|
println!("{}", s);
|
||||||
|
}));
|
||||||
let mut engine = Engine::new(executor);
|
let mut engine = Engine::new(executor);
|
||||||
let mut mutator = StdScheduledMutator::new();
|
let mut mutator = StdScheduledMutator::new();
|
||||||
mutator.add_mutation(mutation_bitflip);
|
mutator.add_mutation(mutation_bitflip);
|
||||||
|
@ -734,10 +734,14 @@ impl LlmpReceiver {
|
|||||||
|
|
||||||
/// Returns the next message, tag, buf, if avaliable, else None
|
/// Returns the next message, tag, buf, if avaliable, else None
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn recv_buf(&mut self) -> Result<Option<(u32, &[u8])>, AflError> {
|
pub fn recv_buf(&mut self) -> Result<Option<(u32, u32, &[u8])>, AflError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
Ok(match self.recv()? {
|
Ok(match self.recv()? {
|
||||||
Some(msg) => Some(((*msg).tag, (*msg).as_slice(&self.current_recv_map)?)),
|
Some(msg) => Some((
|
||||||
|
(*msg).sender,
|
||||||
|
(*msg).tag,
|
||||||
|
(*msg).as_slice(&self.current_recv_map)?,
|
||||||
|
)),
|
||||||
None => None,
|
None => None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -745,10 +749,14 @@ impl LlmpReceiver {
|
|||||||
|
|
||||||
/// Returns the next message, tag, buf, looping until it becomes available
|
/// Returns the next message, tag, buf, looping until it becomes available
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn recv_buf_blocking(&mut self) -> Result<(u32, &[u8]), AflError> {
|
pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), AflError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let msg = self.recv_blocking()?;
|
let msg = self.recv_blocking()?;
|
||||||
Ok(((*msg).tag, (*msg).as_slice(&self.current_recv_map)?))
|
Ok((
|
||||||
|
(*msg).sender,
|
||||||
|
(*msg).tag,
|
||||||
|
(*msg).as_slice(&self.current_recv_map)?,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1116,13 +1124,13 @@ impl LlmpClient {
|
|||||||
|
|
||||||
/// Returns the next message, tag, buf, if avaliable, else None
|
/// Returns the next message, tag, buf, if avaliable, else None
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn recv_buf(&mut self) -> Result<Option<(u32, &[u8])>, AflError> {
|
pub fn recv_buf(&mut self) -> Result<Option<(u32, u32, &[u8])>, AflError> {
|
||||||
self.llmp_in.recv_buf()
|
self.llmp_in.recv_buf()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Receives a buf from the broker, looping until a messages becomes avaliable
|
/// Receives a buf from the broker, looping until a messages becomes avaliable
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn recv_buf_blocking(&mut self) -> Result<(u32, &[u8]), AflError> {
|
pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), AflError> {
|
||||||
self.llmp_in.recv_buf_blocking()
|
self.llmp_in.recv_buf_blocking()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1175,4 +1183,4 @@ mod tests {
|
|||||||
assert_eq!(broker.llmp_clients.len(), 2);
|
assert_eq!(broker.llmp_clients.len(), 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -85,7 +85,7 @@ pub trait Stats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The client stats for a specific id, creating new if it doesn't exist
|
/// The client stats for a specific id, creating new if it doesn't exist
|
||||||
fn client_stats_mut_for(&mut self, client_id: u64) -> &mut ClientStats {
|
fn client_stats_mut_for(&mut self, client_id: u32) -> &mut ClientStats {
|
||||||
let client_stat_count = self.client_stats().len();
|
let client_stat_count = self.client_stats().len();
|
||||||
for _ in client_stat_count..(client_id + 1) as usize {
|
for _ in client_stat_count..(client_id + 1) as usize {
|
||||||
self.client_stats_mut().push(ClientStats {
|
self.client_stats_mut().push(ClientStats {
|
||||||
@ -99,7 +99,7 @@ pub trait Stats {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SimpleStats<F>
|
pub struct SimpleStats<F>
|
||||||
where
|
where
|
||||||
F: FnMut(String)
|
F: FnMut(String),
|
||||||
{
|
{
|
||||||
print_fn: F,
|
print_fn: F,
|
||||||
start_time: Duration,
|
start_time: Duration,
|
||||||
@ -107,9 +107,9 @@ where
|
|||||||
client_stats: Vec<ClientStats>,
|
client_stats: Vec<ClientStats>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> Stats for SimpleStats<F>
|
impl<F> Stats for SimpleStats<F>
|
||||||
where
|
where
|
||||||
F: FnMut(String)
|
F: FnMut(String),
|
||||||
{
|
{
|
||||||
/// the client stats, mutable
|
/// the client stats, mutable
|
||||||
fn client_stats_mut(&mut self) -> &mut Vec<ClientStats> {
|
fn client_stats_mut(&mut self) -> &mut Vec<ClientStats> {
|
||||||
@ -127,21 +127,27 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show(&mut self, event_msg: String) {
|
fn show(&mut self, event_msg: String) {
|
||||||
let fmt = format!("[{}] corpus: {}, executions: {}, exec/sec: {}", event_msg, self.corpus_size(), self.total_execs(), self.execs_per_sec());
|
let fmt = format!(
|
||||||
|
"[{}] corpus: {}, executions: {}, exec/sec: {}",
|
||||||
|
event_msg,
|
||||||
|
self.corpus_size(),
|
||||||
|
self.total_execs(),
|
||||||
|
self.execs_per_sec()
|
||||||
|
);
|
||||||
(self.print_fn)(fmt);
|
(self.print_fn)(fmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F> SimpleStats<F>
|
impl<F> SimpleStats<F>
|
||||||
where
|
where
|
||||||
F: FnMut(String)
|
F: FnMut(String),
|
||||||
{
|
{
|
||||||
pub fn new(print_fn: F) -> Self {
|
pub fn new(print_fn: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
print_fn: print_fn,
|
print_fn: print_fn,
|
||||||
start_time: utils::current_time(),
|
start_time: utils::current_time(),
|
||||||
corpus_size: 0,
|
corpus_size: 0,
|
||||||
client_stats: vec![]
|
client_stats: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +156,7 @@ where
|
|||||||
print_fn: print_fn,
|
print_fn: print_fn,
|
||||||
start_time: start_time,
|
start_time: start_time,
|
||||||
corpus_size: 0,
|
corpus_size: 0,
|
||||||
client_stats: vec![]
|
client_stats: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +184,9 @@ where
|
|||||||
/// Returns the name of this event
|
/// Returns the name of this event
|
||||||
fn name(&self) -> &str;
|
fn name(&self) -> &str;
|
||||||
/// This method will be called in the broker
|
/// This method will be called in the broker
|
||||||
fn handle_in_broker<ST>(&self, stats: &mut ST) -> Result<BrokerEventResult, AflError> where ST: Stats;
|
fn handle_in_broker<ST>(&self, stats: &mut ST) -> Result<BrokerEventResult, AflError>
|
||||||
|
where
|
||||||
|
ST: Stats;
|
||||||
/// This method will be called in the clients after handle_in_broker (unless BrokerEventResult::Handled) was returned in handle_in_broker
|
/// This method will be called in the clients after handle_in_broker (unless BrokerEventResult::Handled) was returned in handle_in_broker
|
||||||
fn handle_in_client<C, OT, FT, R>(
|
fn handle_in_client<C, OT, FT, R>(
|
||||||
self,
|
self,
|
||||||
@ -310,7 +318,10 @@ where
|
|||||||
|
|
||||||
/// Broker fun
|
/// Broker fun
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_in_broker<ST>(&self, stats: &mut ST) -> Result<BrokerEventResult, AflError> where ST: Stats {
|
fn handle_in_broker<ST>(&self, stats: &mut ST) -> Result<BrokerEventResult, AflError>
|
||||||
|
where
|
||||||
|
ST: Stats,
|
||||||
|
{
|
||||||
match self {
|
match self {
|
||||||
LoggerEvent::NewTestcase {
|
LoggerEvent::NewTestcase {
|
||||||
corpus_size,
|
corpus_size,
|
||||||
@ -538,7 +549,7 @@ pub struct LLMPEvent<'a, I>
|
|||||||
where
|
where
|
||||||
I: Input,
|
I: Input,
|
||||||
{
|
{
|
||||||
sender_id: u64,
|
sender_id: u32,
|
||||||
kind: LLMPEventKind<'a, I>,
|
kind: LLMPEventKind<'a, I>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,7 +586,10 @@ where
|
|||||||
|
|
||||||
/// Broker fun
|
/// Broker fun
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_in_broker<ST>(&self, stats: &mut ST) -> Result<BrokerEventResult, AflError> where ST: Stats {
|
fn handle_in_broker<ST>(&self, stats: &mut ST) -> Result<BrokerEventResult, AflError>
|
||||||
|
where
|
||||||
|
ST: Stats,
|
||||||
|
{
|
||||||
match &self.kind {
|
match &self.kind {
|
||||||
LLMPEventKind::NewTestcase {
|
LLMPEventKind::NewTestcase {
|
||||||
input: _,
|
input: _,
|
||||||
@ -612,8 +626,7 @@ where
|
|||||||
} => {
|
} => {
|
||||||
println!("[LOG {}]: {}", severity_level, message);
|
println!("[LOG {}]: {}", severity_level, message);
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
}
|
} //_ => Ok(BrokerEventResult::Forward),
|
||||||
//_ => Ok(BrokerEventResult::Forward),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,9 +740,13 @@ where
|
|||||||
} => {
|
} => {
|
||||||
let stats = &mut self.stats;
|
let stats = &mut self.stats;
|
||||||
broker.loop_forever(
|
broker.loop_forever(
|
||||||
&mut |_client_id: u32, tag: Tag, msg: &[u8]| {
|
&mut |sender_id: u32, tag: Tag, msg: &[u8]| {
|
||||||
if tag == LLMP_TAG_EVENT_TO_BOTH {
|
if tag == LLMP_TAG_EVENT_TO_BOTH {
|
||||||
let event: LLMPEvent<I> = postcard::from_bytes(msg)?;
|
let kind: LLMPEventKind<I> = postcard::from_bytes(msg)?;
|
||||||
|
let event = LLMPEvent {
|
||||||
|
sender_id: sender_id,
|
||||||
|
kind: kind,
|
||||||
|
};
|
||||||
match event.handle_in_broker(stats)? {
|
match event.handle_in_broker(stats)? {
|
||||||
BrokerEventResult::Forward => {
|
BrokerEventResult::Forward => {
|
||||||
Ok(llmp::LlmpMsgHookResult::ForwardToClients)
|
Ok(llmp::LlmpMsgHookResult::ForwardToClients)
|
||||||
@ -750,7 +767,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn llmp_send<'a>(&mut self, event: LLMPEvent<'a, I>) -> Result<(), AflError> {
|
fn send_event_kind<'a>(&mut self, event: LLMPEventKind<'a, I>) -> Result<(), AflError> {
|
||||||
let serialized = postcard::to_allocvec(&event)?;
|
let serialized = postcard::to_allocvec(&event)?;
|
||||||
self.llmp.send_buf(LLMP_TAG_EVENT_TO_BOTH, &serialized)?;
|
self.llmp.send_buf(LLMP_TAG_EVENT_TO_BOTH, &serialized)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -781,11 +798,15 @@ where
|
|||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
loop {
|
loop {
|
||||||
match client.recv_buf()? {
|
match client.recv_buf()? {
|
||||||
Some((tag, event_buf)) => {
|
Some((sender_id, tag, msg)) => {
|
||||||
if tag == _LLMP_TAG_EVENT_TO_BROKER {
|
if tag == _LLMP_TAG_EVENT_TO_BROKER {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let event: LLMPEvent<I> = postcard::from_bytes(event_buf)?;
|
let kind: LLMPEventKind<I> = postcard::from_bytes(msg)?;
|
||||||
|
let event = LLMPEvent {
|
||||||
|
sender_id: sender_id,
|
||||||
|
kind: kind,
|
||||||
|
};
|
||||||
event.handle_in_client(state, corpus)?;
|
event.handle_in_client(state, corpus)?;
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
@ -807,60 +828,45 @@ where
|
|||||||
corpus_size: usize,
|
corpus_size: usize,
|
||||||
config: String,
|
config: String,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), AflError> {
|
||||||
let event = LLMPEvent {
|
let kind = LLMPEventKind::NewTestcase {
|
||||||
sender_id: 0,
|
input: Ptr::Ref(input),
|
||||||
kind: LLMPEventKind::NewTestcase {
|
observers_buf: postcard::to_allocvec(observers)?,
|
||||||
input: Ptr::Ref(input),
|
corpus_size: corpus_size,
|
||||||
observers_buf: postcard::to_allocvec(observers)?,
|
client_config: config,
|
||||||
corpus_size: corpus_size,
|
|
||||||
client_config: config,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
self.llmp_send(event)
|
self.send_event_kind(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_stats(&mut self, executions: usize, execs_over_sec: u64) -> Result<(), AflError> {
|
fn update_stats(&mut self, executions: usize, execs_over_sec: u64) -> Result<(), AflError> {
|
||||||
let event = LLMPEvent {
|
let kind = LLMPEventKind::UpdateStats {
|
||||||
sender_id: 0,
|
executions: executions,
|
||||||
kind: LLMPEventKind::UpdateStats {
|
execs_over_sec: execs_over_sec,
|
||||||
executions: executions,
|
phantom: PhantomData,
|
||||||
execs_over_sec: execs_over_sec,
|
|
||||||
phantom: PhantomData,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
self.llmp_send(event)
|
self.send_event_kind(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn crash(&mut self, input: &I) -> Result<(), AflError> {
|
fn crash(&mut self, input: &I) -> Result<(), AflError> {
|
||||||
let event = LLMPEvent {
|
let kind = LLMPEventKind::Crash {
|
||||||
sender_id: 0,
|
input: input.clone(),
|
||||||
kind: LLMPEventKind::Crash {
|
|
||||||
input: input.clone(),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
self.llmp_send(event)
|
self.send_event_kind(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timeout(&mut self, input: &I) -> Result<(), AflError> {
|
fn timeout(&mut self, input: &I) -> Result<(), AflError> {
|
||||||
let event = LLMPEvent {
|
let kind = LLMPEventKind::Timeout {
|
||||||
sender_id: 0,
|
input: input.clone(),
|
||||||
kind: LLMPEventKind::Timeout {
|
|
||||||
input: input.clone(),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
self.llmp_send(event)
|
self.send_event_kind(kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log(&mut self, severity_level: u8, message: String) -> Result<(), AflError> {
|
fn log(&mut self, severity_level: u8, message: String) -> Result<(), AflError> {
|
||||||
let event = LLMPEvent {
|
let kind = LLMPEventKind::Log {
|
||||||
sender_id: 0,
|
severity_level: severity_level,
|
||||||
kind: LLMPEventKind::Log {
|
message: message,
|
||||||
severity_level: severity_level,
|
phantom: PhantomData,
|
||||||
message: message,
|
|
||||||
phantom: PhantomData,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
self.llmp_send(event)
|
self.send_event_kind(kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user