]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuxml2argvtest: Cache QAPI schema between tests
authorPeter Krempa <pkrempa@redhat.com>
Fri, 19 Feb 2021 15:19:09 +0000 (16:19 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Sat, 20 Feb 2021 12:27:44 +0000 (13:27 +0100)
It's quite wasteful to reparse the QAPI schema for each _CAPS_ test.

Add a simple cache filled lazily by encountered schemas.

The time saving on my box is quite significant:

real 0m3.318s
user 0m3.203s
sys 0m0.107s

vs

real 0m2.223s
user 0m2.134s
sys 0m0.084s

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
tests/qemuxml2argvtest.c
tests/testutilsqemu.h

index db438c5466c56b11bcf9d7fb64d4f783f0c25b35..647187404ccb298c037e8a6c6402fa5b0e078ccd 100644 (file)
@@ -523,13 +523,22 @@ testCompareXMLToArgvValidateSchema(virQEMUDriverPtr drv,
     qemuDomainObjPrivatePtr priv = NULL;
     size_t nargs = 0;
     size_t i;
-    g_autoptr(GHashTable) schema = NULL;
+    GHashTable *schema = NULL;
     g_autoptr(virCommand) cmd = NULL;
     unsigned int parseFlags = info->parseFlags;
     bool netdevQAPIfied = false;
 
-    if (info->schemafile)
-        schema = testQEMUSchemaLoad(info->schemafile);
+    if (info->schemafile) {
+        /* lookup and insert into cache if not found */
+        if (!g_hash_table_lookup_extended(info->qapiSchemaCache,
+                                          info->schemafile,
+                                          NULL, (void **) &schema)) {
+            schema = testQEMUSchemaLoad(info->schemafile);
+            g_hash_table_insert(info->qapiSchemaCache,
+                                g_strdup(info->schemafile),
+                                schema);
+        }
+    }
 
     /* comment out with line comment to enable schema checking for non _CAPS tests
     if (!schema)
@@ -779,6 +788,7 @@ mymain(void)
     int ret = 0;
     g_autofree char *fakerootdir = NULL;
     g_autoptr(GHashTable) capslatest = NULL;
+    g_autoptr(GHashTable) qapiSchemaCache = virHashNew((GDestroyNotify) virHashFree);
 
     fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
@@ -872,6 +882,7 @@ mymain(void)
         static struct testQemuInfo info = { \
             .name = _name, \
         }; \
+        info.qapiSchemaCache = qapiSchemaCache; \
         if (testQemuInfoSetArgs(&info, capslatest, \
                                 __VA_ARGS__, ARG_END) < 0) \
             return EXIT_FAILURE; \
index 0c6f0ea3780754c5363a46b858785f8331c804bd..86ba69e96b799eeac7fa34ca5c5fa9677f1f6602 100644 (file)
@@ -66,6 +66,7 @@ struct testQemuInfo {
     unsigned int parseFlags;
     virArch arch;
     char *schemafile;
+    GHashTable *qapiSchemaCache;
 };
 
 virCapsPtr testQemuCapsInit(void);