mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
tests: Add virtTestCompareToFile
Replaces a common pattern used in many test files
This commit is contained in:
parent
bdbe26b504
commit
ca32929908
@ -19,7 +19,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
const char *ldcmdline,
|
||||
const char *dmcmdline)
|
||||
{
|
||||
char *expectargv = NULL, *expectld = NULL, *expectdm = NULL;
|
||||
int len;
|
||||
char *actualargv = NULL, *actualld = NULL, *actualdm = NULL;
|
||||
virDomainDefPtr vmdef = NULL;
|
||||
@ -54,51 +53,23 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
if (!(actualld = virCommandToString(ldcmd)))
|
||||
goto out;
|
||||
|
||||
len = virtTestLoadFile(cmdline, &expectargv);
|
||||
if (len < 0)
|
||||
if (virtTestCompareToFile(actualargv, cmdline) < 0)
|
||||
goto out;
|
||||
|
||||
if (len && expectargv[len - 1] == '\n')
|
||||
expectargv[len - 1] = '\0';
|
||||
|
||||
len = virtTestLoadFile(ldcmdline, &expectld);
|
||||
if (len < 0)
|
||||
if (virtTestCompareToFile(actualld, ldcmdline) < 0)
|
||||
goto out;
|
||||
|
||||
if (len && expectld[len - 1] == '\n')
|
||||
expectld[len - 1] = '\0';
|
||||
if (virtTestCompareToFile(formatted, xml) < 0)
|
||||
goto out;
|
||||
|
||||
len = virFileReadAllQuiet(dmcmdline, 1000, &expectdm);
|
||||
if (len < 0) {
|
||||
if (actualdm != NULL) {
|
||||
virtTestDifference(stderr, "", actualdm);
|
||||
if (virFileExists(dmcmdline) || actualdm) {
|
||||
if (virtTestCompareToFile(actualdm, dmcmdline) < 0)
|
||||
goto out;
|
||||
}
|
||||
} else if (len && expectdm[len - 1] == '\n') {
|
||||
expectdm[len - 1] = '\0';
|
||||
}
|
||||
|
||||
if (STRNEQ(expectargv, actualargv)) {
|
||||
virtTestDifference(stderr, expectargv, actualargv);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (STRNEQ(expectld, actualld)) {
|
||||
virtTestDifference(stderr, expectld, actualld);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (expectdm && STRNEQ(expectdm, actualdm)) {
|
||||
virtTestDifference(stderr, expectdm, actualdm);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
VIR_FREE(expectargv);
|
||||
VIR_FREE(expectld);
|
||||
VIR_FREE(expectdm);
|
||||
VIR_FREE(actualargv);
|
||||
VIR_FREE(actualld);
|
||||
VIR_FREE(actualdm);
|
||||
|
@ -14,14 +14,10 @@ static bhyveConn driver;
|
||||
static int
|
||||
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
|
||||
{
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
virDomainDefPtr def = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(def = virDomainDefParseFile(inxml, driver.caps, driver.xmlopt,
|
||||
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
||||
goto fail;
|
||||
@ -29,15 +25,12 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
|
||||
if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
virtTestDifference(stderr, outXmlData, actual);
|
||||
if (virtTestCompareToFile(actual, outxml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virDomainDefFree(def);
|
||||
return ret;
|
||||
|
@ -158,7 +158,6 @@ cpuTestCompareXML(const char *arch,
|
||||
bool updateCPU)
|
||||
{
|
||||
char *xml = NULL;
|
||||
char *expected = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
|
||||
@ -166,24 +165,16 @@ cpuTestCompareXML(const char *arch,
|
||||
abs_srcdir, arch, name) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(xml, &expected) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(actual = virCPUDefFormat(cpu, NULL, updateCPU)))
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(expected, actual)) {
|
||||
if (virTestGetVerbose())
|
||||
fprintf(stderr, "\nCompared to %s-%s.xml", arch, name);
|
||||
virtTestDifference(stderr, expected, actual);
|
||||
if (virtTestCompareToFile(actual, xml) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(xml);
|
||||
VIR_FREE(expected);
|
||||
VIR_FREE(actual);
|
||||
return ret;
|
||||
}
|
||||
|
@ -178,16 +178,12 @@ test_virDomainCapsFormat(const void *opaque)
|
||||
virDomainCapsPtr domCaps = NULL;
|
||||
char *path = NULL;
|
||||
char *domCapsXML = NULL;
|
||||
char *domCapsFromFile = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&path, "%s/domaincapsschemadata/domaincaps-%s.xml",
|
||||
abs_srcdir, data->filename) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virFileReadAll(path, 8192, &domCapsFromFile) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(domCaps = buildVirDomainCaps(data->emulatorbin, data->machine,
|
||||
data->arch, data->type,
|
||||
data->fillFunc, data->opaque)))
|
||||
@ -196,14 +192,11 @@ test_virDomainCapsFormat(const void *opaque)
|
||||
if (!(domCapsXML = virDomainCapsFormat(domCaps)))
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(domCapsFromFile, domCapsXML)) {
|
||||
virtTestDifference(stderr, domCapsFromFile, domCapsXML);
|
||||
if (virtTestCompareToFile(domCapsXML, path) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(domCapsFromFile);
|
||||
VIR_FREE(domCapsXML);
|
||||
VIR_FREE(path);
|
||||
virObjectUnref(domCaps);
|
||||
|
@ -25,14 +25,10 @@ static virDomainXMLOptionPtr xmlopt;
|
||||
static int
|
||||
testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
|
||||
{
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virDomainDefPtr def = NULL;
|
||||
|
||||
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(def = virDomainDefParseFile(inxml, caps, xmlopt,
|
||||
live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
||||
goto fail;
|
||||
@ -45,14 +41,11 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
|
||||
if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
virtTestDifference(stderr, outXmlData, actual);
|
||||
if (virtTestCompareToFile(actual, outxml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
fail:
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virDomainDefFree(def);
|
||||
return ret;
|
||||
|
@ -21,7 +21,6 @@
|
||||
static int
|
||||
testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps)
|
||||
{
|
||||
char *outConfData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virNetworkDefPtr dev = NULL;
|
||||
@ -30,9 +29,6 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr
|
||||
char *pidfile = NULL;
|
||||
dnsmasqContext *dctx = NULL;
|
||||
|
||||
if (virtTestLoadFile(outconf, &outConfData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(dev = virNetworkDefParseFile(inxml)))
|
||||
goto fail;
|
||||
|
||||
@ -49,15 +45,12 @@ testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr
|
||||
dctx, caps) < 0)
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outConfData, actual)) {
|
||||
virtTestDifference(stderr, outConfData, actual);
|
||||
if (virtTestCompareToFile(actual, outconf) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(outConfData);
|
||||
VIR_FREE(actual);
|
||||
VIR_FREE(pidfile);
|
||||
virCommandFree(cmd);
|
||||
|
@ -48,7 +48,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
const char *cmdline)
|
||||
{
|
||||
char *expectargv = NULL;
|
||||
int len;
|
||||
char *actualargv = NULL;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
virNetworkDefPtr def = NULL;
|
||||
@ -69,15 +68,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
virtTestClearCommandPath(actualargv);
|
||||
virCommandSetDryRun(NULL, NULL, NULL);
|
||||
|
||||
len = virtTestLoadFile(cmdline, &expectargv);
|
||||
if (len < 0)
|
||||
if (virtTestCompareToFile(actualargv, cmdline) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(expectargv, actualargv)) {
|
||||
virtTestDifference(stderr, expectargv, actualargv);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
|
@ -20,29 +20,22 @@ static int
|
||||
testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
|
||||
unsigned int flags)
|
||||
{
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virNetworkDefPtr dev = NULL;
|
||||
|
||||
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(dev = virNetworkDefParseFile(inxml)))
|
||||
goto fail;
|
||||
|
||||
if (!(actual = virNetworkDefFormat(dev, flags)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
virtTestDifference(stderr, outXmlData, actual);
|
||||
if (virtTestCompareToFile(actual, outxml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virNetworkDefFree(dev);
|
||||
return ret;
|
||||
|
@ -23,7 +23,6 @@ testCompareXMLToXMLFiles(const char *netxml, const char *updatexml,
|
||||
int parentIndex, bool expectFailure)
|
||||
{
|
||||
char *updateXmlData = NULL;
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virNetworkDefPtr def = NULL;
|
||||
@ -42,13 +41,8 @@ testCompareXMLToXMLFiles(const char *netxml, const char *updatexml,
|
||||
goto fail;
|
||||
|
||||
if (!expectFailure) {
|
||||
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
||||
if (virtTestCompareToFile(actual, outxml) < 0)
|
||||
goto error;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
virtTestDifference(stderr, outXmlData, actual);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
@ -65,7 +59,6 @@ testCompareXMLToXMLFiles(const char *netxml, const char *updatexml,
|
||||
}
|
||||
error:
|
||||
VIR_FREE(updateXmlData);
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virNetworkDefFree(def);
|
||||
return ret;
|
||||
|
@ -31,13 +31,9 @@ linuxTestCompareFiles(const char *cpuinfofile,
|
||||
{
|
||||
int ret = -1;
|
||||
char *actualData = NULL;
|
||||
char *expectData = NULL;
|
||||
virNodeInfo nodeinfo;
|
||||
FILE *cpuinfo;
|
||||
|
||||
if (virtTestLoadFile(outputfile, &expectData) < 0)
|
||||
goto fail;
|
||||
|
||||
cpuinfo = fopen(cpuinfofile, "r");
|
||||
if (!cpuinfo) {
|
||||
fprintf(stderr, "unable to open: %s : %s\n",
|
||||
@ -66,15 +62,12 @@ linuxTestCompareFiles(const char *cpuinfofile,
|
||||
nodeinfo.cores, nodeinfo.threads) < 0)
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(actualData, expectData)) {
|
||||
virtTestDifference(stderr, expectData, actualData);
|
||||
if (virtTestCompareToFile(actualData, outputfile) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(expectData);
|
||||
VIR_FREE(actualData);
|
||||
return ret;
|
||||
}
|
||||
@ -109,16 +102,12 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
|
||||
{
|
||||
int ret = -1;
|
||||
char *actualData = NULL;
|
||||
char *expectData = NULL;
|
||||
FILE *cpustat = NULL;
|
||||
virNodeCPUStatsPtr params = NULL;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i;
|
||||
int nparams = 0;
|
||||
|
||||
if (virtTestLoadFile(outfile, &expectData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(cpustat = fopen(cpustatfile, "r"))) {
|
||||
virReportSystemError(errno, "failed to open '%s': ", cpustatfile);
|
||||
goto fail;
|
||||
@ -150,17 +139,14 @@ linuxCPUStatsCompareFiles(const char *cpustatfile,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (STRNEQ(actualData, expectData)) {
|
||||
virtTestDifference(stderr, expectData, actualData);
|
||||
if (virtTestCompareToFile(actualData, outfile) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
virBufferFreeAndReset(&buf);
|
||||
VIR_FORCE_FCLOSE(cpustat);
|
||||
VIR_FREE(expectData);
|
||||
VIR_FREE(actualData);
|
||||
VIR_FREE(params);
|
||||
return ret;
|
||||
|
@ -372,8 +372,6 @@ static int testSetDefaultParameters(virNWFilterHashTablePtr vars)
|
||||
static int testCompareXMLToArgvFiles(const char *xml,
|
||||
const char *cmdline)
|
||||
{
|
||||
char *expectargv = NULL;
|
||||
int len;
|
||||
char *actualargv = NULL;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
virNWFilterHashTablePtr vars = virNWFilterHashTableCreate(0);
|
||||
@ -407,20 +405,13 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
|
||||
testRemoveCommonRules(actualargv);
|
||||
|
||||
len = virtTestLoadFile(cmdline, &expectargv);
|
||||
if (len < 0)
|
||||
if (virtTestCompareToFile(actualargv, cmdline) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(expectargv, actualargv)) {
|
||||
virtTestDifference(stderr, expectargv, actualargv);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virBufferFreeAndReset(&buf);
|
||||
VIR_FREE(expectargv);
|
||||
VIR_FREE(actualargv);
|
||||
virNWFilterInstReset(&inst);
|
||||
virNWFilterHashTableFree(vars);
|
||||
|
@ -23,14 +23,10 @@ static int
|
||||
testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
|
||||
bool expect_error)
|
||||
{
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virNWFilterDefPtr dev = NULL;
|
||||
|
||||
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
virResetLastError();
|
||||
|
||||
if (!(dev = virNWFilterDefParseFile(inxml))) {
|
||||
@ -44,16 +40,13 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
|
||||
if (!(actual = virNWFilterDefFormat(dev)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
virtTestDifference(stderr, outXmlData, actual);
|
||||
if (virtTestCompareToFile(actual, outxml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
done:
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virNWFilterDefFree(dev);
|
||||
return ret;
|
||||
|
@ -28,23 +28,6 @@
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
|
||||
static int
|
||||
testCompareXMLToXML(const char *inxmldata, const char *outxmldata)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
if (STRNEQ(outxmldata, inxmldata)) {
|
||||
virtTestDifference(stderr, outxmldata, inxmldata);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
typedef struct _testQemuData testQemuData;
|
||||
typedef testQemuData *testQemuDataPtr;
|
||||
struct _testQemuData {
|
||||
@ -139,7 +122,7 @@ testQemuCapsXML(const void *opaque)
|
||||
int ret = -1;
|
||||
const testQemuData *data = opaque;
|
||||
char *capsFile = NULL, *xmlFile = NULL;
|
||||
char *capsData = NULL, *xmlData = NULL;
|
||||
char *capsData = NULL;
|
||||
char *capsXml = NULL;
|
||||
virCapsPtr capsProvided = NULL;
|
||||
|
||||
@ -151,9 +134,6 @@ testQemuCapsXML(const void *opaque)
|
||||
abs_srcdir, data->base) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(xmlFile, &xmlData) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(capsFile, &capsData) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -164,14 +144,15 @@ testQemuCapsXML(const void *opaque)
|
||||
if (!capsXml)
|
||||
goto cleanup;
|
||||
|
||||
ret = testCompareXMLToXML(capsXml, xmlData);
|
||||
if (virtTestCompareToFile(capsXml, xmlFile) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(xmlFile);
|
||||
VIR_FREE(capsFile);
|
||||
VIR_FREE(capsXml);
|
||||
VIR_FREE(capsData);
|
||||
VIR_FREE(xmlData);
|
||||
virObjectUnref(capsProvided);
|
||||
return ret;
|
||||
}
|
||||
|
@ -2129,7 +2129,6 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
|
||||
char *jsonFile = NULL;
|
||||
char *dataFile = NULL;
|
||||
char *jsonStr = NULL;
|
||||
char *expected = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
|
||||
@ -2144,8 +2143,7 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
|
||||
abs_srcdir, data->name) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(jsonFile, &jsonStr) < 0 ||
|
||||
virtTestLoadFile(dataFile, &expected) < 0)
|
||||
if (virtTestLoadFile(jsonFile, &jsonStr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddItem(test, "qom-list",
|
||||
@ -2175,17 +2173,14 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
|
||||
if (!(actual = cpuDataFormat(cpuData)))
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(expected, actual)) {
|
||||
virtTestDifference(stderr, expected, actual);
|
||||
if (virtTestCompareToFile(actual, dataFile) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
VIR_FREE(jsonFile);
|
||||
VIR_FREE(dataFile);
|
||||
VIR_FREE(jsonStr);
|
||||
VIR_FREE(expected);
|
||||
VIR_FREE(actual);
|
||||
cpuDataFree(cpuData);
|
||||
qemuMonitorTestFree(test);
|
||||
|
@ -253,8 +253,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
int migrateFd,
|
||||
virQemuXML2ArgvTestFlags flags)
|
||||
{
|
||||
char *expectargv = NULL;
|
||||
int len;
|
||||
char *actualargv = NULL;
|
||||
int ret = -1;
|
||||
virDomainDefPtr vmdef = NULL;
|
||||
@ -373,16 +371,8 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
if (!(actualargv = virCommandToString(cmd)))
|
||||
goto out;
|
||||
|
||||
len = virtTestLoadFile(cmdline, &expectargv);
|
||||
if (len < 0)
|
||||
if (virtTestCompareToFile(actualargv, cmdline) < 0)
|
||||
goto out;
|
||||
if (len && expectargv[len - 1] == '\n')
|
||||
expectargv[len - 1] = '\0';
|
||||
|
||||
if (STRNEQ(expectargv, actualargv)) {
|
||||
virtTestDifference(stderr, expectargv, actualargv);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ok:
|
||||
if (!virtTestOOMActive() &&
|
||||
@ -395,7 +385,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
|
||||
out:
|
||||
VIR_FREE(log);
|
||||
VIR_FREE(expectargv);
|
||||
VIR_FREE(actualargv);
|
||||
virCommandFree(cmd);
|
||||
virDomainDefFree(vmdef);
|
||||
|
@ -34,8 +34,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
bool json,
|
||||
bool expectError)
|
||||
{
|
||||
char *expectargv = NULL;
|
||||
int len;
|
||||
char *actualargv = NULL;
|
||||
int ret = -1;
|
||||
virDomainDefPtr vmdef = NULL;
|
||||
@ -48,12 +46,6 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
if (!(conn = virGetConnect()))
|
||||
goto fail;
|
||||
|
||||
len = virtTestLoadFile(cmdline, &expectargv);
|
||||
if (len < 0)
|
||||
goto fail;
|
||||
if (len && expectargv[len - 1] == '\n')
|
||||
expectargv[len - 1] = '\0';
|
||||
|
||||
if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
|
||||
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
||||
goto fail;
|
||||
@ -144,17 +136,14 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
memmove(start_skip, end_skip, strlen(end_skip) + 1);
|
||||
}
|
||||
|
||||
if (STRNEQ(expectargv, actualargv)) {
|
||||
virtTestDifference(stderr, expectargv, actualargv);
|
||||
if (virtTestCompareToFile(actualargv, cmdline) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(log);
|
||||
VIR_FREE(emulator);
|
||||
VIR_FREE(expectargv);
|
||||
VIR_FREE(actualargv);
|
||||
virCommandFree(cmd);
|
||||
virDomainDefFree(vmdef);
|
||||
|
@ -11,29 +11,22 @@
|
||||
static int
|
||||
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
|
||||
{
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virSecretDefPtr secret = NULL;
|
||||
|
||||
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(secret = virSecretDefParseFile(inxml)))
|
||||
goto fail;
|
||||
|
||||
if (!(actual = virSecretDefFormat(secret)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
virtTestDifference(stderr, outXmlData, actual);
|
||||
if (virtTestCompareToFile(actual, outxml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virSecretDefFree(secret);
|
||||
return ret;
|
||||
|
@ -21,7 +21,6 @@ static virCapsPtr caps;
|
||||
static int
|
||||
testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
|
||||
{
|
||||
char *xmlData = NULL;
|
||||
char *sexprData = NULL;
|
||||
char *gotxml = NULL;
|
||||
int id;
|
||||
@ -36,9 +35,6 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
|
||||
conn = virGetConnect();
|
||||
if (!conn) goto fail;
|
||||
|
||||
if (virtTestLoadFile(xml, &xmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (virtTestLoadFile(sexpr, &sexprData) < 0)
|
||||
goto fail;
|
||||
|
||||
@ -68,15 +64,12 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
|
||||
if (!(gotxml = virDomainDefFormat(def, 0)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(xmlData, gotxml)) {
|
||||
virtTestDifference(stderr, xmlData, gotxml);
|
||||
if (virtTestCompareToFile(gotxml, xml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(xmlData);
|
||||
VIR_FREE(sexprData);
|
||||
VIR_FREE(gotxml);
|
||||
virDomainDefFree(def);
|
||||
|
@ -19,29 +19,22 @@
|
||||
static int
|
||||
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
|
||||
{
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virStoragePoolDefPtr dev = NULL;
|
||||
|
||||
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(dev = virStoragePoolDefParseFile(inxml)))
|
||||
goto fail;
|
||||
|
||||
if (!(actual = virStoragePoolDefFormat(dev)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
virtTestDifference(stderr, outXmlData, actual);
|
||||
if (virtTestCompareToFile(actual, outxml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virStoragePoolDefFree(dev);
|
||||
return ret;
|
||||
|
@ -43,12 +43,9 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||
int imgformat,
|
||||
unsigned long parse_flags)
|
||||
{
|
||||
char *expectedCmdline = NULL;
|
||||
char *actualCmdline = NULL;
|
||||
int ret = -1;
|
||||
|
||||
int len;
|
||||
|
||||
virCommandPtr cmd = NULL;
|
||||
virConnectPtr conn;
|
||||
|
||||
@ -98,16 +95,8 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||
if (!(actualCmdline = virCommandToString(cmd)))
|
||||
goto cleanup;
|
||||
|
||||
len = virtTestLoadFile(cmdline, &expectedCmdline);
|
||||
if (len < 0)
|
||||
if (virtTestCompareToFile(actualCmdline, cmdline) < 0)
|
||||
goto cleanup;
|
||||
if (len && expectedCmdline[len-1] == '\n')
|
||||
expectedCmdline[len-1] = '\0';
|
||||
|
||||
if (STRNEQ_NULLABLE(expectedCmdline, actualCmdline)) {
|
||||
virtTestDifference(stderr, expectedCmdline, actualCmdline);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
@ -118,7 +107,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||
virStorageVolDefFree(inputvol);
|
||||
virCommandFree(cmd);
|
||||
VIR_FREE(actualCmdline);
|
||||
VIR_FREE(expectedCmdline);
|
||||
virObjectUnref(conn);
|
||||
return ret;
|
||||
}
|
||||
|
@ -20,15 +20,11 @@ static int
|
||||
testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
|
||||
const char *outxml, unsigned int flags)
|
||||
{
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virStoragePoolDefPtr pool = NULL;
|
||||
virStorageVolDefPtr dev = NULL;
|
||||
|
||||
if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(pool = virStoragePoolDefParseFile(poolxml)))
|
||||
goto fail;
|
||||
|
||||
@ -38,15 +34,12 @@ testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
|
||||
if (!(actual = virStorageVolDefFormat(pool, dev)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(outXmlData, actual)) {
|
||||
virtTestDifference(stderr, outXmlData, actual);
|
||||
if (virtTestCompareToFile(actual, outxml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virStoragePoolDefFree(pool);
|
||||
virStorageVolDefFree(dev);
|
||||
|
@ -62,7 +62,6 @@ static int
|
||||
testSysinfo(const void *data)
|
||||
{
|
||||
int result = -1;
|
||||
char *sysfsExpectData = NULL;
|
||||
const char *sysfsActualData;
|
||||
virSysinfoDefPtr ret = NULL;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
@ -71,10 +70,8 @@ testSysinfo(const void *data)
|
||||
virSysinfoSetup(testdata->decoder, testdata->sysinfo, testdata->cpuinfo);
|
||||
|
||||
if (!testdata->expected ||
|
||||
virtTestLoadFile(testdata->expected, &sysfsExpectData) < 0 ||
|
||||
!(ret = virSysinfoRead())) {
|
||||
!(ret = virSysinfoRead()))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virSysinfoFormat(&buf, ret) < 0)
|
||||
goto cleanup;
|
||||
@ -82,15 +79,12 @@ testSysinfo(const void *data)
|
||||
if (!(sysfsActualData = virBufferCurrentContent(&buf)))
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(sysfsActualData, sysfsExpectData)) {
|
||||
virtTestDifference(stderr, sysfsExpectData, sysfsActualData);
|
||||
if (virtTestCompareToFile(sysfsActualData, testdata->expected) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(sysfsExpectData);
|
||||
virSysinfoDefFree(ret);
|
||||
virBufferFreeAndReset(&buf);
|
||||
|
||||
|
@ -596,6 +596,39 @@ int virtTestDifferenceBin(FILE *stream,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* @param strcontent: String input content
|
||||
* @param filename: File to compare strcontent against
|
||||
*/
|
||||
int
|
||||
virtTestCompareToFile(const char *strcontent,
|
||||
const char *filename)
|
||||
{
|
||||
int ret = -1;
|
||||
char *filecontent = NULL;
|
||||
char *fixedcontent = NULL;
|
||||
|
||||
if (virtTestLoadFile(filename, &filecontent) < 0)
|
||||
goto failure;
|
||||
|
||||
if (filecontent[strlen(filecontent) - 1] == '\n' &&
|
||||
strcontent[strlen(strcontent) - 1] != '\n') {
|
||||
if (virAsprintf(&fixedcontent, "%s\n", strcontent) < 0)
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (STRNEQ(fixedcontent ? fixedcontent : strcontent, filecontent)) {
|
||||
virtTestDifference(stderr, strcontent, filecontent);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
failure:
|
||||
VIR_FREE(fixedcontent);
|
||||
VIR_FREE(filecontent);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
virtTestErrorFuncQuiet(void *data ATTRIBUTE_UNUSED,
|
||||
virErrorPtr err ATTRIBUTE_UNUSED)
|
||||
|
@ -73,6 +73,8 @@ int virtTestDifferenceBin(FILE *stream,
|
||||
const char *expect,
|
||||
const char *actual,
|
||||
size_t length);
|
||||
int virtTestCompareToFile(const char *strcontent,
|
||||
const char *filename);
|
||||
|
||||
unsigned int virTestGetDebug(void);
|
||||
unsigned int virTestGetVerbose(void);
|
||||
|
@ -106,7 +106,6 @@ test_virCapabilitiesFormat(const void *opaque)
|
||||
struct virCapabilitiesFormatData *data = (struct virCapabilitiesFormatData *) opaque;
|
||||
virCapsPtr caps = NULL;
|
||||
char *capsXML = NULL;
|
||||
char *capsFromFile = NULL;
|
||||
char *path = NULL;
|
||||
int ret = -1;
|
||||
|
||||
@ -121,20 +120,13 @@ test_virCapabilitiesFormat(const void *opaque)
|
||||
abs_srcdir, data->filename) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virFileReadAll(path, 8192, &capsFromFile) < 0)
|
||||
if (virtTestCompareToFile(capsXML, path) < 0)
|
||||
goto cleanup;
|
||||
|
||||
|
||||
if (STRNEQ(capsXML, capsFromFile)) {
|
||||
virtTestDifference(stderr, capsFromFile, capsXML);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(path);
|
||||
VIR_FREE(capsFromFile);
|
||||
VIR_FREE(capsXML);
|
||||
virObjectUnref(caps);
|
||||
return ret;
|
||||
|
@ -166,7 +166,6 @@ testCgroupDetectMounts(const void *args)
|
||||
const char *file = args;
|
||||
char *mounts = NULL;
|
||||
char *parsed = NULL;
|
||||
char *expected = NULL;
|
||||
const char *actual;
|
||||
virCgroupPtr group = NULL;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
@ -182,9 +181,6 @@ testCgroupDetectMounts(const void *args)
|
||||
if (virCgroupDetectMountsFromFile(group, mounts, false) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(parsed, &expected) < 0)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
||||
virBufferAsprintf(&buf, "%-12s %s\n",
|
||||
virCgroupControllerTypeToString(i),
|
||||
@ -194,17 +190,14 @@ testCgroupDetectMounts(const void *args)
|
||||
goto cleanup;
|
||||
|
||||
actual = virBufferCurrentContent(&buf);
|
||||
if (STRNEQ(expected, actual)) {
|
||||
virtTestDifference(stderr, expected, actual);
|
||||
if (virtTestCompareToFile(actual, parsed) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(mounts);
|
||||
VIR_FREE(parsed);
|
||||
VIR_FREE(expected);
|
||||
virCgroupFree(&group);
|
||||
virBufferFreeAndReset(&buf);
|
||||
return result;
|
||||
|
@ -72,16 +72,12 @@ testCompareFiles(const char *vmx, const char *xml)
|
||||
{
|
||||
int ret = -1;
|
||||
char *vmxData = NULL;
|
||||
char *xmlData = NULL;
|
||||
char *formatted = NULL;
|
||||
virDomainDefPtr def = NULL;
|
||||
|
||||
if (virtTestLoadFile(vmx, &vmxData) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(xml, &xmlData) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(def = virVMXParseConfig(&ctx, xmlopt, vmxData)))
|
||||
goto cleanup;
|
||||
|
||||
@ -93,16 +89,13 @@ testCompareFiles(const char *vmx, const char *xml)
|
||||
if (!(formatted = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
||||
goto cleanup;
|
||||
|
||||
if (STRNEQ(xmlData, formatted)) {
|
||||
virtTestDifference(stderr, xmlData, formatted);
|
||||
if (virtTestCompareToFile(formatted, xml) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(vmxData);
|
||||
VIR_FREE(xmlData);
|
||||
VIR_FREE(formatted);
|
||||
virDomainDefFree(def);
|
||||
|
||||
|
@ -18,7 +18,6 @@ static int
|
||||
testCompareFiles(virArch hostmachine, const char *xml_rel,
|
||||
const char *cpuinfo_rel, const char *capabilities_rel)
|
||||
{
|
||||
char *expectxml = NULL;
|
||||
char *actualxml = NULL;
|
||||
FILE *fp1 = NULL, *fp2 = NULL;
|
||||
virCapsPtr caps = NULL;
|
||||
@ -34,9 +33,6 @@ testCompareFiles(virArch hostmachine, const char *xml_rel,
|
||||
virAsprintf(&capabilities, "%s/%s", abs_srcdir, capabilities_rel) < 0)
|
||||
goto fail;
|
||||
|
||||
if (virtTestLoadFile(xml, &expectxml) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(fp1 = fopen(cpuinfo, "r")))
|
||||
goto fail;
|
||||
|
||||
@ -49,15 +45,12 @@ testCompareFiles(virArch hostmachine, const char *xml_rel,
|
||||
if (!(actualxml = virCapabilitiesFormatXML(caps)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(expectxml, actualxml)) {
|
||||
virtTestDifference(stderr, expectxml, actualxml);
|
||||
if (virtTestCompareToFile(actualxml, xml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(expectxml);
|
||||
VIR_FREE(actualxml);
|
||||
VIR_FREE(xml);
|
||||
VIR_FREE(cpuinfo);
|
||||
|
@ -48,7 +48,6 @@ static virDomainXMLOptionPtr xmlopt;
|
||||
static int
|
||||
testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
{
|
||||
char *xmcfgData = NULL;
|
||||
char *gotxmcfgData = NULL;
|
||||
virConfPtr conf = NULL;
|
||||
virConnectPtr conn = NULL;
|
||||
@ -62,9 +61,6 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
conn = virGetConnect();
|
||||
if (!conn) goto fail;
|
||||
|
||||
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(def = virDomainDefParseFile(xml, caps, xmlopt,
|
||||
VIR_DOMAIN_XML_INACTIVE)))
|
||||
goto fail;
|
||||
@ -81,15 +77,12 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
goto fail;
|
||||
gotxmcfgData[wrote] = '\0';
|
||||
|
||||
if (STRNEQ(xmcfgData, gotxmcfgData)) {
|
||||
virtTestDifference(stderr, xmcfgData, gotxmcfgData);
|
||||
if (virtTestCompareToFile(gotxmcfgData, xmcfg) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(xmcfgData);
|
||||
VIR_FREE(gotxmcfgData);
|
||||
if (conf)
|
||||
virConfFree(conf);
|
||||
@ -104,7 +97,6 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
static int
|
||||
testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
{
|
||||
char *xmlData = NULL;
|
||||
char *xmcfgData = NULL;
|
||||
char *gotxml = NULL;
|
||||
virConfPtr conf = NULL;
|
||||
@ -115,9 +107,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
conn = virGetConnect();
|
||||
if (!conn) goto fail;
|
||||
|
||||
if (virtTestLoadFile(xml, &xmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
|
||||
goto fail;
|
||||
|
||||
@ -131,17 +120,14 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
VIR_DOMAIN_XML_SECURE)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(xmlData, gotxml)) {
|
||||
virtTestDifference(stderr, xmlData, gotxml);
|
||||
if (virtTestCompareToFile(gotxml, xml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
if (conf)
|
||||
virConfFree(conf);
|
||||
VIR_FREE(xmlData);
|
||||
VIR_FREE(xmcfgData);
|
||||
VIR_FREE(gotxml);
|
||||
virDomainDefFree(def);
|
||||
|
@ -45,7 +45,6 @@ static virDomainXMLOptionPtr xmlopt;
|
||||
static int
|
||||
testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
{
|
||||
char *xmcfgData = NULL;
|
||||
char *gotxmcfgData = NULL;
|
||||
virConfPtr conf = NULL;
|
||||
int ret = -1;
|
||||
@ -60,9 +59,6 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
conn = virGetConnect();
|
||||
if (!conn) goto fail;
|
||||
|
||||
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
|
||||
goto fail;
|
||||
|
||||
/* Many puppies died to bring you this code. */
|
||||
priv.xendConfigVersion = xendConfigVersion;
|
||||
priv.caps = caps;
|
||||
@ -84,15 +80,12 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
goto fail;
|
||||
gotxmcfgData[wrote] = '\0';
|
||||
|
||||
if (STRNEQ(xmcfgData, gotxmcfgData)) {
|
||||
virtTestDifference(stderr, xmcfgData, gotxmcfgData);
|
||||
if (virtTestCompareToFile(gotxmcfgData, xmcfg) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(xmcfgData);
|
||||
VIR_FREE(gotxmcfgData);
|
||||
if (conf)
|
||||
virConfFree(conf);
|
||||
@ -105,7 +98,6 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
static int
|
||||
testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
{
|
||||
char *xmlData = NULL;
|
||||
char *xmcfgData = NULL;
|
||||
char *gotxml = NULL;
|
||||
virConfPtr conf = NULL;
|
||||
@ -117,9 +109,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
conn = virGetConnect();
|
||||
if (!conn) goto fail;
|
||||
|
||||
if (virtTestLoadFile(xml, &xmlData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
|
||||
goto fail;
|
||||
|
||||
@ -137,17 +126,14 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(xmlData, gotxml)) {
|
||||
virtTestDifference(stderr, xmlData, gotxml);
|
||||
if (virtTestCompareToFile(gotxml, xml) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
if (conf)
|
||||
virConfFree(conf);
|
||||
VIR_FREE(xmlData);
|
||||
VIR_FREE(xmcfgData);
|
||||
VIR_FREE(gotxml);
|
||||
virDomainDefFree(def);
|
||||
|
@ -23,14 +23,10 @@ static virDomainXMLOptionPtr xmlopt;
|
||||
static int
|
||||
testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
|
||||
{
|
||||
char *sexprData = NULL;
|
||||
char *gotsexpr = NULL;
|
||||
int ret = -1;
|
||||
virDomainDefPtr def = NULL;
|
||||
|
||||
if (virtTestLoadFile(sexpr, &sexprData) < 0)
|
||||
goto fail;
|
||||
|
||||
if (!(def = virDomainDefParseFile(xml, caps, xmlopt,
|
||||
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
||||
goto fail;
|
||||
@ -43,15 +39,12 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
|
||||
if (!(gotsexpr = xenFormatSxpr(NULL, def, xendConfigVersion)))
|
||||
goto fail;
|
||||
|
||||
if (STRNEQ(sexprData, gotsexpr)) {
|
||||
virtTestDifference(stderr, sexprData, gotsexpr);
|
||||
if (virtTestCompareToFile(gotsexpr, sexpr) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
VIR_FREE(sexprData);
|
||||
VIR_FREE(gotsexpr);
|
||||
virDomainDefFree(def);
|
||||
|
||||
|
@ -73,13 +73,9 @@ static int
|
||||
testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
|
||||
{
|
||||
int result = -1;
|
||||
char *vmxData = NULL;
|
||||
char *formatted = NULL;
|
||||
virDomainDefPtr def = NULL;
|
||||
|
||||
if (virtTestLoadFile(vmx, &vmxData) < 0)
|
||||
goto failure;
|
||||
|
||||
def = virDomainDefParseFile(xml, caps, xmlopt,
|
||||
VIR_DOMAIN_DEF_PARSE_INACTIVE);
|
||||
|
||||
@ -92,19 +88,15 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
|
||||
}
|
||||
|
||||
formatted = virVMXFormatConfig(&ctx, xmlopt, def, virtualHW_version);
|
||||
|
||||
if (formatted == NULL)
|
||||
goto failure;
|
||||
|
||||
if (STRNEQ(vmxData, formatted)) {
|
||||
virtTestDifference(stderr, vmxData, formatted);
|
||||
if (virtTestCompareToFile(formatted, vmx) < 0)
|
||||
goto failure;
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
failure:
|
||||
VIR_FREE(vmxData);
|
||||
VIR_FREE(formatted);
|
||||
virDomainDefFree(def);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user