Executions field in Testcase
This commit is contained in:
parent
6cd2d69bfc
commit
6dd107c4ef
@ -22,6 +22,15 @@ pub enum OnDiskMetadataFormat {
|
|||||||
JsonPretty,
|
JsonPretty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A corpus able to store testcases to disk, and load them from disk, when they are being used.
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct OnDiskMetadata<'a> {
|
||||||
|
metadata: &'a SerdeAnyMap,
|
||||||
|
exec_time: &'a Option<Duration>,
|
||||||
|
executions: &'a usize,
|
||||||
|
}
|
||||||
|
|
||||||
/// A corpus able to store testcases to disk, and load them from disk, when they are being used.
|
/// A corpus able to store testcases to disk, and load them from disk, when they are being used.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
|
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
|
||||||
@ -91,6 +100,12 @@ where
|
|||||||
tmpfile_name.file_name().unwrap().to_string_lossy()
|
tmpfile_name.file_name().unwrap().to_string_lossy()
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let ondisk_meta = OnDiskMetadata {
|
||||||
|
metadata: testcase.metadata(),
|
||||||
|
exec_time: testcase.exec_time(),
|
||||||
|
executions: testcase.executions(),
|
||||||
|
};
|
||||||
|
|
||||||
let mut tmpfile = File::create(&tmpfile_name)?;
|
let mut tmpfile = File::create(&tmpfile_name)?;
|
||||||
|
|
||||||
let serialized = match self.meta_format.as_ref().unwrap() {
|
let serialized = match self.meta_format.as_ref().unwrap() {
|
||||||
|
@ -29,6 +29,8 @@ where
|
|||||||
exec_time: Option<Duration>,
|
exec_time: Option<Duration>,
|
||||||
/// Cached len of the input, if any
|
/// Cached len of the input, if any
|
||||||
cached_len: Option<usize>,
|
cached_len: Option<usize>,
|
||||||
|
/// Number of executions done at discovery time
|
||||||
|
executions: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I> HasMetadata for Testcase<I>
|
impl<I> HasMetadata for Testcase<I>
|
||||||
@ -148,6 +150,7 @@ where
|
|||||||
metadata: SerdeAnyMap::new(),
|
metadata: SerdeAnyMap::new(),
|
||||||
exec_time: None,
|
exec_time: None,
|
||||||
cached_len: None,
|
cached_len: None,
|
||||||
|
executions: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,6 +163,20 @@ where
|
|||||||
metadata: SerdeAnyMap::new(),
|
metadata: SerdeAnyMap::new(),
|
||||||
exec_time: None,
|
exec_time: None,
|
||||||
cached_len: None,
|
cached_len: None,
|
||||||
|
executions: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new Testcase instance given an [`Input`] and the number of executions
|
||||||
|
#[inline]
|
||||||
|
pub fn with_executions(input: I, executions: usize) -> Self {
|
||||||
|
Testcase {
|
||||||
|
input: Some(input),
|
||||||
|
filename: None,
|
||||||
|
metadata: SerdeAnyMap::new(),
|
||||||
|
exec_time: None,
|
||||||
|
cached_len: None,
|
||||||
|
executions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,6 +190,7 @@ where
|
|||||||
metadata: SerdeAnyMap::new(),
|
metadata: SerdeAnyMap::new(),
|
||||||
exec_time: None,
|
exec_time: None,
|
||||||
cached_len: None,
|
cached_len: None,
|
||||||
|
executions: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ where
|
|||||||
self.objective_mut().discard_metadata(state, &input)?;
|
self.objective_mut().discard_metadata(state, &input)?;
|
||||||
|
|
||||||
// Add the input to the main corpus
|
// Add the input to the main corpus
|
||||||
let mut testcase = Testcase::new(input.clone());
|
let mut testcase = Testcase::with_executions(input.clone(), *state.executions());
|
||||||
self.feedback_mut().append_metadata(state, &mut testcase)?;
|
self.feedback_mut().append_metadata(state, &mut testcase)?;
|
||||||
let idx = state.corpus_mut().add(testcase)?;
|
let idx = state.corpus_mut().add(testcase)?;
|
||||||
self.scheduler_mut().on_add(state, idx)?;
|
self.scheduler_mut().on_add(state, idx)?;
|
||||||
@ -393,7 +393,7 @@ where
|
|||||||
self.feedback_mut().discard_metadata(state, &input)?;
|
self.feedback_mut().discard_metadata(state, &input)?;
|
||||||
|
|
||||||
// The input is a solution, add it to the respective corpus
|
// The input is a solution, add it to the respective corpus
|
||||||
let mut testcase = Testcase::new(input);
|
let mut testcase = Testcase::with_executions(input, *state.executions());
|
||||||
self.objective_mut().append_metadata(state, &mut testcase)?;
|
self.objective_mut().append_metadata(state, &mut testcase)?;
|
||||||
state.solutions_mut().add(testcase)?;
|
state.solutions_mut().add(testcase)?;
|
||||||
|
|
||||||
@ -487,7 +487,7 @@ where
|
|||||||
self.objective_mut().discard_metadata(state, &input)?;
|
self.objective_mut().discard_metadata(state, &input)?;
|
||||||
|
|
||||||
// Add the input to the main corpus
|
// Add the input to the main corpus
|
||||||
let mut testcase = Testcase::new(input.clone());
|
let mut testcase = Testcase::with_executions(input.clone(), *state.executions());
|
||||||
self.feedback_mut().append_metadata(state, &mut testcase)?;
|
self.feedback_mut().append_metadata(state, &mut testcase)?;
|
||||||
let idx = state.corpus_mut().add(testcase)?;
|
let idx = state.corpus_mut().add(testcase)?;
|
||||||
self.scheduler_mut().on_add(state, idx)?;
|
self.scheduler_mut().on_add(state, idx)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user