[PATCH v1 1/2] dts: add methods for closing ports to testpmd

jspewock at iol.unh.edu jspewock at iol.unh.edu
Wed Aug 14 20:20:04 CEST 2024


From: Jeremy Spewock <jspewock at iol.unh.edu>

Closing ports is a standard configuration feature that is available in
testpmd but the framework lacks the ability to access this command
through the Testpmd API. This patch adds a method that performs this
action and verifies the results of sending the command to allow
developers to have more control over the state of the ports that
testpmd is aware of.

Depends-on: patch-142952 ("dts: add ability to start/stop testpmd
ports")

Signed-off-by: Jeremy Spewock <jspewock at iol.unh.edu>
---
 dts/framework/remote_session/testpmd_shell.py | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py
index ca24b28070..51593c61f5 100644
--- a/dts/framework/remote_session/testpmd_shell.py
+++ b/dts/framework/remote_session/testpmd_shell.py
@@ -805,6 +805,27 @@ def start_all_ports(self, verify: bool = True) -> None:
 
         self.ports_started = True
 
+    @requires_stopped_ports
+    def close_all_ports(self, verify: bool = True) -> None:
+        """Close all ports.
+
+        Args:
+            verify: If :data:`True` the output of the close command will be scanned in an attempt
+                to verify that all ports were stopped successfully. Defaults to :data:`True`.
+
+        Raises:
+            InteractiveCommandExecutionError: If `verify` is :data:`True` and at lease one port
+                failed to close.
+        """
+        port_close_output = self.send_command("port close all")
+        if verify:
+            if type(self._app_params.ports) is list:
+                num_ports = len(self._app_params.ports)
+                if not all(
+                    f"Port {p_id} is closed" in port_close_output for p_id in range(num_ports)
+                ):
+                    raise InteractiveCommandExecutionError("Ports were not closed successfully.")
+
     def show_port_info_all(self) -> list[TestPmdPort]:
         """Returns the information of all the ports.
 
-- 
2.45.2



More information about the dev mailing list