serialize testcase
This commit is contained in:
parent
7771071491
commit
e1779e4503
@ -19,5 +19,5 @@ libc = "0.2" # For (*nix) libc
|
|||||||
num = "*"
|
num = "*"
|
||||||
xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust
|
xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust
|
||||||
serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib
|
serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib
|
||||||
serde_traitobject = { version = "0.2.7" } # trait obj serialization lib
|
typetag = "0.1"
|
||||||
postcard = "0.5.1" # no_std compatible serde serialization fromat
|
postcard = "0.5.1" # no_std compatible serde serialization fromat
|
@ -1,13 +1,13 @@
|
|||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::rc::Rc;
|
use alloc::rc::Rc;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use core::any::Any;
|
use core::any::{Any, TypeId};
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use core::convert::Into;
|
use core::convert::Into;
|
||||||
use core::default::Default;
|
use core::default::Default;
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use serde_traitobject::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::inputs::Input;
|
use crate::inputs::Input;
|
||||||
use crate::AflError;
|
use crate::AflError;
|
||||||
@ -18,7 +18,8 @@ use crate::AflError;
|
|||||||
|
|
||||||
// TODO: Give example
|
// TODO: Give example
|
||||||
/// Metadata for a testcase
|
/// Metadata for a testcase
|
||||||
pub trait TestcaseMetadata: Any + Serialize + Deserialize<'static> {
|
#[typetag::serde(tag = "type")]
|
||||||
|
pub trait TestcaseMetadata: Any {
|
||||||
/// The name of this metadata - used to find it in the list of avaliable metadatas
|
/// The name of this metadata - used to find it in the list of avaliable metadatas
|
||||||
fn name(&self) -> &'static str;
|
fn name(&self) -> &'static str;
|
||||||
}
|
}
|
||||||
@ -36,7 +37,7 @@ where
|
|||||||
/// Accumulated fitness from all the feedbacks
|
/// Accumulated fitness from all the feedbacks
|
||||||
fitness: u32,
|
fitness: u32,
|
||||||
/// Map of metadatas associated with this testcase
|
/// Map of metadatas associated with this testcase
|
||||||
metadatas: HashMap<&'static str, Box<dyn TestcaseMetadata>>,
|
metadatas: HashMap<String, Box<dyn TestcaseMetadata>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> Into<Rc<RefCell<Self>>> for Testcase<I>
|
impl<I> Into<Rc<RefCell<Self>>> for Testcase<I>
|
||||||
@ -99,12 +100,12 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get all the metadatas into an HashMap (mutable)
|
/// Get all the metadatas into an HashMap (mutable)
|
||||||
pub fn metadatas(&mut self) -> &mut HashMap<&'static str, Box<dyn TestcaseMetadata>> {
|
pub fn metadatas(&mut self) -> &mut HashMap<String, Box<dyn TestcaseMetadata>> {
|
||||||
&mut self.metadatas
|
&mut self.metadatas
|
||||||
}
|
}
|
||||||
/// Add a metadata
|
/// Add a metadata
|
||||||
pub fn add_metadata(&mut self, meta: Box<dyn TestcaseMetadata>) {
|
pub fn add_metadata(&mut self, meta: Box<dyn TestcaseMetadata>) {
|
||||||
self.metadatas.insert(meta.name(), meta);
|
self.metadatas.insert(meta.name().to_string(), meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new Testcase instace given an input
|
/// Create a new Testcase instace given an input
|
||||||
|
@ -106,6 +106,9 @@ where
|
|||||||
message: String,
|
message: String,
|
||||||
phantom: PhantomData<(S, C, E, I, R)>,
|
phantom: PhantomData<(S, C, E, I, R)>,
|
||||||
},
|
},
|
||||||
|
None {
|
||||||
|
phantom: PhantomData<(S, C, E, I, R)>,
|
||||||
|
},
|
||||||
//Custom {sender_id: u64, custom_event: CE},
|
//Custom {sender_id: u64, custom_event: CE},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,34 +125,35 @@ where
|
|||||||
match self {
|
match self {
|
||||||
Event::LoadInitial {
|
Event::LoadInitial {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => "Initial",
|
} => "Initial",
|
||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
testcase: _,
|
testcase: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => "New Testcase",
|
} => "New Testcase",
|
||||||
Event::UpdateStats {
|
Event::UpdateStats {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
new_execs: _,
|
new_execs: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => "Stats",
|
} => "Stats",
|
||||||
Event::Crash {
|
Event::Crash {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
input: _,
|
input: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => "Crash",
|
} => "Crash",
|
||||||
Event::Timeout {
|
Event::Timeout {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
input: _,
|
input: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => "Timeout",
|
} => "Timeout",
|
||||||
Event::Log {
|
Event::Log {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
severity_level: _,
|
severity_level: _,
|
||||||
message: _,
|
message: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => "Log",
|
} => "Log",
|
||||||
|
Event::None { phantom: _ } => "None",
|
||||||
//Event::Custom {sender_id, custom_event} => custom_event.name(),
|
//Event::Custom {sender_id, custom_event} => custom_event.name(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,16 +164,19 @@ where
|
|||||||
_corpus: &mut C,
|
_corpus: &mut C,
|
||||||
) -> Result<BrokerEventResult, AflError> {
|
) -> Result<BrokerEventResult, AflError> {
|
||||||
match self {
|
match self {
|
||||||
Event::LoadInitial { sender_id: _, phantom } => Ok(BrokerEventResult::Handled),
|
Event::LoadInitial {
|
||||||
|
sender_id: _,
|
||||||
|
phantom: _,
|
||||||
|
} => Ok(BrokerEventResult::Handled),
|
||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
testcase: _,
|
testcase: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => Ok(BrokerEventResult::Forward),
|
} => Ok(BrokerEventResult::Forward),
|
||||||
Event::UpdateStats {
|
Event::UpdateStats {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
new_execs: _,
|
new_execs: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => {
|
} => {
|
||||||
// TODO
|
// TODO
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
@ -177,12 +184,12 @@ where
|
|||||||
Event::Crash {
|
Event::Crash {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
input: _,
|
input: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => Ok(BrokerEventResult::Handled),
|
} => Ok(BrokerEventResult::Handled),
|
||||||
Event::Timeout {
|
Event::Timeout {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
input: _,
|
input: _,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => {
|
} => {
|
||||||
// TODO
|
// TODO
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
@ -191,30 +198,38 @@ where
|
|||||||
sender_id,
|
sender_id,
|
||||||
severity_level,
|
severity_level,
|
||||||
message,
|
message,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => {
|
} => {
|
||||||
//TODO: broker.log()
|
//TODO: broker.log()
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
println!("{}[{}]: {}", sender_id, severity_level, message);
|
println!("{}[{}]: {}", sender_id, severity_level, message);
|
||||||
Ok(BrokerEventResult::Handled)
|
Ok(BrokerEventResult::Handled)
|
||||||
}
|
},
|
||||||
|
Event::None {
|
||||||
|
phantom: _,
|
||||||
|
} => 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(
|
fn handle_in_client(
|
||||||
&self,
|
&mut self,
|
||||||
/*client: &dyn EventManager<S, C, E, I, R>,*/ _state: &mut S,
|
/*client: &dyn EventManager<S, C, E, I, R>,*/ _state: &mut S,
|
||||||
corpus: &mut C,
|
corpus: &mut C,
|
||||||
) -> Result<(), AflError> {
|
) -> Result<(), AflError> {
|
||||||
match self {
|
match std::mem::replace(
|
||||||
|
self,
|
||||||
|
Event::None {
|
||||||
|
phantom: PhantomData,
|
||||||
|
},
|
||||||
|
) {
|
||||||
Event::NewTestcase {
|
Event::NewTestcase {
|
||||||
sender_id: _,
|
sender_id: _,
|
||||||
testcase,
|
testcase,
|
||||||
phantom,
|
phantom: _,
|
||||||
} => {
|
} => {
|
||||||
corpus.add(*testcase);
|
corpus.add(testcase);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(AflError::Unknown(
|
_ => Err(AflError::Unknown(
|
||||||
@ -307,7 +322,7 @@ where
|
|||||||
}
|
}
|
||||||
handled
|
handled
|
||||||
.iter()
|
.iter()
|
||||||
.zip(self.events.iter())
|
.zip(self.events.iter_mut())
|
||||||
.map(|(x, event)| match x {
|
.map(|(x, event)| match x {
|
||||||
BrokerEventResult::Forward => event.handle_in_client(state, corpus),
|
BrokerEventResult::Forward => event.handle_in_client(state, corpus),
|
||||||
// Ignore broker-only events
|
// Ignore broker-only events
|
||||||
|
@ -170,6 +170,8 @@ where
|
|||||||
pub struct MapNoveltiesMetadata {
|
pub struct MapNoveltiesMetadata {
|
||||||
novelties: Vec<usize>,
|
novelties: Vec<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[typetag::serde]
|
||||||
impl TestcaseMetadata for MapNoveltiesMetadata {
|
impl TestcaseMetadata for MapNoveltiesMetadata {
|
||||||
fn name(&self) -> &'static str {
|
fn name(&self) -> &'static str {
|
||||||
"MapNoveltiesMetadata"
|
"MapNoveltiesMetadata"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user