[PATCH 3/6] tests: Share domain XML2XML compare helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This creates a shared function in testutils.c that consolidates all
the slightly different implementations.
---
 tests/bhyvexml2xmltest.c | 30 +++-----------------------
 tests/lxcxml2xmltest.c   | 50 +++----------------------------------------
 tests/qemuxml2xmltest.c  | 55 ++++--------------------------------------------
 tests/testutils.c        | 34 ++++++++++++++++++++++++++++++
 tests/testutils.h        |  6 ++++++
 5 files changed, 50 insertions(+), 125 deletions(-)

diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c
index 826baea..d860a41 100644
--- a/tests/bhyvexml2xmltest.c
+++ b/tests/bhyvexml2xmltest.c
@@ -11,31 +11,6 @@
 
 static bhyveConn driver;
 
-static int
-testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
-{
-    char *actual = NULL;
-    virDomainDefPtr def = NULL;
-    int ret = -1;
-
-    if (!(def = virDomainDefParseFile(inxml, driver.caps, driver.xmlopt,
-                                      VIR_DOMAIN_DEF_PARSE_INACTIVE)))
-        goto fail;
-
-    if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE)))
-        goto fail;
-
-    if (virtTestCompareToFile(actual, outxml) < 0)
-        goto fail;
-
-    ret = 0;
-
- fail:
-    VIR_FREE(actual);
-    virDomainDefFree(def);
-    return ret;
-}
-
 struct testInfo {
     const char *name;
     bool different;
@@ -55,8 +30,9 @@ testCompareXMLToXMLHelper(const void *data)
                     abs_srcdir, info->name) < 0)
         goto cleanup;
 
-    ret = testCompareXMLToXMLFiles(xml_in,
-                                   info->different ? xml_out : xml_in);
+    ret = testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, xml_in,
+                                     info->different ? xml_out : xml_in,
+                                     false);
 
  cleanup:
     VIR_FREE(xml_in);
diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c
index 8d824b9..e460d0a 100644
--- a/tests/lxcxml2xmltest.c
+++ b/tests/lxcxml2xmltest.c
@@ -22,35 +22,6 @@
 static virCapsPtr caps;
 static virDomainXMLOptionPtr xmlopt;
 
-static int
-testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
-{
-    char *actual = NULL;
-    int ret = -1;
-    virDomainDefPtr def = NULL;
-
-    if (!(def = virDomainDefParseFile(inxml, caps, xmlopt,
-                                      live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE)))
-        goto fail;
-
-    if (!virDomainDefCheckABIStability(def, def)) {
-        fprintf(stderr, "ABI stability check failed on %s", inxml);
-        goto fail;
-    }
-
-    if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE)))
-        goto fail;
-
-    if (virtTestCompareToFile(actual, outxml) < 0)
-        goto fail;
-
-    ret = 0;
- fail:
-    VIR_FREE(actual);
-    virDomainDefFree(def);
-    return ret;
-}
-
 struct testInfo {
     const char *name;
     int different;
@@ -71,24 +42,9 @@ testCompareXMLToXMLHelper(const void *data)
                     abs_srcdir, info->name) < 0)
         goto cleanup;
 
-    if (info->different) {
-        if (testCompareXMLToXMLFiles(xml_in, xml_out, false) < 0)
-            goto cleanup;
-    } else {
-        if (testCompareXMLToXMLFiles(xml_in, xml_in, false) < 0)
-            goto cleanup;
-    }
-    if (!info->inactive_only) {
-        if (info->different) {
-            if (testCompareXMLToXMLFiles(xml_in, xml_out, true) < 0)
-                goto cleanup;
-        } else {
-            if (testCompareXMLToXMLFiles(xml_in, xml_in, true) < 0)
-                goto cleanup;
-        }
-    }
-
-    ret = 0;
+    ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in,
+                                     info->different ? xml_out : xml_in,
+                                     !info->inactive_only);
  cleanup:
     VIR_FREE(xml_in);
     VIR_FREE(xml_out);
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index d654182..312bb53 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -40,56 +40,12 @@ struct testInfo {
 };
 
 static int
-testXML2XMLHelper(const char *inxml,
-                  const char *inXmlData,
-                  const char *outxml,
-                  const char *outXmlData,
-                  bool live)
-{
-    char *actual = NULL;
-    int ret = -1;
-    virDomainDefPtr def = NULL;
-    unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE;
-    unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;
-    if (!live)
-        format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
-
-    if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt,
-                                        parse_flags)))
-        goto fail;
-
-    if (!virDomainDefCheckABIStability(def, def)) {
-        VIR_TEST_DEBUG("ABI stability check failed on %s", inxml);
-        goto fail;
-    }
-
-    if (!(actual = virDomainDefFormat(def, format_flags)))
-        goto fail;
-
-    if (STRNEQ(outXmlData, actual)) {
-        virtTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml);
-        goto fail;
-    }
-
-    ret = 0;
-
- fail:
-    VIR_FREE(actual);
-    virDomainDefFree(def);
-    return ret;
-}
-
-
-static int
 testXML2XMLActive(const void *opaque)
 {
     const struct testInfo *info = opaque;
 
-    return testXML2XMLHelper(info->inName,
-                             info->inFile,
-                             info->outActiveName,
-                             info->outActiveFile,
-                             true);
+    return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt,
+                                      info->inName, info->outActiveName, true);
 }
 
 
@@ -98,11 +54,8 @@ testXML2XMLInactive(const void *opaque)
 {
     const struct testInfo *info = opaque;
 
-    return testXML2XMLHelper(info->inName,
-                             info->inFile,
-                             info->outInactiveName,
-                             info->outInactiveFile,
-                             false);
+    return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName,
+                                      info->outInactiveName, false);
 }
 
 
diff --git a/tests/testutils.c b/tests/testutils.c
index 0091fcd..4ffea0c 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -1072,6 +1072,40 @@ virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void)
 }
 
 
+int
+testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt,
+                           const char *infile, const char *outfile, bool live)
+{
+    char *actual = NULL;
+    int ret = -1;
+    virDomainDefPtr def = NULL;
+    unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE;
+    unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;
+    if (!live)
+        format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
+
+    if (!(def = virDomainDefParseFile(infile, caps, xmlopt, parse_flags)))
+        goto fail;
+
+    if (!virDomainDefCheckABIStability(def, def)) {
+        VIR_TEST_DEBUG("ABI stability check failed on %s", infile);
+        goto fail;
+    }
+
+    if (!(actual = virDomainDefFormat(def, format_flags)))
+        goto fail;
+
+    if (virtTestCompareToFile(actual, outfile) < 0)
+        goto fail;
+
+    ret = 0;
+ fail:
+    VIR_FREE(actual);
+    virDomainDefFree(def);
+    return ret;
+}
+
+
 static int virtTestCounter;
 static char virtTestCounterStr[128];
 static char *virtTestCounterPrefixEndOffset;
diff --git a/tests/testutils.h b/tests/testutils.h
index 3bd9004..b1d7397 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -137,4 +137,10 @@ int virtTestMain(int argc,
 virCapsPtr virTestGenericCapsInit(void);
 virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
 
+int testCompareDomXML2XMLFiles(virCapsPtr caps,
+                               virDomainXMLOptionPtr xmlopt,
+                               const char *inxml,
+                               const char *outfile,
+                               bool live);
+
 #endif /* __VIT_TEST_UTILS_H__ */
-- 
2.5.0

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]