mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-03 20:15:45 +00:00
tests: Add integration test for vhost-user-net client mode
Refactor the existing vhost-user-net integration tests in order to extend it with an extra test for vhost-user client mode. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
8f9ffe5417
commit
b2b577257f
@ -194,31 +194,28 @@ mod tests {
|
|||||||
ip: &str,
|
ip: &str,
|
||||||
tap: Option<&str>,
|
tap: Option<&str>,
|
||||||
num_queues: usize,
|
num_queues: usize,
|
||||||
) -> (std::process::Child, String) {
|
client_mode: bool,
|
||||||
|
) -> (std::process::Command, String) {
|
||||||
let vunet_socket_path =
|
let vunet_socket_path =
|
||||||
String::from(tmp_dir.as_path().join("vunet.sock").to_str().unwrap());
|
String::from(tmp_dir.as_path().join("vunet.sock").to_str().unwrap());
|
||||||
|
|
||||||
// Start the daemon
|
// Start the daemon
|
||||||
let net_params = if let Some(tap_str) = tap {
|
let net_params = if let Some(tap_str) = tap {
|
||||||
format!(
|
format!(
|
||||||
"tap={},ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024",
|
"tap={},ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024,client={}",
|
||||||
tap_str, ip, vunet_socket_path, num_queues
|
tap_str, ip, vunet_socket_path, num_queues, client_mode
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024",
|
"ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024,client={}",
|
||||||
ip, vunet_socket_path, num_queues
|
ip, vunet_socket_path, num_queues, client_mode
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let child = Command::new(clh_command("vhost_user_net"))
|
let mut command = Command::new(clh_command("vhost_user_net"));
|
||||||
.args(&["--net-backend", net_params.as_str()])
|
command.args(&["--net-backend", net_params.as_str()]);
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
thread::sleep(std::time::Duration::new(10, 0));
|
(command, vunet_socket_path)
|
||||||
|
|
||||||
(child, vunet_socket_path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn curl_command(api_socket: &str, method: &str, url: &str, http_body: Option<&str>) {
|
fn curl_command(api_socket: &str, method: &str, url: &str, http_body: Option<&str>) {
|
||||||
@ -917,13 +914,14 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PrepareNetDaemon =
|
type PrepareNetDaemon =
|
||||||
dyn Fn(&TempDir, &str, Option<&str>, usize) -> (std::process::Child, String);
|
dyn Fn(&TempDir, &str, Option<&str>, usize, bool) -> (std::process::Command, String);
|
||||||
|
|
||||||
fn test_vhost_user_net(
|
fn test_vhost_user_net(
|
||||||
tap: Option<&str>,
|
tap: Option<&str>,
|
||||||
num_queues: usize,
|
num_queues: usize,
|
||||||
prepare_vhost_user_net_daemon: Option<&PrepareNetDaemon>,
|
prepare_daemon: &PrepareNetDaemon,
|
||||||
generate_host_mac: bool,
|
generate_host_mac: bool,
|
||||||
|
client_mode_daemon: bool,
|
||||||
) {
|
) {
|
||||||
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);
|
||||||
@ -940,29 +938,33 @@ mod tests {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let (net_params, daemon_child) = {
|
let (mut daemon_command, vunet_socket_path) = prepare_daemon(
|
||||||
let prepare_daemon = prepare_vhost_user_net_daemon.unwrap();
|
&guest.tmp_dir,
|
||||||
// Start the daemon
|
&guest.network.host_ip,
|
||||||
let (daemon_child, vunet_socket_path) =
|
tap,
|
||||||
prepare_daemon(&guest.tmp_dir, &guest.network.host_ip, tap, num_queues);
|
num_queues,
|
||||||
|
client_mode_daemon,
|
||||||
|
);
|
||||||
|
|
||||||
(
|
let net_params = format!(
|
||||||
format!(
|
"vhost_user=true,mac={},socket={},num_queues={},queue_size=1024{},vhost_mode={}",
|
||||||
"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()
|
},
|
||||||
}
|
if client_mode_daemon {
|
||||||
),
|
"server"
|
||||||
Some(daemon_child),
|
} else {
|
||||||
)
|
"client"
|
||||||
};
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let mut child = GuestCommand::new(&guest)
|
let mut ch_command = GuestCommand::new(&guest);
|
||||||
|
ch_command
|
||||||
.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()])
|
||||||
@ -970,9 +972,22 @@ mod tests {
|
|||||||
.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])
|
||||||
.capture_output()
|
.capture_output();
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
let mut daemon_child: std::process::Child;
|
||||||
|
let mut child: std::process::Child;
|
||||||
|
|
||||||
|
if client_mode_daemon {
|
||||||
|
child = ch_command.spawn().unwrap();
|
||||||
|
// Make sure the VMM is waiting for the backend to connect
|
||||||
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
|
daemon_child = daemon_command.spawn().unwrap();
|
||||||
|
} else {
|
||||||
|
daemon_child = daemon_command.spawn().unwrap();
|
||||||
|
// Make sure the backend is waiting for the VMM to connect
|
||||||
|
thread::sleep(std::time::Duration::new(10, 0));
|
||||||
|
child = ch_command.spawn().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
let r = std::panic::catch_unwind(|| {
|
let r = std::panic::catch_unwind(|| {
|
||||||
guest.wait_vm_boot(None).unwrap();
|
guest.wait_vm_boot(None).unwrap();
|
||||||
@ -1055,11 +1070,9 @@ mod tests {
|
|||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
let output = child.wait_with_output().unwrap();
|
let output = child.wait_with_output().unwrap();
|
||||||
|
|
||||||
if let Some(mut daemon_child) = daemon_child {
|
thread::sleep(std::time::Duration::new(5, 0));
|
||||||
thread::sleep(std::time::Duration::new(5, 0));
|
let _ = daemon_child.kill();
|
||||||
let _ = daemon_child.kill();
|
let _ = daemon_child.wait();
|
||||||
let _ = daemon_child.wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
handle_child_output(r, &output);
|
handle_child_output(r, &output);
|
||||||
}
|
}
|
||||||
@ -2590,7 +2603,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vhost_user_net_default() {
|
fn test_vhost_user_net_default() {
|
||||||
test_vhost_user_net(None, 2, Some(&prepare_vhost_user_net_daemon), false)
|
test_vhost_user_net(None, 2, &prepare_vhost_user_net_daemon, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -2598,7 +2611,8 @@ mod tests {
|
|||||||
test_vhost_user_net(
|
test_vhost_user_net(
|
||||||
Some("mytap0"),
|
Some("mytap0"),
|
||||||
2,
|
2,
|
||||||
Some(&prepare_vhost_user_net_daemon),
|
&prepare_vhost_user_net_daemon,
|
||||||
|
false,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -2608,14 +2622,15 @@ mod tests {
|
|||||||
test_vhost_user_net(
|
test_vhost_user_net(
|
||||||
Some("vunet-tap0"),
|
Some("vunet-tap0"),
|
||||||
2,
|
2,
|
||||||
Some(&prepare_vhost_user_net_daemon),
|
&prepare_vhost_user_net_daemon,
|
||||||
|
false,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vhost_user_net_multiple_queues() {
|
fn test_vhost_user_net_multiple_queues() {
|
||||||
test_vhost_user_net(None, 4, Some(&prepare_vhost_user_net_daemon), false)
|
test_vhost_user_net(None, 4, &prepare_vhost_user_net_daemon, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -2623,7 +2638,8 @@ mod tests {
|
|||||||
test_vhost_user_net(
|
test_vhost_user_net(
|
||||||
Some("vunet-tap1"),
|
Some("vunet-tap1"),
|
||||||
4,
|
4,
|
||||||
Some(&prepare_vhost_user_net_daemon),
|
&prepare_vhost_user_net_daemon,
|
||||||
|
false,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -2631,7 +2647,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
fn test_vhost_user_net_host_mac() {
|
fn test_vhost_user_net_host_mac() {
|
||||||
test_vhost_user_net(None, 2, Some(&prepare_vhost_user_net_daemon), true)
|
test_vhost_user_net(None, 2, &prepare_vhost_user_net_daemon, true, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_vhost_user_net_client_mode() {
|
||||||
|
test_vhost_user_net(None, 2, &prepare_vhost_user_net_daemon, false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user