]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: qemu: Use qmp schema data from the qemucapabilities test
authorPeter Krempa <pkrempa@redhat.com>
Mon, 9 Jul 2018 13:44:52 +0000 (15:44 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 10 Jul 2018 11:37:50 +0000 (13:37 +0200)
Add helpers that allow using the latest schema from the replies from an
actual qemu which are recorded for the purpose of the qemucapabilities
test instead of an unsynced copy stored in qemuqapischema.json.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/qemumonitorjsontest.c
tests/testutilsqemuschema.c
tests/testutilsqemuschema.h

index c85bcbfc3b5a358dd8cca76f77ba4d495550dac7..9039cef423f827c5ea59a544884c362914ffdc3f 100644 (file)
@@ -2860,7 +2860,8 @@ mymain(void)
     virQEMUDriver driver;
     testQemuMonitorJSONSimpleFuncData simpleFunc;
     struct testQAPISchemaData qapiData;
-    char *metaschema = NULL;
+    virJSONValuePtr metaschema = NULL;
+    char *metaschemastr = NULL;
 
 #if !WITH_YAJL
     fputs("libvirt not compiled with JSON support, skipping this test\n", stderr);
@@ -3062,20 +3063,22 @@ mymain(void)
     DO_TEST_QAPI_SCHEMA("alternate 2", "blockdev-add/arg-type", false,
                         "{\"driver\":\"qcow2\",\"file\": 1234}");
 
-    if (!(metaschema = virTestLoadFilePath("qemuqapischema.json", NULL))) {
-        VIR_TEST_VERBOSE("failed to load qapi schema\n");
+    if (!(metaschema = testQEMUSchemaGetLatest()) ||
+        !(metaschemastr = virJSONValueToString(metaschema, false))) {
+        VIR_TEST_VERBOSE("failed to load latest qapi schema\n");
         ret = -1;
         goto cleanup;
     }
 
     DO_TEST_QAPI_SCHEMA("schema-meta", "query-qmp-schema/ret-type", true,
-                        metaschema);
+                        metaschemastr);
 
 
 #undef DO_TEST_QAPI_SCHEMA
 
  cleanup:
-    VIR_FREE(metaschema);
+    VIR_FREE(metaschemastr);
+    virJSONValueFree(metaschema);
     virHashFree(qapiData.schema);
     qemuTestDriverFree(&driver);
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
index 46bbc4f1e50f312781f6442b04948ce88a506082..1cec5265e1d2846d37895afc155e910d61a66cf9 100644 (file)
@@ -17,6 +17,7 @@
  */
 #include <config.h>
 #include "testutils.h"
+#include "testutilsqemu.h"
 #include "testutilsqemuschema.h"
 #include "qemu/qemu_qapi.h"
 
@@ -516,13 +517,71 @@ testQEMUSchemaValidate(virJSONValuePtr obj,
 }
 
 
+/**
+ * testQEMUSchemaGetLatest:
+ *
+ * Returns the schema data as the qemu monitor would reply from the latest
+ * replies file used for qemucapabilitiestest for the x86_64 architecture.
+ */
+virJSONValuePtr
+testQEMUSchemaGetLatest(void)
+{
+    char *capsLatestFile = NULL;
+    char *capsLatest = NULL;
+    char *schemaReply;
+    char *end;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr schema = NULL;
+
+    if (!(capsLatestFile = testQemuGetLatestCapsForArch(abs_srcdir "/qemucapabilitiesdata",
+                                                        "x86_64", "replies"))) {
+        VIR_TEST_VERBOSE("failed to find latest caps replies\n");
+        return NULL;
+    }
+
+    VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile);
+
+    if (virTestLoadFile(capsLatestFile, &capsLatest) < 0)
+        goto cleanup;
+
+    if (!(schemaReply = strstr(capsLatest, "\"execute\": \"query-qmp-schema\"")) ||
+        !(schemaReply = strstr(schemaReply, "\n\n")) ||
+        !(end = strstr(schemaReply + 2, "\n\n"))) {
+        VIR_TEST_VERBOSE("failed to find reply to 'query-qmp-schema' in '%s'\n",
+                         capsLatestFile);
+        goto cleanup;
+    }
+
+    schemaReply += 2;
+    *end = '\0';
+
+    if (!(reply = virJSONValueFromString(schemaReply))) {
+        VIR_TEST_VERBOSE("failed to parse 'query-qmp-schema' reply from '%s'\n",
+                         capsLatestFile);
+        goto cleanup;
+    }
+
+    if (!(schema = virJSONValueObjectStealArray(reply, "return"))) {
+        VIR_TEST_VERBOSE("missing qapi schema data in reply in '%s'\n",
+                         capsLatestFile);
+        goto cleanup;
+    }
+
+ cleanup:
+    VIR_FREE(capsLatestFile);
+    VIR_FREE(capsLatest);
+    virJSONValueFree(reply);
+    return schema;
+}
+
+
 virHashTablePtr
 testQEMUSchemaLoad(void)
 {
-    virJSONValuePtr schemajson;
+    virJSONValuePtr schema;
 
-    if (!(schemajson = virTestLoadFileJSON("qemuqapischema.json", NULL)))
+    if (!(schema = testQEMUSchemaGetLatest()))
         return NULL;
 
-    return virQEMUQAPISchemaConvert(schemajson);
+    return virQEMUQAPISchemaConvert(schema);
 }
index cb383db174b8b92a6fe9b40e8ce0425c6b4ab7f9..c69435f4205c532b7f2384b753fdfc8d15bec7ed 100644 (file)
@@ -26,5 +26,8 @@ testQEMUSchemaValidate(virJSONValuePtr obj,
                        virHashTablePtr schema,
                        virBufferPtr debug);
 
+virJSONValuePtr
+testQEMUSchemaGetLatest(void);
+
 virHashTablePtr
 testQEMUSchemaLoad(void);