HasLen for input and exec_time in Testcase

This commit is contained in:
Andrea Fioraldi 2021-02-17 13:50:56 +01:00
parent a60ef073ed
commit 31d94925d0
4 changed files with 29 additions and 4 deletions

View File

@ -181,6 +181,7 @@ where
}
}
#[macro_export]
macro_rules! tuple_for_each {
($fn_name:ident, $trait_name:path, $tuple_name:ident, $body:expr) => {
mod $fn_name {
@ -211,6 +212,7 @@ macro_rules! tuple_for_each {
};
}
#[macro_export]
macro_rules! tuple_for_each_mut {
($fn_name:ident, $trait_name:path, $tuple_name:ident, $body:expr) => {
mod $fn_name {

View File

@ -2,7 +2,7 @@
//! It will contain a respective input, and metadata.
use alloc::string::String;
use core::{convert::Into, default::Default, option::Option};
use core::{convert::Into, default::Default, option::Option, time::Duration};
use serde::{Deserialize, Serialize};
use crate::{
@ -26,6 +26,8 @@ where
fitness: u32,
/// Map of metadatas associated with this testcase
metadatas: SerdeAnyMap,
/// Time needed to execute the input
exec_time: Option<Duration>,
}
/// Impl of a testcase
@ -141,6 +143,7 @@ where
filename: None,
fitness: 0,
metadatas: SerdeAnyMap::new(),
exec_time: None,
}
}
@ -152,6 +155,7 @@ where
filename: Some(filename),
fitness: 0,
metadatas: SerdeAnyMap::new(),
exec_time: None,
}
}
@ -162,6 +166,7 @@ where
filename: None,
fitness: 0,
metadatas: SerdeAnyMap::new(),
exec_time: None,
}
}
}

View File

@ -5,7 +5,7 @@ use alloc::{borrow::ToOwned, rc::Rc, vec::Vec};
use core::{cell::RefCell, convert::From};
use serde::{Deserialize, Serialize};
use crate::inputs::{HasBytesVec, HasTargetBytes, Input, TargetBytes};
use crate::inputs::{HasBytesVec, HasTargetBytes, HasLen, Input, TargetBytes};
/// A bytes input is the basic input
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
@ -42,6 +42,13 @@ impl HasTargetBytes for BytesInput {
}
}
impl HasLen for BytesInput {
#[inline]
fn len(&self) -> usize {
self.bytes.len()
}
}
impl From<Vec<u8>> for BytesInput {
fn from(bytes: Vec<u8>) -> Self {
Self::new(bytes)

View File

@ -33,7 +33,9 @@ pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug
#[cfg(not(feature = "std"))]
/// Write this input to the file
fn to_file<P>(&self, _path: P) -> Result<(), Error>
where {
where
P: AsRef<Path>,
{
Err(Error::NotImplemented("Not suppored in no_std".into()))
}
@ -52,7 +54,9 @@ where {
/// Write this input to the file
#[cfg(not(feature = "std"))]
fn from_file<P>(_path: P) -> Result<Self, Error>
where {
where
P: AsRef<Path>,
{
Err(Error::NotImplemented("Not suppored in no_std".into()))
}
}
@ -96,3 +100,10 @@ pub trait HasBytesVec {
/// The internal bytes map (as mutable borrow)
fn bytes_mut(&mut self) -> &mut Vec<u8>;
}
/// Has a length field
pub trait HasLen {
/// The lenght
fn len(&self) -> usize;
}