mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-21 07:21:15 +00:00
qcow: Fix clippy issues inside tests
Found by: cargo clippy --all-features --all --tests Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
053c9e4d73
commit
abc6672f21
@ -1868,7 +1868,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_header_crazy_file_size_rejected() {
|
fn test_header_crazy_file_size_rejected() {
|
||||||
let mut header = valid_header_v3();
|
let mut header = valid_header_v3();
|
||||||
&mut header[24..32].copy_from_slice(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1e]);
|
header[24..32].copy_from_slice(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1e]);
|
||||||
with_basic_file(&header, |disk_file: RawFile| {
|
with_basic_file(&header, |disk_file: RawFile| {
|
||||||
QcowFile::from(disk_file).expect_err("Failed to create file.");
|
QcowFile::from(disk_file).expect_err("Failed to create file.");
|
||||||
});
|
});
|
||||||
@ -1917,7 +1917,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_header_huge_num_refcounts() {
|
fn test_header_huge_num_refcounts() {
|
||||||
let mut header = valid_header_v3();
|
let mut header = valid_header_v3();
|
||||||
&mut header[56..60].copy_from_slice(&[0x02, 0x00, 0xe8, 0xff]);
|
header[56..60].copy_from_slice(&[0x02, 0x00, 0xe8, 0xff]);
|
||||||
with_basic_file(&header, |disk_file: RawFile| {
|
with_basic_file(&header, |disk_file: RawFile| {
|
||||||
QcowFile::from(disk_file).expect_err("Created disk with crazy refcount clusters");
|
QcowFile::from(disk_file).expect_err("Created disk with crazy refcount clusters");
|
||||||
});
|
});
|
||||||
@ -1926,7 +1926,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_header_huge_refcount_offset() {
|
fn test_header_huge_refcount_offset() {
|
||||||
let mut header = valid_header_v3();
|
let mut header = valid_header_v3();
|
||||||
&mut header[48..56].copy_from_slice(&[0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00]);
|
header[48..56].copy_from_slice(&[0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x02, 0x00]);
|
||||||
with_basic_file(&header, |disk_file: RawFile| {
|
with_basic_file(&header, |disk_file: RawFile| {
|
||||||
QcowFile::from(disk_file).expect_err("Created disk with crazy refcount offset");
|
QcowFile::from(disk_file).expect_err("Created disk with crazy refcount offset");
|
||||||
});
|
});
|
||||||
@ -1936,11 +1936,11 @@ mod tests {
|
|||||||
fn write_read_start() {
|
fn write_read_start() {
|
||||||
with_basic_file(&valid_header_v3(), |disk_file: RawFile| {
|
with_basic_file(&valid_header_v3(), |disk_file: RawFile| {
|
||||||
let mut q = QcowFile::from(disk_file).unwrap();
|
let mut q = QcowFile::from(disk_file).unwrap();
|
||||||
q.write(b"test first bytes")
|
q.write_all(b"test first bytes")
|
||||||
.expect("Failed to write test string.");
|
.expect("Failed to write test string.");
|
||||||
let mut buf = [0u8; 4];
|
let mut buf = [0u8; 4];
|
||||||
q.seek(SeekFrom::Start(0)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0)).expect("Failed to seek.");
|
||||||
q.read(&mut buf).expect("Failed to read.");
|
q.read_exact(&mut buf).expect("Failed to read.");
|
||||||
assert_eq!(&buf, b"test");
|
assert_eq!(&buf, b"test");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1951,10 +1951,10 @@ mod tests {
|
|||||||
let mut q = QcowFile::from(disk_file).unwrap();
|
let mut q = QcowFile::from(disk_file).unwrap();
|
||||||
let b = [0x55u8; 0x1000];
|
let b = [0x55u8; 0x1000];
|
||||||
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
||||||
q.write(&b).expect("Failed to write test string.");
|
q.write_all(&b).expect("Failed to write test string.");
|
||||||
let mut buf = [0u8; 4];
|
let mut buf = [0u8; 4];
|
||||||
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
||||||
q.read(&mut buf).expect("Failed to read.");
|
q.read_exact(&mut buf).expect("Failed to read.");
|
||||||
assert_eq!(buf[0], 0x55);
|
assert_eq!(buf[0], 0x55);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1966,7 +1966,7 @@ mod tests {
|
|||||||
// Write some test data.
|
// Write some test data.
|
||||||
let b = [0x55u8; 0x1000];
|
let b = [0x55u8; 0x1000];
|
||||||
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
||||||
q.write(&b).expect("Failed to write test string.");
|
q.write_all(&b).expect("Failed to write test string.");
|
||||||
// Overwrite the test data with zeroes.
|
// Overwrite the test data with zeroes.
|
||||||
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
||||||
let nwritten = q.write_zeroes(0x200).expect("Failed to write zeroes.");
|
let nwritten = q.write_zeroes(0x200).expect("Failed to write zeroes.");
|
||||||
@ -1974,7 +1974,7 @@ mod tests {
|
|||||||
// Verify that the correct part of the data was zeroed out.
|
// Verify that the correct part of the data was zeroed out.
|
||||||
let mut buf = [0u8; 0x1000];
|
let mut buf = [0u8; 0x1000];
|
||||||
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0xfff2000)).expect("Failed to seek.");
|
||||||
q.read(&mut buf).expect("Failed to read.");
|
q.read_exact(&mut buf).expect("Failed to read.");
|
||||||
assert_eq!(buf[0], 0);
|
assert_eq!(buf[0], 0);
|
||||||
assert_eq!(buf[0x1FF], 0);
|
assert_eq!(buf[0x1FF], 0);
|
||||||
assert_eq!(buf[0x200], 0x55);
|
assert_eq!(buf[0x200], 0x55);
|
||||||
@ -1992,7 +1992,7 @@ mod tests {
|
|||||||
// Write some test data.
|
// Write some test data.
|
||||||
let b = [0x55u8; CHUNK_SIZE];
|
let b = [0x55u8; CHUNK_SIZE];
|
||||||
q.seek(SeekFrom::Start(0)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0)).expect("Failed to seek.");
|
||||||
q.write(&b).expect("Failed to write test string.");
|
q.write_all(&b).expect("Failed to write test string.");
|
||||||
// Overwrite the full cluster with zeroes.
|
// Overwrite the full cluster with zeroes.
|
||||||
q.seek(SeekFrom::Start(0)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0)).expect("Failed to seek.");
|
||||||
let nwritten = q.write_zeroes(CHUNK_SIZE).expect("Failed to write zeroes.");
|
let nwritten = q.write_zeroes(CHUNK_SIZE).expect("Failed to write zeroes.");
|
||||||
@ -2000,7 +2000,7 @@ mod tests {
|
|||||||
// Verify that the data was zeroed out.
|
// Verify that the data was zeroed out.
|
||||||
let mut buf = [0u8; CHUNK_SIZE];
|
let mut buf = [0u8; CHUNK_SIZE];
|
||||||
q.seek(SeekFrom::Start(0)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(0)).expect("Failed to seek.");
|
||||||
q.read(&mut buf).expect("Failed to read.");
|
q.read_exact(&mut buf).expect("Failed to read.");
|
||||||
assert_eq!(buf[0], 0);
|
assert_eq!(buf[0], 0);
|
||||||
assert_eq!(buf[CHUNK_SIZE - 1], 0);
|
assert_eq!(buf[CHUNK_SIZE - 1], 0);
|
||||||
});
|
});
|
||||||
@ -2024,7 +2024,7 @@ mod tests {
|
|||||||
let mut q = QcowFile::from(disk_file).unwrap();
|
let mut q = QcowFile::from(disk_file).unwrap();
|
||||||
let mut b = [5u8; 16];
|
let mut b = [5u8; 16];
|
||||||
q.seek(SeekFrom::Start(1000)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(1000)).expect("Failed to seek.");
|
||||||
q.read(&mut b).expect("Failed to read.");
|
q.read_exact(&mut b).expect("Failed to read.");
|
||||||
assert_eq!(0, b[0]);
|
assert_eq!(0, b[0]);
|
||||||
assert_eq!(0, b[15]);
|
assert_eq!(0, b[15]);
|
||||||
});
|
});
|
||||||
@ -2397,7 +2397,7 @@ mod tests {
|
|||||||
for xfer in &xfers {
|
for xfer in &xfers {
|
||||||
q.seek(SeekFrom::Start(xfer.addr)).expect("Failed to seek.");
|
q.seek(SeekFrom::Start(xfer.addr)).expect("Failed to seek.");
|
||||||
if xfer.write {
|
if xfer.write {
|
||||||
q.write(&b).expect("Failed to write.");
|
q.write_all(&b).expect("Failed to write.");
|
||||||
} else {
|
} else {
|
||||||
let read_count: usize = q.read(&mut b).expect("Failed to read.");
|
let read_count: usize = q.read(&mut b).expect("Failed to read.");
|
||||||
assert_eq!(read_count, BUF_SIZE);
|
assert_eq!(read_count, BUF_SIZE);
|
||||||
|
Loading…
Reference in New Issue
Block a user