mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-02 01:45:21 +00:00
tests: Port vhost_user_block tests to new methodology
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
8f4e1382a9
commit
23174800ca
@ -1188,7 +1188,6 @@ mod tests {
|
|||||||
prepare_vhost_user_blk_daemon: Option<&PrepareBlkDaemon>,
|
prepare_vhost_user_blk_daemon: Option<&PrepareBlkDaemon>,
|
||||||
self_spawned: bool,
|
self_spawned: bool,
|
||||||
) {
|
) {
|
||||||
test_block!(tb, "", {
|
|
||||||
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
||||||
let guest = Guest::new(&mut focal);
|
let guest = Guest::new(&mut focal);
|
||||||
let api_socket = temp_api_path(&guest.tmp_dir);
|
let api_socket = temp_api_path(&guest.tmp_dir);
|
||||||
@ -1225,7 +1224,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut cloud_child = GuestCommand::new(&guest)
|
let mut child = GuestCommand::new(&guest)
|
||||||
.args(&["--cpus", format!("boot={}", num_queues).as_str()])
|
.args(&["--cpus", format!("boot={}", num_queues).as_str()])
|
||||||
.args(&["--memory", "size=512M,hotplug_size=2048M,shared=on"])
|
.args(&["--memory", "size=512M,hotplug_size=2048M,shared=on"])
|
||||||
.args(&["--kernel", kernel_path.to_str().unwrap()])
|
.args(&["--kernel", kernel_path.to_str().unwrap()])
|
||||||
@ -1246,14 +1245,15 @@ mod tests {
|
|||||||
])
|
])
|
||||||
.default_net()
|
.default_net()
|
||||||
.args(&["--api-socket", &api_socket])
|
.args(&["--api-socket", &api_socket])
|
||||||
|
.capture_output()
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(120, 0));
|
thread::sleep(std::time::Duration::new(120, 0));
|
||||||
|
|
||||||
|
let r = std::panic::catch_unwind(|| {
|
||||||
// Check both if /dev/vdc exists and if the block size is 16M.
|
// Check both if /dev/vdc exists and if the block size is 16M.
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("lsblk | grep vdc | grep -c 16M")
|
.ssh_command("lsblk | grep vdc | grep -c 16M")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1264,8 +1264,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check if this block is RO or RW.
|
// Check if this block is RO or RW.
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("lsblk | grep vdc | awk '{print $5}'")
|
.ssh_command("lsblk | grep vdc | awk '{print $5}'")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1277,8 +1276,7 @@ mod tests {
|
|||||||
|
|
||||||
// Check if the number of queues in /sys/block/vdc/mq matches the
|
// Check if the number of queues in /sys/block/vdc/mq matches the
|
||||||
// expected num_queues.
|
// expected num_queues.
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("ls -ll /sys/block/vdc/mq | grep ^d | wc -l")
|
.ssh_command("ls -ll /sys/block/vdc/mq | grep ^d | wc -l")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1290,19 +1288,20 @@ mod tests {
|
|||||||
|
|
||||||
// Mount the device
|
// Mount the device
|
||||||
let mount_ro_rw_flag = if readonly { "ro,noload" } else { "rw" };
|
let mount_ro_rw_flag = if readonly { "ro,noload" } else { "rw" };
|
||||||
guest.ssh_command("mkdir mount_image")?;
|
guest.ssh_command("mkdir mount_image").unwrap();
|
||||||
guest.ssh_command(
|
guest
|
||||||
|
.ssh_command(
|
||||||
format!(
|
format!(
|
||||||
"sudo mount -o {} -t ext4 /dev/vdc mount_image/",
|
"sudo mount -o {} -t ext4 /dev/vdc mount_image/",
|
||||||
mount_ro_rw_flag
|
mount_ro_rw_flag
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
)?;
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Check the content of the block device. The file "foo" should
|
// Check the content of the block device. The file "foo" should
|
||||||
// contain "bar".
|
// contain "bar".
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("cat mount_image/foo")
|
.ssh_command("cat mount_image/foo")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1326,12 +1325,11 @@ mod tests {
|
|||||||
|
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
|
|
||||||
aver!(tb, guest.get_total_memory().unwrap_or_default() > 960_000);
|
assert!(guest.get_total_memory().unwrap_or_default() > 960_000);
|
||||||
|
|
||||||
// Check again the content of the block device after the resize
|
// Check again the content of the block device after the resize
|
||||||
// has been performed.
|
// has been performed.
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("cat mount_image/foo")
|
.ssh_command("cat mount_image/foo")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1341,11 +1339,12 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unmount the device
|
// Unmount the device
|
||||||
guest.ssh_command("sudo umount /dev/vdc")?;
|
guest.ssh_command("sudo umount /dev/vdc").unwrap();
|
||||||
guest.ssh_command("rm -r mount_image")?;
|
guest.ssh_command("rm -r mount_image").unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
let _ = cloud_child.kill();
|
let _ = child.kill();
|
||||||
let _ = cloud_child.wait();
|
let output = child.wait_with_output().unwrap();
|
||||||
|
|
||||||
if let Some(mut daemon_child) = daemon_child {
|
if let Some(mut daemon_child) = daemon_child {
|
||||||
thread::sleep(std::time::Duration::new(5, 0));
|
thread::sleep(std::time::Duration::new(5, 0));
|
||||||
@ -1353,8 +1352,7 @@ mod tests {
|
|||||||
let _ = daemon_child.wait();
|
let _ = daemon_child.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
handle_child_output(r, &output);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_boot_from_vhost_user_blk(
|
fn test_boot_from_vhost_user_blk(
|
||||||
@ -1364,7 +1362,6 @@ mod tests {
|
|||||||
prepare_vhost_user_blk_daemon: Option<&PrepareBlkDaemon>,
|
prepare_vhost_user_blk_daemon: Option<&PrepareBlkDaemon>,
|
||||||
self_spawned: bool,
|
self_spawned: bool,
|
||||||
) {
|
) {
|
||||||
test_block!(tb, "", {
|
|
||||||
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
||||||
let guest = Guest::new(&mut focal);
|
let guest = Guest::new(&mut focal);
|
||||||
|
|
||||||
@ -1406,7 +1403,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut cloud_child = GuestCommand::new(&guest)
|
let mut child = GuestCommand::new(&guest)
|
||||||
.args(&["--cpus", format!("boot={}", num_queues).as_str()])
|
.args(&["--cpus", format!("boot={}", num_queues).as_str()])
|
||||||
.args(&["--memory", "size=512M,shared=on"])
|
.args(&["--memory", "size=512M,shared=on"])
|
||||||
.args(&["--kernel", kernel_path.to_str().unwrap()])
|
.args(&["--kernel", kernel_path.to_str().unwrap()])
|
||||||
@ -1421,18 +1418,16 @@ mod tests {
|
|||||||
.as_str(),
|
.as_str(),
|
||||||
])
|
])
|
||||||
.default_net()
|
.default_net()
|
||||||
|
.capture_output()
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(40, 0));
|
thread::sleep(std::time::Duration::new(40, 0));
|
||||||
|
|
||||||
|
let r = std::panic::catch_unwind(|| {
|
||||||
// Just check the VM booted correctly.
|
// Just check the VM booted correctly.
|
||||||
aver_eq!(
|
assert_eq!(guest.get_cpu_count().unwrap_or_default(), num_queues as u32);
|
||||||
tb,
|
assert!(guest.get_total_memory().unwrap_or_default() > 480_000);
|
||||||
guest.get_cpu_count().unwrap_or_default(),
|
|
||||||
num_queues as u32
|
|
||||||
);
|
|
||||||
aver!(tb, guest.get_total_memory().unwrap_or_default() > 480_000);
|
|
||||||
|
|
||||||
if self_spawned {
|
if self_spawned {
|
||||||
// The reboot is not supported with mmio, so no reason to test it.
|
// The reboot is not supported with mmio, so no reason to test it.
|
||||||
@ -1445,7 +1440,7 @@ mod tests {
|
|||||||
.parse::<u32>()
|
.parse::<u32>()
|
||||||
.unwrap_or(1);
|
.unwrap_or(1);
|
||||||
|
|
||||||
aver_eq!(tb, reboot_count, 0);
|
assert_eq!(reboot_count, 0);
|
||||||
guest.ssh_command("sudo reboot").unwrap_or_default();
|
guest.ssh_command("sudo reboot").unwrap_or_default();
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
@ -1455,12 +1450,12 @@ mod tests {
|
|||||||
.trim()
|
.trim()
|
||||||
.parse::<u32>()
|
.parse::<u32>()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
aver_eq!(tb, reboot_count, 1);
|
assert_eq!(reboot_count, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
let _ = cloud_child.kill();
|
let _ = child.kill();
|
||||||
let _ = cloud_child.wait();
|
let output = child.wait_with_output().unwrap();
|
||||||
|
|
||||||
if let Some(mut daemon_child) = daemon_child {
|
if let Some(mut daemon_child) = daemon_child {
|
||||||
thread::sleep(std::time::Duration::new(5, 0));
|
thread::sleep(std::time::Duration::new(5, 0));
|
||||||
@ -1468,8 +1463,7 @@ mod tests {
|
|||||||
let _ = daemon_child.wait();
|
let _ = daemon_child.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
handle_child_output(r, &output);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_virtio_fs(
|
fn test_virtio_fs(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user