[PATCH v2 2/7] dts: add waiting for port up in testpmd
jspewock at iol.unh.edu
jspewock at iol.unh.edu
Fri Nov 10 00:20:12 CET 2023
From: Jeremy Spewock <jspewock at iol.unh.edu>
Added a method within the testpmd interactive shell that polls the
status of ports and verifies that the link status on a given port is
"up." Polling will continue until either the link comes up, or the
timeout is reached.
Signed-off-by: Jeremy Spewock <jspewock at iol.unh.edu>
---
.../remote_session/remote/testpmd_shell.py | 29 +++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/dts/framework/remote_session/remote/testpmd_shell.py b/dts/framework/remote_session/remote/testpmd_shell.py
index 1455b5a199..3ea16c7ab3 100644
--- a/dts/framework/remote_session/remote/testpmd_shell.py
+++ b/dts/framework/remote_session/remote/testpmd_shell.py
@@ -1,9 +1,12 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2023 University of New Hampshire
+import time
from pathlib import PurePath
from typing import Callable
+from framework.settings import SETTINGS
+
from .interactive_shell import InteractiveShell
@@ -47,3 +50,29 @@ def get_devices(self) -> list[TestPmdDevice]:
if "device name:" in line.lower():
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".
+
+ Arguments:
+ port_id: Port to check the link status on.
+ timeout: time to wait for the link to come up.
+
+ Returns:
+ If the link came up in time or not.
+ """
+ time_to_stop = time.time() + timeout
+ while time.time() < time_to_stop:
+ port_info = self.send_command(f"show port info {port_id}")
+ if "Link status: up" in port_info:
+ break
+ time.sleep(0.5)
+ else:
+ self._logger.error(
+ f"The link for port {port_id} did not come up in the given timeout."
+ )
+ return "Link status: up" in port_info
+
+ def close(self) -> None:
+ self.send_command("exit", "")
+ return super().close()
--
2.42.0
More information about the dev
mailing list