[v2,1/6] tests: qemuxml2xml: Set name in testQemuInfo

Message ID 3abd123ee44624f2a2da812b0764aae0d06b0906.1555369583.git.crobinso@redhat.com
State Accepted
Commit 352dd945cf98bcadf1fbac0b776e35c30b49193c
Headers show
Series
  • tests: qemuxml2xml: add DO_TEST_CAPS*
Related show

Commit Message

Cole Robinson April 15, 2019, 11:09 p.m.
Use the same pattern that is used in qemuxml2argvtest, setting the
name in a static testQemuInfo instance inside the test macros

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 tests/qemuxml2xmltest.c | 47 +++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Comments

Andrea Bolognani April 16, 2019, 8:36 a.m. | #1
On Mon, 2019-04-15 at 19:09 -0400, Cole Robinson wrote:
[...]
> @@ -148,7 +146,6 @@ mymain(void)

>  {

>      int ret = 0;

>      char *fakerootdir;

> -    struct testQemuInfo info;

>      virQEMUDriverConfigPtr cfg = NULL;

>      virHashTablePtr capslatest = NULL;

>  

> @@ -168,39 +165,40 @@ mymain(void)

>  

>      setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);

>  

> -    memset(&info, 0, sizeof(info));

> -

>      if (qemuTestDriverInit(&driver) < 0)

>          return EXIT_FAILURE;

>  

>      cfg = virQEMUDriverGetConfig(&driver);

>  

> -# define DO_TEST_FULL(name, when, ...) \

> +# define DO_TEST_FULL(_name, when, ...) \

>      do { \

> +        static struct testQemuInfo info = { \

> +            .name = _name, \

> +        }; \


Since we're calling testQemuInfoClear() at the end of the macro
already, we could probably avoid creating a new structure every
single time and reuse the same one over and over again, as this test
was doing. But we can do that in a later patch, and now that the
code is identical between xml2argv and xml2xml it's gonna be easier
to change both at the same time.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>


-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Patch

diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 8a7a56f764..59c0c2c483 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -90,19 +90,18 @@  testCompareStatusXMLToXMLFiles(const void *opaque)
 
 static int
 testInfoSetPaths(struct testQemuInfo *info,
-                 const char *name,
                  int when)
 {
     VIR_FREE(info->infile);
     VIR_FREE(info->outfile);
 
     if (virAsprintf(&info->infile, "%s/qemuxml2argvdata/%s.xml",
-                    abs_srcdir, name) < 0)
+                    abs_srcdir, info->name) < 0)
         goto error;
 
     if (virAsprintf(&info->outfile,
                     "%s/qemuxml2xmloutdata/%s-%s.xml",
-                    abs_srcdir, name,
+                    abs_srcdir, info->name,
                     when == WHEN_ACTIVE ? "active" : "inactive") < 0)
         goto error;
 
@@ -111,7 +110,7 @@  testInfoSetPaths(struct testQemuInfo *info,
 
         if (virAsprintf(&info->outfile,
                         "%s/qemuxml2xmloutdata/%s.xml",
-                        abs_srcdir, name) < 0)
+                        abs_srcdir, info->name) < 0)
             goto error;
     }
 
@@ -126,11 +125,10 @@  testInfoSetPaths(struct testQemuInfo *info,
 static const char *statusPath = abs_srcdir "/qemustatusxml2xmldata/";
 
 static int
-testInfoSetStatusPaths(struct testQemuInfo *info,
-                       const char *name)
+testInfoSetStatusPaths(struct testQemuInfo *info)
 {
-    if (virAsprintf(&info->infile, "%s%s-in.xml", statusPath, name) < 0 ||
-        virAsprintf(&info->outfile, "%s%s-out.xml", statusPath, name) < 0)
+    if (virAsprintf(&info->infile, "%s%s-in.xml", statusPath, info->name) < 0 ||
+        virAsprintf(&info->outfile, "%s%s-out.xml", statusPath, info->name) < 0)
         goto error;
 
     return 0;
@@ -148,7 +146,6 @@  mymain(void)
 {
     int ret = 0;
     char *fakerootdir;
-    struct testQemuInfo info;
     virQEMUDriverConfigPtr cfg = NULL;
     virHashTablePtr capslatest = NULL;
 
@@ -168,39 +165,40 @@  mymain(void)
 
     setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
 
-    memset(&info, 0, sizeof(info));
-
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
     cfg = virQEMUDriverGetConfig(&driver);
 
-# define DO_TEST_FULL(name, when, ...) \
+# define DO_TEST_FULL(_name, when, ...) \
     do { \
+        static struct testQemuInfo info = { \
+            .name = _name, \
+        }; \
         if (testQemuInfoSetArgs(&info, capslatest, \
                                 __VA_ARGS__, \
                                 ARG_END) < 0 || \
             qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0) { \
-            VIR_TEST_DEBUG("Failed to generate test data for '%s'", name); \
+            VIR_TEST_DEBUG("Failed to generate test data for '%s'", _name); \
             return -1; \
         } \
  \
         if (when & WHEN_INACTIVE) { \
-            if (testInfoSetPaths(&info, name, WHEN_INACTIVE) < 0) { \
-                VIR_TEST_DEBUG("Failed to generate inactive paths for '%s'", name); \
+            if (testInfoSetPaths(&info, WHEN_INACTIVE) < 0) { \
+                VIR_TEST_DEBUG("Failed to generate inactive paths for '%s'", _name); \
                 return -1; \
             } \
-            if (virTestRun("QEMU XML-2-XML-inactive " name, \
+            if (virTestRun("QEMU XML-2-XML-inactive " _name, \
                             testXML2XMLInactive, &info) < 0) \
                 ret = -1; \
         } \
  \
         if (when & WHEN_ACTIVE) { \
-            if (testInfoSetPaths(&info, name, WHEN_ACTIVE) < 0) { \
-                VIR_TEST_DEBUG("Failed to generate active paths for '%s'", name); \
+            if (testInfoSetPaths(&info, WHEN_ACTIVE) < 0) { \
+                VIR_TEST_DEBUG("Failed to generate active paths for '%s'", _name); \
                 return -1; \
             } \
-            if (virTestRun("QEMU XML-2-XML-active " name, \
+            if (virTestRun("QEMU XML-2-XML-active " _name, \
                             testXML2XMLActive, &info) < 0) \
                 ret = -1; \
         } \
@@ -1253,18 +1251,21 @@  mymain(void)
             QEMU_CAPS_VIRTIO_SCSI,
             QEMU_CAPS_MCH_EXTENDED_TSEG_MBYTES);
 
-# define DO_TEST_STATUS(name) \
+# define DO_TEST_STATUS(_name) \
     do { \
+        static struct testQemuInfo info = { \
+            .name = _name, \
+        }; \
         if (testQemuInfoSetArgs(&info, capslatest, \
                                 ARG_QEMU_CAPS, QEMU_CAPS_LAST, \
                                 ARG_END) < 0 || \
             qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) < 0 || \
-            testInfoSetStatusPaths(&info, name) < 0) { \
-            VIR_TEST_DEBUG("Failed to generate status test data for '%s'", name); \
+            testInfoSetStatusPaths(&info) < 0) { \
+            VIR_TEST_DEBUG("Failed to generate status test data for '%s'", _name); \
             return -1; \
         } \
 \
-        if (virTestRun("QEMU status XML-2-XML " name, \
+        if (virTestRun("QEMU status XML-2-XML " _name, \
                        testCompareStatusXMLToXMLFiles, &info) < 0) \
             ret = -1; \
 \