dts: add new testpmd shell functions
PATCH 1/2 dts: add new testpmd shell functions
Add support for setting Mac address, set flow control, VF mode in the testpmd shell.
--- dts/framework/remote_session/testpmd_shell.py | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+)
dts/framework/remote_session/testpmd_shell.py +120 -0
@@ -1932,6 +1932,78 @@ def set_vlan_filter(self, port: int, enable: bool, verify: bool = True) -> None: filter on port {port}""" ) + def set_mac_address(self, port: int, mac_address: str): + """Sets Mac Address + + Args: + port (int): Port Id + mac_address (str): MAC Address to be set + """ + self.send_command(f"mac_addr set {port} {mac_address}") + + def set_flow_control( + self, + port: int, + rx: bool = True, + tx: bool = True, + high_water: int = 0, + low_water: int = 0, + pause_time: int = 0, + send_xon: bool = False, + mac_ctrl_frame_fwd: bool = False, + autoneg: bool = False, + ): + """Set Flow Control. + + Args: + rx (bool): Enable Reactive Extensions + tx (bool): Enable Transmit + high_water (int): High threshold value to trigger XOFF, + low_water (int): Low threshold value to trigger XON. + pause_time (int): Pause quota in the Pause frame. + send_xon (bool): Send XON frame. + mac_ctrl_frame_fwd (bool): Enable receiving MAC control frames. + autoneg (bool): _description_ + port (int): Change the auto-negotiation parameter. + """ + + self.send_command( + f"set flow_ctrl rx {'on' if rx else 'off'} tx {'on' if tx else 'off'} {high_water} {low_water} {pause_time} {1 if send_xon else 0} mac_ctrl_frame_fwd {'on' if mac_ctrl_frame_fwd else 'off'} autoneg {'on' if autoneg else 'off'} {port}" + ) + + def show_port_flow_info(self, port: int): + """Show port info flow + + Args: + port (int): port id + + Returns: + str: port flow control config + """ + output = self.send_command(f"show port {port} flow_ctrl") + output = TestPmdPortFlowCtrl.parse(output) + return output + + def set_port_VF_mode(self, port: int, vf_id: int, rxmode: str, enable: bool): + """Set VF receive mode of a port + + Args: + port (int): Port id + vf_id (int): Virtual Function id + rxmode (str): AUPE Accepts untagged VLAN. + ROPE Accepts unicast hash. + BAM Accepts broadcast packets. + MPE Accepts all multicast packets. + enable (bool): Enables vf mode + """ + rxmode_valid = ["AUPE", "ROPE", "BAM", "MPE"] + if rxmode in rxmode_valid: + self.send_command( + f"set port {port} vf {vf_id} rxmode {rxmode} {'on' if enable else 'off'}" + ) + else: + raise InteractiveCommandExecutionError(f"{rxmode} is an invlaid rxmode") + def rx_vlan(self, vlan: int, port: int, add: bool, verify: bool = True) -> None: """Add specified vlan tag to the filter list on a port. Requires vlan filter to be on.
@@ -2315,6 +2387,50 @@ def get_capabilities_mcast_filtering( command = str.replace(command, "add", "remove", 1) self.send_command(command) + def get_capabilities_flow_ctrl( + self, + supported_capabilities: MutableSet["NicCapability"], + unsupported_capabilities: MutableSet["NicCapability"], + ) -> None: + """Get Flow control capability from `show port <port_id> flow_ctrl` and check for a testpmd error code + + Args: + supported_capabilities: Supported capabilities will be added to this set. + unsupported_capabilities: Unsupported capabilities will be added to this set. + """ + self._logger.debug("Getting flow ctrl capabilities.") + command = f"show port {self.ports[0].id} flow_ctrl" + output = self.send_command(command) + if "Flow control infos" in output: + supported_capabilities.add(NicCapability.FLOW_CTRL) + else: + unsupported_capabilities.add(NicCapability.FLOW_CTRL) + + +@dataclass +class TestPmdPortFlowCtrl(TextParser): + """Dataclass representation of the common parts of the testpmd `show port <port_id> flow_ctrl` command.""" + + flow_ctrl_rx: bool = field(metadata=TextParser.find(r"Rx pause: on")) + #: + flow_ctrl_tx: bool = field(metadata=TextParser.find(r"Tx pause: on")) + #: + flow_ctrl_high_water: int = field( + metadata=TextParser.find_int(r"High waterline: (0x[a-fA-F\d]+)") + ) + #: + flow_ctrl_low_water: int = field( + metadata=TextParser.find_int(r"Low waterline: (0x[a-fA-F\d]+)") + ) + #: + flow_ctrl_pause_time: int = field(metadata=TextParser.find_int(r"Pause time: (0x[a-fA-F\d]+)")) + #: + flow_ctrl_send_xon: bool = field(metadata=TextParser.find(r"Tx pause: on")) + #: + flow_ctrl_mac_ctrl_frame_fwd: bool = field(metadata=TextParser.find(r"Tx pause: on")) + #: + flow_ctrl_autoneg: bool = field(metadata=TextParser.find(r"Autoneg: on")) + class NicCapability(NoAliasEnum): """A mapping between capability names and the associated :class:`TestPmdShell` methods.
@@ -2450,6 +2566,10 @@ class NicCapability(NoAliasEnum): MCAST_FILTERING: TestPmdShellCapabilityMethod = functools.partial( TestPmdShell.get_capabilities_mcast_filtering ) + #: Device supports flow ctrl. + FLOW_CTRL: TestPmdShellCapabilityMethod = functools.partial( + TestPmdShell.get_capabilities_flow_ctrl + ) def __call__( self,
Signature · 1 line
2.43.0
PATCH 2/2 dts: add port restart configuration persistency test
Added test that sets various port settings and verifies that they persist after a port restart.
--- ...stSuite_port_restart_config_persistency.py | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 dts/tests/TestSuite_port_restart_config_persistency.py
dts/tests/TestSuite_port_restart_config_persistency.py new file +117 -0
@@ -0,0 +1,117 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Arm Limited + +"""Port config persistency Test suite. + +Changes configuration of ports and verifies that the configuration persists after a +port is restarted. +""" + +from framework.remote_session.testpmd_shell import TestPmdShell +from framework.test_suite import TestSuite, func_test +from framework.testbed_model.capability import NicCapability, requires + +ALTERNATIVE_MTU: int = 800 +STANDARD_MTU: int = 1500 +ALTERNATITVE_MAC_ADDRESS: str = "40:A6:B7:9E:B4:81" + + +class TestPortRestartConfigPersistency(TestSuite): + """Port config persistency Test suite.""" + + def restart_port_and_verify(self, id, testpmd, changed_value) -> None: + """Fetches all of the port configs, restarts all of the ports, fetches all the port + configs again and then compares the two the configs and varifies that they are the same. + """ + + testpmd.start_all_ports() + testpmd.wait_link_status_up(port_id=id, timeout=10) + + port_info_before = testpmd.show_port_info(id) + all_info_before = port_info_before.__dict__ + try: + flow_info_before = testpmd.show_port_flow_info(id) + all_info_before.update(flow_info_before.__dict__) + except: + pass + + testpmd.stop_all_ports() + testpmd.start_all_ports() + testpmd.wait_link_status_up(port_id=id, timeout=10) + + port_info_after = testpmd.show_port_info(id) + all_info_after = port_info_after.__dict__ + try: + flow_info_after = testpmd.show_port_flow_info(id) + all_info_after.update(flow_info_after.__dict__) + except: + pass + + self.verify( + all_info_before == all_info_after, + f"Port configuration for {changed_value} was not retained through port restart", + ) + testpmd.stop_all_ports() + + @func_test + def port_configuration_persistence(self) -> None: + """Port restart configuration Persistency Test. + + Steps: + For each port set the port MTU, VLAN Filter, Mac Address, VF mode, and Promiscuous Mode. + + Verify: + Check that the configuration persists after the port is restarted. + """ + + with TestPmdShell(self.sut_node) as testpmd: + testpmd.stop_all_ports() + all_ports = [port.id for port in testpmd.show_port_info_all()] + for port_id in all_ports: + testpmd.set_port_mtu(port_id=port_id, mtu=STANDARD_MTU, verify=True) + + self.restart_port_and_verify(port_id, testpmd, "mtu") + + testpmd.set_port_mtu(port_id=port_id, mtu=ALTERNATIVE_MTU, verify=True) + + self.restart_port_and_verify(port_id, testpmd, "mtu") + + testpmd.set_vlan_filter(port=port_id, enable=True, verify=True) + + self.restart_port_and_verify(port_id, testpmd, "VLAN_filter") + + testpmd.set_mac_address(port=port_id, mac_address=ALTERNATITVE_MAC_ADDRESS) + + self.restart_port_and_verify(port_id, testpmd, "mac_address") + + testpmd.set_port_VF_mode(port=port_id, vf_id=port_id, rxmode="AUPE", enable=True) + + self.restart_port_and_verify(port_id, testpmd, "VF_mode") + + testpmd.set_promisc(port=port_id, enable=True, verify=False) + + self.restart_port_and_verify(port_id, testpmd, "Promiscuous_Mode") + + @requires(NicCapability.FLOW_CTRL) + @func_test + def flow_ctrl_port_configuration_persistence(self) -> None: + """Flow Control port restart configuration Persistency Test. + + Steps: + For each port enable flow control for RX and TX individualy. + Verify: + Check that the configuration persists after the port is restarted. + """ + + with TestPmdShell(self.sut_node) as testpmd: + testpmd.stop_all_ports() + all_ports = [port.id for port in testpmd.show_port_info_all()] + for port_id in all_ports: + + testpmd.set_flow_control(port=port_id, rx=True, tx=False) + + self.restart_port_and_verify(port_id, testpmd, "flow_ctrl") + + testpmd.set_flow_control(port=port_id, rx=False, tx=True) + + self.restart_port_and_verify(port_id, testpmd, "flow_ctrl")
Signature · 1 line
2.43.0
v2 cover dts: Add port restart configuration persistency testsuite
In reply to Thomas Wilksv2:
- Removed Vf check
- Fixed spelling
- Fixed Docstrings
- Added verification to testpmd commands
- Extracted flow control parameters into a dataclass
- Fixed syntax in testsuite
Thomas Wilks (2):
dts: add new testpmd shell functions
dts: add port restart configuration persistency test
dts/framework/remote_session/testpmd_shell.py | 126 ++++++++++++++++++ ...stSuite_port_restart_config_persistency.py | 101 ++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 dts/tests/TestSuite_port_restart_config_persistency.py
Signature · 1 line
2.43.0
PATCH v2 1/2 dts: add new testpmd shell functions
Add support for setting Mac address, set flow control in the testpmd shell.
--- dts/framework/remote_session/testpmd_shell.py | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+)
dts/framework/remote_session/testpmd_shell.py +126 -0
@@ -1348,6 +1348,49 @@ class RxOffloadCapabilities(TextParser): per_port: RxOffloadCapability = field(metadata=RxOffloadCapability.make_parser(True)) +@dataclass +class TestPmdPortFlowCtrl(TextParser): + """Class representing a port's flow control parameters. + + The parameters can also be parsed from the output of ``show port <port_id> flow_ctrl``. + """ + + #: Enable Reactive Extensions. + rx: bool = field(default=False, metadata=TextParser.find(r"Rx pause: on")) + #: Enable Transmit. + tx: bool = field(default=False, metadata=TextParser.find(r"Tx pause: on")) + #: High threshold value to trigger XOFF. + high_water: int = field( + default=0, metadata=TextParser.find_int(r"High waterline: (0x[a-fA-F\d]+)") + ) + #: Low threshold value to trigger XON. + low_water: int = field( + default=0, metadata=TextParser.find_int(r"Low waterline: (0x[a-fA-F\d]+)") + ) + #: Pause quota in the Pause frame. + pause_time: int = field(default=0, metadata=TextParser.find_int(r"Pause time: (0x[a-fA-F\d]+)")) + #: Send XON frame. + send_xon: bool = field(default=False, metadata=TextParser.find(r"Tx pause: on")) + #: Enable receiving MAC control frames. + mac_ctrl_frame_fwd: bool = field(default=False, metadata=TextParser.find(r"Tx pause: on")) + #: Change the auto-negotiation parameter. + autoneg: bool = field(default=False, metadata=TextParser.find(r"Autoneg: on")) + + def __str__(self) -> str: + """Returns the string representation of this instance.""" + ret = ( + f"rx {'on' if self.rx else 'off'} " + f"tx {'on' if self.tx else 'off'} " + f"{self.high_water} " + f"{self.low_water} " + f"{self.pause_time} " + f"{1 if self.send_xon else 0} " + f"mac_ctrl_frame_fwd {'on' if self.mac_ctrl_frame_fwd else 'off'} " + f"autoneg {'on' if self.autoneg else 'off'}" + ) + return ret + + def requires_stopped_ports(func: TestPmdShellMethod) -> TestPmdShellMethod: """Decorator for :class:`TestPmdShell` commands methods that require stopped ports.
@@ -1932,6 +1975,66 @@ def set_vlan_filter(self, port: int, enable: bool, verify: bool = True) -> None: filter on port {port}""" ) + def set_mac_address(self, port: int, mac_address: str, verify: bool = True) -> None: + """Set port's MAC address. + + Args: + port: The number of the requested port. + mac_address: The MAC address to set. + verify: If :data:`True`, the output of the command is scanned to verify that + the mac address is set in the specified port. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the command + fails to execute. + """ + output = self.send_command(f"mac_addr set {port} {mac_address}", skip_first_line=True) + if verify: + if output.strip(): + self._logger.debug( + f"Testpmd failed to set MAC address {mac_address} on port {port}." + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to set MAC address {mac_address} on port {port}." + ) + + def set_flow_control( + self, port: int, flow_ctrl: TestPmdPortFlowCtrl, verify: bool = True + ) -> None: + """Set the given `port`'s flow control. + + Args: + port: The number of the requested port. + flow_ctrl: The requested flow control parameters. + verify: If :data:`True`, the output of the command is scanned to verify that + the flow control in the specified port is set. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the command + fails to execute. + """ + output = self.send_command(f"set flow_ctrl {flow_ctrl} {port}", skip_first_line=True) + if verify: + if output.strip(): + self._logger.debug(f"Testpmd failed to set the {flow_ctrl} in port {port}.") + raise InteractiveCommandExecutionError( + f"Testpmd failed to set the {flow_ctrl} in port {port}." + ) + + def show_port_flow_info(self, port: int) -> TestPmdPortFlowCtrl | None: + """Show port info flow. + + Args: + port: The number of the requested port. + + Returns: + The current port flow control parameters if supported, otherwise :data:`None`. + """ + output = self.send_command(f"show port {port} flow_ctrl") + if "Flow control infos" in output: + return TestPmdPortFlowCtrl.parse(output) + return None + def rx_vlan(self, vlan: int, port: int, add: bool, verify: bool = True) -> None: """Add specified vlan tag to the filter list on a port. Requires vlan filter to be on.
@@ -2315,6 +2418,25 @@ def get_capabilities_mcast_filtering( command = str.replace(command, "add", "remove", 1) self.send_command(command) + def get_capabilities_flow_ctrl( + self, + supported_capabilities: MutableSet["NicCapability"], + unsupported_capabilities: MutableSet["NicCapability"], + ) -> None: + """Get flow control capability and check for testpmd failure. + + Args: + supported_capabilities: Supported capabilities will be added to this set. + unsupported_capabilities: Unsupported capabilities will be added to this set. + """ + self._logger.debug("Getting flow ctrl capabilities.") + command = f"show port {self.ports[0].id} flow_ctrl" + output = self.send_command(command) + if "Flow control infos" in output: + supported_capabilities.add(NicCapability.FLOW_CTRL) + else: + unsupported_capabilities.add(NicCapability.FLOW_CTRL) + class NicCapability(NoAliasEnum): """A mapping between capability names and the associated :class:`TestPmdShell` methods.
@@ -2450,6 +2572,10 @@ class NicCapability(NoAliasEnum): MCAST_FILTERING: TestPmdShellCapabilityMethod = functools.partial( TestPmdShell.get_capabilities_mcast_filtering ) + #: Device supports flow ctrl. + FLOW_CTRL: TestPmdShellCapabilityMethod = functools.partial( + TestPmdShell.get_capabilities_flow_ctrl + ) def __call__( self,
Signature · 1 line
2.43.0
PATCH v2 2/2 dts: add port restart configuration persistency test
In reply to Thomas WilksAdded test that sets various port settings and verifies that they persist after a port restart.
--- ...stSuite_port_restart_config_persistency.py | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 dts/tests/TestSuite_port_restart_config_persistency.py
dts/tests/TestSuite_port_restart_config_persistency.py new file +101 -0
@@ -0,0 +1,101 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Arm Limited + +"""Port config persistency test suite. + +Changes configuration of ports and verifies that the configuration persists after a +port is restarted. +""" + +from dataclasses import asdict + +from framework.remote_session.testpmd_shell import TestPmdPortFlowCtrl, TestPmdShell +from framework.test_suite import TestSuite, func_test +from framework.testbed_model.capability import NicCapability, requires + +ALTERNATIVE_MTU: int = 800 +STANDARD_MTU: int = 1500 +ALTERNATIVE_MAC_ADDRESS: str = "42:A6:B7:9E:B4:81" + + +class TestPortRestartConfigPersistency(TestSuite): + """Port config persistency test suite.""" + + def restart_port_and_verify(self, id, testpmd, changed_value) -> None: + """Fetch port config, restart and verify persistency.""" + testpmd.start_all_ports() + testpmd.wait_link_status_up(port_id=id, timeout=10) + + port_info_before = testpmd.show_port_info(id) + all_info_before = asdict(port_info_before) + + flow_info_before = testpmd.show_port_flow_info(id) + + if flow_info_before: + all_info_before.update(asdict(flow_info_before)) + + testpmd.stop_all_ports() + testpmd.start_all_ports() + testpmd.wait_link_status_up(port_id=id, timeout=10) + + port_info_after = testpmd.show_port_info(id) + all_info_after = asdict(port_info_after) + + flow_info_after = testpmd.show_port_flow_info(id) + if flow_info_after: + all_info_after.update(asdict(flow_info_after)) + + self.verify( + all_info_before == all_info_after, + f"Port configuration for {changed_value} was not retained through port restart.", + ) + testpmd.stop_all_ports() + + @func_test + def port_configuration_persistence(self) -> None: + """Port restart configuration persistency test. + + Steps: + For each port set the port MTU, VLAN filter, mac address, and promiscuous mode. + + Verify: + The configuration persists after the port is restarted. + """ + with TestPmdShell(self.sut_node, disable_device_start=True) as testpmd: + for port_id in range(len(self.sut_node.ports)): + testpmd.set_port_mtu(port_id=port_id, mtu=STANDARD_MTU, verify=True) + self.restart_port_and_verify(port_id, testpmd, "MTU") + + testpmd.set_port_mtu(port_id=port_id, mtu=ALTERNATIVE_MTU, verify=True) + self.restart_port_and_verify(port_id, testpmd, "MTU") + + testpmd.set_vlan_filter(port=port_id, enable=True, verify=True) + self.restart_port_and_verify(port_id, testpmd, "VLAN filter") + + testpmd.set_mac_address( + port=port_id, mac_address=ALTERNATIVE_MAC_ADDRESS, verify=True + ) + self.restart_port_and_verify(port_id, testpmd, "MAC address") + + testpmd.set_promisc(port=port_id, enable=True, verify=True) + self.restart_port_and_verify(port_id, testpmd, "promiscuous mode") + + @requires(NicCapability.FLOW_CTRL) + @func_test + def flow_ctrl_port_configuration_persistence(self) -> None: + """Flow control port configuration persistency test. + + Steps: + For each port enable flow control for RX and TX individually. + Verify: + The configuration persists after the port is restarted. + """ + with TestPmdShell(self.sut_node, disable_device_start=True) as testpmd: + for port_id in range(len(self.sut_node.ports)): + flow_ctrl = TestPmdPortFlowCtrl(rx=True) + testpmd.set_flow_control(port=port_id, flow_ctrl=flow_ctrl) + self.restart_port_and_verify(port_id, testpmd, "flow_ctrl") + + flow_ctrl = TestPmdPortFlowCtrl(tx=True) + testpmd.set_flow_control(port=port_id, flow_ctrl=flow_ctrl) + self.restart_port_and_verify(port_id, testpmd, "flow_ctrl")
Signature · 1 line
2.43.0