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

feat: support peek_many and pop_many #12

Merged
merged 10 commits into from
Dec 16, 2023
Prev Previous commit
fix: ensure that oldest page is reset
* Add unit test to verify that pages have been erased.
  • Loading branch information
lulf committed Dec 15, 2023
commit cfe1396ce456f3f0229816423c1e528ace10c64e
26 changes: 26 additions & 0 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ impl<'d, S: MultiwriteNorFlash> QueueIterator<'d, S> {
),
)
.map_err(Error::Storage)?;
self.oldest_page = None;
}
Ok(())
}
Expand Down Expand Up @@ -579,6 +580,31 @@ mod tests {
}
}

#[test]
fn push_pop_many_oldest_erased() {
let mut flash = MockFlashBig::default();
let flash_range = 0x00..0x1000;
let mut data_buffer = [0; 1024];

// Fill up over 2 pages worth of data
for i in 0..64 {
println!("{i}");
let data = vec![i as u8; 32];
push(&mut flash, flash_range.clone(), &data, false).unwrap();
}

let mut popper = pop_many(&mut flash, flash_range.clone());
let mut i = 0;
while let Some(v) = popper.next(&mut data_buffer).unwrap() {
println!("{i}");
let data = vec![i as u8; 32];
assert_eq!(&v, &data, "At {i}");
i += 1;
}
// After pop'ing all elements, first two pages should be fully erased
assert_eq!(&flash.as_bytes()[..2048], &[0xff; 2048])
}

#[test]
fn push_peek_pop_many() {
let mut flash = MockFlashBig::default();
Expand Down