mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +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 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 {
|
struct testInfo {
|
||||||
const char *name;
|
const char *name;
|
||||||
bool different;
|
bool different;
|
||||||
@ -55,8 +30,9 @@ testCompareXMLToXMLHelper(const void *data)
|
|||||||
abs_srcdir, info->name) < 0)
|
abs_srcdir, info->name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = testCompareXMLToXMLFiles(xml_in,
|
ret = testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, xml_in,
|
||||||
info->different ? xml_out : xml_in);
|
info->different ? xml_out : xml_in,
|
||||||
|
false);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(xml_in);
|
VIR_FREE(xml_in);
|
||||||
|
@ -22,35 +22,6 @@
|
|||||||
static virCapsPtr caps;
|
static virCapsPtr caps;
|
||||||
static virDomainXMLOptionPtr xmlopt;
|
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 {
|
struct testInfo {
|
||||||
const char *name;
|
const char *name;
|
||||||
int different;
|
int different;
|
||||||
@ -71,24 +42,9 @@ testCompareXMLToXMLHelper(const void *data)
|
|||||||
abs_srcdir, info->name) < 0)
|
abs_srcdir, info->name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (info->different) {
|
ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in,
|
||||||
if (testCompareXMLToXMLFiles(xml_in, xml_out, false) < 0)
|
info->different ? xml_out : xml_in,
|
||||||
goto cleanup;
|
!info->inactive_only);
|
||||||
} 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;
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(xml_in);
|
VIR_FREE(xml_in);
|
||||||
VIR_FREE(xml_out);
|
VIR_FREE(xml_out);
|
||||||
|
@ -39,57 +39,13 @@ struct testInfo {
|
|||||||
char *outInactiveFile;
|
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
|
static int
|
||||||
testXML2XMLActive(const void *opaque)
|
testXML2XMLActive(const void *opaque)
|
||||||
{
|
{
|
||||||
const struct testInfo *info = opaque;
|
const struct testInfo *info = opaque;
|
||||||
|
|
||||||
return testXML2XMLHelper(info->inName,
|
return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt,
|
||||||
info->inFile,
|
info->inName, info->outActiveName, true);
|
||||||
info->outActiveName,
|
|
||||||
info->outActiveFile,
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,11 +54,8 @@ testXML2XMLInactive(const void *opaque)
|
|||||||
{
|
{
|
||||||
const struct testInfo *info = opaque;
|
const struct testInfo *info = opaque;
|
||||||
|
|
||||||
return testXML2XMLHelper(info->inName,
|
return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName,
|
||||||
info->inFile,
|
info->outInactiveName, false);
|
||||||
info->outInactiveName,
|
|
||||||
info->outInactiveFile,
|
|
||||||
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 int virtTestCounter;
|
||||||
static char virtTestCounterStr[128];
|
static char virtTestCounterStr[128];
|
||||||
static char *virtTestCounterPrefixEndOffset;
|
static char *virtTestCounterPrefixEndOffset;
|
||||||
|
@ -137,4 +137,10 @@ int virtTestMain(int argc,
|
|||||||
virCapsPtr virTestGenericCapsInit(void);
|
virCapsPtr virTestGenericCapsInit(void);
|
||||||
virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
|
virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
|
||||||
|
|
||||||
|
int testCompareDomXML2XMLFiles(virCapsPtr caps,
|
||||||
|
virDomainXMLOptionPtr xmlopt,
|
||||||
|
const char *inxml,
|
||||||
|
const char *outfile,
|
||||||
|
bool live);
|
||||||
|
|
||||||
#endif /* __VIT_TEST_UTILS_H__ */
|
#endif /* __VIT_TEST_UTILS_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user