qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
	"John Levon" <john.levon@nutanix.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PULL 18/23] tests/functional: return output from cmd.py helpers
Date: Tue,  9 Sep 2025 15:51:42 +0200	[thread overview]
Message-ID: <20250909135147.612345-19-thuth@redhat.com> (raw)
In-Reply-To: <20250909135147.612345-1-thuth@redhat.com>

From: John Levon <john.levon@nutanix.com>

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>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20250903201931.168317-2-john.levon@nutanix.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/functional/qemu_test/cmd.py | 53 +++++++++++++++++++++++++------
 1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/tests/functional/qemu_test/cmd.py b/tests/functional/qemu_test/cmd.py
index dc5f422b77d..c19dfc577ff 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'):
@@ -140,10 +164,12 @@ def interrupt_interactive_console_until_pattern(test, success_message,
     :param failure_message: if this message appears, test fails
     :param interrupt_string: a string to send to the console before trying
                              to read a new line
+
+    :return: The collected output (in bytes form).
     """
     assert success_message
-    _console_interaction(test, success_message, failure_message,
-                         interrupt_string, True)
+    return _console_interaction(test, success_message, failure_message,
+                                interrupt_string, True)
 
 def wait_for_console_pattern(test, success_message, failure_message=None,
                              vm=None):
@@ -155,9 +181,12 @@ def wait_for_console_pattern(test, success_message, failure_message=None,
     :type test: :class:`qemu_test.QemuSystemTest`
     :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, None, vm=vm)
+    return _console_interaction(test, success_message, failure_message,
+                                None, vm=vm)
 
 def exec_command(test, command):
     """
@@ -168,8 +197,10 @@ def exec_command(test, command):
     :type test: :class:`qemu_test.QemuSystemTest`
     :param command: the command to send
     :type command: str
+
+    :return: The collected output (in bytes form).
     """
-    _console_interaction(test, None, None, command + '\r')
+    return _console_interaction(test, None, None, command + '\r')
 
 def exec_command_and_wait_for_pattern(test, command,
                                       success_message, failure_message=None):
@@ -184,9 +215,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')
 
 def get_qemu_img(test):
     test.log.debug('Looking for and selecting a qemu-img binary')
-- 
2.51.0



  parent reply	other threads:[~2025-09-09 13:54 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09 13:51 [PULL 00/23] Functional tests and misc patches Thomas Huth
2025-09-09 13:51 ` [PULL 01/23] hw/display/bcm2835_fb: Move inclusion of console.h to the .c file Thomas Huth
2025-09-09 13:51 ` [PULL 02/23] Revert "meson.build: Disable -fzero-call-used-regs on OpenBSD" Thomas Huth
2025-09-09 13:51 ` [PULL 03/23] hw/mips/malta: Silence warning from ubsan Thomas Huth
2025-09-09 13:51 ` [PULL 04/23] system/physmem: " Thomas Huth
2025-09-15 16:17   ` Richard Henderson
2025-09-09 13:51 ` [PULL 05/23] ui/vnc: Fix crash when specifying [vnc] without id in the config file Thomas Huth
2025-09-09 13:51 ` [PULL 06/23] tests/functional/m68k: Avoid ResourceWarning in the nextcube test Thomas Huth
2025-09-09 13:51 ` [PULL 07/23] tests/functional: enable force refresh of cached assets Thomas Huth
2025-09-09 13:51 ` [PULL 08/23] tests/functional: fix formatting of exception args Thomas Huth
2025-09-09 13:51 ` [PULL 09/23] tests/functional: handle URLError when fetching assets Thomas Huth
2025-09-09 13:51 ` [PULL 10/23] tests/functional/arm: Update test ASPEED SDK v03.02 for AST1030 Thomas Huth
2025-09-09 13:51 ` [PULL 11/23] tests/functional/arm: Update test ASPEED SDK v09.07 for AST2500 Thomas Huth
2025-09-09 13:51 ` [PULL 12/23] tests/functional/arm: Update test ASPEED SDK v09.07 for AST2600 Thomas Huth
2025-09-09 13:51 ` [PULL 13/23] tests/functional/arm: Update test ASPEED SDK v09.07 for AST2700 vbootrom Thomas Huth
2025-09-09 13:51 ` [PULL 14/23] gitlab: replace avocado results files with meson results files Thomas Huth
2025-09-09 13:51 ` [PULL 15/23] gitlab: always include entire of meson-logs directory Thomas Huth
2025-09-09 13:51 ` [PULL 16/23] gitlab: include all junit XML files from meson Thomas Huth
2025-09-09 13:51 ` [PULL 17/23] gitlab: prevent duplicated meson log artifacts in test jobs Thomas Huth
2025-09-09 13:51 ` Thomas Huth [this message]
2025-09-09 13:51 ` [PULL 19/23] tests/functional: add vm param to cmd.py helpers Thomas Huth
2025-09-09 13:51 ` [PULL 20/23] tests/functional: fix infinite loop on console EOF Thomas Huth
2025-09-09 13:51 ` [PULL 21/23] tests/functional: avoid duplicate messages on failures Thomas Huth
2025-09-09 13:51 ` [PULL 22/23] tests/functional: avoid tearDown failure when QEMU dies Thomas Huth
2025-09-09 13:51 ` [PULL 23/23] tests/functional: purge scratch dir on test startup Thomas Huth
2025-09-11 13:12 ` [PULL 00/23] Functional tests and misc patches Peter Maydell

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=20250909135147.612345-19-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=berrange@redhat.com \
    --cc=john.levon@nutanix.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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).