MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / discard_sets_zero_flag

Function discard_sets_zero_flag

block/src/qcow/mod.rs:3344–3383  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3342
3343 #[test]
3344 fn discard_sets_zero_flag() {
3345 with_basic_file(&valid_header_v3(), |disk_file: RawFile| {
3346 let mut q = QcowFile::from(disk_file).unwrap();
3347
3348 // Write some test data to allocate a cluster
3349 let test_data = [0x42u8; 4096];
3350 q.seek(SeekFrom::Start(0x10000)).expect("Failed to seek.");
3351 q.write_all(&test_data).expect("Failed to write test data.");
3352
3353 // Verify data was written
3354 let mut buf = [0u8; 4096];
3355 q.seek(SeekFrom::Start(0x10000)).expect("Failed to seek.");
3356 q.read_exact(&mut buf).expect("Failed to read.");
3357 assert_eq!(buf[0], 0x42);
3358 assert_eq!(buf[4095], 0x42);
3359
3360 // DISCARD the full cluster (via write_zeroes which calls punch_hole)
3361 q.seek(SeekFrom::Start(0x10000)).expect("Failed to seek.");
3362 let nwritten = q.write_zeroes(4096).expect("Failed to discard cluster.");
3363 assert_eq!(nwritten, 4096);
3364
3365 // Verify reads now return zeros (due to zero flag)
3366 q.seek(SeekFrom::Start(0x10000)).expect("Failed to seek.");
3367 q.read_exact(&mut buf).expect("Failed to read.");
3368 assert_eq!(buf[0], 0);
3369 assert_eq!(buf[4095], 0);
3370
3371 // Write new data to the trimmed cluster
3372 let new_data = [0x99u8; 4096];
3373 q.seek(SeekFrom::Start(0x10000)).expect("Failed to seek.");
3374 q.write_all(&new_data)
3375 .expect("Failed to write to trimmed cluster.");
3376
3377 // Verify new data can be read (cluster was reallocated)
3378 q.seek(SeekFrom::Start(0x10000)).expect("Failed to seek.");
3379 q.read_exact(&mut buf).expect("Failed to read.");
3380 assert_eq!(buf[0], 0x99);
3381 assert_eq!(buf[4095], 0x99);
3382 });
3383 }
3384
3385 #[test]
3386 fn test_header() {

Callers

nothing calls this directly

Calls 4

with_basic_fileFunction · 0.85
valid_header_v3Function · 0.85
seekMethod · 0.45
write_zeroesMethod · 0.45

Tested by

no test coverage detected