Skip to content

Commit df8206c

Browse files
committed
test(pci): parametrize uvm_plain* with pci
Move the PCI configuration to the VM factory so that we can have uvm_plain* fixtures also run the tests on PCIe kernels. Also cleanup some places where the uvm_plain was simpler. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent 9d0b3f5 commit df8206c

File tree

8 files changed

+36
-33
lines changed

8 files changed

+36
-33
lines changed

tests/conftest.py

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

508508

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

514514

515515
@pytest.fixture
@@ -535,12 +535,12 @@ def artifact_dir():
535535

536536

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

545545

546546
guest_kernel_6_1_debug = pytest.fixture(
@@ -583,8 +583,8 @@ def uvm_booted(
583583
mem_size_mib=256,
584584
):
585585
"""Return a booted uvm"""
586-
uvm = microvm_factory.build(guest_kernel, rootfs)
587-
uvm.spawn(pci=pci_enabled)
586+
uvm = microvm_factory.build(guest_kernel, rootfs, pci=pci_enabled)
587+
uvm.spawn()
588588
uvm.basic_config(vcpu_count=vcpu_count, mem_size_mib=mem_size_mib)
589589
uvm.set_cpu_template(cpu_template)
590590
uvm.add_net_iface()

tests/framework/microvm.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ def __init__(
191191
jailer_kwargs: Optional[dict] = None,
192192
numa_node=None,
193193
custom_cpu_template: Path = None,
194+
pci: bool = False,
194195
):
195196
"""Set up microVM attributes, paths, and data structures."""
196197
# pylint: disable=too-many-statements
197198
# Unique identifier for this machine.
198199
assert microvm_id is not None
199200
self._microvm_id = microvm_id
200201

201-
self.pci_enabled = False
202202
self.kernel_file = None
203203
self.rootfs_file = None
204204
self.ssh_key = None
@@ -222,6 +222,10 @@ def __init__(
222222
**jailer_kwargs,
223223
)
224224

225+
self.pci_enabled = pci
226+
if pci:
227+
self.jailer.extra_args["enable-pci"] = None
228+
225229
# Copy the /etc/localtime file in the jailer root
226230
self.jailer.jailed_path("/etc/localtime", subdir="etc")
227231

@@ -612,7 +616,6 @@ def spawn(
612616
log_show_origin=False,
613617
metrics_path="fc.ndjson",
614618
emit_metrics: bool = False,
615-
pci: bool = False,
616619
):
617620
"""Start a microVM as a daemon or in a screen session."""
618621
# pylint: disable=subprocess-run-check
@@ -658,10 +661,6 @@ def spawn(
658661
# Checking the timings requires DEBUG level log messages
659662
self.time_api_requests = False
660663

661-
if pci:
662-
self.pci_enabled = True
663-
self.jailer.extra_args["enable-pci"] = None
664-
665664
cmd = [
666665
*self._pre_cmd,
667666
str(self.jailer_binary_path),

tests/integration_tests/functional/test_kernel_cmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_init_params(uvm_plain):
2121
# Ubuntu version from the /etc/issue file.
2222
vm.basic_config(
2323
vcpu_count=1,
24-
boot_args="console=ttyS0 reboot=k panic=1 init=/bin/cat -- /etc/issue",
24+
boot_args="console=ttyS0 reboot=k panic=1" " init=/bin/cat -- /etc/issue",
2525
)
2626

2727
vm.start()

tests/integration_tests/functional/test_serial_io.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def test_serial_console_login(uvm_plain_any):
9999
microvm.memory_monitor = None
100100

101101
# Set up the microVM with 1 vCPU and a serial console.
102-
microvm.basic_config(
103-
vcpu_count=1, boot_args="console=ttyS0 reboot=k panic=1 pci=off"
104-
)
102+
microvm.basic_config(vcpu_count=1, boot_args="console=ttyS0 reboot=k panic=1")
105103

106104
microvm.start()
107105

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_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)