[PATCH 1/4] qemuxml2argvtest: Cache QAPI schema between tests

Peter Krempa pkrempa at redhat.com
Fri Feb 19 15:53:18 UTC 2021


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 at redhat.com>
---
 tests/qemuxml2argvtest.c | 17 ++++++++++++++---
 tests/testutilsqemu.h    |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index db438c5466..647187404c 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -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; \
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 0c6f0ea378..86ba69e96b 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -66,6 +66,7 @@ struct testQemuInfo {
     unsigned int parseFlags;
     virArch arch;
     char *schemafile;
+    GHashTable *qapiSchemaCache;
 };

 virCapsPtr testQemuCapsInit(void);
-- 
2.29.2




More information about the libvir-list mailing list