Skip to content

Commit

Permalink
Add cache fuzz for map and prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
diondokter committed Feb 7, 2024
1 parent 1cbef99 commit 0d8858f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

(DD-MM-YY)

## Unreleased
## 0.8.1 07-02-24

- Added new PagePointerCache that caches more than the PageStateCache. See the readme for more details.

## 0.8.0 05-12-24

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sequential-storage"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "A crate for storing data in flash with minimal erase cycles."
Expand Down
25 changes: 18 additions & 7 deletions fuzz/fuzz_targets/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@ use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::fuzz_target;
use rand::SeedableRng;
use sequential_storage::{
cache::{CacheImpl, NoCache, PagePointerCache, PageStateCache},
map::{MapError, StorageItem},
mock_flash::{MockFlashBase, MockFlashError, WriteCountCheck},
};
use std::{collections::HashMap, ops::Range};

fuzz_target!(|data: Input| fuzz(data));
const PAGES: usize = 4;
const WORD_SIZE: usize = 4;
const WORDS_PER_PAGE: usize = 256;

fuzz_target!(|data: Input| match data.cache_type {
CacheType::NoCache => fuzz(data, NoCache::new()),
CacheType::PageStateCache => fuzz(data, PageStateCache::<PAGES>::new()),
CacheType::PagePointerCache => fuzz(data, PagePointerCache::<PAGES>::new()),
});

#[derive(Arbitrary, Debug, Clone)]
struct Input {
seed: u64,
fuel: u16,
ops: Vec<Op>,
cache_type: CacheType,
}

#[derive(Arbitrary, Debug, Clone)]
Expand Down Expand Up @@ -86,20 +96,21 @@ impl StorageItem for TestItem {
}
}

fn fuzz(ops: Input) {
const PAGES: usize = 4;
const WORD_SIZE: usize = 4;
const WORDS_PER_PAGE: usize = 256;
#[derive(Arbitrary, Debug, Clone)]
enum CacheType {
NoCache,
PageStateCache,
PagePointerCache,
}

fn fuzz(ops: Input, mut cache: impl CacheImpl) {
let mut flash = MockFlashBase::<PAGES, WORD_SIZE, WORDS_PER_PAGE>::new(
WriteCountCheck::OnceOnly,
Some(ops.fuel as u32),
true,
);
const FLASH_RANGE: Range<u32> = 0x000..0x1000;

let mut cache = sequential_storage::cache::NoCache::new();

let mut map = HashMap::new();
#[repr(align(4))]
struct AlignedBuf([u8; 260]);
Expand Down
2 changes: 1 addition & 1 deletion src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl<'d> Item<'d> {
data: &[u8],
address: u32,
) -> Result<(), Error<S::Error>> {
cache.notice_item_written::<S>(flash_range, address, &header);
cache.notice_item_written::<S>(flash_range, address, header);
header.write(flash, address).await?;

let (data_block, data_left) = data.split_at(round_down_to_alignment_usize::<S>(data.len()));
Expand Down

0 comments on commit 0d8858f

Please sign in to comment.