Skip to content

Commit 8767dac

Browse files
Consolidate pop byte harness coverage
1 parent debc377 commit 8767dac

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- added Kani verification harnesses for `Bytes::pop_front` and `Bytes::pop_back`
45
- avoid flushing empty memory maps in `Section::freeze` to prevent macOS errors
56
- derived zerocopy traits for `SectionHandle` to allow storing handles in `ByteArea` sections
67
- added example demonstrating `ByteArea` with multiple typed sections, concurrent mutations, and freezing or persisting the area

src/bytes.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,40 @@ mod verification {
590590
assert_eq!(bytes.as_ref(), copy.as_ref());
591591
}
592592

593+
#[kani::proof]
594+
#[kani::unwind(16)]
595+
pub fn check_pop_front_behaviour() {
596+
let data: Vec<u8> = Vec::bounded_any::<16>();
597+
let mut bytes = Bytes::from_source(data.clone());
598+
let snapshot = bytes.clone();
599+
600+
if let Some((expected, remainder)) = data.split_first() {
601+
let popped = bytes.pop_front().expect("non-empty slice");
602+
assert_eq!(popped, *expected);
603+
assert_eq!(bytes.as_ref(), remainder);
604+
} else {
605+
assert!(bytes.pop_front().is_none());
606+
assert_eq!(bytes.as_ref(), snapshot.as_ref());
607+
}
608+
}
609+
610+
#[kani::proof]
611+
#[kani::unwind(16)]
612+
pub fn check_pop_back_behaviour() {
613+
let data: Vec<u8> = Vec::bounded_any::<16>();
614+
let mut bytes = Bytes::from_source(data.clone());
615+
let snapshot = bytes.clone();
616+
617+
if let Some((expected, remainder)) = data.split_last() {
618+
let popped = bytes.pop_back().expect("non-empty slice");
619+
assert_eq!(popped, *expected);
620+
assert_eq!(bytes.as_ref(), remainder);
621+
} else {
622+
assert!(bytes.pop_back().is_none());
623+
assert_eq!(bytes.as_ref(), snapshot.as_ref());
624+
}
625+
}
626+
593627
#[kani::proof]
594628
#[kani::unwind(16)]
595629
pub fn check_slice_to_bytes_ok() {

0 commit comments

Comments
 (0)