moved llmp test:
This commit is contained in:
parent
2641cd0f79
commit
a001f3055c
@ -95,7 +95,7 @@ pub type LlmpMsgHookFn = unsafe fn(client_id: u32, msg: *mut LlmpMsg) -> LlmpMsg
|
||||
pub type Tag = u32;
|
||||
|
||||
/// Sending end on a (unidirectional) sharedmap channel
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LlmpSender {
|
||||
/// ID of this sender. Only used in the broker.
|
||||
pub id: u32,
|
||||
@ -112,7 +112,7 @@ pub struct LlmpSender {
|
||||
}
|
||||
|
||||
/// Receiving end on a (unidirectional) sharedmap channel
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LlmpReceiver {
|
||||
pub id: u32,
|
||||
/// Pointer to the last meg this received
|
||||
@ -122,7 +122,7 @@ pub struct LlmpReceiver {
|
||||
}
|
||||
|
||||
/// Client side of LLMP
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LlmpClient {
|
||||
/// Outgoing channel to the broker
|
||||
pub llmp_out: LlmpSender,
|
||||
@ -131,14 +131,14 @@ pub struct LlmpClient {
|
||||
}
|
||||
|
||||
/// A page wrapper
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LlmpSharedMap {
|
||||
/// Shmem containg the actual (unsafe) page,
|
||||
/// shared between one LlmpSender and one LlmpReceiver
|
||||
shmem: AflShmem,
|
||||
}
|
||||
/// Message sent over the "wire"
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[repr(C, packed)]
|
||||
pub struct LlmpMsg {
|
||||
/// A tag
|
||||
@ -622,7 +622,9 @@ impl LlmpSender {
|
||||
|
||||
/// Receiving end of an llmp channel
|
||||
impl LlmpReceiver {
|
||||
// Never inline, to not get some strange effects
|
||||
/// Read next message.
|
||||
#[inline(never)]
|
||||
unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, AflError> {
|
||||
/* DBG("recv %p %p\n", page, last_msg); */
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
@ -1109,3 +1111,51 @@ impl LlmpClient {
|
||||
self.llmp_in.recv_buf_blocking()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
use super::{
|
||||
LlmpConnection::{self, IsBroker, IsClient},
|
||||
Tag,
|
||||
};
|
||||
|
||||
#[test]
|
||||
pub fn llmp_connection() {
|
||||
let mut broker = match LlmpConnection::on_port(1337).unwrap() {
|
||||
IsClient { client: _ } => panic!("Could not bind to port as broker"),
|
||||
IsBroker {
|
||||
broker,
|
||||
listener_thread: _,
|
||||
} => broker,
|
||||
};
|
||||
|
||||
// Add the first client (2nd, actually, because of the tcp listener client)
|
||||
let mut client = match LlmpConnection::on_port(1337).unwrap() {
|
||||
IsBroker {
|
||||
broker: _,
|
||||
listener_thread: _,
|
||||
} => panic!("Second connect should be a client!"),
|
||||
IsClient { client } => client,
|
||||
};
|
||||
|
||||
// Give the (background) tcp thread a few millis to post the message
|
||||
sleep(Duration::from_millis(100));
|
||||
broker.once().unwrap();
|
||||
|
||||
let tag: Tag = 0x1337;
|
||||
let arr: [u8; 1] = [1u8];
|
||||
// Send stuff
|
||||
client.send_buf(tag, &arr).unwrap();
|
||||
// Forward stuff to clients
|
||||
broker.once().unwrap();
|
||||
let (tag2, arr2) = client.recv_buf_blocking().unwrap();
|
||||
assert_eq!(tag, tag2);
|
||||
assert_eq!(arr[0], arr2[0]);
|
||||
|
||||
// We want at least the tcp and sender clients.
|
||||
assert_eq!(broker.llmp_clients.len(), 2);
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +173,7 @@ where
|
||||
/// Return the number of processes events or an error
|
||||
fn process(&mut self, state: &mut State<I, R>, corpus: &mut C) -> Result<usize, AflError>;
|
||||
|
||||
#[inline]
|
||||
fn on_recv(&self, _state: &mut State<I, R>, _corpus: &mut C) -> Result<(), AflError> {
|
||||
// TODO: Better way to move out of testcase, or get ref
|
||||
//Ok(corpus.add(self.testcase.take().unwrap()))
|
||||
@ -223,6 +224,8 @@ where
|
||||
//TODO: broker.log()
|
||||
#[cfg(feature = "std")]
|
||||
println!("{}[{}]: {}", sender_id, severity_level, message);
|
||||
// Silence warnings for no_std
|
||||
let (_, _, _) = (sender_id, severity_level, message);
|
||||
Ok(BrokerEventResult::Handled)
|
||||
}
|
||||
Event::None { phantom: _ } => Ok(BrokerEventResult::Handled),
|
||||
@ -298,6 +301,7 @@ where
|
||||
W: Write,
|
||||
//CE: CustomEvent<I>,
|
||||
{
|
||||
#[inline]
|
||||
fn fire<'a>(&mut self, event: Event<'a, I>) -> Result<(), AflError> {
|
||||
match self.handle_in_broker(&event)? {
|
||||
BrokerEventResult::Forward => (), //self.handle_in_client(event, state, corpus)?,
|
||||
@ -566,16 +570,12 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use std::{thread, time::Duration};
|
||||
|
||||
use crate::events::Event;
|
||||
use crate::inputs::bytes::BytesInput;
|
||||
use crate::observers::observer_serde::NamedSerdeAnyMap;
|
||||
use crate::observers::{Observer, StdMapObserver};
|
||||
use crate::serde_anymap::{Ptr, PtrMut};
|
||||
|
||||
use super::llmp::{LlmpConnection, Tag};
|
||||
|
||||
static mut MAP: [u32; 4] = [0; 4];
|
||||
|
||||
#[test]
|
||||
@ -611,38 +611,4 @@ mod tests {
|
||||
_ => panic!("mistmatch".to_string()),
|
||||
};
|
||||
}
|
||||
|
||||
use crate::events::tests::LlmpConnection::{IsBroker, IsClient};
|
||||
|
||||
#[test]
|
||||
pub fn llmp_connection() {
|
||||
let mut broker = match LlmpConnection::on_port(1337).unwrap() {
|
||||
IsClient { client } => panic!("Could not bind to port as broker"),
|
||||
IsBroker {
|
||||
broker,
|
||||
listener_thread,
|
||||
} => broker,
|
||||
};
|
||||
let mut client = match LlmpConnection::on_port(1337).unwrap() {
|
||||
IsBroker {
|
||||
broker,
|
||||
listener_thread,
|
||||
} => panic!("Second connect should be a client!"),
|
||||
IsClient { client } => client,
|
||||
};
|
||||
// Add the first client (2nd, actually, because of the tcp listener client)
|
||||
broker.once().unwrap();
|
||||
assert_eq!(broker.llmp_clients.len(), 2);
|
||||
|
||||
let tag: Tag = 0x1337;
|
||||
let arr: [u8; 1] = [1u8];
|
||||
// Send stuff
|
||||
client.send_buf(tag, &arr).unwrap();
|
||||
// Forward stuff to clients
|
||||
broker.once().unwrap();
|
||||
broker.once().unwrap();
|
||||
let (tag2, arr2) = client.recv_buf_blocking().unwrap();
|
||||
assert_eq!(tag, tag2);
|
||||
assert_eq!(arr[0], arr2[0]);
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ const AFL_RET_SUCCESS: c_uint = 0;
|
||||
// A generic sharememory region to be used by any functions (queues or feedbacks
|
||||
// too.)
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AflShmem {
|
||||
pub shm_str: [u8; 20],
|
||||
pub shm_id: c_int,
|
||||
|
@ -169,7 +169,6 @@ mod tests {
|
||||
use crate::executors::inmemory::InMemoryExecutor;
|
||||
use crate::executors::{Executor, ExitKind};
|
||||
use crate::inputs::{HasTargetBytes, Input, TargetBytes};
|
||||
use crate::AflError;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user