mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 19:32:20 +00:00
qcow: Make unit tests pass
Rather than relying on shared memory for a temporary file for QCOW testing instead use tempfile crate to get a temporary file. The vector cache tests also need a trivial update after the refactor. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
9a17871630
commit
a50c54671c
@ -14,3 +14,6 @@ libc = "*"
|
|||||||
log = "*"
|
log = "*"
|
||||||
remain = "*"
|
remain = "*"
|
||||||
vmm-sys-util = { git = "https://github.com/rust-vmm/vmm-sys-util" }
|
vmm-sys-util = { git = "https://github.com/rust-vmm/vmm-sys-util" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = "*"
|
||||||
|
@ -1623,7 +1623,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Seek, SeekFrom, Write};
|
use std::io::{Read, Seek, SeekFrom, Write};
|
||||||
use sys_util::SharedMemory;
|
use tempfile::tempfile;
|
||||||
|
|
||||||
fn valid_header() -> Vec<u8> {
|
fn valid_header() -> Vec<u8> {
|
||||||
vec![
|
vec![
|
||||||
@ -1652,8 +1652,7 @@ mod tests {
|
|||||||
where
|
where
|
||||||
F: FnMut(File),
|
F: FnMut(File),
|
||||||
{
|
{
|
||||||
let shm = SharedMemory::new(None).unwrap();
|
let mut disk_file: File = tempfile().unwrap();
|
||||||
let mut disk_file: File = shm.into();
|
|
||||||
disk_file.write_all(&header).unwrap();
|
disk_file.write_all(&header).unwrap();
|
||||||
disk_file.set_len(0x5_0000).unwrap();
|
disk_file.set_len(0x5_0000).unwrap();
|
||||||
disk_file.seek(SeekFrom::Start(0)).unwrap();
|
disk_file.seek(SeekFrom::Start(0)).unwrap();
|
||||||
@ -1665,8 +1664,8 @@ mod tests {
|
|||||||
where
|
where
|
||||||
F: FnMut(QcowFile),
|
F: FnMut(QcowFile),
|
||||||
{
|
{
|
||||||
let shm = SharedMemory::new(None).unwrap();
|
let tmp = tempfile().unwrap();
|
||||||
let qcow_file = QcowFile::new(shm.into(), file_size).unwrap();
|
let qcow_file = QcowFile::new(tmp, file_size).unwrap();
|
||||||
|
|
||||||
testfn(qcow_file); // File closed when the function exits.
|
testfn(qcow_file); // File closed when the function exits.
|
||||||
}
|
}
|
||||||
@ -1674,8 +1673,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn default_header() {
|
fn default_header() {
|
||||||
let header = QcowHeader::create_for_size(0x10_0000);
|
let header = QcowHeader::create_for_size(0x10_0000);
|
||||||
let shm = SharedMemory::new(None).unwrap();
|
let mut disk_file: File = tempfile().unwrap();
|
||||||
let mut disk_file: File = shm.into();
|
|
||||||
header
|
header
|
||||||
.write_to(&mut disk_file)
|
.write_to(&mut disk_file)
|
||||||
.expect("Failed to write header to shm.");
|
.expect("Failed to write header to shm.");
|
||||||
|
@ -178,8 +178,8 @@ mod tests {
|
|||||||
|
|
||||||
// Check that three of the four items inserted are still there and that the most recently
|
// Check that three of the four items inserted are still there and that the most recently
|
||||||
// inserted is one of them.
|
// inserted is one of them.
|
||||||
let num_items = (0..=3).filter(|k| cache.contains_key(&k)).count();
|
let num_items = (0..=3).filter(|k| cache.contains_key(*k)).count();
|
||||||
assert_eq!(num_items, 3);
|
assert_eq!(num_items, 3);
|
||||||
assert!(cache.contains_key(&3));
|
assert!(cache.contains_key(3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user