From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0A69343D5B; Tue, 26 Mar 2024 20:05:20 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 72C5C427E3; Tue, 26 Mar 2024 20:04:43 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mails.dpdk.org (Postfix) with ESMTP id D8B7A40ED6 for ; Tue, 26 Mar 2024 20:04:40 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 109B1339; Tue, 26 Mar 2024 12:05:14 -0700 (PDT) Received: from localhost.localdomain (unknown [10.57.16.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C18B13F64C; Tue, 26 Mar 2024 12:04:37 -0700 (PDT) From: Luca Vizzarro To: dev@dpdk.org Cc: =?UTF-8?q?Juraj=20Linke=C5=A1?= , Luca Vizzarro , Jack Bond-Preston , Honnappa Nagarahalli Subject: [PATCH 6/6] dts: add statefulness to TestPmdShell Date: Tue, 26 Mar 2024 19:04:22 +0000 Message-Id: <20240326190422.577028-7-luca.vizzarro@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240326190422.577028-1-luca.vizzarro@arm.com> References: <20240326190422.577028-1-luca.vizzarro@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This commit provides a state container for TestPmdShell. It currently only indicates whether the packet forwarding has started or not, and the number of ports which were given to the shell. This also fixes the behaviour of `wait_link_status_up` to use the command timeout as inherited from InteractiveShell. Signed-off-by: Luca Vizzarro Reviewed-by: Jack Bond-Preston Reviewed-by: Honnappa Nagarahalli --- dts/framework/remote_session/testpmd_shell.py | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index a823dc53be..ea1d254f86 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -678,19 +678,27 @@ def __str__(self) -> str: return self.pci_address +@dataclass(slots=True) +class TestPmdState: + """Session state container.""" + + #: + packet_forwarding_started: bool = False + + #: The number of ports which were allowed on the command-line when testpmd was started. + number_of_ports: int = 0 + + class TestPmdShell(InteractiveShell): """Testpmd interactive shell. The testpmd shell users should never use the :meth:`~.interactive_shell.InteractiveShell.send_command` method directly, but rather call specialized methods. If there isn't one that satisfies a need, it should be added. - - Attributes: - number_of_ports: The number of ports which were allowed on the command-line when testpmd - was started. """ - number_of_ports: int + #: Current state + state: TestPmdState = TestPmdState() #: The path to the testpmd executable. path: ClassVar[PurePath] = PurePath("app", "dpdk-testpmd") @@ -723,7 +731,13 @@ def _start_application(self, get_privileged_command: Callable[[str], str] | None if self._app_args.app_params is None: self._app_args.app_params = TestPmdParameters() - self.number_of_ports = len(self._app_args.ports) if self._app_args.ports is not None else 0 + assert isinstance(self._app_args.app_params, TestPmdParameters) + + if self._app_args.app_params.auto_start: + self.state.packet_forwarding_started = True + + if self._app_args.ports is not None: + self.state.number_of_ports = len(self._app_args.ports) super()._start_application(get_privileged_command) @@ -746,12 +760,14 @@ def start(self, verify: bool = True) -> None: self._logger.debug(f"Failed to start packet forwarding: \n{start_cmd_output}") raise InteractiveCommandExecutionError("Testpmd failed to start packet forwarding.") - for port_id in range(self.number_of_ports): + for port_id in range(self.state.number_of_ports): if not self.wait_link_status_up(port_id): raise InteractiveCommandExecutionError( "Not all ports came up after starting packet forwarding in testpmd." ) + self.state.packet_forwarding_started = True + def stop(self, verify: bool = True) -> None: """Stop packet forwarding. @@ -773,6 +789,8 @@ def stop(self, verify: bool = True) -> None: self._logger.debug(f"Failed to stop packet forwarding: \n{stop_cmd_output}") raise InteractiveCommandExecutionError("Testpmd failed to stop packet forwarding.") + self.state.packet_forwarding_started = False + def get_devices(self) -> list[TestPmdDevice]: """Get a list of device names that are known to testpmd. @@ -788,19 +806,16 @@ def get_devices(self) -> list[TestPmdDevice]: dev_list.append(TestPmdDevice(line)) return dev_list - def wait_link_status_up(self, port_id: int, timeout=SETTINGS.timeout) -> bool: - """Wait until the link status on the given port is "up". + def wait_link_status_up(self, port_id: int) -> bool: + """Wait until the link status on the given port is "up". Times out. Arguments: port_id: Port to check the link status on. - timeout: Time to wait for the link to come up. The default value for this - argument may be modified using the :option:`--timeout` command-line argument - or the :envvar:`DTS_TIMEOUT` environment variable. Returns: Whether the link came up in time or not. """ - time_to_stop = time.time() + timeout + time_to_stop = time.time() + self._timeout port_info: str = "" while time.time() < time_to_stop: port_info = self.send_command(f"show port info {port_id}") -- 2.34.1