Skip to content

Commit a25863b

Browse files
committed
Add PF support fixture for tests
1 parent 3b1d805 commit a25863b

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

tests/validation/common/nicctl.py

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ def _nicctl_path(self) -> str:
2424
return str(self.connection.path(self.mtl_path, "script", self.tool_name))
2525
return str(self.connection.path(nicctl_path, self.tool_name))
2626

27-
def _parse_vf_list(self, output: str, all: bool = True) -> list:
27+
def _parse_vf_list(self, output: str) -> list:
2828
if "No VFs found" in output:
2929
return []
30-
vf_info_regex = r"\d{1,3}\s+(.+)\s+vfio" if all else r"(\d{4}:\S+)"
30+
vf_info_regex = r"(\d{4}[0-9a-fA-F:.]+)\(?\S*\)?\s+\S*\s*vfio"
3131
return re.findall(vf_info_regex, output)
3232

3333
def vfio_list(self, pci_addr: str = "all") -> list:
3434
"""Returns list of VFs created on host."""
3535
resp = self.connection.execute_command(
3636
f"{self.nicctl} list {pci_addr}", shell=True
3737
)
38-
return self._parse_vf_list(resp.stdout, "all" in pci_addr)
38+
return self._parse_vf_list(resp.stdout)
3939

4040
def create_vfs(self, pci_id: str, num_of_vfs: int = 6) -> list:
4141
"""Create VFs on NIC.
@@ -68,3 +68,73 @@ def prepare_vfs_for_test(self, nic: NetworkInterface) -> list:
6868
self.create_vfs(nic_pci)
6969
self.host.vfs = self.vfio_list(nic_pci)
7070
return self.host.vfs
71+
72+
def bind_pmd(self, pci_id: str) -> None:
73+
"""Bind VF to DPDK PMD driver."""
74+
self.connection.execute_command(
75+
self.nicctl + " bind_pmd " + pci_id, shell=True
76+
)
77+
78+
def bind_kernel(self, pci_id: str) -> None:
79+
"""Bind VF to kernel driver."""
80+
self.connection.execute_command(
81+
self.nicctl + " bind_kernel " + pci_id, shell=True
82+
)
83+
84+
85+
class InterfaceSetup:
86+
def __init__(self, hosts, mtl_path):
87+
self.hosts = hosts
88+
self.mtl_path = mtl_path
89+
self.nicctl_objs = {host.name: Nicctl(mtl_path, host) for host in hosts.values()}
90+
self.customs = []
91+
self.cleanups = []
92+
93+
def get_test_interfaces(self, hosts, interface_type="VF", count=2):
94+
selected_interfaces = {k: [] for k in hosts.keys()}
95+
for host in hosts.values():
96+
if getattr(host.topology.extra_info, "custom_interface", None):
97+
selected_interfaces[host.name] = [
98+
host.topology.extra_info["custom_interface"]]
99+
self.customs.append(host.name)
100+
if len(selected_interfaces[host.name]) < count:
101+
raise Exception(f"Not enough interfaces for test on host {host.name} in extra_info.custom_interface")
102+
else:
103+
if interface_type == "VF":
104+
vfs = self.nicctl_objs[host.name].create_vfs(host.network_interfaces[0].pci_address.lspci, count)
105+
selected_interfaces[host.name] = vfs
106+
self.register_cleanup(self.nicctl_objs[host.name], host.network_interfaces[0].pci_address.lspci, interface_type)
107+
elif interface_type == "PF":
108+
try:
109+
selected_interfaces[host.name] = []
110+
for i in range(count):
111+
self.nicctl_objs[host.name].bind_pmd(host.network_interfaces[i].pci_address.lspci)
112+
selected_interfaces[host.name].append(str(host.network_interfaces[i]))
113+
self.register_cleanup(self.nicctl_objs[host.name], host.network_interfaces[i].pci_address.lspci, interface_type)
114+
except IndexError:
115+
raise Exception(f"Not enough interfaces for test on host {host.name} in topology config.")
116+
elif interface_type == "VFxPF":
117+
for i in range(count):
118+
vfs = self.nicctl_objs[host.name].create_vfs(host.network_interfaces[i].pci_address.lspci, 1)
119+
selected_interfaces[host.name].extend(vfs)
120+
self.register_cleanup(self.nicctl_objs[host.name], host.network_interfaces[i].pci_address.lspci, "VF")
121+
else:
122+
raise Exception(f"Unknown interface type {interface_type}")
123+
return selected_interfaces
124+
125+
def get_test_interfaces_list(self, hosts, interface_type="VF", count=2):
126+
selected_interfaces = self.get_test_interfaces(hosts, interface_type, count)
127+
interface_list = []
128+
for host in hosts.values():
129+
interface_list.extend(selected_interfaces[host.name])
130+
return interface_list
131+
132+
def register_cleanup(self, nicctl, interface, if_type):
133+
self.cleanups.append((nicctl, interface, if_type))
134+
135+
def cleanup(self):
136+
for nicctl, interface, if_type in self.cleanups:
137+
if if_type == "VF":
138+
nicctl.disable_vf(interface)
139+
elif if_type == "PF":
140+
nicctl.bind_kernel(interface)

tests/validation/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import pytest
1313
from common.mtl_manager.mtlManager import MtlManager
14-
from common.nicctl import Nicctl
14+
from common.nicctl import InterfaceSetup, Nicctl
1515
from compliance.compliance_client import PcapComplianceClient
1616
from create_pcap_file.netsniff import NetsniffRecorder, calculate_packets_per_frame
1717
from mfd_common_libs.custom_logger import add_logging_level
@@ -124,6 +124,13 @@ def nic_port_list(hosts: dict, mtl_path) -> None:
124124
host.vfs = vfs
125125

126126

127+
@pytest.fixture(scope="function")
128+
def setup_interfaces(hosts, test_config, mtl_path):
129+
interface_setup = InterfaceSetup(hosts, mtl_path)
130+
yield interface_setup
131+
interface_setup.cleanup()
132+
133+
127134
@pytest.fixture(scope="session")
128135
def test_time(test_config: dict) -> int:
129136
test_time = test_config.get("test_time", 30)

tests/validation/tests/single/st30p/st30p_channel/test_st30p_channel.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright(c) 2024-2025 Intel Corporation
33
import logging
44

5+
from common.nicctl import InterfaceSetup
56
import mtl_engine.RxTxApp as rxtxapp
67
import pytest
78
from common.integrity.integrity_runner import FileAudioIntegrityRunner
@@ -35,7 +36,7 @@ def test_st30p_channel(
3536
hosts,
3637
build,
3738
media,
38-
nic_port_list,
39+
setup_interfaces: InterfaceSetup,
3940
test_time,
4041
audio_channel,
4142
request,
@@ -49,12 +50,13 @@ def test_st30p_channel(
4950
SDBQ1001_audio_channel_check(audio_channel, media_file_info["format"], request)
5051

5152
host = list(hosts.values())[0]
53+
interfaces_list = setup_interfaces.get_test_interfaces_list(hosts, test_config.get("interface_type", "VF"))
5254
out_file_url = host.connection.path(media_file_path).parent / "out.pcm"
5355

5456
config = rxtxapp.create_empty_config()
5557
config = rxtxapp.add_st30p_sessions(
5658
config=config,
57-
nic_port_list=host.vfs,
59+
nic_port_list=interfaces_list,
5860
test_mode="multicast",
5961
audio_format=media_file_info["format"],
6062
audio_channel=[audio_channel],

0 commit comments

Comments
 (0)