mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
tests: Share domain XML2XML compare helper
This creates a shared function in testutils.c that consolidates all the slightly different implementations.
This commit is contained in:
parent
ace4aecd5e
commit
5770c17074
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user