[libvirt] [PATCH 5/8] tests: Add failure flags to CompareDomainXML2XML

Cole Robinson crobinso at redhat.com
Tue Mar 8 16:36:36 UTC 2016


Will be used in future patches
---
 tests/bhyvexml2xmltest.c   |  2 +-
 tests/genericxml2xmltest.c |  2 +-
 tests/lxcxml2xmltest.c     |  2 +-
 tests/qemuxml2xmltest.c    |  5 +++--
 tests/testutils.c          | 10 ++++++++--
 tests/testutils.h          |  4 ++++
 6 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c
index 8f556ee..87bc39c 100644
--- a/tests/bhyvexml2xmltest.c
+++ b/tests/bhyvexml2xmltest.c
@@ -32,7 +32,7 @@ testCompareXMLToXMLHelper(const void *data)
 
     ret = testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, xml_in,
                                      info->different ? xml_out : xml_in,
-                                     false,
+                                     false, 0,
                                      NULL, NULL, 0);
 
  cleanup:
diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c
index bf9b11d..666fc86 100644
--- a/tests/genericxml2xmltest.c
+++ b/tests/genericxml2xmltest.c
@@ -39,7 +39,7 @@ testCompareXMLToXMLHelper(const void *data)
 
     ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in,
                                      info->different ? xml_out : xml_in,
-                                     !info->inactive_only,
+                                     !info->inactive_only, 0,
                                      NULL, NULL, 0);
  cleanup:
     VIR_FREE(xml_in);
diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c
index 0b51340..c2140bc 100644
--- a/tests/lxcxml2xmltest.c
+++ b/tests/lxcxml2xmltest.c
@@ -45,7 +45,7 @@ testCompareXMLToXMLHelper(const void *data)
 
     ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in,
                                      info->different ? xml_out : xml_in,
-                                     !info->inactive_only,
+                                     !info->inactive_only, 0,
                                      NULL, NULL, info->parse_flags);
  cleanup:
     VIR_FREE(xml_in);
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 251effd..b3568df 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -52,7 +52,8 @@ testXML2XMLActive(const void *opaque)
     const struct testInfo *info = opaque;
 
     return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt,
-                                      info->inName, info->outActiveName, true,
+                                      info->inName, info->outActiveName,
+                                      true, 0,
                                       qemuXML2XMLPreFormatCallback, opaque, 0);
 }
 
@@ -63,7 +64,7 @@ testXML2XMLInactive(const void *opaque)
     const struct testInfo *info = opaque;
 
     return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName,
-                                      info->outInactiveName, false,
+                                      info->outInactiveName, false, 0,
                                       qemuXML2XMLPreFormatCallback, opaque, 0);
 }
 
diff --git a/tests/testutils.c b/tests/testutils.c
index b1bd4e8..ec1ee38 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -1052,7 +1052,8 @@ virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void)
 
 int
 testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt,
-                           const char *infile, const char *outfile, bool live,
+                           const char *infile, const char *outfile,
+                           bool live, testCompareDomXML2XMLFlags flags,
                            testCompareDomXML2XMLPreFormatCallback cb,
                            const void *opaque, unsigned int parseFlags)
 {
@@ -1067,8 +1068,12 @@ testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt,
     if (!live)
         format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
 
-    if (!(def = virDomainDefParseFile(infile, caps, xmlopt, parse_flags)))
+    if (!(def = virDomainDefParseFile(infile, caps, xmlopt, parse_flags))) {
+        if (!virtTestOOMActive() &&
+            (flags & TEST_COMPARE_DOM_XML2XML_FLAG_EXPECT_PARSE_ERROR))
+            goto ok;
         goto fail;
+    }
 
     if (!virDomainDefCheckABIStability(def, def)) {
         VIR_TEST_DEBUG("ABI stability check failed on %s", infile);
@@ -1084,6 +1089,7 @@ testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt,
     if (virtTestCompareToFile(actual, outfile) < 0)
         goto fail;
 
+ ok:
     ret = 0;
  fail:
     VIR_FREE(actual);
diff --git a/tests/testutils.h b/tests/testutils.h
index 752fa52..a09fd58 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -134,6 +134,9 @@ int virtTestMain(int argc,
 virCapsPtr virTestGenericCapsInit(void);
 virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
 
+typedef enum {
+    TEST_COMPARE_DOM_XML2XML_FLAG_EXPECT_PARSE_ERROR = 1 << 0,
+} testCompareDomXML2XMLFlags;
 typedef int (*testCompareDomXML2XMLPreFormatCallback)(virDomainDefPtr def,
                                                       const void *opaque);
 int testCompareDomXML2XMLFiles(virCapsPtr caps,
@@ -141,6 +144,7 @@ int testCompareDomXML2XMLFiles(virCapsPtr caps,
                                const char *inxml,
                                const char *outfile,
                                bool live,
+                               testCompareDomXML2XMLFlags flags,
                                testCompareDomXML2XMLPreFormatCallback cb,
                                const void *opaque,
                                unsigned int parseFlags);
-- 
2.5.0




More information about the libvir-list mailing list