[v3,2/7] dts: add waiting for port up in testpmd

Message ID 20231113202833.12900-3-jspewock@iol.unh.edu (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series dts: Port scatter suite over |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jeremy Spewock Nov. 13, 2023, 8:28 p.m. UTC
  From: Jeremy Spewock <jspewock@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@iol.unh.edu>
---
 .../remote_session/remote/testpmd_shell.py    | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
  

Comments

Juraj Linkeš Nov. 16, 2023, 7:05 p.m. UTC | #1
On Mon, Nov 13, 2023 at 9:28 PM <jspewock@iol.unh.edu> wrote:
>
> From: Jeremy Spewock <jspewock@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@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.
> +        """

Again with the docstrings - the new thing here is the usage of
SETTINGS. Here's an example:

The YAML test run configuration file is specified in the
:option:`--config-file` command line
argument or the :envvar:`DTS_CFG_FILE` environment variable.

The rule is to first mention the cmdline arg, then the env var.

> +        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
>
  
Jeremy Spewock Nov. 17, 2023, 6:09 p.m. UTC | #2
On Thu, Nov 16, 2023 at 2:05 PM Juraj Linkeš <juraj.linkes@pantheon.tech>
wrote:

> On Mon, Nov 13, 2023 at 9:28 PM <jspewock@iol.unh.edu> wrote:
> >
> > From: Jeremy Spewock <jspewock@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@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.
> > +        """
>
> Again with the docstrings - the new thing here is the usage of
> SETTINGS. Here's an example:
>
> The YAML test run configuration file is specified in the
> :option:`--config-file` command line
> argument or the :envvar:`DTS_CFG_FILE` environment variable.
>
> The rule is to first mention the cmdline arg, then the env var.
>
>
Good catch, I'll change this.


> > +        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
> >
>
  

Patch

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()