[03/12] tests: qemuxml2xml: Remove info->outActiveName

Message ID 6451264a9031a9fd8182a0a4459166bcfb54125a.1554137098.git.crobinso@redhat.com
State New
Headers show
Series
  • tests: qemuxml2xml: add DO_TEST_CAPS*
Related show

Commit Message

Cole Robinson April 1, 2019, 4:47 p.m.
Reuse info->outfile for it. This requires us to set paths before
each virTestRun invocation

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

---
 tests/qemuxml2xmltest.c | 61 +++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 36 deletions(-)

-- 
2.21.0

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

Comments

Andrea Bolognani April 10, 2019, 3:50 p.m. | #1
On Mon, 2019-04-01 at 12:47 -0400, Cole Robinson wrote:
[...]
> @@ -40,8 +39,7 @@ testXML2XMLActive(const void *opaque)

>      const struct testInfo *info = opaque;

>  

>      return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt,

> -                                      info->infile, info->outfile, true,

> -                                      0,

> +                                      info->infile, info->outfile, true, 0,

>                                        TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS);


Unrelated formatting change. Squash this hunk into the previous
commit.

[...]
> @@ -134,40 +130,26 @@ testInfoSetPaths(struct testInfo *info,

>                   const char *name,

>                   int when)

>  {

> +    VIR_FREE(info->infile);

> +    VIR_FREE(info->outfile);


It's a tad wasteful to free() info->infile just to generate an
identical string immediately afterwards, but in the grand scheme of
things I guess it's barely even a rounding error :)

With the comment above addressed,

  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 0ced565fbc..538ccae8fd 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -28,7 +28,6 @@  enum {
 struct testInfo {
     char *infile;
     char *outfile;
-    char *outInactiveName;
 
     virQEMUCapsPtr qemuCaps;
 };
@@ -40,8 +39,7 @@  testXML2XMLActive(const void *opaque)
     const struct testInfo *info = opaque;
 
     return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt,
-                                      info->infile, info->outfile, true,
-                                      0,
+                                      info->infile, info->outfile, true, 0,
                                       TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS);
 }
 
@@ -51,9 +49,8 @@  testXML2XMLInactive(const void *opaque)
 {
     const struct testInfo *info = opaque;
 
-    return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->infile,
-                                      info->outInactiveName, false,
-                                      0,
+    return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt,
+                                      info->infile, info->outfile, false, 0,
                                       TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS);
 }
 
@@ -103,7 +100,6 @@  testInfoClear(struct testInfo *info)
 {
     VIR_FREE(info->infile);
     VIR_FREE(info->outfile);
-    VIR_FREE(info->outInactiveName);
 
     virObjectUnref(info->qemuCaps);
 }
@@ -134,40 +130,26 @@  testInfoSetPaths(struct testInfo *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)
         goto error;
 
-    if (when & WHEN_INACTIVE) {
-        if (virAsprintf(&info->outInactiveName,
-                        "%s/qemuxml2xmloutdata/%s-inactive.xml",
-                        abs_srcdir, name) < 0)
-            goto error;
-
-        if (!virFileExists(info->outInactiveName)) {
-            VIR_FREE(info->outInactiveName);
+    if (virAsprintf(&info->outfile,
+                    "%s/qemuxml2xmloutdata/%s-%s.xml",
+                    abs_srcdir, name,
+                    when == WHEN_ACTIVE ? "active" : "inactive") < 0)
+        goto error;
 
-            if (virAsprintf(&info->outInactiveName,
-                            "%s/qemuxml2xmloutdata/%s.xml",
-                            abs_srcdir, name) < 0)
-                goto error;
-        }
-    }
+    if (!virFileExists(info->outfile)) {
+        VIR_FREE(info->outfile);
 
-    if (when & WHEN_ACTIVE) {
         if (virAsprintf(&info->outfile,
-                        "%s/qemuxml2xmloutdata/%s-active.xml",
+                        "%s/qemuxml2xmloutdata/%s.xml",
                         abs_srcdir, name) < 0)
             goto error;
-
-        if (!virFileExists(info->outfile)) {
-            VIR_FREE(info->outfile);
-
-            if (virAsprintf(&info->outfile,
-                            "%s/qemuxml2xmloutdata/%s.xml",
-                            abs_srcdir, name) < 0)
-                goto error;
-        }
     }
 
     return 0;
@@ -227,20 +209,27 @@  mymain(void)
 
 # define DO_TEST_FULL(name, when, gic, ...) \
     do { \
-        if (testInfoSetCommon(&info, gic) < 0 || \
-            testInfoSetPaths(&info, name, when) < 0) { \
+        if (testInfoSetCommon(&info, gic) < 0) { \
             VIR_TEST_DEBUG("Failed to generate test data for '%s'", name); \
             return -1; \
         } \
         virQEMUCapsSetList(info.qemuCaps, __VA_ARGS__, QEMU_CAPS_LAST); \
  \
-        if (info.outInactiveName) { \
+        if (when & WHEN_INACTIVE) { \
+            if (testInfoSetPaths(&info, name, WHEN_INACTIVE) < 0) { \
+                VIR_TEST_DEBUG("Failed to generate inactive paths for '%s'", name); \
+                return -1; \
+            } \
             if (virTestRun("QEMU XML-2-XML-inactive " name, \
                             testXML2XMLInactive, &info) < 0) \
                 ret = -1; \
         } \
  \
-        if (info.outfile) { \
+        if (when & WHEN_ACTIVE) { \
+            if (testInfoSetPaths(&info, name, WHEN_ACTIVE) < 0) { \
+                VIR_TEST_DEBUG("Failed to generate active paths for '%s'", name); \
+                return -1; \
+            } \
             if (virTestRun("QEMU XML-2-XML-active " name, \
                             testXML2XMLActive, &info) < 0) \
                 ret = -1; \