Make calibration stage independent of powerschedules (#589)
* fix * clippy
This commit is contained in:
parent
e77e147a74
commit
f732b76115
@ -31,6 +31,8 @@ where
|
|||||||
cached_len: Option<usize>,
|
cached_len: Option<usize>,
|
||||||
/// Number of executions done at discovery time
|
/// Number of executions done at discovery time
|
||||||
executions: usize,
|
executions: usize,
|
||||||
|
/// Number of fuzzing iterations of this particular input updated in perform_mutational
|
||||||
|
fuzz_level: usize,
|
||||||
/// If it has been fuzzed
|
/// If it has been fuzzed
|
||||||
fuzzed: bool,
|
fuzzed: bool,
|
||||||
}
|
}
|
||||||
@ -154,6 +156,18 @@ where
|
|||||||
&mut self.executions
|
&mut self.executions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the `fuzz_level`
|
||||||
|
#[inline]
|
||||||
|
pub fn fuzz_level(&self) -> usize {
|
||||||
|
self.fuzz_level
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the `fuzz_level`
|
||||||
|
#[inline]
|
||||||
|
pub fn set_fuzz_leve(&mut self, fuzz_level: usize) {
|
||||||
|
self.fuzz_level = fuzz_level;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get if it was fuzzed
|
/// Get if it was fuzzed
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fuzzed(&self) -> bool {
|
pub fn fuzzed(&self) -> bool {
|
||||||
@ -216,6 +230,7 @@ where
|
|||||||
metadata: SerdeAnyMap::new(),
|
metadata: SerdeAnyMap::new(),
|
||||||
exec_time: None,
|
exec_time: None,
|
||||||
cached_len: None,
|
cached_len: None,
|
||||||
|
fuzz_level: 0,
|
||||||
executions: 0,
|
executions: 0,
|
||||||
fuzzed: false,
|
fuzzed: false,
|
||||||
}
|
}
|
||||||
@ -264,8 +279,6 @@ where
|
|||||||
pub struct PowerScheduleTestcaseMetaData {
|
pub struct PowerScheduleTestcaseMetaData {
|
||||||
/// Number of bits set in bitmap, updated in calibrate_case
|
/// Number of bits set in bitmap, updated in calibrate_case
|
||||||
bitmap_size: u64,
|
bitmap_size: u64,
|
||||||
/// Number of fuzzing iterations, updated in perform_mutational
|
|
||||||
fuzz_level: u64,
|
|
||||||
/// Number of queue cycles behind
|
/// Number of queue cycles behind
|
||||||
handicap: u64,
|
handicap: u64,
|
||||||
/// Path depth, initialized in on_add
|
/// Path depth, initialized in on_add
|
||||||
@ -280,7 +293,6 @@ impl PowerScheduleTestcaseMetaData {
|
|||||||
pub fn new(depth: u64) -> Self {
|
pub fn new(depth: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
bitmap_size: 0,
|
bitmap_size: 0,
|
||||||
fuzz_level: 0,
|
|
||||||
handicap: 0,
|
handicap: 0,
|
||||||
depth,
|
depth,
|
||||||
n_fuzz_entry: 0,
|
n_fuzz_entry: 0,
|
||||||
@ -298,17 +310,6 @@ impl PowerScheduleTestcaseMetaData {
|
|||||||
self.bitmap_size = val;
|
self.bitmap_size = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the fuzz level
|
|
||||||
#[must_use]
|
|
||||||
pub fn fuzz_level(&self) -> u64 {
|
|
||||||
self.fuzz_level
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the fuzz level
|
|
||||||
pub fn set_fuzz_level(&mut self, val: u64) {
|
|
||||||
self.fuzz_level = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the handicap
|
/// Get the handicap
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn handicap(&self) -> u64 {
|
pub fn handicap(&self) -> u64 {
|
||||||
|
@ -73,7 +73,8 @@ where
|
|||||||
#[allow(
|
#[allow(
|
||||||
clippy::cast_precision_loss,
|
clippy::cast_precision_loss,
|
||||||
clippy::too_many_lines,
|
clippy::too_many_lines,
|
||||||
clippy::cast_sign_loss
|
clippy::cast_sign_loss,
|
||||||
|
clippy::cast_lossless
|
||||||
)]
|
)]
|
||||||
fn compute(entry: &mut Testcase<I>, state: &S) -> Result<f64, Error> {
|
fn compute(entry: &mut Testcase<I>, state: &S) -> Result<f64, Error> {
|
||||||
let psmeta = state
|
let psmeta = state
|
||||||
@ -195,7 +196,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PowerSchedule::FAST => {
|
PowerSchedule::FAST => {
|
||||||
if tcmeta.fuzz_level() != 0 {
|
if entry.fuzz_level() != 0 {
|
||||||
let lg = libm::log2(f64::from(psmeta.n_fuzz()[tcmeta.n_fuzz_entry()]));
|
let lg = libm::log2(f64::from(psmeta.n_fuzz()[tcmeta.n_fuzz_entry()]));
|
||||||
|
|
||||||
match lg {
|
match lg {
|
||||||
@ -234,11 +235,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PowerSchedule::LIN => {
|
PowerSchedule::LIN => {
|
||||||
factor = (tcmeta.fuzz_level() as f64)
|
factor = (entry.fuzz_level() as f64)
|
||||||
/ f64::from(psmeta.n_fuzz()[tcmeta.n_fuzz_entry()] + 1);
|
/ f64::from(psmeta.n_fuzz()[tcmeta.n_fuzz_entry()] + 1);
|
||||||
}
|
}
|
||||||
PowerSchedule::QUAD => {
|
PowerSchedule::QUAD => {
|
||||||
factor = ((tcmeta.fuzz_level() * tcmeta.fuzz_level()) as f64)
|
factor = ((entry.fuzz_level() * entry.fuzz_level()) as f64)
|
||||||
/ f64::from(psmeta.n_fuzz()[tcmeta.n_fuzz_entry()] + 1);
|
/ f64::from(psmeta.n_fuzz()[tcmeta.n_fuzz_entry()] + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,7 +298,7 @@ where
|
|||||||
|
|
||||||
// This means that this testcase has never gone through the calibration stage before1,
|
// This means that this testcase has never gone through the calibration stage before1,
|
||||||
// In this case we'll just return the default weight
|
// In this case we'll just return the default weight
|
||||||
if tcmeta.fuzz_level() == 0 || psmeta.cycles() == 0 {
|
if entry.fuzz_level() == 0 || psmeta.cycles() == 0 {
|
||||||
return Ok(weight);
|
return Ok(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,7 +345,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// was it fuzzed before?
|
// was it fuzzed before?
|
||||||
if tcmeta.fuzz_level() == 0 {
|
if entry.fuzz_level() == 0 {
|
||||||
weight *= 2.0;
|
weight *= 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,27 +59,12 @@ where
|
|||||||
corpus_idx: usize,
|
corpus_idx: usize,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
// Run this stage only once for each corpus entry
|
// Run this stage only once for each corpus entry
|
||||||
if state
|
if state.corpus().get(corpus_idx)?.borrow_mut().fuzz_level() > 0 {
|
||||||
.corpus()
|
|
||||||
.get(corpus_idx)?
|
|
||||||
.borrow_mut()
|
|
||||||
.metadata()
|
|
||||||
.get::<PowerScheduleTestcaseMetaData>()
|
|
||||||
.ok_or_else(|| {
|
|
||||||
Error::KeyNotFound("PowerScheduleTescaseMetatdata not found".to_string())
|
|
||||||
})?
|
|
||||||
.fuzz_level()
|
|
||||||
> 0
|
|
||||||
{
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut iter = self.stage_max;
|
let mut iter = self.stage_max;
|
||||||
let handicap = state
|
|
||||||
.metadata()
|
|
||||||
.get::<PowerScheduleMetadata>()
|
|
||||||
.ok_or_else(|| Error::KeyNotFound("PowerScheduleMetadata not found".to_string()))?
|
|
||||||
.queue_cycles();
|
|
||||||
let input = state
|
let input = state
|
||||||
.corpus()
|
.corpus()
|
||||||
.get(corpus_idx)?
|
.get(corpus_idx)?
|
||||||
@ -175,36 +160,48 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let psmeta = state
|
// If power schedule is used, update it
|
||||||
.metadata_mut()
|
let use_powerschedule = state.has_metadata::<PowerScheduleMetadata>()
|
||||||
.get_mut::<PowerScheduleMetadata>()
|
&& state
|
||||||
.ok_or_else(|| Error::KeyNotFound("PowerScheduleMetadata not found".to_string()))?;
|
.corpus()
|
||||||
|
.get(corpus_idx)?
|
||||||
|
.borrow()
|
||||||
|
.has_metadata::<PowerScheduleTestcaseMetaData>();
|
||||||
|
|
||||||
let map = executor
|
if use_powerschedule {
|
||||||
.observers()
|
let map = executor
|
||||||
.match_name::<O>(&self.map_observer_name)
|
.observers()
|
||||||
.ok_or_else(|| Error::KeyNotFound("MapObserver not found".to_string()))?;
|
.match_name::<O>(&self.map_observer_name)
|
||||||
|
.ok_or_else(|| Error::KeyNotFound("MapObserver not found".to_string()))?;
|
||||||
|
|
||||||
let bitmap_size = map.count_bytes();
|
let bitmap_size = map.count_bytes();
|
||||||
|
|
||||||
psmeta.set_exec_time(psmeta.exec_time() + total_time);
|
let psmeta = state
|
||||||
psmeta.set_cycles(psmeta.cycles() + (iter as u64));
|
.metadata_mut()
|
||||||
psmeta.set_bitmap_size(psmeta.bitmap_size() + bitmap_size);
|
.get_mut::<PowerScheduleMetadata>()
|
||||||
psmeta.set_bitmap_entries(psmeta.bitmap_entries() + 1);
|
.unwrap();
|
||||||
|
let handicap = psmeta.queue_cycles();
|
||||||
|
|
||||||
let mut testcase = state.corpus().get(corpus_idx)?.borrow_mut();
|
psmeta.set_exec_time(psmeta.exec_time() + total_time);
|
||||||
|
psmeta.set_cycles(psmeta.cycles() + (iter as u64));
|
||||||
|
psmeta.set_bitmap_size(psmeta.bitmap_size() + bitmap_size);
|
||||||
|
psmeta.set_bitmap_entries(psmeta.bitmap_entries() + 1);
|
||||||
|
|
||||||
testcase.set_exec_time(total_time / (iter as u32));
|
let mut testcase = state.corpus().get(corpus_idx)?.borrow_mut();
|
||||||
// println!("time: {:#?}", testcase.exec_time());
|
let fuzz_level = testcase.fuzz_level();
|
||||||
let data = testcase
|
|
||||||
.metadata_mut()
|
|
||||||
.get_mut::<PowerScheduleTestcaseMetaData>()
|
|
||||||
.ok_or_else(|| Error::KeyNotFound("PowerScheduleTestData not found".to_string()))?;
|
|
||||||
|
|
||||||
data.set_bitmap_size(bitmap_size);
|
testcase.set_exec_time(total_time / (iter as u32));
|
||||||
data.set_handicap(handicap);
|
testcase.set_fuzz_leve(fuzz_level + 1);
|
||||||
data.set_fuzz_level(data.fuzz_level() + 1);
|
// println!("time: {:#?}", testcase.exec_time());
|
||||||
// println!("data: {:#?}", data);
|
|
||||||
|
let data = testcase
|
||||||
|
.metadata_mut()
|
||||||
|
.get_mut::<PowerScheduleTestcaseMetaData>()
|
||||||
|
.ok_or_else(|| Error::KeyNotFound("PowerScheduleTestData not found".to_string()))?;
|
||||||
|
|
||||||
|
data.set_bitmap_size(bitmap_size);
|
||||||
|
data.set_handicap(handicap);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user