]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testQemuGetRealCaps: Integrate fetching of QMP schema
authorPeter Krempa <pkrempa@redhat.com>
Thu, 9 Mar 2023 14:15:40 +0000 (15:15 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 3 Apr 2023 07:19:07 +0000 (09:19 +0200)
Move the lookup of the corresponding QMP schema used for validation of
QMP commands from 'testCompareXMLToArgvValidateSchema' to
testQemuGetRealCaps as an optional step.

This will simplify using QMP command validation in other tests which
will use testQemuGetRealCaps.

'testutilsqemuschema' module is now linked into 'test_utils_qemu' as it
contains no monitor-specific code itself and after this patch it's
referenced directly from that module.

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

index 11010ebc6ced23be96518faef3e2b02838d52f8f..8958e68a692e081733a634b721fb44d4990530aa 100644 (file)
@@ -147,13 +147,13 @@ endif
 if conf.has('WITH_QEMU')
   test_utils_qemu_lib = static_library(
     'test_utils_qemu',
-    [ 'testutilsqemu.c' ],
+    [ 'testutilsqemu.c', 'testutilsqemuschema.c' ],
     dependencies: [ tests_dep ],
   )
 
   test_utils_qemu_monitor_lib = static_library(
     'test_utils_qemu_monitor',
-    [ 'qemumonitortestutils.c', 'testutilsqemuschema.c' ],
+    [ 'qemumonitortestutils.c', ],
     dependencies: [ tests_dep ],
   )
 
index 7f3b2985ebc88b37475e4b50d3b6e3e0810c6d9b..e0d237bb2d0d3346f70d29385eac81c146650087 100644 (file)
@@ -549,32 +549,14 @@ testCompareXMLToArgvValidateSchema(virCommand *cmd,
                                    struct testQemuInfo *info)
 {
     g_auto(GStrv) args = NULL;
-    GHashTable *schema = NULL;
-
-    /* comment out with line comment to enable schema checking for non _CAPS tests
-    if (!info->schemafile)
-        info->schemafile =  testQemuGetLatestCapsForArch(virArchToString(info->arch), "replies");
-    // */
-
-    if (info->schemafile) {
-        /* lookup and insert into cache if not found */
-        if (!g_hash_table_lookup_extended(info->conf->qapiSchemaCache,
-                                          info->schemafile,
-                                          NULL, (void **) &schema)) {
-            schema = testQEMUSchemaLoad(info->schemafile);
-            g_hash_table_insert(info->conf->qapiSchemaCache,
-                                g_strdup(info->schemafile),
-                                schema);
-        }
-    }
 
-    if (!schema)
+    if (!info->qmpSchema)
         return 0;
 
     if (virCommandGetArgList(cmd, &args) < 0)
         return -1;
 
-    if (testCompareXMLToArgvValidateSchemaCommand(args, schema) < 0)
+    if (testCompareXMLToArgvValidateSchemaCommand(args, info->qmpSchema) < 0)
         return -1;
 
     return 0;
index a1c55170d9ccbd3364f14c3a9d781298f1ac031c..0d7892353c1c520bf8a1243634a021687ece32e4 100644 (file)
@@ -2,6 +2,7 @@
 #ifdef WITH_QEMU
 
 # include "testutilsqemu.h"
+# include "testutilsqemuschema.h"
 # include "testutilshostcpus.h"
 # include "testutils.h"
 # include "viralloc.h"
@@ -910,11 +911,16 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
  * @variant: capabilities variant to fetch caps for
  * @capsLatestFiles: hash table containing latest version of capabilities for the  @arch+@variant tuple
  * @capsCache: hash table filled with the cache of capabilities
- * @capsReplies: Filled with path to the corresponding '.replies' file
+ * @schemaCache: hash table for caching QMP schemas (may be NULL, see below)
+ * @schema: Filled with the QMP schema (hash table) (may be NULL, see below)
  *
  * Fetches and returns the appropriate virQEMUCaps for the @arch+@version+@variant
  * tuple. The returned pointer is a copy of the cached object and thus can
  * be freely modified. Caller is responsible for freeing it.
+ *
+ * If @schemaCache and @schema are non-NULL, @schema is filled with with a
+ * pointer (borrowed from the cache) to the hash table representing the QEMU QMP
+ * schema used for validation of the monitor traffic.
  */
 virQEMUCaps *
 testQemuGetRealCaps(const char *arch,
@@ -922,7 +928,8 @@ testQemuGetRealCaps(const char *arch,
                     const char *variant,
                     GHashTable *capsLatestFiles,
                     GHashTable *capsCache,
-                    char **capsReplies)
+                    GHashTable *schemaCache,
+                    GHashTable **schema)
 {
     g_autofree char *capsfile = NULL;
     bool stripmachinealiases = false;
@@ -960,10 +967,16 @@ testQemuGetRealCaps(const char *arch,
     if (stripmachinealiases)
         virQEMUCapsStripMachineAliases(ret);
 
-    if (capsReplies) {
-        /* provide path to the replies file for schema testing */
-        capsfile[strlen(capsfile) - 3] = '\0';
-        *capsReplies = g_strdup_printf("%sreplies", capsfile);
+    /* strip 'xml' suffix so that we can format the file to '.replies' */
+    capsfile[strlen(capsfile) - 3] = '\0';
+
+    if (schemaCache && schema) {
+        g_autofree char *schemafile = g_strdup_printf("%sreplies", capsfile);
+
+        if (!g_hash_table_lookup_extended(schemaCache, schemafile, NULL, (void **) schema)) {
+            *schema = testQEMUSchemaLoad(schemafile);
+            g_hash_table_insert(schemaCache, g_strdup(schemafile), *schema);
+        }
     }
 
     return ret;
@@ -1001,7 +1014,8 @@ testQemuInfoInitArgs(struct testQemuInfo *info)
                                              info->args.capsvariant,
                                              info->conf->capslatest,
                                              info->conf->capscache,
-                                             &info->schemafile);
+                                             info->conf->qapiSchemaCache,
+                                             &info->qmpSchema);
 
         if (!info->qemuCaps)
             return -1;
@@ -1028,7 +1042,6 @@ testQemuInfoClear(struct testQemuInfo *info)
 {
     VIR_FREE(info->infile);
     VIR_FREE(info->outfile);
-    VIR_FREE(info->schemafile);
     VIR_FREE(info->errfile);
     virObjectUnref(info->qemuCaps);
     g_clear_pointer(&info->args.fakeCapsAdd, virBitmapFree);
index d7ee73beedbec7d8c5c4d744c9d692106f234d60..1e6611daa3b383ea46f97afad936f55766e4536a 100644 (file)
@@ -99,7 +99,7 @@ struct testQemuInfo {
     unsigned int flags;
     unsigned int parseFlags;
     virArch arch;
-    char *schemafile;
+    GHashTable *qmpSchema; /* borrowed pointer from the cache */
 
     struct testQemuArgs args;
     struct testQemuConf *conf;
@@ -158,5 +158,6 @@ testQemuGetRealCaps(const char *arch,
                     const char *variant,
                     GHashTable *capsLatestFiles,
                     GHashTable *capsCache,
-                    char **capsReplies);
+                    GHashTable *schemaCache,
+                    GHashTable **schema);
 #endif