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

Function refcount_subbyte_max_values

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

Source from the content-addressed store, hash-verified

2870 /// Test sub-byte refcount read/write roundtrip with max values.
2871 #[test]
2872 fn refcount_subbyte_max_values() {
2873 for (bits, max_val) in [(1u64, 1u64), (2, 3), (4, 15)] {
2874 let file = vmm_sys_util::tempfile::TempFile::new().unwrap().into_file();
2875 let cluster_size = 0x10000u64;
2876 file.set_len(cluster_size * 2).unwrap();
2877 let raw = RawFile::new(file, false);
2878 let mut qcow_raw = QcowRawFile::from(raw, cluster_size, bits).unwrap();
2879
2880 let entries = (cluster_size * 8 / bits) as usize;
2881 let mut table: Vec<u64> = (0..entries as u64).map(|i| i % (max_val + 1)).collect();
2882 table[0] = max_val;
2883 table[entries - 1] = max_val;
2884
2885 qcow_raw.write_refcount_block(cluster_size, &table).unwrap();
2886 let read_table = qcow_raw.read_refcount_block(cluster_size).unwrap();
2887
2888 assert_eq!(read_table.len(), entries);
2889 for (i, (&written, &read)) in table.iter().zip(read_table.iter()).enumerate() {
2890 assert_eq!(read, written & max_val, "{bits}-bit entry {i} mismatch");
2891 }
2892 }
2893 }
2894
2895 /// Test byte-aligned refcounts with max values.
2896 #[test]

Callers

nothing calls this directly

Calls 6

newFunction · 0.85
write_refcount_blockMethod · 0.80
read_refcount_blockMethod · 0.80
iterMethod · 0.80
set_lenMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected