Skip to content

Commit ba6aeb3

Browse files
Manciukicbchalios
authored andcommitted
test(pci): parametrize uvm_plain* with pci
All tests using uvm_plain or uvm_plain_any will start using PCI as well, allowing more coverage for the PCI code. This requires moving the PCI configuration to the VM factory from the spawn method. Signed-off-by: Riccardo Mancini <[email protected]> Signed-off-by: Babis Chalios <[email protected]>
1 parent cfd66ec commit ba6aeb3

File tree

10 files changed

+55
-55
lines changed

10 files changed

+55
-55
lines changed

tests/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,9 @@ def rootfs_rw():
509509

510510

511511
@pytest.fixture
512-
def uvm_plain(microvm_factory, guest_kernel_linux_5_10, rootfs):
512+
def uvm_plain(microvm_factory, guest_kernel_linux_5_10, rootfs, pci_enabled):
513513
"""Create a vanilla VM, non-parametrized"""
514-
return microvm_factory.build(guest_kernel_linux_5_10, rootfs)
514+
return microvm_factory.build(guest_kernel_linux_5_10, rootfs, pci=pci_enabled)
515515

516516

517517
@pytest.fixture
@@ -537,12 +537,12 @@ def artifact_dir():
537537

538538

539539
@pytest.fixture
540-
def uvm_plain_any(microvm_factory, guest_kernel, rootfs):
540+
def uvm_plain_any(microvm_factory, guest_kernel, rootfs, pci_enabled):
541541
"""All guest kernels
542542
kernel: all
543543
rootfs: Ubuntu 24.04
544544
"""
545-
return microvm_factory.build(guest_kernel, rootfs)
545+
return microvm_factory.build(guest_kernel, rootfs, pci=pci_enabled)
546546

547547

