[PATCH v2 20/23] testutilsqemu: Introduce struct to hold data valid for all test runs

Peter Krempa pkrempa at redhat.com
Tue Aug 17 16:25:21 UTC 2021


We pass multiple caching objects to individual tests which don't change.
To prevent always having to pass them individually to
'testQemuInfoSetArgs' introduce 'struct testQemuConf' which will hold
all of them and just the struct will be passed to the tests.

Additionally this will make the conf available from inside the test run.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tests/qemustatusxml2xmltest.c |  8 +++++---
 tests/qemuxml2argvtest.c      | 20 ++++++++++----------
 tests/qemuxml2xmltest.c       |  9 ++++++---
 tests/testutilsqemu.c         | 13 +++++++------
 tests/testutilsqemu.h         | 13 ++++++++++---
 5 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/tests/qemustatusxml2xmltest.c b/tests/qemustatusxml2xmltest.c
index ac007405a6..995ef68a4c 100644
--- a/tests/qemustatusxml2xmltest.c
+++ b/tests/qemustatusxml2xmltest.c
@@ -72,11 +72,13 @@ mymain(void)
     int ret = 0;
     g_autofree char *fakerootdir = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
-    g_autoptr(GHashTable) capslatest = NULL;
+    g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
     g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData);
     g_autoptr(virConnect) conn = NULL;
+    struct testQemuConf testConf = { .capslatest = capslatest,
+                                     .capscache = capscache,
+                                     .qapiSchemaCache = NULL };

-    capslatest = testQemuGetLatestCaps();
     if (!capslatest)
         return EXIT_FAILURE;

@@ -110,7 +112,7 @@ mymain(void)
         static struct testQemuInfo info = { \
             .name = _name, \
         }; \
