Skip to content

Commit

Permalink
superblock: Speed up tests with preallocated shared buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Ikey Doherty <ikey@serpentos.com>
  • Loading branch information
ikeycode committed May 19, 2024
1 parent 3b91ace commit fe51dc4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions blsforme/src/superblock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,18 @@ mod tests {
("xfs", Kind::XFS),
];

// Pre-allocate a buffer for determination tests
let mut memory: Vec<u8> = Vec::with_capacity(6 * 1024 * 1024);

for (fsname, _kind) in tests.into_iter() {
// Swings and roundabouts: Unpack ztd image in memory to get the Seekable trait we need
// While each Superblock API is non-seekable, we enforce superblock::for_reader to be seekable
// to make sure we pre-read a blob and pass it in for rewind/speed.
memory.clear();

let mut fi = fs::File::open(format!("../test/blocks/{fsname}.img.zst"))
.expect("Cannot find test image");
let mut stream = zstd::stream::Decoder::new(&mut fi).expect("Unable to decode stream");
// Roughly 6mib unpack target needed
let mut memory = Vec::with_capacity(6 * 1024 * 1024);
stream
.read_to_end(&mut memory)
.expect("Could not unpack ext4 filesystem in memory");
Expand Down

0 comments on commit fe51dc4

Please sign in to comment.