]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: qemucapsprobemock: Prepare 'qemucapsprobe' for the new format
authorPeter Krempa <pkrempa@redhat.com>
Thu, 3 May 2018 15:29:36 +0000 (17:29 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Jun 2018 08:27:50 +0000 (10:27 +0200)
Change the output of qemucapsprobe to record the commands used for
querying. This allows to easily identify which reply belongs to which
command and also will allow to test whether we use stable queries.

This change includes changing dropping of the QMP greeting from the file
and reformatting of the query and output to stdout.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
tests/qemucapsprobemock.c

index a0d2acb69a673dc1a1a63d376fac92b9412df9ae..5936975505b1c9717030d19c55b71c6468ce52de 100644 (file)
@@ -37,6 +37,7 @@
         } \
     } while (0)
 
+static bool first = true;
 
 static void
 printLineSkipEmpty(const char *line,
@@ -60,9 +61,22 @@ int
 qemuMonitorSend(qemuMonitorPtr mon,
                 qemuMonitorMessagePtr msg)
 {
+    char *reformatted;
+
     REAL_SYM(realQemuMonitorSend);
 
-    fprintf(stderr, "%s", msg->txBuffer);
+    if (!(reformatted = virJSONStringReformat(msg->txBuffer, true))) {
+        fprintf(stderr, "Failed to reformat command string '%s'\n", msg->txBuffer);
+        abort();
+    }
+
+    if (first)
+        first = false;
+    else
+        printLineSkipEmpty("\n", stdout);
+
+    printLineSkipEmpty(reformatted, stdout);
+    VIR_FREE(reformatted);
 
     return realQemuMonitorSend(mon, msg);
 }
@@ -77,7 +91,6 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
                              const char *line,
                              qemuMonitorMessagePtr msg)
 {
-    static bool first = true;
     virJSONValuePtr value = NULL;
     char *json = NULL;
     int ret;
@@ -93,14 +106,14 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
             abort();
         }
 
-        if (first) {
+        /* Ignore QMP greeting */
+        if (virJSONValueObjectHasKey(value, "QMP"))
+            goto cleanup;
+
+        if (first)
             first = false;
-        } else {
-            /* Ignore QMP greeting if it's not the first one */
-            if (virJSONValueObjectHasKey(value, "QMP"))
-                goto cleanup;
-            putchar('\n');
-        }
+        else
+            printLineSkipEmpty("\n", stdout);
 
         printLineSkipEmpty(json, stdout);
     }