mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
tests: extract _test_pci_bar_reprogramming wrapper
Extract test logic from test_pci_bar_reprogramming into a shared _test_pci_bar_reprogramming wrapper function in tests_wrappers.rs. The kernel_path selection for aarch64 (edk2) is kept in the parent test case. The wrapper uses default_kernel_cmdline() for kernel/cmdline setup. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
bff6e40eaa
commit
b478fa0ffd
@@ -2471,3 +2471,84 @@ pub(crate) fn _test_direct_kernel_boot_noacpi(guest: &Guest) {
|
||||
|
||||
handle_child_output(r, &output);
|
||||
}
|
||||
|
||||
pub(crate) fn _test_pci_bar_reprogramming(guest: &Guest) {
|
||||
let mut child = GuestCommand::new(guest)
|
||||
.default_cpus()
|
||||
.default_memory()
|
||||
.default_kernel_cmdline()
|
||||
.default_disks()
|
||||
.args([
|
||||
"--net",
|
||||
guest.default_net_string().as_str(),
|
||||
"tap=,mac=8a:6b:6f:5a:de:ac,ip=192.168.3.1,mask=255.255.255.128",
|
||||
])
|
||||
.capture_output()
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
let r = std::panic::catch_unwind(|| {
|
||||
guest.wait_vm_boot().unwrap();
|
||||
|
||||
// 2 network interfaces + default localhost ==> 3 interfaces
|
||||
assert_eq!(
|
||||
guest
|
||||
.ssh_command("ip -o link | wc -l")
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.unwrap_or_default(),
|
||||
3
|
||||
);
|
||||
|
||||
let init_bar_addr = guest
|
||||
.ssh_command("sudo awk '{print $1; exit}' /sys/bus/pci/devices/0000:00:05.0/resource")
|
||||
.unwrap();
|
||||
|
||||
// Remove the PCI device
|
||||
guest
|
||||
.ssh_command("echo 1 | sudo tee /sys/bus/pci/devices/0000:00:05.0/remove")
|
||||
.unwrap();
|
||||
|
||||
// Only 1 network interface left + default localhost ==> 2 interfaces
|
||||
assert_eq!(
|
||||
guest
|
||||
.ssh_command("ip -o link | wc -l")
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.unwrap_or_default(),
|
||||
2
|
||||
);
|
||||
|
||||
// Remove the PCI device
|
||||
guest
|
||||
.ssh_command("echo 1 | sudo tee /sys/bus/pci/rescan")
|
||||
.unwrap();
|
||||
|
||||
// Back to 2 network interface + default localhost ==> 3 interfaces
|
||||
assert_eq!(
|
||||
guest
|
||||
.ssh_command("ip -o link | wc -l")
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.unwrap_or_default(),
|
||||
3
|
||||
);
|
||||
|
||||
let new_bar_addr = guest
|
||||
.ssh_command("sudo awk '{print $1; exit}' /sys/bus/pci/devices/0000:00:05.0/resource")
|
||||
.unwrap();
|
||||
|
||||
// Let's compare the BAR addresses for our virtio-net device.
|
||||
// They should be different as we expect the BAR reprogramming
|
||||
// to have happened.
|
||||
assert_ne!(init_bar_addr, new_bar_addr);
|
||||
});
|
||||
|
||||
kill_child(&mut child);
|
||||
let output = child.wait_with_output().unwrap();
|
||||
|
||||
handle_child_output(r, &output);
|
||||
}
|
||||
|
||||
@@ -2524,97 +2524,12 @@ mod common_parallel {
|
||||
// properly probed first, then removing it, and adding it again by doing a
|
||||
// rescan.
|
||||
fn test_pci_bar_reprogramming() {
|
||||
let disk_config = UbuntuDiskConfig::new(JAMMY_IMAGE_NAME.to_string());
|
||||
let guest = Guest::new(Box::new(disk_config));
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
let kernel_path = direct_kernel_boot_path();
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
let kernel_path = edk2_path();
|
||||
|
||||
let mut child = GuestCommand::new(&guest)
|
||||
.default_cpus()
|
||||
.default_memory()
|
||||
.args(["--kernel", kernel_path.to_str().unwrap()])
|
||||
.args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
|
||||
.default_disks()
|
||||
.args([
|
||||
"--net",
|
||||
guest.default_net_string().as_str(),
|
||||
"tap=,mac=8a:6b:6f:5a:de:ac,ip=192.168.3.1,mask=255.255.255.128",
|
||||
])
|
||||
.capture_output()
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
let r = std::panic::catch_unwind(|| {
|
||||
guest.wait_vm_boot().unwrap();
|
||||
|
||||
// 2 network interfaces + default localhost ==> 3 interfaces
|
||||
assert_eq!(
|
||||
guest
|
||||
.ssh_command("ip -o link | wc -l")
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.unwrap_or_default(),
|
||||
3
|
||||
);
|
||||
|
||||
let init_bar_addr = guest
|
||||
.ssh_command(
|
||||
"sudo awk '{print $1; exit}' /sys/bus/pci/devices/0000:00:05.0/resource",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Remove the PCI device
|
||||
guest
|
||||
.ssh_command("echo 1 | sudo tee /sys/bus/pci/devices/0000:00:05.0/remove")
|
||||
.unwrap();
|
||||
|
||||
// Only 1 network interface left + default localhost ==> 2 interfaces
|
||||
assert_eq!(
|
||||
guest
|
||||
.ssh_command("ip -o link | wc -l")
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.unwrap_or_default(),
|
||||
2
|
||||
);
|
||||
|
||||
// Remove the PCI device
|
||||
guest
|
||||
.ssh_command("echo 1 | sudo tee /sys/bus/pci/rescan")
|
||||
.unwrap();
|
||||
|
||||
// Back to 2 network interface + default localhost ==> 3 interfaces
|
||||
assert_eq!(
|
||||
guest
|
||||
.ssh_command("ip -o link | wc -l")
|
||||
.unwrap()
|
||||
.trim()
|
||||
.parse::<u32>()
|
||||
.unwrap_or_default(),
|
||||
3
|
||||
);
|
||||
|
||||
let new_bar_addr = guest
|
||||
.ssh_command(
|
||||
"sudo awk '{print $1; exit}' /sys/bus/pci/devices/0000:00:05.0/resource",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Let's compare the BAR addresses for our virtio-net device.
|
||||
// They should be different as we expect the BAR reprogramming
|
||||
// to have happened.
|
||||
assert_ne!(init_bar_addr, new_bar_addr);
|
||||
});
|
||||
|
||||
kill_child(&mut child);
|
||||
let output = child.wait_with_output().unwrap();
|
||||
|
||||
handle_child_output(r, &output);
|
||||
let guest =
|
||||
basic_regular_guest!(JAMMY_IMAGE_NAME).with_kernel_path(edk2_path().to_str().unwrap());
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
let guest = basic_regular_guest!(JAMMY_IMAGE_NAME);
|
||||
_test_pci_bar_reprogramming(&guest);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user