]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: qemu: Add QMP schema checking in qemuMonitorTestProcessCommandVerbatim
authorPeter Krempa <pkrempa@redhat.com>
Fri, 7 Jun 2019 08:38:06 +0000 (10:38 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 7 Jun 2019 14:18:45 +0000 (16:18 +0200)
In case when we are testing a QMP command we can try to schema check it
so that we catch inconsistencies.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
tests/qemumonitortestutils.c

index 1cd35830aff66003e02c640ae70b3804243a367c..0de90482430c2c3ab924a2737e09bfe0b5a1b373 100644 (file)
@@ -690,14 +690,30 @@ qemuMonitorTestProcessCommandVerbatim(qemuMonitorTestPtr test,
     struct qemuMonitorTestHandlerData *data = item->opaque;
     VIR_AUTOFREE(char *) reformatted = NULL;
     VIR_AUTOFREE(char *) errmsg = NULL;
+    VIR_AUTOPTR(virJSONValue) json = NULL;
+    virJSONValuePtr cmdargs;
+    const char *cmdname;
     int ret = -1;
+    int rc;
 
     /* JSON strings will be reformatted to simplify checking */
     if (test->json || test->agent) {
-        if (!(reformatted = virJSONStringReformat(cmdstr, false)))
+        if (!(json = virJSONValueFromString(cmdstr)) ||
+            !(reformatted = virJSONValueToString(json, false)))
             return -1;
 
         cmdstr = reformatted;
+
+        /* in this case we do a best-effort schema check if we can find the command */
+        if ((cmdname = virJSONValueObjectGetString(json, "execute"))) {
+            cmdargs = virJSONValueObjectGet(json, "arguments");
+
+            if ((rc = qemuMonitorTestProcessCommandDefaultValidate(test, cmdname, cmdargs)) < 0)
+                return -1;
+
+            if (rc == 1)
+                return 0;
+        }
     }
 
     if (STREQ(data->command_name, cmdstr)) {