@@ -40,10 +40,10 @@ impl_serdeany!(UnstableEntriesMetadata);
40
40
impl UnstableEntriesMetadata {
41
41
#[ must_use]
42
42
/// Create a new [`struct@UnstableEntriesMetadata`]
43
- pub fn new ( entries : HashSet < usize > , map_len : usize ) -> Self {
43
+ pub fn new ( ) -> Self {
44
44
Self {
45
- unstable_entries : entries ,
46
- map_len,
45
+ unstable_entries : HashSet :: new ( ) ,
46
+ map_len : 0 ,
47
47
}
48
48
}
49
49
@@ -60,6 +60,12 @@ impl UnstableEntriesMetadata {
60
60
}
61
61
}
62
62
63
+ impl Default for UnstableEntriesMetadata {
64
+ fn default ( ) -> Self {
65
+ Self :: new ( )
66
+ }
67
+ }
68
+
63
69
/// Default name for `CalibrationStage`; derived from AFL++
64
70
pub const CALIBRATION_STAGE_NAME : & str = "calibration" ;
65
71
/// The calibration stage will measure the average exec time and the target's stability for this input.
@@ -220,25 +226,20 @@ where
220
226
i += 1 ;
221
227
}
222
228
229
+ let mut send_default_stability = false ;
223
230
let unstable_found = !unstable_entries. is_empty ( ) ;
224
231
if unstable_found {
232
+ let metadata = state. metadata_or_insert_with ( UnstableEntriesMetadata :: new) ;
233
+
225
234
// If we see new stable entries executing this new corpus entries, then merge with the existing one
226
- if state. has_metadata :: < UnstableEntriesMetadata > ( ) {
227
- let existing = state
228
- . metadata_map_mut ( )
229
- . get_mut :: < UnstableEntriesMetadata > ( )
230
- . unwrap ( ) ;
231
- for item in unstable_entries {
232
- existing. unstable_entries . insert ( item) ; // Insert newly found items
233
- }
234
- existing. map_len = map_len;
235
- } else {
236
- state. add_metadata :: < UnstableEntriesMetadata > ( UnstableEntriesMetadata :: new (
237
- HashSet :: from_iter ( unstable_entries) ,
238
- map_len,
239
- ) ) ;
235
+ for item in unstable_entries {
236
+ metadata. unstable_entries . insert ( item) ; // Insert newly found items
240
237
}
241
- } ;
238
+ metadata. map_len = map_len;
239
+ } else if !state. has_metadata :: < UnstableEntriesMetadata > ( ) {
240
+ send_default_stability = true ;
241
+ state. add_metadata ( UnstableEntriesMetadata :: new ( ) ) ;
242
+ }
242
243
243
244
// If weighted scheduler or powerscheduler is used, update it
244
245
if state. has_metadata :: < SchedulerMetadata > ( ) {
@@ -300,6 +301,7 @@ where
300
301
if let Some ( meta) = state. metadata_map ( ) . get :: < UnstableEntriesMetadata > ( ) {
301
302
let unstable_entries = meta. unstable_entries ( ) . len ( ) ;
302
303
let map_len = meta. map_len ( ) ;
304
+ debug_assert_ne ! ( map_len, 0 , "The map_len must never be 0" ) ;
303
305
mgr. fire (
304
306
state,
305
307
Event :: UpdateUserStats {
@@ -315,6 +317,18 @@ where
315
317
} ,
316
318
) ?;
317
319
}
320
+ } else if send_default_stability {
321
+ mgr. fire (
322
+ state,
323
+ Event :: UpdateUserStats {
324
+ name : Cow :: from ( "stability" ) ,
325
+ value : UserStats :: new (
326
+ UserStatsValue :: Ratio ( map_len as u64 , map_len as u64 ) ,
327
+ AggregatorOps :: Avg ,
328
+ ) ,
329
+ phantom : PhantomData ,
330
+ } ,
331
+ ) ?;
318
332
}
319
333
320
334
Ok ( ( ) )
0 commit comments