tests: Port vhost_user_net tests to new methodology

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-08-12 12:20:14 +01:00
parent effff460d4
commit 8f4e1382a9

View File

@ -1024,24 +1024,23 @@ mod tests {
self_spawned: bool, self_spawned: bool,
generate_host_mac: bool, generate_host_mac: 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);
let mut workload_path = dirs::home_dir().unwrap(); let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads"); workload_path.push("workloads");
let kernel_path = direct_kernel_boot_path().unwrap(); let kernel_path = direct_kernel_boot_path().unwrap();
let host_mac = if generate_host_mac { let host_mac = if generate_host_mac {
Some(MacAddr::local_random()) Some(MacAddr::local_random())
} else { } else {
None None
}; };
let (net_params, daemon_child) = if self_spawned { let (net_params, daemon_child) = if self_spawned {
( (
format!( format!(
"vhost_user=true,mac={},ip={},mask=255.255.255.0,num_queues={},queue_size=1024{}", "vhost_user=true,mac={},ip={},mask=255.255.255.0,num_queues={},queue_size=1024{}",
guest.network.guest_mac, guest.network.host_ip, num_queues, guest.network.guest_mac, guest.network.host_ip, num_queues,
@ -1053,48 +1052,49 @@ mod tests {
), ),
None, None,
) )
} else { } else {
let prepare_daemon = prepare_vhost_user_net_daemon.unwrap(); let prepare_daemon = prepare_vhost_user_net_daemon.unwrap();
// Start the daemon // Start the daemon
let (daemon_child, vunet_socket_path) = let (daemon_child, vunet_socket_path) =
prepare_daemon(&guest.tmp_dir, &guest.network.host_ip, tap, num_queues); prepare_daemon(&guest.tmp_dir, &guest.network.host_ip, tap, num_queues);
( (
format!( format!(
"vhost_user=true,mac={},socket={},num_queues={},queue_size=1024{}", "vhost_user=true,mac={},socket={},num_queues={},queue_size=1024{}",
guest.network.guest_mac, guest.network.guest_mac,
vunet_socket_path, vunet_socket_path,
num_queues, num_queues,
if let Some(host_mac) = host_mac { if let Some(host_mac) = host_mac {
format!(",host_mac={}", host_mac) format!(",host_mac={}", host_mac)
} else { } else {
"".to_owned() "".to_owned()
} }
), ),
Some(daemon_child), Some(daemon_child),
) )
}; };
let mut cloud_child = GuestCommand::new(&guest) let mut child = GuestCommand::new(&guest)
.args(&["--cpus", format!("boot={}", num_queues / 2).as_str()]) .args(&["--cpus", format!("boot={}", num_queues / 2).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()])
.args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE]) .args(&["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.default_disks() .default_disks()
.args(&["--net", net_params.as_str()]) .args(&["--net", net_params.as_str()])
.args(&["--api-socket", &api_socket]) .args(&["--api-socket", &api_socket])
.spawn() .capture_output()
.unwrap(); .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 let Some(tap_name) = tap { if let Some(tap_name) = tap {
let tap_count = std::process::Command::new("bash") let tap_count = std::process::Command::new("bash")
.arg("-c") .arg("-c")
.arg(format!("ip link | grep -c {}", tap_name)) .arg(format!("ip link | grep -c {}", tap_name))
.output() .output()
.expect("Expected checking of tap count to succeed"); .expect("Expected checking of tap count to succeed");
aver_eq!(tb, String::from_utf8_lossy(&tap_count.stdout).trim(), "1"); assert_eq!(String::from_utf8_lossy(&tap_count.stdout).trim(), "1");
} }
if let Some(host_mac) = tap { if let Some(host_mac) = tap {
@ -1103,7 +1103,7 @@ mod tests {
.arg(format!("ip link | grep -c {}", host_mac)) .arg(format!("ip link | grep -c {}", host_mac))
.output() .output()
.expect("Expected checking of host mac to succeed"); .expect("Expected checking of host mac to succeed");
aver_eq!(tb, String::from_utf8_lossy(&mac_count.stdout).trim(), "1"); assert_eq!(String::from_utf8_lossy(&mac_count.stdout).trim(), "1");
} }
// 1 network interface + default localhost ==> 2 interfaces // 1 network interface + default localhost ==> 2 interfaces
@ -1112,8 +1112,7 @@ mod tests {
// it does not define any --net network interface. That means all // it does not define any --net network interface. That means all
// the ssh communication in that test happens through the network // the ssh communication in that test happens through the network
// interface backed by vhost-user-net. // interface backed by vhost-user-net.
aver_eq!( assert_eq!(
tb,
guest guest
.ssh_command("ip -o link | wc -l") .ssh_command("ip -o link | wc -l")
.unwrap_or_default() .unwrap_or_default()
@ -1134,8 +1133,7 @@ mod tests {
// Based on the above, the total vectors should 14. // Based on the above, the total vectors should 14.
// This is a PCI only feature. // This is a PCI only feature.
#[cfg(all(not(feature = "mmio"), feature = "acpi"))] #[cfg(all(not(feature = "mmio"), feature = "acpi"))]
aver_eq!( assert_eq!(
tb,
guest guest
.ssh_command("grep -c PCI-MSI /proc/interrupts") .ssh_command("grep -c PCI-MSI /proc/interrupts")
.unwrap_or_default() .unwrap_or_default()
@ -1164,20 +1162,20 @@ mod tests {
// Here by simply checking the size (through ssh), we validate // Here by simply checking the size (through ssh), we validate
// the connection is still working, which means vhost-user-net // the connection is still working, which means vhost-user-net
// keeps working after the resize. // keeps working after the resize.
aver!(tb, guest.get_total_memory().unwrap_or_default() > 960_000); assert!(guest.get_total_memory().unwrap_or_default() > 960_000);
} }
let _ = cloud_child.kill();
let _ = cloud_child.wait();
if let Some(mut daemon_child) = daemon_child {
thread::sleep(std::time::Duration::new(5, 0));
let _ = daemon_child.kill();
let _ = daemon_child.wait();
}
Ok(())
}); });
let _ = child.kill();
let output = child.wait_with_output().unwrap();
if let Some(mut daemon_child) = daemon_child {
thread::sleep(std::time::Duration::new(5, 0));
let _ = daemon_child.kill();
let _ = daemon_child.wait();
}
handle_child_output(r, &output);
} }
type PrepareBlkDaemon = type PrepareBlkDaemon =