mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-07-15 13:47:14 +00:00
tests: Port virtiofs tests to new methodology
This required a bit of rearranging as it is not possible to call prepare_daemon() inside a catch_unwind{} block. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
23174800ca
commit
32b70e354c
@ -1473,7 +1473,6 @@ mod tests {
|
|||||||
prepare_daemon: &dyn Fn(&TempDir, &str, &str) -> (std::process::Child, String),
|
prepare_daemon: &dyn Fn(&TempDir, &str, &str) -> (std::process::Child, String),
|
||||||
hotplug: bool,
|
hotplug: 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);
|
||||||
@ -1518,20 +1517,17 @@ mod tests {
|
|||||||
guest_command.args(&["--fs", fs_params.as_str()]);
|
guest_command.args(&["--fs", fs_params.as_str()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut child = guest_command.spawn().unwrap();
|
let mut child = guest_command.capture_output().spawn().unwrap();
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(20, 0));
|
thread::sleep(std::time::Duration::new(20, 0));
|
||||||
|
let r = std::panic::catch_unwind(|| {
|
||||||
if hotplug {
|
if hotplug {
|
||||||
// Add fs to the VM
|
// Add fs to the VM
|
||||||
let (cmd_success, cmd_output) =
|
let (cmd_success, cmd_output) =
|
||||||
remote_command_w_output(&api_socket, "add-fs", Some(&fs_params));
|
remote_command_w_output(&api_socket, "add-fs", Some(&fs_params));
|
||||||
aver!(tb, cmd_success);
|
assert!(cmd_success);
|
||||||
aver!(
|
assert!(String::from_utf8_lossy(&cmd_output)
|
||||||
tb,
|
.contains("{\"id\":\"myfs0\",\"bdf\":\"0000:00:06.0\"}"));
|
||||||
String::from_utf8_lossy(&cmd_output)
|
|
||||||
.contains("{\"id\":\"myfs0\",\"bdf\":\"0000:00:06.0\"}")
|
|
||||||
);
|
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
}
|
}
|
||||||
@ -1543,8 +1539,7 @@ mod tests {
|
|||||||
echo ok",
|
echo ok",
|
||||||
dax_mount_param
|
dax_mount_param
|
||||||
);
|
);
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest.ssh_command(&mount_cmd).unwrap_or_default().trim(),
|
guest.ssh_command(&mount_cmd).unwrap_or_default().trim(),
|
||||||
"ok"
|
"ok"
|
||||||
);
|
);
|
||||||
@ -1552,16 +1547,14 @@ mod tests {
|
|||||||
// Check the cache size is the expected one.
|
// Check the cache size is the expected one.
|
||||||
// With virtio-mmio the cache doesn't appear in /proc/iomem
|
// With virtio-mmio the cache doesn't appear in /proc/iomem
|
||||||
#[cfg(not(feature = "mmio"))]
|
#[cfg(not(feature = "mmio"))]
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.valid_virtio_fs_cache_size(dax, cache_size)
|
.valid_virtio_fs_cache_size(dax, cache_size)
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
// Check file1 exists and its content is "foo"
|
// Check file1 exists and its content is "foo"
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("cat mount_dir/file1")
|
.ssh_command("cat mount_dir/file1")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1569,8 +1562,7 @@ mod tests {
|
|||||||
"foo"
|
"foo"
|
||||||
);
|
);
|
||||||
// Check file2 does not exist
|
// Check file2 does not exist
|
||||||
aver_ne!(
|
assert_ne!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("ls mount_dir/file2")
|
.ssh_command("ls mount_dir/file2")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1578,8 +1570,7 @@ mod tests {
|
|||||||
"mount_dir/file2"
|
"mount_dir/file2"
|
||||||
);
|
);
|
||||||
// Check file3 exists and its content is "bar"
|
// Check file3 exists and its content is "bar"
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("cat mount_dir/file3")
|
.ssh_command("cat mount_dir/file3")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1604,12 +1595,11 @@ mod tests {
|
|||||||
resize_command(&api_socket, None, Some(desired_ram), None);
|
resize_command(&api_socket, None, Some(desired_ram), None);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
// After the resize, check again that file1 exists and its
|
// After the resize, check again that file1 exists and its
|
||||||
// content is "foo".
|
// content is "foo".
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("cat mount_dir/file1")
|
.ssh_command("cat mount_dir/file1")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@ -1620,25 +1610,26 @@ mod tests {
|
|||||||
|
|
||||||
if hotplug {
|
if hotplug {
|
||||||
// Remove from VM
|
// Remove from VM
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("sudo umount mount_dir && echo ok")
|
.ssh_command("sudo umount mount_dir && echo ok")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.trim(),
|
.trim(),
|
||||||
"ok"
|
"ok"
|
||||||
);
|
);
|
||||||
aver!(
|
assert!(remote_command(&api_socket, "remove-device", Some("myfs0")));
|
||||||
tb,
|
}
|
||||||
remote_command(&api_socket, "remove-device", Some("myfs0"),)
|
});
|
||||||
);
|
|
||||||
|
|
||||||
|
let (r, hotplug_daemon_child) = if r.is_ok() && hotplug {
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
let (mut daemon_child, virtiofsd_socket_path) = prepare_daemon(
|
let (daemon_child, virtiofsd_socket_path) = prepare_daemon(
|
||||||
&guest.tmp_dir,
|
&guest.tmp_dir,
|
||||||
shared_dir.to_str().unwrap(),
|
shared_dir.to_str().unwrap(),
|
||||||
virtiofsd_cache,
|
virtiofsd_cache,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let r = std::panic::catch_unwind(|| {
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
let fs_params = format!(
|
let fs_params = format!(
|
||||||
"id=myfs0,tag=myfs,socket={},num_queues=1,queue_size=1024,dax={}{}",
|
"id=myfs0,tag=myfs,socket={},num_queues=1,queue_size=1024,dax={}{}",
|
||||||
@ -1648,12 +1639,9 @@ mod tests {
|
|||||||
// Add back and check it works
|
// Add back and check it works
|
||||||
let (cmd_success, cmd_output) =
|
let (cmd_success, cmd_output) =
|
||||||
remote_command_w_output(&api_socket, "add-fs", Some(&fs_params));
|
remote_command_w_output(&api_socket, "add-fs", Some(&fs_params));
|
||||||
aver!(tb, cmd_success);
|
assert!(cmd_success);
|
||||||
aver!(
|
assert!(String::from_utf8_lossy(&cmd_output)
|
||||||
tb,
|
.contains("{\"id\":\"myfs0\",\"bdf\":\"0000:00:06.0\"}"));
|
||||||
String::from_utf8_lossy(&cmd_output)
|
|
||||||
.contains("{\"id\":\"myfs0\",\"bdf\":\"0000:00:06.0\"}")
|
|
||||||
);
|
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
// Mount shared directory through virtio_fs filesystem
|
// Mount shared directory through virtio_fs filesystem
|
||||||
let mount_cmd = format!(
|
let mount_cmd = format!(
|
||||||
@ -1662,30 +1650,37 @@ mod tests {
|
|||||||
echo ok",
|
echo ok",
|
||||||
dax_mount_param
|
dax_mount_param
|
||||||
);
|
);
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest.ssh_command(&mount_cmd).unwrap_or_default().trim(),
|
guest.ssh_command(&mount_cmd).unwrap_or_default().trim(),
|
||||||
"ok"
|
"ok"
|
||||||
);
|
);
|
||||||
// Check file1 exists and its content is "foo"
|
// Check file1 exists and its content is "foo"
|
||||||
aver_eq!(
|
assert_eq!(
|
||||||
tb,
|
|
||||||
guest
|
guest
|
||||||
.ssh_command("cat mount_dir/file1")
|
.ssh_command("cat mount_dir/file1")
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.trim(),
|
.trim(),
|
||||||
"foo"
|
"foo"
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
(r, Some(daemon_child))
|
||||||
|
} else {
|
||||||
|
(r, None)
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = child.kill();
|
||||||
|
let output = child.wait_with_output().unwrap();
|
||||||
|
|
||||||
|
let _ = daemon_child.kill();
|
||||||
|
let _ = daemon_child.wait();
|
||||||
|
|
||||||
|
if let Some(mut daemon_child) = hotplug_daemon_child {
|
||||||
let _ = daemon_child.kill();
|
let _ = daemon_child.kill();
|
||||||
let _ = daemon_child.wait();
|
let _ = daemon_child.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = child.kill();
|
handle_child_output(r, &output);
|
||||||
let _ = daemon_child.kill();
|
|
||||||
let _ = child.wait();
|
|
||||||
let _ = daemon_child.wait();
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_virtio_pmem(discard_writes: bool, specify_size: bool) {
|
fn test_virtio_pmem(discard_writes: bool, specify_size: bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user