diff mbox

[03/24] libqtest: add QTEST_LOG for debugging qtest testcases

Message ID 1382978620-16641-4-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Oct. 28, 2013, 4:43 p.m. UTC
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/libqtest.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Kevin Wolf Oct. 30, 2013, 12:08 p.m. UTC | #1
Am 28.10.2013 um 17:43 hat Paolo Bonzini geschrieben:
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tests/libqtest.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Nice idea, this looks useful.

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
diff mbox

Patch

diff --git a/tests/libqtest.c b/tests/libqtest.c
index 5205a43..6e42d01 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -129,11 +129,12 @@  QTestState *qtest_init(const char *extra_args)
     if (pid == 0) {
         command = g_strdup_printf("%s "
                                   "-qtest unix:%s,nowait "
-                                  "-qtest-log /dev/null "
+                                  "-qtest-log %s "
                                   "-qmp unix:%s,nowait "
                                   "-pidfile %s "
                                   "-machine accel=qtest "
                                   "%s", qemu_binary, s->socket_path,
+                                  getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null",
                                   s->qmp_socket_path, pid_file,
                                   extra_args ?: "");
         execlp("/bin/sh", "sh", "-c", command, NULL);
@@ -295,6 +296,7 @@  bool qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
 {
     bool has_reply = false;
     int nesting = 0;
+    int log = getenv("QTEST_LOG") != NULL;
 
     /* Send QMP request */
     socket_sendf(s->qmp_fd, fmt, ap);
@@ -314,6 +316,9 @@  bool qtest_qmpv(QTestState *s, const char *fmt, va_list ap)
             exit(1);
         }
 
+        if (log) {
+            len = write(2, &c, 1);
+        }
         switch (c) {
         case '{':
             nesting++;