[libvirt] [PATCH 05/12] tests: testQemuCapsIterate: Pass suffix to callback

Andrea Bolognani abologna at redhat.com
Wed Oct 23 10:42:55 UTC 2019


Right now users need to hardcode the suffix, which is not a big
deal since they're the ones who passed it to testQemuCapsIterate()
in the first place; however, since we're already passing most of
the information to the callback and we're going to add more later
on, it makes sense to be consistent and pass the suffix too.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 tests/qemucapabilitiestest.c |  8 ++++++--
 tests/qemucaps2xmltest.c     |  8 ++++++--
 tests/testutilsqemu.c        | 11 +++++++++--
 tests/testutilsqemu.h        |  1 +
 4 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c
index 6b8d2676e3..cc2242df50 100644
--- a/tests/qemucapabilitiestest.c
+++ b/tests/qemucapabilitiestest.c
@@ -38,6 +38,7 @@ struct _testQemuData {
     const char *inputDir;
     const char *outputDir;
     const char *archName;
+    const char *suffix;
     const char *base;
     int ret;
 };
@@ -77,8 +78,9 @@ testQemuCaps(const void *opaque)
     unsigned int fakeMicrocodeVersion = 0;
     const char *p;
 
-    if (virAsprintf(&repliesFile, "%s/%s.%s.replies",
-                    data->inputDir, data->base, data->archName) < 0 ||
+    if (virAsprintf(&repliesFile, "%s/%s.%s.%s",
+                    data->inputDir, data->base,
+                    data->archName, data->suffix) < 0 ||
         virAsprintf(&capsFile, "%s/%s.%s.xml",
                     data->outputDir, data->base, data->archName) < 0)
         goto cleanup;
@@ -182,6 +184,7 @@ static int
 doCapsTest(const char *inputDir,
            const char *base,
            const char *archName,
+           const char *suffix,
            void *opaque)
 {
     testQemuDataPtr data = (testQemuDataPtr) opaque;
@@ -196,6 +199,7 @@ doCapsTest(const char *inputDir,
     data->inputDir = inputDir;
     data->base = base;
     data->archName = archName;
+    data->suffix = suffix;
 
     if (virTestRun(title, testQemuCaps, data) < 0)
         data->ret = -1;
diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c
index 8985b20ac6..7a41e9cdd3 100644
--- a/tests/qemucaps2xmltest.c
+++ b/tests/qemucaps2xmltest.c
@@ -33,6 +33,7 @@ struct _testQemuData {
     const char *outputDir;
     const char *base;
     const char *archName;
+    const char *suffix;
     int ret;
 };
 
@@ -145,8 +146,9 @@ testQemuCapsXML(const void *opaque)
                     data->outputDir, data->archName) < 0)
         goto cleanup;
 
-    if (virAsprintf(&capsFile, "%s/%s.%s.xml",
-                    data->inputDir, data->base, data->archName) < 0)
+    if (virAsprintf(&capsFile, "%s/%s.%s.%s",
+                    data->inputDir, data->base,
+                    data->archName, data->suffix) < 0)
         goto cleanup;
 
     if (virTestLoadFile(capsFile, &capsData) < 0)
@@ -176,6 +178,7 @@ static int
 doCapsTest(const char *inputDir,
            const char *base,
            const char *archName,
+           const char *suffix,
            void *opaque)
 {
     testQemuDataPtr data = (testQemuDataPtr) opaque;
@@ -187,6 +190,7 @@ doCapsTest(const char *inputDir,
     data->inputDir = inputDir;
     data->base = base;
     data->archName = archName;
+    data->suffix = suffix;
 
     if (virTestRun(title, testQemuCapsXML, data) < 0)
         data->ret = -1;
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 75c8180c7a..1f0270f488 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -936,9 +936,16 @@ testQemuCapsIterate(const char *suffix,
         archName[0] = '\0';
         archName++;
 
-        /* Run the user-provided callback */
-        if (callback(TEST_QEMU_CAPS_PATH, base, archName, opaque) < 0)
+        /* Run the user-provided callback.
+         *
+         * We skip the dot that, as verified earlier, starts the suffix
+         * to make it nicer to rebuild the original file name from inside
+         * the callback.
+         */
+        if (callback(TEST_QEMU_CAPS_PATH, base,
+                     archName, suffix + 1, opaque) < 0) {
             goto cleanup;
+        }
     }
 
     if (rc < 0)
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 07373f8ce6..2c8c4960e9 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -99,6 +99,7 @@ virHashTablePtr testQemuGetLatestCaps(void);
 typedef int (*testQemuCapsIterateCallback)(const char *inputDir,
                                            const char *base,
                                            const char *archName,
+                                           const char *suffix,
                                            void *opaque);
 int testQemuCapsIterate(const char *suffix,
                         testQemuCapsIterateCallback callback,
-- 
2.21.0




More information about the libvir-list mailing list