OnDiskMetadata

This commit is contained in:
Andrea Fioraldi 2021-11-29 14:28:55 +01:00
parent 6dd107c4ef
commit cf5b4dfb18
2 changed files with 20 additions and 5 deletions

View File

@ -1,14 +1,17 @@
//! The ondisk corpus stores unused testcases to disk.
use alloc::vec::Vec;
use core::cell::RefCell;
use core::{cell::RefCell, time::Duration};
use serde::{Deserialize, Serialize};
use std::{fs::OpenOptions, path::PathBuf};
#[cfg(feature = "std")]
use std::{fs, fs::File, io::Write};
use crate::{corpus::Corpus, corpus::Testcase, inputs::Input, state::HasMetadata, Error};
use crate::{
bolts::serdeany::SerdeAnyMap, corpus::Corpus, corpus::Testcase, inputs::Input,
state::HasMetadata, Error,
};
/// Options for the the format of the on-disk metadata
#[cfg(feature = "std")]
@ -109,9 +112,9 @@ where
let mut tmpfile = File::create(&tmpfile_name)?;
let serialized = match self.meta_format.as_ref().unwrap() {
OnDiskMetadataFormat::Postcard => postcard::to_allocvec(testcase.metadata())?,
OnDiskMetadataFormat::Json => serde_json::to_vec(testcase.metadata())?,
OnDiskMetadataFormat::JsonPretty => serde_json::to_vec_pretty(testcase.metadata())?,
OnDiskMetadataFormat::Postcard => postcard::to_allocvec(&ondisk_meta)?,
OnDiskMetadataFormat::Json => serde_json::to_vec(&ondisk_meta)?,
OnDiskMetadataFormat::JsonPretty => serde_json::to_vec_pretty(&ondisk_meta)?,
};
tmpfile.write_all(&serialized)?;
fs::rename(&tmpfile_name, &filename)?;

View File

@ -138,6 +138,18 @@ where
self.exec_time = Some(time);
}
/// Get the executions
#[inline]
pub fn executions(&self) -> &usize {
&self.executions
}
/// Get the executions (mut)
#[inline]
pub fn executions_mut(&mut self) -> &mut usize {
&mut self.executions
}
/// Create a new Testcase instace given an input
#[inline]
pub fn new<T>(input: T) -> Self