Patchwork qtest: fix infinite loop when QEMU aborts abruptly

login
register
mail settings
Submitter Anthony Liguori
Date June 27, 2012, 1:23 p.m.
Message ID <1340803396-7211-1-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/167649/
State New
Headers show

Comments

Anthony Liguori - June 27, 2012, 1:23 p.m.
From Markus:

Makes "make check" hang:

    QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 gtester -k --verbose -m=quick tests/crash-test tests/rtc-test
    TEST: tests/crash-test... (pid=972)
    qemu-system-x86_64: Device needs media, but drive is empty
[Nothing happens, wait a while, then hit ^C]
    make: *** [check-qtest-x86_64] Interrupt

This was due to the fact that we weren't checked for errors when
reading from the QMP socket.  This patch adds appropriate error
checking.

Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 tests/libqtest.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
Markus Armbruster - June 27, 2012, 3:31 p.m.
Anthony Liguori <aliguori@us.ibm.com> writes:

>>From Markus:
>
> Makes "make check" hang:
>
>     QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 gtester -k --verbose -m=quick tests/crash-test tests/rtc-test
>     TEST: tests/crash-test... (pid=972)
>     qemu-system-x86_64: Device needs media, but drive is empty
> [Nothing happens, wait a while, then hit ^C]
>     make: *** [check-qtest-x86_64] Interrupt
>
> This was due to the fact that we weren't checked for errors when
> reading from the QMP socket.  This patch adds appropriate error
> checking.
>
> Reported-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Tested-by: Markus Armbruster <armbru@redhat.com>

Patch

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 1d73fd1..071b6be 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -291,6 +291,11 @@  void qtest_qmp(QTestState *s, const char *fmt, ...)
             continue;
         }
 
+        if (len == -1 || len == 0) {
+            fprintf(stderr, "Broken pipe\n");
+            exit(1);
+        }
+
         switch (c) {
         case '{':
             nesting++;