From eaafe426a647cd9b1d063fc4f1afe88e2ab846f0 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 22 Jan 2026 11:21:07 +0100 Subject: [PATCH] tests: qcow: Add unit test for zero bit helpers Add test for l2_entry_is_zero() and related helper functions. Signed-off-by: Anatol Belski --- block/src/qcow/mod.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/block/src/qcow/mod.rs b/block/src/qcow/mod.rs index 732c10e4b..e3aa04349 100644 --- a/block/src/qcow/mod.rs +++ b/block/src/qcow/mod.rs @@ -2597,6 +2597,26 @@ mod unit_tests { }); } + #[test] + fn test_l2_entry_zero_flag() { + let empty_entry: u64 = 0; + let standard_entry: u64 = 0x1000; + let zero_flag_entry: u64 = 0x1000 | ZERO_FLAG; + let compressed_entry: u64 = COMPRESSED_FLAG; + + assert!(l2_entry_is_empty(empty_entry)); + assert!(!l2_entry_is_empty(standard_entry)); + + assert!(!l2_entry_is_compressed(standard_entry)); + assert!(l2_entry_is_compressed(compressed_entry)); + + assert!(!l2_entry_is_zero(standard_entry)); + assert!(l2_entry_is_zero(zero_flag_entry)); + + // Note: l2_entry_is_zero() only checks bit 0, so compressed entries + // must be checked first as the code does in file_read. + } + #[test] fn test_header_1_tb_file() { let mut header = test_huge_header();