]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testutilsqemuschema: Allow loading non-latest schema
authorPeter Krempa <pkrempa@redhat.com>
Fri, 15 May 2020 14:32:40 +0000 (16:32 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 20 May 2020 07:41:58 +0000 (09:41 +0200)
Add testQEMUSchemaLoad and refactor internals so that we can load the
QMP schema from an arbitrary caps replies file.

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

index a900d8c117965ce1b25475196fcd6bb1e773d954..d9bc00903d702bd61887416b6aff7ef9e01f7008 100644 (file)
@@ -607,37 +607,23 @@ testQEMUSchemaValidateCommand(const char *command,
 }
 
 
-/**
- * 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(const char* arch)
+static virJSONValuePtr
+testQEMUSchemaLoadReplies(const char *filename)
 {
-    g_autofree char *capsLatestFile = NULL;
-    g_autofree char *capsLatest = NULL;
+    g_autofree char *caps = NULL;
     char *schemaReply;
     char *end;
     g_autoptr(virJSONValue) reply = NULL;
     virJSONValuePtr schema = NULL;
 
-    if (!(capsLatestFile = testQemuGetLatestCapsForArch(arch, "replies"))) {
-        VIR_TEST_VERBOSE("failed to find latest caps replies");
+    if (virTestLoadFile(filename, &caps) < 0)
         return NULL;
-    }
 
-    VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile);
-
-    if (virTestLoadFile(capsLatestFile, &capsLatest) < 0)
-        return NULL;
-
-    if (!(schemaReply = strstr(capsLatest, "\"execute\": \"query-qmp-schema\"")) ||
+    if (!(schemaReply = strstr(caps, "\"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'",
-                         capsLatestFile);
+                         filename);
         return NULL;
     }
 
@@ -646,13 +632,13 @@ testQEMUSchemaGetLatest(const char* arch)
 
     if (!(reply = virJSONValueFromString(schemaReply))) {
         VIR_TEST_VERBOSE("failed to parse 'query-qmp-schema' reply from '%s'",
-                         capsLatestFile);
+                         filename);
         return NULL;
     }
 
     if (!(schema = virJSONValueObjectStealArray(reply, "return"))) {
         VIR_TEST_VERBOSE("missing qapi schema data in reply in '%s'",
-                         capsLatestFile);
+                         filename);
         return NULL;
     }
 
@@ -660,6 +646,28 @@ testQEMUSchemaGetLatest(const char* arch)
 }
 
 
+/**
+ * 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(const char *arch)
+{
+    g_autofree char *capsLatestFile = NULL;
+
+    if (!(capsLatestFile = testQemuGetLatestCapsForArch(arch, "replies"))) {
+        VIR_TEST_VERBOSE("failed to find latest caps replies");
+        return NULL;
+    }
+
+    VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile);
+
+    return testQEMUSchemaLoadReplies(capsLatestFile);
+}
+
+
 virHashTablePtr
 testQEMUSchemaLoadLatest(const char *arch)
 {
@@ -670,3 +678,15 @@ testQEMUSchemaLoadLatest(const char *arch)
 
     return virQEMUQAPISchemaConvert(schema);
 }
+
+
+virHashTablePtr
+testQEMUSchemaLoad(const char *filename)
+{
+    virJSONValuePtr schema;
+
+    if (!(schema = testQEMUSchemaLoadReplies(filename)))
+        return NULL;
+
+    return virQEMUQAPISchemaConvert(schema);
+}
index acedb776776cba4bc44ec75c88375c242c15ac91..c90a6b626d4498e573808f7fe106a4df0b0ffa33 100644 (file)
@@ -42,3 +42,6 @@ testQEMUSchemaGetLatest(const char* arch);
 
 virHashTablePtr
 testQEMUSchemaLoadLatest(const char *arch);
+
+virHashTablePtr
+testQEMUSchemaLoad(const char *filename);