tests: Extend test_tap_from_fd() with using multiple TAP fds

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2021-01-26 21:13:58 -08:00 committed by Rob Bradford
parent ff54909d2c
commit f7502057d9

View File

@ -5673,27 +5673,35 @@ mod tests {
let guest = Guest::new(&mut focal); let guest = Guest::new(&mut focal);
let kernel_path = direct_kernel_boot_path().unwrap(); let kernel_path = direct_kernel_boot_path().unwrap();
// Create a TAP interface with multi-queue enabled
let num_queue_pairs: usize = 2;
use std::str::FromStr; use std::str::FromStr;
let taps = net_util::open_tap( let taps = net_util::open_tap(
Some("chtap0"), Some("chtap0"),
Some(std::net::Ipv4Addr::from_str(&guest.network.host_ip).unwrap()), Some(std::net::Ipv4Addr::from_str(&guest.network.host_ip).unwrap()),
None, None,
&mut None, &mut None,
1, num_queue_pairs,
Some(libc::O_RDWR | libc::O_NONBLOCK), Some(libc::O_RDWR | libc::O_NONBLOCK),
) )
.unwrap(); .unwrap();
let tap_fd = taps[0].as_raw_fd();
let mut child = GuestCommand::new(&guest) let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"]) .args(&["--cpus", &format!("boot={}", num_queue_pairs)])
.args(&["--memory", "size=512M"]) .args(&["--memory", "size=512M"])
.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(&[ .args(&[
"--net", "--net",
&format!("fd={},mac={}", tap_fd, guest.network.guest_mac), &format!(
"fd={}:{},mac={},num_queues={}",
taps[0].as_raw_fd(),
taps[1].as_raw_fd(),
guest.network.guest_mac,
num_queue_pairs * 2
),
]) ])
.capture_output() .capture_output()
.spawn() .spawn()