diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index 826baea4031e093bdfb23f569df13819775b2b12..d860a41dd31f131efcc4d28c5ba44b37cb15b65f 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 8d824b9bcf2dbfc1fa6f39a49e5eeb21246b286c..e460d0af21d238e137a13df4b376e64e15297250 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 d65418265f201892f62cd307cb30b5fd118d6b52..312bb53eacdc1e633d7a966f092ad0864d5e62d0 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -39,57 +39,13 @@ struct testInfo { char *outInactiveFile; }; -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 0091fcd432a761c42aadb98672527d6905b29131..4ffea0c4ad9386471437b961b4d97f49ffd793ab 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 3bd90044a873a1c38a1a4463b1b98edae380b586..b1d7397c8aac01352ebcfab2aa6f5c56649c2849 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__ */