pub struct BufferStorage { /* private fields */ }Expand description
Simulates a flash storage using a buffer in memory.
This buffer storage can be used in place of an actual flash storage. It is particularly useful for tests and fuzzing, for which it has dedicated functionalities.
This storage tracks how many times words are written between page erase cycles, how many times pages are erased, and whether an operation flips bits in the wrong direction. Operations panic if those conditions are broken (optional). This storage also permits to interrupt operations for inspection or to corrupt the operation.
Implementations§
Source§impl BufferStorage
impl BufferStorage
Sourcepub fn new(storage: Box<[u8]>, options: BufferOptions) -> BufferStorage
pub fn new(storage: Box<[u8]>, options: BufferOptions) -> BufferStorage
Creates a buffer storage.
§Panics
The following preconditions must hold:
options.word_sizemust be a power of two.options.page_sizemust be a power of two.options.page_sizemust be word-aligned.storage.len()must be page-aligned.
Sourcepub fn arm_interruption(&mut self, delay: usize)
pub fn arm_interruption(&mut self, delay: usize)
Arms an interruption after a given delay.
Before each subsequent mutable operation (write or erase), the delay is decremented if
positive. If the delay is elapsed, the operation is saved and the INTERRUPTION error is
returned. Subsequent operations will panic until either of:
§Panics
Panics if an interruption is already armed.
Sourcepub fn disarm_interruption(&mut self) -> usize
pub fn disarm_interruption(&mut self) -> usize
Sourcepub fn reset_interruption(&mut self)
pub fn reset_interruption(&mut self)
Sourcepub fn corrupt_operation(&mut self, corrupt: BufferCorruptFunction<'_>)
pub fn corrupt_operation(&mut self, corrupt: BufferCorruptFunction<'_>)
Corrupts an interrupted operation.
Applies the corruption function to the storage. Counters are updated accordingly:
- If a word is fully written, its counter is incremented regardless of whether other words of the same operation have been fully written.
- If a page is fully erased, its counter is incremented (and its word counters are reset).
§Panics
Panics if any of the following conditions hold:
- An interruption was not armed.
- An interruption was armed but did not trigger.
- The corruption function corrupts more bits than allowed.
- The interrupted operation itself would have panicked.
Sourcepub fn get_word_writes(&self, word: usize) -> usize
pub fn get_word_writes(&self, word: usize) -> usize
Returns the number of times a word was written.
Sourcepub fn get_page_erases(&self, page: usize) -> usize
pub fn get_page_erases(&self, page: usize) -> usize
Returns the number of times a page was erased.
Sourcepub fn set_page_erases(&mut self, page: usize, cycle: usize)
pub fn set_page_erases(&mut self, page: usize, cycle: usize)
Sets the number of times a page was erased.
Trait Implementations§
Source§impl Clone for BufferStorage
impl Clone for BufferStorage
Source§fn clone(&self) -> BufferStorage
fn clone(&self) -> BufferStorage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more