[PATCH] qtest: Allow and ignore blank lines in input

Peter Maydell posted 1 patch 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20251106151959.1088095-1-peter.maydell@linaro.org
Maintainers: Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
system/qtest.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
[PATCH] qtest: Allow and ignore blank lines in input
Posted by Peter Maydell 3 months ago
Currently the code that reads the qtest protocol commands insists
that every input line has a command.  If it receives a line with
nothing but whitespace it will trip an assertion in
qtest_process_command().

This is a little awkward for the case where we are feeding qtest a
set of bug-reproduction commands via standard input or a file,
because it means you need to be careful not to leave a blank line at
the start or the end when cutting and pasting the command sequence
from a bug report.

Change the code to allow and ignore blank lines in the input.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 system/qtest.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/system/qtest.c b/system/qtest.c
index e4d1cd75daa..baef06d4d1b 100644
--- a/system/qtest.c
+++ b/system/qtest.c
@@ -69,6 +69,9 @@ static void *qtest_server_send_opaque;
  * so clients should always handle many async messages before the response
  * comes in.
  *
+ * Extra ASCII space characters in command inputs are permitted and ignored.
+ * Lines containing only spaces are permitted and ignored.
+ *
  * Valid requests
  * ^^^^^^^^^^^^^^
  *
@@ -367,7 +370,11 @@ static void qtest_process_command(CharFrontend *chr, gchar **words)
         fprintf(qtest_log_fp, "\n");
     }
 
-    g_assert(command);
+    if (!command) {
+        /* Input line was blank: ignore it */
+        return;
+    }
+
     if (strcmp(words[0], "irq_intercept_out") == 0
         || strcmp(words[0], "irq_intercept_in") == 0) {
         DeviceState *dev;
-- 
2.43.0
Re: [PATCH] qtest: Allow and ignore blank lines in input
Posted by Philippe Mathieu-Daudé 2 months, 2 weeks ago
On 6/11/25 16:19, Peter Maydell wrote:
> Currently the code that reads the qtest protocol commands insists
> that every input line has a command.  If it receives a line with
> nothing but whitespace it will trip an assertion in
> qtest_process_command().
> 
> This is a little awkward for the case where we are feeding qtest a
> set of bug-reproduction commands via standard input or a file,
> because it means you need to be careful not to leave a blank line at
> the start or the end when cutting and pasting the command sequence
> from a bug report.
> 
> Change the code to allow and ignore blank lines in the input.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   system/qtest.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)

Queued, thanks.
Re: [PATCH] qtest: Allow and ignore blank lines in input
Posted by Fabiano Rosas 2 months, 2 weeks ago
Peter Maydell <peter.maydell@linaro.org> writes:

> Currently the code that reads the qtest protocol commands insists
> that every input line has a command.  If it receives a line with
> nothing but whitespace it will trip an assertion in
> qtest_process_command().
>
> This is a little awkward for the case where we are feeding qtest a
> set of bug-reproduction commands via standard input or a file,
> because it means you need to be careful not to leave a blank line at
> the start or the end when cutting and pasting the command sequence
> from a bug report.
>
> Change the code to allow and ignore blank lines in the input.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  system/qtest.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/system/qtest.c b/system/qtest.c
> index e4d1cd75daa..baef06d4d1b 100644
> --- a/system/qtest.c
> +++ b/system/qtest.c
> @@ -69,6 +69,9 @@ static void *qtest_server_send_opaque;
>   * so clients should always handle many async messages before the response
>   * comes in.
>   *
> + * Extra ASCII space characters in command inputs are permitted and ignored.
> + * Lines containing only spaces are permitted and ignored.
> + *
>   * Valid requests
>   * ^^^^^^^^^^^^^^
>   *
> @@ -367,7 +370,11 @@ static void qtest_process_command(CharFrontend *chr, gchar **words)
>          fprintf(qtest_log_fp, "\n");
>      }
>  
> -    g_assert(command);
> +    if (!command) {
> +        /* Input line was blank: ignore it */
> +        return;
> +    }
> +
>      if (strcmp(words[0], "irq_intercept_out") == 0
>          || strcmp(words[0], "irq_intercept_in") == 0) {
>          DeviceState *dev;

Reviewed-by: Fabiano Rosas <farosas@suse.de>

Queued