<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,sans-serif"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Nov 16, 2023 at 2:05 PM Juraj Linkeš <juraj.linkes@pantheon.tech> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mon, Nov 13, 2023 at 9:28 PM <<a href="mailto:jspewock@iol.unh.edu" target="_blank">jspewock@iol.unh.edu</a>> wrote:<br>
><br>
> From: Jeremy Spewock <<a href="mailto:jspewock@iol.unh.edu" target="_blank">jspewock@iol.unh.edu</a>><br>
><br>
> Added a method within the testpmd interactive shell that polls the<br>
> status of ports and verifies that the link status on a given port is<br>
> "up." Polling will continue until either the link comes up, or the<br>
> timeout is reached.<br>
><br>
> Signed-off-by: Jeremy Spewock <<a href="mailto:jspewock@iol.unh.edu" target="_blank">jspewock@iol.unh.edu</a>><br>
> ---<br>
>  .../remote_session/remote/testpmd_shell.py    | 29 +++++++++++++++++++<br>
>  1 file changed, 29 insertions(+)<br>
><br>
> diff --git a/dts/framework/remote_session/remote/testpmd_shell.py b/dts/framework/remote_session/remote/testpmd_shell.py<br>
> index 1455b5a199..3ea16c7ab3 100644<br>
> --- a/dts/framework/remote_session/remote/testpmd_shell.py<br>
> +++ b/dts/framework/remote_session/remote/testpmd_shell.py<br>
> @@ -1,9 +1,12 @@<br>
>  # SPDX-License-Identifier: BSD-3-Clause<br>
>  # Copyright(c) 2023 University of New Hampshire<br>
><br>
> +import time<br>
>  from pathlib import PurePath<br>
>  from typing import Callable<br>
><br>
> +from framework.settings import SETTINGS<br>
> +<br>
>  from .interactive_shell import InteractiveShell<br>
><br>
><br>
> @@ -47,3 +50,29 @@ def get_devices(self) -> list[TestPmdDevice]:<br>
>              if "device name:" in line.lower():<br>
>                  dev_list.append(TestPmdDevice(line))<br>
>          return dev_list<br>
> +<br>
> +    def wait_link_status_up(self, port_id: int, timeout=SETTINGS.timeout) -> bool:<br>
> +        """Wait until the link status on the given port is "up".<br>
> +<br>
> +        Arguments:<br>
> +            port_id: Port to check the link status on.<br>
> +            timeout: time to wait for the link to come up.<br>
> +<br>
> +        Returns:<br>
> +            If the link came up in time or not.<br>
> +        """<br>
<br>
Again with the docstrings - the new thing here is the usage of<br>
SETTINGS. Here's an example:<br>
<br>
The YAML test run configuration file is specified in the<br>
:option:`--config-file` command line<br>
argument or the :envvar:`DTS_CFG_FILE` environment variable.<br>
<br>
The rule is to first mention the cmdline arg, then the env var.<br>
<br></blockquote><div><br></div><div><div style="font-family:arial,sans-serif" class="gmail_default">Good catch, I'll change this.<br></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> +        time_to_stop = time.time() + timeout<br>
> +        while time.time() < time_to_stop:<br>
> +            port_info = self.send_command(f"show port info {port_id}")<br>
> +            if "Link status: up" in port_info:<br>
> +                break<br>
> +            time.sleep(0.5)<br>
> +        else:<br>
> +            self._logger.error(<br>
> +                f"The link for port {port_id} did not come up in the given timeout."<br>
> +            )<br>
> +        return "Link status: up" in port_info<br>
> +<br>
> +    def close(self) -> None:<br>
> +        self.send_command("exit", "")<br>
> +        return super().close()<br>
> --<br>
> 2.42.0<br>
><br>
</blockquote></div></div>