Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caching #19

Merged
merged 15 commits into from
Feb 5, 2024
7 changes: 7 additions & 0 deletions fuzz/fuzz_targets/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ fn fuzz(ops: Input) {
);
const FLASH_RANGE: Range<u32> = 0x000..0x1000;

let mut cache = sequential_storage::cache::NoCache;

let mut map = HashMap::new();
#[repr(align(4))]
struct AlignedBuf([u8; 260]);
Expand All @@ -123,6 +125,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::map::store_item(
&mut flash,
FLASH_RANGE,
&mut cache,
&mut buf.0,
item.clone(),
)) {
Expand All @@ -137,6 +140,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::map::fetch_item::<TestItem, _>(
&mut flash,
FLASH_RANGE,
&mut cache,
&mut buf.0,
item.key,
)) {
Expand Down Expand Up @@ -167,6 +171,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::map::try_repair::<TestItem, _>(
&mut flash,
FLASH_RANGE,
&mut cache,
&mut buf.0,
))
.unwrap();
Expand All @@ -180,6 +185,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::map::fetch_item::<TestItem, _>(
&mut flash,
FLASH_RANGE,
&mut cache,
&mut buf.0,
key,
)) {
Expand Down Expand Up @@ -213,6 +219,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::map::try_repair::<TestItem, _>(
&mut flash,
FLASH_RANGE,
&mut cache,
&mut buf.0,
))
.unwrap();
Expand Down
16 changes: 16 additions & 0 deletions fuzz/fuzz_targets/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ fn fuzz(ops: Input) {
);
const FLASH_RANGE: Range<u32> = 0x000..0x1000;

let mut cache = sequential_storage::cache::NoCache;

let mut order = VecDeque::new();
let mut buf = AlignedBuf([0; MAX_VALUE_SIZE + 1]);

Expand All @@ -73,6 +75,7 @@ fn fuzz(ops: Input) {
let max_fit = match block_on(sequential_storage::queue::find_max_fit(
&mut flash,
FLASH_RANGE,
&mut cache,
)) {
Ok(val) => val,
Err(Error::Corrupted {
Expand All @@ -86,6 +89,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::queue::try_repair(
&mut flash,
FLASH_RANGE,
&mut cache,
))
.unwrap();
corruption_repaired = true;
Expand All @@ -99,6 +103,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::queue::push(
&mut flash,
FLASH_RANGE,
&mut cache,
&buf.0[..val.len()],
false,
)) {
Expand Down Expand Up @@ -145,6 +150,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::queue::try_repair(
&mut flash,
FLASH_RANGE,
&mut cache,
))
.unwrap();
corruption_repaired = true;
Expand All @@ -157,6 +163,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::queue::pop(
&mut flash,
FLASH_RANGE,
&mut cache,
&mut buf.0,
)) {
Ok(value) => {
Expand Down Expand Up @@ -193,6 +200,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::queue::try_repair(
&mut flash,
FLASH_RANGE,
&mut cache,
))
.unwrap();
corruption_repaired = true;
Expand All @@ -205,6 +213,7 @@ fn fuzz(ops: Input) {
let mut popper = match block_on(sequential_storage::queue::pop_many(
&mut flash,
FLASH_RANGE,
&mut cache,
)) {
Ok(val) => val,
Err(Error::Corrupted {
Expand All @@ -218,6 +227,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::queue::try_repair(
&mut flash,
FLASH_RANGE,
&mut cache,
))
.unwrap();
corruption_repaired = true;
Expand Down Expand Up @@ -267,6 +277,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::queue::try_repair(
&mut flash,
FLASH_RANGE,
&mut cache,
))
.unwrap();
corruption_repaired = true;
Expand All @@ -282,6 +293,7 @@ fn fuzz(ops: Input) {
match block_on(sequential_storage::queue::peek(
&mut flash,
FLASH_RANGE,
&mut cache,
&mut buf.0,
)) {
Ok(value) => {
Expand All @@ -301,6 +313,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::queue::try_repair(
&mut flash,
FLASH_RANGE,
&mut cache,
))
.unwrap();
corruption_repaired = true;
Expand All @@ -313,6 +326,7 @@ fn fuzz(ops: Input) {
let mut peeker = match block_on(sequential_storage::queue::peek_many(
&mut flash,
FLASH_RANGE,
&mut cache,
)) {
Ok(val) => val,
Err(Error::Corrupted {
Expand All @@ -326,6 +340,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::queue::try_repair(
&mut flash,
FLASH_RANGE,
&mut cache,
))
.unwrap();
corruption_repaired = true;
Expand Down Expand Up @@ -357,6 +372,7 @@ fn fuzz(ops: Input) {
block_on(sequential_storage::queue::try_repair(
&mut flash,
FLASH_RANGE,
&mut cache,
))
.unwrap();
corruption_repaired = true;
Expand Down
Loading