548548
guest_kernel_6_1_debug = pytest.fixture(
@@ -585,8 +585,8 @@ def uvm_booted(
585585
mem_size_mib=256,
586586
):
587587
"""Return a booted uvm"""
588-
uvm = microvm_factory.build(guest_kernel, rootfs)
589-
uvm.spawn(pci=pci_enabled)
588+
uvm = microvm_factory.build(guest_kernel, rootfs, pci=pci_enabled)
589+
uvm.spawn()
590590
uvm.basic_config(vcpu_count=vcpu_count, mem_size_mib=mem_size_mib)
591591
uvm.set_cpu_template(cpu_template)
592592
uvm.add_net_iface()

tests/framework/microvm.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ def __init__(
206206
jailer_kwargs: Optional[dict] = None,
207207
numa_node=None,
208208
custom_cpu_template: Path = None,
209+
pci: bool = False,
209210
):
210211
"""Set up microVM attributes, paths, and data structures."""
211212
# pylint: disable=too-many-statements
212213
# Unique identifier for this machine.
213214
assert microvm_id is not None
214215
self._microvm_id = microvm_id
215216

216-
self.pci_enabled = False
217217
self.kernel_file = None
218218
self.rootfs_file = None
219219
self.ssh_key = None
@@ -237,6 +237,10 @@ def __init__(
237237
**jailer_kwargs,
238238
)
239239

240+
self.pci_enabled = pci
241+
if pci:
242+
self.jailer.extra_args["enable-pci"] = None
243+
240244
# Copy the /etc/localtime file in the jailer root
241245
self.jailer.jailed_path("/etc/localtime", subdir="etc")
242246

@@ -635,7 +639,6 @@ def spawn(
635639
log_show_origin=False,
636640
metrics_path="fc.ndjson",
637641
emit_metrics: bool = False,
638-
pci: bool = False,
639642
):
640643
"""Start a microVM as a daemon or in a screen session."""
641644
# pylint: disable=subprocess-run-check
@@ -681,10 +684,6 @@ def spawn(
681684
# Checking the timings requires DEBUG level log messages
682685
self.time_api_requests = False
683686

684-
if pci:
685-
self.pci_enabled = True
686-
self.jailer.extra_args["enable-pci"] = None
687-
688687
cmd = [
689688
*self._pre_cmd,
690689
str(self.jailer_binary_path),

tests/integration_tests/functional/test_max_devices.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ def max_devices(uvm):
2929
raise ValueError("Unknown platform")
3030

3131

32-
def test_attach_maximum_devices(microvm_factory, guest_kernel, rootfs, pci_enabled):
32+
def test_attach_maximum_devices(uvm_plain_any):
3333
"""
3434
Test attaching maximum number of devices to the microVM.
3535
"""
36-
test_microvm = microvm_factory.build(guest_kernel, rootfs, monitor_memory=False)
37-
test_microvm.spawn(pci=pci_enabled)
36+
test_microvm = uvm_plain_any
37+
test_microvm.memory_monitor = None
38+
test_microvm.spawn()
3839

3940
# The default 256mib is not enough for 94 ssh connections on aarch64.
4041
test_microvm.basic_config(mem_size_mib=512)
@@ -52,12 +53,13 @@ def test_attach_maximum_devices(microvm_factory, guest_kernel, rootfs, pci_enabl
5253
test_microvm.ssh_iface(i).check_output("sync")
5354

5455

55-
def test_attach_too_many_devices(microvm_factory, guest_kernel, rootfs, pci_enabled):
56+
def test_attach_too_many_devices(uvm_plain):
5657
"""
5758
Test attaching to a microVM more devices than available IRQs.
5859
"""
59-
test_microvm = microvm_factory.build(guest_kernel, rootfs, monitor_memory=False)
60-
test_microvm.spawn(pci=pci_enabled)
60+
test_microvm = uvm_plain
61+
test_microvm.memory_monitor = None
62+
test_microvm.spawn()
6163

6264
# Set up a basic microVM.
6365
test_microvm.basic_config()
@@ -73,7 +75,7 @@ def test_attach_too_many_devices(microvm_factory, guest_kernel, rootfs, pci_enab
7375
# `MAX_DEVICES_ATTACHED` devices should fail.
7476
error_str = (
7577
("Could not find an available device slot on the PCI bus.")
76-
if pci_enabled
78+
if test_microvm.pci_enabled
7779
else (
7880
"Failed to allocate requested resource: The requested resource"
7981
" is not available."

tests/integration_tests/functional/test_net_config_space.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313
PAYLOAD_DATA_SIZE = 20
1414

1515

16-
def test_net_change_mac_address(
17-
uvm_plain_any, pci_enabled, change_net_config_space_bin
18-
):
16+
def test_net_change_mac_address(uvm_plain_any, change_net_config_space_bin):
1917
"""
2018
Test changing the MAC address of the network device.
2119
"""
2220

2321
test_microvm = uvm_plain_any
2422
test_microvm.help.enable_console()
25-
test_microvm.spawn(pci=pci_enabled)
23+
test_microvm.spawn()
2624
test_microvm.basic_config(boot_args="ipv6.disable=1")
2725

2826
# Data exchange interface ('eth0' in guest).

tests/integration_tests/functional/test_rng.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
from host_tools.network import SSHConnection
99

1010

11-
def uvm_with_rng_booted(
12-
microvm_factory, guest_kernel, rootfs, rate_limiter, pci_enabled
13-
):
11+
def uvm_with_rng_booted(uvm_plain_any, microvm_factory, rate_limiter):
1412
"""Return a booted microvm with virtio-rng configured"""
15-
uvm = microvm_factory.build(guest_kernel, rootfs)
16-
uvm.spawn(log_level="INFO", pci=pci_enabled)
13+
# pylint: disable=unused-argument
14+
uvm = uvm_plain_any
15+
uvm.spawn(log_level="INFO")
1716
uvm.basic_config(vcpu_count=2, mem_size_mib=256)
1817
uvm.add_net_iface()
1918
uvm.api.entropy.put(rate_limiter=rate_limiter)
@@ -23,13 +22,9 @@ def uvm_with_rng_booted(
2322
return uvm
2423

2524

26-
def uvm_with_rng_restored(
27-
microvm_factory, guest_kernel, rootfs, rate_limiter, pci_enabled
28-
):
25+
def uvm_with_rng_restored(uvm_plain_any, microvm_factory, rate_limiter):
2926
"""Return a restored uvm with virtio-rng configured"""
30-
uvm = uvm_with_rng_booted(
31-
microvm_factory, guest_kernel, rootfs, rate_limiter, pci_enabled
32-
)
27+
uvm = uvm_with_rng_booted(uvm_plain_any, microvm_factory, rate_limiter)
3328
snapshot = uvm.snapshot_full()
3429
uvm.kill()
3530
uvm2 = microvm_factory.build_from_snapshot(snapshot)
@@ -50,9 +45,9 @@ def rate_limiter(request):
5045

5146

5247
@pytest.fixture
53-
def uvm_any(microvm_factory, uvm_ctor, guest_kernel, rootfs, rate_limiter, pci_enabled):
48+
def uvm_any(microvm_factory, uvm_ctor, uvm_plain_any, rate_limiter):
5449
"""Return booted and restored uvms"""
55-
return uvm_ctor(microvm_factory, guest_kernel, rootfs, rate_limiter, pci_enabled)
50+
return uvm_ctor(uvm_plain_any, microvm_factory, rate_limiter)
5651

5752

5853
def list_rng_available(ssh_connection: SSHConnection) -> list[str]:

tests/integration_tests/functional/test_vsock.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737
TEST_WORKER_COUNT = 10
3838

3939

40-
def test_vsock(uvm_plain_any, pci_enabled, bin_vsock_path, test_fc_session_root_path):
40+
def test_vsock(uvm_plain_any, bin_vsock_path, test_fc_session_root_path):
4141
"""
4242
Test guest and host vsock initiated connections.
4343
4444
Check the module docstring for details on the setup.
4545
"""
4646

4747
vm = uvm_plain_any
48-
vm.spawn(pci=pci_enabled)
48+
vm.spawn()
4949

5050
vm.basic_config()
5151
vm.add_net_iface()
@@ -102,12 +102,12 @@ def negative_test_host_connections(vm, blob_path, blob_hash):
102102
validate_fc_metrics(metrics)
103103

104104

105-
def test_vsock_epipe(uvm_plain, pci_enabled, bin_vsock_path, test_fc_session_root_path):
105+
def test_vsock_epipe(uvm_plain_any, bin_vsock_path, test_fc_session_root_path):
106106
"""
107107
Vsock negative test to validate SIGPIPE/EPIPE handling.
108108
"""
109-
vm = uvm_plain
110-
vm.spawn(pci=pci_enabled)
109+
vm = uvm_plain_any
110+
vm.spawn()
111111
vm.basic_config()
112112
vm.add_net_iface()
113113
vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path=f"/{VSOCK_UDS_PATH}")
@@ -129,7 +129,7 @@ def test_vsock_epipe(uvm_plain, pci_enabled, bin_vsock_path, test_fc_session_roo
129129

130130

131131
def test_vsock_transport_reset_h2g(
132-
uvm_plain, pci_enabled, microvm_factory, bin_vsock_path, test_fc_session_root_path
132+
uvm_plain_any, microvm_factory, bin_vsock_path, test_fc_session_root_path
133133
):
134134
"""
135135
Vsock transport reset test.
@@ -146,8 +146,8 @@ def test_vsock_transport_reset_h2g(
146146
6. Close VM -> Load VM from Snapshot -> check that vsock
147147
device is still working.
148148
"""
149-
test_vm = uvm_plain
150-
test_vm.spawn(pci=pci_enabled)
149+
test_vm = uvm_plain_any
150+
test_vm.spawn()
151151
test_vm.basic_config(vcpu_count=2, mem_size_mib=256)
152152
test_vm.add_net_iface()
153153
test_vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path=f"/{VSOCK_UDS_PATH}")
@@ -215,12 +215,12 @@ def test_vsock_transport_reset_h2g(
215215
validate_fc_metrics(metrics)
216216

217217

218-
def test_vsock_transport_reset_g2h(uvm_plain, pci_enabled, microvm_factory):
218+
def test_vsock_transport_reset_g2h(uvm_plain_any, microvm_factory):
219219
"""
220220
Vsock transport reset test.
221221
"""
222-
test_vm = uvm_plain
223-
test_vm.spawn(pci=pci_enabled)
222+
test_vm = uvm_plain_any
223+
test_vm.spawn()
224224
test_vm.basic_config(vcpu_count=2, mem_size_mib=256)
225225
test_vm.add_net_iface()
226226
test_vm.api.vsock.put(vsock_id="vsock0", guest_cid=3, uds_path=f"/{VSOCK_UDS_PATH}")

tests/integration_tests/performance/test_block.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ def test_block_performance(
176176
"""
177177
Execute block device emulation benchmarking scenarios.
178178
"""
179-
vm = microvm_factory.build(guest_kernel_acpi, rootfs, monitor_memory=False)
180-
vm.spawn(log_level="Info", emit_metrics=True, pci=pci_enabled)
179+
vm = microvm_factory.build(
180+
guest_kernel_acpi, rootfs, monitor_memory=False, pci=pci_enabled
181+
)
182+
vm.spawn(log_level="Info", emit_metrics=True)
181183
vm.basic_config(vcpu_count=vcpus, mem_size_mib=GUEST_MEM_MIB)
182184
vm.add_net_iface()
183185
# Add a secondary block device for benchmark tests.

tests/integration_tests/performance/test_boottime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ def launch_vm_with_boot_timer(
9898
microvm_factory, guest_kernel_acpi, rootfs_rw, vcpu_count, mem_size_mib, pci_enabled
9999
):
100100
"""Launches a microVM with guest-timer and returns the reported metrics for it"""
101-
vm = microvm_factory.build(guest_kernel_acpi, rootfs_rw)
101+
vm = microvm_factory.build(guest_kernel_acpi, rootfs_rw, pci=pci_enabled)
102102
vm.jailer.extra_args.update({"boot-timer": None})
103-
vm.spawn(pci=pci_enabled)
103+
vm.spawn()
104104
vm.basic_config(
105105
vcpu_count=vcpu_count,
106106
mem_size_mib=mem_size_mib,

tests/integration_tests/performance/test_network.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ def network_microvm(request, microvm_factory, guest_kernel_acpi, rootfs, pci_ena
4545
guest_mem_mib = 1024
4646
guest_vcpus = request.param
4747

48-
vm = microvm_factory.build(guest_kernel_acpi, rootfs, monitor_memory=False)
49-
vm.spawn(log_level="Info", emit_metrics=True, pci=pci_enabled)
48+
vm = microvm_factory.build(
49+
guest_kernel_acpi, rootfs, monitor_memory=False, pci=pci_enabled
50+
)
51+
vm.spawn(log_level="Info", emit_metrics=True)
5052
vm.basic_config(vcpu_count=guest_vcpus, mem_size_mib=guest_mem_mib)
5153
vm.add_net_iface()
5254
vm.start()

tests/integration_tests/performance/test_vsock.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ def test_vsock_throughput(
9595
pytest.skip("bidrectional test only done with at least 2 vcpus")
9696

9797
mem_size_mib = 1024
98-
vm = microvm_factory.build(guest_kernel_acpi, rootfs, monitor_memory=False)
99-
vm.spawn(log_level="Info", emit_metrics=True, pci=pci_enabled)
98+
vm = microvm_factory.build(
99+
guest_kernel_acpi, rootfs, monitor_memory=False, pci=pci_enabled
100+
)
101+
vm.spawn(log_level="Info", emit_metrics=True)
100102
vm.basic_config(vcpu_count=vcpus, mem_size_mib=mem_size_mib)
101103
vm.add_net_iface()
102104
# Create a vsock device

0 commit comments

Comments
 (0)