bytesinput to_file raw

This commit is contained in:
Andrea Fioraldi 2021-04-22 15:55:13 +02:00
parent 7b772fedc5
commit 3124d03665
2 changed files with 46 additions and 6 deletions

View File

@ -84,8 +84,12 @@ where
time, time,
executions, executions,
} => { } => {
stats.client_stats_mut_for(0).update_corpus_size(*corpus_size as u64); stats
stats.client_stats_mut_for(0).update_executions(*executions as u64, *time); .client_stats_mut_for(0)
.update_corpus_size(*corpus_size as u64);
stats
.client_stats_mut_for(0)
.update_executions(*executions as u64, *time);
stats.display(event.name().to_string()); stats.display(event.name().to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
@ -95,12 +99,16 @@ where
phantom: _, phantom: _,
} => { } => {
// TODO: The stats buffer should be added on client add. // TODO: The stats buffer should be added on client add.
stats.client_stats_mut_for(0).update_executions(*executions as u64, *time); stats
.client_stats_mut_for(0)
.update_executions(*executions as u64, *time);
stats.display(event.name().to_string()); stats.display(event.name().to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::Objective { objective_size } => { Event::Objective { objective_size } => {
stats.client_stats_mut_for(0).update_objective_size(*objective_size as u64); stats
.client_stats_mut_for(0)
.update_objective_size(*objective_size as u64);
stats.display(event.name().to_string()); stats.display(event.name().to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }

View File

@ -4,8 +4,17 @@
use alloc::{borrow::ToOwned, rc::Rc, vec::Vec}; use alloc::{borrow::ToOwned, rc::Rc, vec::Vec};
use core::{cell::RefCell, convert::From}; use core::{cell::RefCell, convert::From};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "std")]
use std::{
fs::File,
io::{Read, Write},
path::Path,
};
use crate::inputs::{HasBytesVec, HasLen, HasTargetBytes, Input, TargetBytes}; use crate::{
inputs::{HasBytesVec, HasLen, HasTargetBytes, Input, TargetBytes},
Error,
};
/// A bytes input is the basic input /// A bytes input is the basic input
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)] #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
@ -14,7 +23,30 @@ pub struct BytesInput {
bytes: Vec<u8>, bytes: Vec<u8>,
} }
impl Input for BytesInput {} impl Input for BytesInput {
#[cfg(feature = "std")]
/// Write this input to the file
fn to_file<P>(&self, path: P) -> Result<(), Error>
where
P: AsRef<Path>,
{
let mut file = File::create(path)?;
file.write_all(&self.bytes)?;
Ok(())
}
/// Load the contents of this input from a file
#[cfg(feature = "std")]
fn from_file<P>(path: P) -> Result<Self, Error>
where
P: AsRef<Path>,
{
let mut file = File::open(path)?;
let mut bytes: Vec<u8> = vec![];
file.read_to_end(&mut bytes)?;
Ok(BytesInput::new(bytes))
}
}
/// Rc Ref-cell from Input /// Rc Ref-cell from Input
impl From<BytesInput> for Rc<RefCell<BytesInput>> { impl From<BytesInput> for Rc<RefCell<BytesInput>> {