@@ -35,6 +35,7 @@ enum Op {
35
35
Store ( StoreOp ) ,
36
36
Fetch ( u8 ) ,
37
37
Remove ( u8 ) ,
38
+ RemoveAll ,
38
39
}
39
40
40
41
#[ derive( Arbitrary , Debug , Clone ) ]
@@ -64,7 +65,11 @@ enum CacheType {
64
65
65
66
fn fuzz ( ops : Input , mut cache : impl KeyCacheImpl < u8 > + Debug ) {
66
67
let mut flash = MockFlashBase :: < PAGES , WORD_SIZE , WORDS_PER_PAGE > :: new (
67
- if ops. ops . iter ( ) . any ( |op| matches ! ( op, Op :: Remove ( _) ) ) {
68
+ if ops
69
+ . ops
70
+ . iter ( )
71
+ . any ( |op| matches ! ( op, Op :: Remove ( _) | Op :: RemoveAll ) )
72
+ {
68
73
WriteCountCheck :: Twice
69
74
} else {
70
75
WriteCountCheck :: OnceOnly
@@ -190,6 +195,7 @@ fn fuzz(ops: Input, mut cache: impl KeyCacheImpl<u8> + Debug) {
190
195
value : MockFlashError :: EarlyShutoff ( _) ,
191
196
backtrace : _backtrace,
192
197
} ) => {
198
+ // Check if the item is still there. It might or it might not and either is fine
193
199
match block_on ( sequential_storage:: map:: fetch_item :: < u8 , & [ u8 ] , _ > (
194
200
& mut flash,
195
201
FLASH_RANGE ,
@@ -220,6 +226,54 @@ fn fuzz(ops: Input, mut cache: impl KeyCacheImpl<u8> + Debug) {
220
226
Err ( e) => panic ! ( "{e:?}" ) ,
221
227
}
222
228
}
229
+ Op :: RemoveAll => {
230
+ match block_on ( sequential_storage:: map:: remove_all_items :: < u8 , _ > (
231
+ & mut flash,
232
+ FLASH_RANGE ,
233
+ & mut cache,
234
+ & mut buf. 0 ,
235
+ ) ) {
236
+ Ok ( ( ) ) => {
237
+ map. clear ( ) ;
238
+ }
239
+ Err ( Error :: Storage {
240
+ value : MockFlashError :: EarlyShutoff ( _) ,
241
+ backtrace : _backtrace,
242
+ } ) => {
243
+ for key in map. keys ( ) . copied ( ) . collect :: < Vec < _ > > ( ) {
244
+ // Check if the item is still there. It might or it might not and either is fine
245
+ match block_on ( sequential_storage:: map:: fetch_item :: < u8 , & [ u8 ] , _ > (
246
+ & mut flash,
247
+ FLASH_RANGE ,
248
+ & mut cache,
249
+ & mut buf. 0 ,
250
+ key,
251
+ ) ) {
252
+ Ok ( Some ( _) ) => {
253
+ #[ cfg( fuzzing_repro) ]
254
+ eprintln ! ( "Early shutoff when removing item {key}! Originated from:\n {_backtrace:#}" ) ;
255
+ }
256
+ _ => {
257
+ // Could not fetch the item we stored...
258
+ #[ cfg( fuzzing_repro) ]
259
+ eprintln ! ( "Early shutoff when removing item {key}! (but it still removed fully). Originated from:\n {_backtrace:#}" ) ;
260
+ // Even though we got a shutoff, it still managed to store well
261
+ map. remove ( & key) ;
262
+ }
263
+ }
264
+ }
265
+ }
266
+
267
+ Err ( Error :: Corrupted {
268
+ backtrace : _backtrace,
269
+ } ) => {
270
+ #[ cfg( fuzzing_repro) ]
271
+ eprintln ! ( "Corrupted when removing! Originated from:\n {_backtrace:#}" ) ;
272
+ panic ! ( "Corrupted!" ) ;
273
+ }
274
+ Err ( e) => panic ! ( "{e:?}" ) ,
275
+ }
276
+ }
223
277
}
224
278
}
225
279
}
0 commit comments