Report 100% stability if no unstable edges are found (extends #2215) (#2217)

* Report 100% stability if no unstable edges are found

* Use metadtata

---------

Co-authored-by: sadeli413 <sadeli0x19d@gmail.com>
This commit is contained in:
Dominik Maier 2024-05-19 14:41:28 +02:00 committed by GitHub
parent dfd3b3278e
commit cf01d04151
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,10 +40,10 @@ impl_serdeany!(UnstableEntriesMetadata);
impl UnstableEntriesMetadata { impl UnstableEntriesMetadata {
#[must_use] #[must_use]
/// Create a new [`struct@UnstableEntriesMetadata`] /// Create a new [`struct@UnstableEntriesMetadata`]
pub fn new(entries: HashSet<usize>, map_len: usize) -> Self { pub fn new() -> Self {
Self { Self {
unstable_entries: entries, unstable_entries: HashSet::new(),
map_len, map_len: 0,
} }
} }
@ -60,6 +60,12 @@ impl UnstableEntriesMetadata {
} }
} }
impl Default for UnstableEntriesMetadata {
fn default() -> Self {
Self::new()
}
}
/// Default name for `CalibrationStage`; derived from AFL++ /// Default name for `CalibrationStage`; derived from AFL++
pub const CALIBRATION_STAGE_NAME: &str = "calibration"; pub const CALIBRATION_STAGE_NAME: &str = "calibration";
/// The calibration stage will measure the average exec time and the target's stability for this input. /// The calibration stage will measure the average exec time and the target's stability for this input.
@ -220,25 +226,20 @@ where
i += 1; i += 1;
} }
let mut send_default_stability = false;
let unstable_found = !unstable_entries.is_empty(); let unstable_found = !unstable_entries.is_empty();
if unstable_found { if unstable_found {
let metadata = state.metadata_or_insert_with(UnstableEntriesMetadata::new);
// If we see new stable entries executing this new corpus entries, then merge with the existing one // If we see new stable entries executing this new corpus entries, then merge with the existing one
if state.has_metadata::<UnstableEntriesMetadata>() { for item in unstable_entries {
let existing = state metadata.unstable_entries.insert(item); // Insert newly found items
.metadata_map_mut()
.get_mut::<UnstableEntriesMetadata>()
.unwrap();
for item in unstable_entries {
existing.unstable_entries.insert(item); // Insert newly found items
}
existing.map_len = map_len;
} else {
state.add_metadata::<UnstableEntriesMetadata>(UnstableEntriesMetadata::new(
HashSet::from_iter(unstable_entries),
map_len,
));
} }
}; metadata.map_len = map_len;
} else if !state.has_metadata::<UnstableEntriesMetadata>() {
send_default_stability = true;
state.add_metadata(UnstableEntriesMetadata::new());
}
// If weighted scheduler or powerscheduler is used, update it // If weighted scheduler or powerscheduler is used, update it
if state.has_metadata::<SchedulerMetadata>() { if state.has_metadata::<SchedulerMetadata>() {
@ -300,6 +301,7 @@ where
if let Some(meta) = state.metadata_map().get::<UnstableEntriesMetadata>() { if let Some(meta) = state.metadata_map().get::<UnstableEntriesMetadata>() {
let unstable_entries = meta.unstable_entries().len(); let unstable_entries = meta.unstable_entries().len();
let map_len = meta.map_len(); let map_len = meta.map_len();
debug_assert_ne!(map_len, 0, "The map_len must never be 0");
mgr.fire( mgr.fire(
state, state,
Event::UpdateUserStats { Event::UpdateUserStats {
@ -315,6 +317,18 @@ where
}, },
)?; )?;
} }
} else if send_default_stability {
mgr.fire(
state,
Event::UpdateUserStats {
name: Cow::from("stability"),
value: UserStats::new(
UserStatsValue::Ratio(map_len as u64, map_len as u64),
AggregatorOps::Avg,
),
phantom: PhantomData,
},
)?;
} }
Ok(()) Ok(())