-        if (testQemuInfoSetArgs(&info, capscache, capslatest, ARG_END) < 0 || \
+        if (testQemuInfoSetArgs(&info, &testConf, ARG_END) < 0 || \
             qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \
             VIR_TEST_DEBUG("Failed to generate status test data for '%s'", _name); \
             return -1; \
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 80ae2aa329..0dbb6ad94b 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -535,11 +535,11 @@ testCompareXMLToArgvValidateSchema(virQEMUDriver *drv,

     if (info->schemafile) {
         /* lookup and insert into cache if not found */
-        if (!g_hash_table_lookup_extended(info->qapiSchemaCache,
+        if (!g_hash_table_lookup_extended(info->conf->qapiSchemaCache,
                                           info->schemafile,
                                           NULL, (void **) &schema)) {
             schema = testQEMUSchemaLoad(info->schemafile);
-            g_hash_table_insert(info->qapiSchemaCache,
+            g_hash_table_insert(info->conf->qapiSchemaCache,
                                 g_strdup(info->schemafile),
                                 schema);
         }
@@ -845,9 +845,15 @@ mymain(void)
 {
     int ret = 0;
     g_autofree char *fakerootdir = NULL;
-    g_autoptr(GHashTable) capslatest = NULL;
+    g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
     g_autoptr(GHashTable) qapiSchemaCache = virHashNew((GDestroyNotify) virHashFree);
     g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData);
+    struct testQemuConf testConf = { .capslatest = capslatest,
+                                     .capscache = capscache,
+                                     .qapiSchemaCache = qapiSchemaCache };
+
+    if (!capslatest)
+        return EXIT_FAILURE;

     fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);

@@ -901,10 +907,6 @@ mymain(void)
     VIR_FREE(driver.config->nvramDir);
     driver.config->nvramDir = g_strdup("/var/lib/libvirt/qemu/nvram");

-    capslatest = testQemuGetLatestCaps();
-    if (!capslatest)
-        return EXIT_FAILURE;
-
     virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware",
                             abs_srcdir "/qemufirmwaredata/etc/qemu/firmware");
     virFileWrapperAddPrefix(PREFIX "/share/qemu/firmware",
@@ -941,9 +943,7 @@ mymain(void)
         static struct testQemuInfo info = { \
             .name = _name, \
         }; \
-        info.qapiSchemaCache = qapiSchemaCache; \
-        if (testQemuInfoSetArgs(&info, capscache, capslatest, \
-                                __VA_ARGS__) < 0) \
+        if (testQemuInfoSetArgs(&info, &testConf, __VA_ARGS__) < 0) \
             ret = -1; \
         testInfoSetPaths(&info, _suffix); \
         if (virTestRun("QEMU XML-2-ARGV " _name _suffix, \
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 04aeba383d..e71b77b967 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -104,14 +104,17 @@ mymain(void)
     int ret = 0;
     g_autofree char *fakerootdir = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
-    g_autoptr(GHashTable) capslatest = NULL;
+    g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
     g_autoptr(GHashTable) capscache = virHashNew(virObjectFreeHashData);
     g_autoptr(virConnect) conn = NULL;
+    struct testQemuConf testConf = { .capslatest = capslatest,
+                                     .capscache = capscache,
+                                     .qapiSchemaCache = NULL };

-    capslatest = testQemuGetLatestCaps();
     if (!capslatest)
         return EXIT_FAILURE;

+
     fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);

     if (!g_mkdtemp(fakerootdir)) {
@@ -151,7 +154,7 @@ mymain(void)
         static struct testQemuInfo info = { \
             .name = _name, \
         }; \
-        if (testQemuInfoSetArgs(&info, capscache, capslatest, __VA_ARGS__) < 0 || \
+        if (testQemuInfoSetArgs(&info, &testConf, __VA_ARGS__) < 0 || \
             qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \
             VIR_TEST_DEBUG("Failed to generate test data for '%s'", _name); \
             ret = -1; \
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 5ff373e954..821f6e2707 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -679,8 +679,7 @@ testQemuCapsIterate(const char *suffix,

 int
 testQemuInfoSetArgs(struct testQemuInfo *info,
-                    GHashTable *capscache,
-                    GHashTable *capslatest, ...)
+                    struct testQemuConf *conf, ...)
 {
     va_list argptr;
     testQemuInfoArgName argname;
@@ -696,7 +695,9 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
     if (!fakeCaps)
         abort();

-    va_start(argptr, capslatest);
+    info->conf = conf;
+
+    va_start(argptr, conf);
     while ((argname = va_arg(argptr, testQemuInfoArgName)) != ARG_END) {
         switch (argname) {
         case ARG_QEMU_CAPS:
@@ -760,18 +761,18 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
         info->arch = virArchFromString(capsarch);

         if (STREQ(capsver, "latest")) {
-            capsfile = g_strdup(virHashLookup(capslatest, capsarch));
+            capsfile = g_strdup(virHashLookup(info->conf->capslatest, capsarch));
             stripmachinealiases = true;
         } else {
             capsfile = g_strdup_printf("%s/caps_%s.%s.xml",
                                        TEST_QEMU_CAPS_PATH, capsver, capsarch);
         }

-        if (!g_hash_table_lookup_extended(capscache, capsfile, NULL, (void **) &cachedcaps)) {
+        if (!g_hash_table_lookup_extended(info->conf->capscache, capsfile, NULL, (void **) &cachedcaps)) {
             if (!(cachedcaps = qemuTestParseCapabilitiesArch(info->arch, capsfile)))
                 goto cleanup;

-            g_hash_table_insert(capscache, g_strdup(capsfile), cachedcaps);
+            g_hash_table_insert(info->conf->capscache, g_strdup(capsfile), cachedcaps);
         }

         if (!(info->qemuCaps = virQEMUCapsNewCopy(cachedcaps)))
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index c6da0745a0..af7e756c05 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -54,6 +54,12 @@ typedef enum {
     FLAG_SLIRP_HELPER       = 1 << 5,
 } testQemuInfoFlags;

+struct testQemuConf {
+    GHashTable *capscache;
+    GHashTable *capslatest;
+    GHashTable *qapiSchemaCache;
+};
+
 struct testQemuInfo {
     const char *name;
     char *infile;
@@ -66,7 +72,8 @@ struct testQemuInfo {
     unsigned int parseFlags;
     virArch arch;
     char *schemafile;
-    GHashTable *qapiSchemaCache;
+
+    struct testQemuConf *conf;
 };

 virCaps *testQemuCapsInit(void);
@@ -110,8 +117,8 @@ int testQemuCapsIterate(const char *suffix,
                         void *opaque);

 int testQemuInfoSetArgs(struct testQemuInfo *info,
-                        GHashTable *capscache,
-                        GHashTable *capslatest, ...);
+                        struct testQemuConf *conf,
+                        ...);
 void testQemuInfoClear(struct testQemuInfo *info);

 #endif
-- 
2.31.1




More information about the libvir-list mailing list