qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: John Levon <john.levon@nutanix.com>
Cc: qemu-devel@nongnu.org, "Cédric Le Goater" <clg@redhat.com>,
	"Thanos Makatos" <thanos.makatos@nutanix.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PATCH 1/3] tests/functional: return output from exec_command_and_wait_for_pattern()
Date: Wed, 20 Aug 2025 17:08:44 +0100	[thread overview]
Message-ID: <aKXzDGOmwREMZFwc@redhat.com> (raw)
In-Reply-To: <20250818110546.2159622-2-john.levon@nutanix.com>

On Mon, Aug 18, 2025 at 12:05:44PM +0100, John Levon wrote:
> Tests might want to look at the whole output from a command execution,
> as well as just logging it. Add support for this.
> 
> Signed-off-by: John Levon <john.levon@nutanix.com>
> ---
>  tests/functional/qemu_test/cmd.py | 38 +++++++++++++++++++++++++++----
>  1 file changed, 33 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/functional/qemu_test/cmd.py b/tests/functional/qemu_test/cmd.py
> index dc5f422b77..6355b1a683 100644
> --- a/tests/functional/qemu_test/cmd.py
> +++ b/tests/functional/qemu_test/cmd.py
> @@ -45,6 +45,9 @@ def is_readable_executable_file(path):
>  # If end of line is seen, with neither @success or @failure
>  # return False
>  #
> +# In both cases, also return the contents of the line (in bytes)
> +# up to that point.
> +#
>  # If @failure is seen, then mark @test as failed
>  def _console_read_line_until_match(test, vm, success, failure):
>      msg = bytes([])
> @@ -76,10 +79,23 @@ def _console_read_line_until_match(test, vm, success, failure):
>      except:
>          console_logger.debug(msg)
>  
> -    return done
> +    return done, msg
>  
>  def _console_interaction(test, success_message, failure_message,
>                           send_string, keep_sending=False, vm=None):
> +    """
> +    Interact with the console until either message is seen.
> +
> +    :param success_message: if this message appears, finish interaction
> +    :param failure_message: if this message appears, test fails
> +    :param send_string: a string to send to the console before trying
> +                        to read a new line
> +    :param keep_sending: keep sending the send string each time
> +    :param vm: the VM to interact with
> +
> +    :return: The collected output (in bytes form).
> +    """
> +
>      assert not keep_sending or send_string
>      assert success_message or send_string
>  
> @@ -101,6 +117,8 @@ def _console_interaction(test, success_message, failure_message,
>      if failure_message is not None:
>          failure_message_b = failure_message.encode()
>  
> +    out = bytes([])
> +
>      while True:
>          if send_string:
>              vm.console_socket.sendall(send_string.encode())
> @@ -113,11 +131,17 @@ def _console_interaction(test, success_message, failure_message,
>                  break
>              continue
>  
> -        if _console_read_line_until_match(test, vm,
> -                                          success_message_b,
> -                                          failure_message_b):
> +        done, line = _console_read_line_until_match(test, vm,
> +                                                    success_message_b,
> +                                                    failure_message_b)
> +
> +        out += line
> +
> +        if done:
>              break
>  
> +    return out
> +
>  def interrupt_interactive_console_until_pattern(test, success_message,
>                                                  failure_message=None,
>                                                  interrupt_string='\r'):
> @@ -184,9 +208,13 @@ def exec_command_and_wait_for_pattern(test, command,
>      :param command: the command to send
>      :param success_message: if this message appears, test succeeds
>      :param failure_message: if this message appears, test fails
> +
> +    :return: The collected output (in bytes form).
>      """
>      assert success_message
> -    _console_interaction(test, success_message, failure_message, command + '\r')
> +
> +    return _console_interaction(test, success_message, failure_message,
> +                                command + '\r')

Looks reasonable, but there are a few other methods whjich call
_console_interaction() - can you make them also return the
matched bytes for consistency.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2025-08-20 16:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-18 11:05 [PATCH 0/3] vfio-user client functional test John Levon
2025-08-18 11:05 ` [PATCH 1/3] tests/functional: return output from exec_command_and_wait_for_pattern() John Levon
2025-08-20 16:08   ` Daniel P. Berrangé [this message]
2025-08-18 11:05 ` [PATCH 2/3] tests/functional: add vm param to console routines John Levon
2025-08-20 16:10   ` Daniel P. Berrangé
2025-08-18 11:05 ` [PATCH 3/3] tests/functional: add a vfio-user smoke test John Levon
2025-08-20 16:14   ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aKXzDGOmwREMZFwc@redhat.com \
    --to=berrange@redhat.com \
    --cc=clg@redhat.com \
    --cc=john.levon@nutanix.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thanos.makatos@nutanix.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).