[v5,1/5] dts: fix InteractiveShell command prompt filtering

Message ID 20240606213420.254260-2-luca.vizzarro@arm.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series dts: testpmd show port info/stats |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Luca Vizzarro June 6, 2024, 9:34 p.m. UTC
When sending a command using an instance of InteractiveShell the output
should filter out the trailing shell prompt when returning it. After
every command two shell prompts are summoned. One is consumed as it is
used as a delimiter for the command output. The second one is not
consumed and left for the next command to be sent.

Given that the consumed prompt is merely a delimiter, this should not be
added to the returned output, as it may be mistakenly be interpreted as
the command's own output.

Bugzilla ID: 1411
Fixes: 88489c0501af ("dts: add smoke tests")

Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
 dts/framework/remote_session/interactive_shell.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Juraj Linkeš June 7, 2024, 11:15 a.m. UTC | #1
On 6. 6. 2024 23:34, Luca Vizzarro wrote:
> When sending a command using an instance of InteractiveShell the output
> should filter out the trailing shell prompt when returning it. After
> every command two shell prompts are summoned. One is consumed as it is
> used as a delimiter for the command output. The second one is not
> consumed and left for the next command to be sent.
> 
> Given that the consumed prompt is merely a delimiter, this should not be
> added to the returned output, as it may be mistakenly be interpreted as
> the command's own output.
> 
> Bugzilla ID: 1411
> Fixes: 88489c0501af ("dts: add smoke tests")
> 
> Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
> Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>

Reviewed-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
  
Jeremy Spewock June 7, 2024, 1:10 p.m. UTC | #2
On Thu, Jun 6, 2024 at 5:34 PM Luca Vizzarro <luca.vizzarro@arm.com> wrote:
>
> When sending a command using an instance of InteractiveShell the output
> should filter out the trailing shell prompt when returning it. After
> every command two shell prompts are summoned. One is consumed as it is
> used as a delimiter for the command output. The second one is not
> consumed and left for the next command to be sent.
>
> Given that the consumed prompt is merely a delimiter, this should not be
> added to the returned output, as it may be mistakenly be interpreted as
> the command's own output.
>
> Bugzilla ID: 1411
> Fixes: 88489c0501af ("dts: add smoke tests")
>
> Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
> Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>

Reviewed-by: Jeremy Spewock <jspewock@iol.unh.edu>
  
Nicholas Pratte June 14, 2024, 8:05 p.m. UTC | #3
Tested-by: Nicholas Pratte <npratte@iol.unh.edu>
Reviewed-by: Nicholas Pratte <npratte@iol.unh.edu>

On Thu, Jun 6, 2024 at 5:34 PM Luca Vizzarro <luca.vizzarro@arm.com> wrote:
>
> When sending a command using an instance of InteractiveShell the output
> should filter out the trailing shell prompt when returning it. After
> every command two shell prompts are summoned. One is consumed as it is
> used as a delimiter for the command output. The second one is not
> consumed and left for the next command to be sent.
>
> Given that the consumed prompt is merely a delimiter, this should not be
> added to the returned output, as it may be mistakenly be interpreted as
> the command's own output.
>
> Bugzilla ID: 1411
> Fixes: 88489c0501af ("dts: add smoke tests")
>
> Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
> Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
> ---
>  dts/framework/remote_session/interactive_shell.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/dts/framework/remote_session/interactive_shell.py b/dts/framework/remote_session/interactive_shell.py
> index 074a541279..aa5d2d9be8 100644
> --- a/dts/framework/remote_session/interactive_shell.py
> +++ b/dts/framework/remote_session/interactive_shell.py
> @@ -132,11 +132,11 @@ def send_command(self, command: str, prompt: str | None = None) -> str:
>          self._stdin.flush()
>          out: str = ""
>          for line in self._stdout:
> -            out += line
>              if prompt in line and not line.rstrip().endswith(
>                  command.rstrip()
>              ):  # ignore line that sent command
>                  break
> +            out += line
>          self._logger.debug(f"Got output: {out}")
>          return out
>
> --
> 2.34.1
>
  

Patch

diff --git a/dts/framework/remote_session/interactive_shell.py b/dts/framework/remote_session/interactive_shell.py
index 074a541279..aa5d2d9be8 100644
--- a/dts/framework/remote_session/interactive_shell.py
+++ b/dts/framework/remote_session/interactive_shell.py
@@ -132,11 +132,11 @@  def send_command(self, command: str, prompt: str | None = None) -> str:
         self._stdin.flush()
         out: str = ""
         for line in self._stdout:
-            out += line
             if prompt in line and not line.rstrip().endswith(
                 command.rstrip()
             ):  # ignore line that sent command
                 break
+            out += line
         self._logger.debug(f"Got output: {out}")
         return out