tests: Lower stack usage below 4096 bytes

Make virtTestLoadFile allocate the buffer to read the file into.

Fix logic error in virtTestLoadFile, stop reading on the first empty line.

Use virFileReadLimFD in virtTestCaptureProgramOutput to avoid manual
buffer handling.
This commit is contained in:
Matthias Bolte 2011-04-25 00:25:10 +02:00
parent 88823ec90a
commit 9ba4eb3c08
24 changed files with 590 additions and 437 deletions

View File

@ -88,12 +88,10 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
# that one off, so we need to manually enable this again # that one off, so we need to manually enable this again
gl_WARN_ADD([-Wjump-misses-init]) gl_WARN_ADD([-Wjump-misses-init])
# This should be < 256 really, but with PATH_MAX everywhere # This should be < 256 really. Currently we're down to 4096,
# we have doom, even with 4096. In fact we have some functions # but using 1024 bytes sized buffers (mostly for virStrerror)
# with several PATH_MAX sized variables :-( We should kill off # stops us from going down further
# all PATH_MAX usage and then lower this limit gl_WARN_ADD([-Wframe-larger-than=4096])
gl_WARN_ADD([-Wframe-larger-than=65700])
dnl gl_WARN_ADD([-Wframe-larger-than=4096])
dnl gl_WARN_ADD([-Wframe-larger-than=256]) dnl gl_WARN_ADD([-Wframe-larger-than=256])
# Extra special flags # Extra special flags

View File

@ -6,32 +6,43 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "conf.h" #include "conf.h"
#include "memory.h"
int main(int argc, char **argv) { int main(int argc, char **argv)
int ret; {
int ret, exit_code = EXIT_FAILURE;
virConfPtr conf; virConfPtr conf;
int len = 10000; int len = 10000;
char buffer[10000]; char *buffer = NULL;
if (argc != 2) { if (argc != 2) {
fprintf(stderr, "Usage: %s conf_file\n", argv[0]); fprintf(stderr, "Usage: %s conf_file\n", argv[0]);
exit(EXIT_FAILURE); goto cleanup;
} }
if (VIR_ALLOC_N(buffer, len) < 0) {
fprintf(stderr, "out of memory\n");
goto cleanup;
}
conf = virConfReadFile(argv[1], 0); conf = virConfReadFile(argv[1], 0);
if (conf == NULL) { if (conf == NULL) {
fprintf(stderr, "Failed to process %s\n", argv[1]); fprintf(stderr, "Failed to process %s\n", argv[1]);
exit(EXIT_FAILURE); goto cleanup;
} }
ret = virConfWriteMem(&buffer[0], &len, conf); ret = virConfWriteMem(buffer, &len, conf);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Failed to serialize %s back\n", argv[1]); fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
exit(EXIT_FAILURE); goto cleanup;
} }
virConfFree(conf); virConfFree(conf);
if (fwrite(buffer, 1, len, stdout) != len) { if (fwrite(buffer, 1, len, stdout) != len) {
fprintf(stderr, "Write failed: %s\n", strerror (errno)); fprintf(stderr, "Write failed: %s\n", strerror (errno));
exit(EXIT_FAILURE); goto cleanup;
} }
exit(EXIT_SUCCESS);
exit_code = EXIT_SUCCESS;
cleanup:
VIR_FREE(buffer);
return exit_code;
} }

View File

@ -42,7 +42,6 @@
static const char *abs_top_srcdir; static const char *abs_top_srcdir;
#define VIR_FROM_THIS VIR_FROM_CPU #define VIR_FROM_THIS VIR_FROM_CPU
#define MAX_FILE 4096
enum compResultShadow { enum compResultShadow {
ERROR = VIR_CPU_COMPARE_ERROR, ERROR = VIR_CPU_COMPARE_ERROR,
@ -89,14 +88,13 @@ struct data {
static virCPUDefPtr static virCPUDefPtr
cpuTestLoadXML(const char *arch, const char *name) cpuTestLoadXML(const char *arch, const char *name)
{ {
char xml[PATH_MAX]; char *xml = NULL;
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
snprintf(xml, PATH_MAX, if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
"%s/cputestdata/%s-%s.xml", goto cleanup;
abs_srcdir, arch, name);
if (!(doc = virXMLParseFile(xml)) || if (!(doc = virXMLParseFile(xml)) ||
!(ctxt = xmlXPathNewContext(doc))) !(ctxt = xmlXPathNewContext(doc)))
@ -108,6 +106,7 @@ cpuTestLoadXML(const char *arch, const char *name)
cleanup: cleanup:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
free(xml);
return cpu; return cpu;
} }
@ -117,7 +116,7 @@ cpuTestLoadMultiXML(const char *arch,
const char *name, const char *name,
unsigned int *count) unsigned int *count)
{ {
char xml[PATH_MAX]; char *xml = NULL;
xmlDocPtr doc = NULL; xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
@ -125,9 +124,8 @@ cpuTestLoadMultiXML(const char *arch,
int n; int n;
int i; int i;
snprintf(xml, PATH_MAX, if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
"%s/cputestdata/%s-%s.xml", goto cleanup;
abs_srcdir, arch, name);
if (!(doc = virXMLParseFile(xml)) || if (!(doc = virXMLParseFile(xml)) ||
!(ctxt = xmlXPathNewContext(doc))) !(ctxt = xmlXPathNewContext(doc)))
@ -149,6 +147,7 @@ cpuTestLoadMultiXML(const char *arch,
*count = n; *count = n;
cleanup: cleanup:
free(xml);
free(nodes); free(nodes);
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc); xmlFreeDoc(doc);
@ -170,17 +169,16 @@ cpuTestCompareXML(const char *arch,
const virCPUDefPtr cpu, const virCPUDefPtr cpu,
const char *name) const char *name)
{ {
char xml[PATH_MAX]; char *xml = NULL;
char expected[MAX_FILE]; char *expected = NULL;
char *expectedPtr = &(expected[0]);
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
snprintf(xml, PATH_MAX, if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
"%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
abs_srcdir, arch, name); goto cleanup;
if (virtTestLoadFile(xml, &expectedPtr, MAX_FILE) < 0) if (virtTestLoadFile(xml, &expected) < 0)
goto cleanup; goto cleanup;
if (!(actual = virCPUDefFormat(cpu, NULL, 0))) if (!(actual = virCPUDefFormat(cpu, NULL, 0)))
@ -194,6 +192,8 @@ cpuTestCompareXML(const char *arch,
ret = 0; ret = 0;
cleanup: cleanup:
free(xml);
free(expected);
free(actual); free(actual);
return ret; return ret;
} }
@ -333,7 +333,7 @@ cpuTestBaseline(const void *arg)
virCPUDefPtr *cpus = NULL; virCPUDefPtr *cpus = NULL;
virCPUDefPtr baseline = NULL; virCPUDefPtr baseline = NULL;
unsigned int ncpus = 0; unsigned int ncpus = 0;
char result[PATH_MAX]; char *result = NULL;
unsigned int i; unsigned int i;
if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus))) if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
@ -353,7 +353,9 @@ cpuTestBaseline(const void *arg)
if (!baseline) if (!baseline)
goto cleanup; goto cleanup;
snprintf(result, PATH_MAX, "%s-result", data->name); if (virAsprintf(&result, "%s-result", data->name) < 0)
goto cleanup;
if (cpuTestCompareXML(data->arch, baseline, result) < 0) if (cpuTestCompareXML(data->arch, baseline, result) < 0)
goto cleanup; goto cleanup;
@ -382,6 +384,7 @@ cleanup:
free(cpus); free(cpus);
} }
virCPUDefFree(baseline); virCPUDefFree(baseline);
free(result);
return ret; return ret;
} }
@ -393,7 +396,7 @@ cpuTestUpdate(const void *arg)
int ret = -1; int ret = -1;
virCPUDefPtr host = NULL; virCPUDefPtr host = NULL;
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
char result[PATH_MAX]; char *result = NULL;
if (!(host = cpuTestLoadXML(data->arch, data->host)) || if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
!(cpu = cpuTestLoadXML(data->arch, data->name))) !(cpu = cpuTestLoadXML(data->arch, data->name)))
@ -402,12 +405,15 @@ cpuTestUpdate(const void *arg)
if (cpuUpdate(cpu, host) < 0) if (cpuUpdate(cpu, host) < 0)
goto cleanup; goto cleanup;
snprintf(result, PATH_MAX, "%s+%s", data->host, data->name); if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
goto cleanup;
ret = cpuTestCompareXML(data->arch, cpu, result); ret = cpuTestCompareXML(data->arch, cpu, result);
cleanup: cleanup:
virCPUDefFree(host); virCPUDefFree(host);
virCPUDefFree(cpu); virCPUDefFree(cpu);
free(result);
return ret; return ret;
} }
@ -465,10 +471,10 @@ static int (*cpuTest[])(const void *) = {
static int static int
cpuTestRun(const char *name, const struct data *data) cpuTestRun(const char *name, const struct data *data)
{ {
char label[PATH_MAX]; char *label = NULL;
snprintf(label, PATH_MAX, "CPU %s(%s): %s", if (virAsprintf(&label, "CPU %s(%s): %s", apis[data->api], data->arch, name) < 0)
apis[data->api], data->arch, name); return -1;
free(virtTestLogContentAndReset()); free(virtTestLogContentAndReset());
@ -480,9 +486,12 @@ cpuTestRun(const char *name, const struct data *data)
fprintf(stderr, "\n%s\n", log); fprintf(stderr, "\n%s\n", log);
free(log); free(log);
} }
free(label);
return -1; return -1;
} }
free(label);
return 0; return 0;
} }
@ -495,15 +504,17 @@ static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char map[PATH_MAX]; char *map = NULL;
abs_top_srcdir = getenv("abs_top_srcdir"); abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir) if (!abs_top_srcdir)
abs_top_srcdir = ".."; abs_top_srcdir = "..";
snprintf(map, PATH_MAX, "%s/src/cpu/cpu_map.xml", abs_top_srcdir); if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
if (cpuMapOverride(map) < 0) cpuMapOverride(map) < 0) {
free(map);
return EXIT_FAILURE; return EXIT_FAILURE;
}
#define DO_TEST(arch, api, name, host, cpu, \ #define DO_TEST(arch, api, name, host, cpu, \
models, nmodels, preferred, result) \ models, nmodels, preferred, result) \
@ -613,6 +624,7 @@ mymain(void)
DO_TEST_GUESTDATA("x86", "host", "guest", models, "qemu64", 0); DO_TEST_GUESTDATA("x86", "host", "guest", models, "qemu64", 0);
DO_TEST_GUESTDATA("x86", "host", "guest", nomodel, NULL, -1); DO_TEST_GUESTDATA("x86", "host", "guest", nomodel, NULL, -1);
free(map);
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }

View File

@ -273,6 +273,7 @@ testEscapeDatastoreItem(const void *data ATTRIBUTE_UNUSED)
} }
} }
VIR_FREE(escaped);
return 0; return 0;
} }
@ -314,6 +315,7 @@ testConvertWindows1252ToUTF8(const void *data ATTRIBUTE_UNUSED)
} }
} }
VIR_FREE(utf8);
return 0; return 0;
} }

View File

@ -13,17 +13,16 @@
#include "interface_conf.h" #include "interface_conf.h"
#include "testutilsqemu.h" #include "testutilsqemu.h"
#define MAX_FILE 4096
static int
static int testCompareXMLToXMLFiles(const char *xml) { testCompareXMLToXMLFiles(const char *xml)
char xmlData[MAX_FILE]; {
char *xmlPtr = &(xmlData[0]); char *xmlData = NULL;
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virInterfaceDefPtr dev = NULL; virInterfaceDefPtr dev = NULL;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail; goto fail;
if (!(dev = virInterfaceDefParseString(xmlData))) if (!(dev = virInterfaceDefParseString(xmlData)))
@ -40,16 +39,26 @@ static int testCompareXMLToXMLFiles(const char *xml) {
ret = 0; ret = 0;
fail: fail:
free(xmlData);
free(actual); free(actual);
virInterfaceDefFree(dev); virInterfaceDefFree(dev);
return ret; return ret;
} }
static int testCompareXMLToXMLHelper(const void *data) { static int
char xml[PATH_MAX]; testCompareXMLToXMLHelper(const void *data)
snprintf(xml, PATH_MAX, "%s/interfaceschemadata/%s.xml", {
abs_srcdir, (const char*)data); int result = -1;
return testCompareXMLToXMLFiles(xml); char *xml = NULL;
if (virAsprintf(&xml, "%s/interfaceschemadata/%s.xml",
abs_srcdir, (const char*)data) < 0)
return -1;
result = testCompareXMLToXMLFiles(xml);
free (xml);
return result;
} }

View File

@ -13,21 +13,18 @@
#include "network_conf.h" #include "network_conf.h"
#include "testutilsqemu.h" #include "testutilsqemu.h"
#define MAX_FILE 4096 static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
{
static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { char *inXmlData = NULL;
char inXmlData[MAX_FILE]; char *outXmlData = NULL;
char *inXmlPtr = &(inXmlData[0]);
char outXmlData[MAX_FILE];
char *outXmlPtr = &(outXmlData[0]);
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virNetworkDefPtr dev = NULL; virNetworkDefPtr dev = NULL;
if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail; goto fail;
if (!(dev = virNetworkDefParseString(inXmlData))) if (!(dev = virNetworkDefParseString(inXmlData)))
@ -44,21 +41,35 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0; ret = 0;
fail: fail:
free(inXmlData);
free(outXmlData);
free(actual); free(actual);
virNetworkDefFree(dev); virNetworkDefFree(dev);
return ret; return ret;
} }
static int testCompareXMLToXMLHelper(const void *data) { static int
char inxml[PATH_MAX]; testCompareXMLToXMLHelper(const void *data)
char outxml[PATH_MAX]; {
snprintf(inxml, PATH_MAX, "%s/networkxml2xmlin/%s.xml", int result = -1;
abs_srcdir, (const char*)data); char *inxml = NULL;
snprintf(outxml, PATH_MAX, "%s/networkxml2xmlout/%s.xml", char *outxml = NULL;
abs_srcdir, (const char*)data);
return testCompareXMLToXMLFiles(inxml, outxml);
}
if (virAsprintf(&inxml, "%s/networkxml2xmlin/%s.xml",
abs_srcdir, (const char*)data) < 0 ||
virAsprintf(&outxml, "%s/networkxml2xmlout/%s.xml",
abs_srcdir, (const char*)data) < 0) {
goto cleanup;
}
result = testCompareXMLToXMLFiles(inxml, outxml);
cleanup:
free(inxml);
free(outxml);
return result;
}
static int static int
mymain(void) mymain(void)

View File

@ -13,17 +13,15 @@
#include "node_device_conf.h" #include "node_device_conf.h"
#include "testutilsqemu.h" #include "testutilsqemu.h"
#define MAX_FILE 4096 static int
testCompareXMLToXMLFiles(const char *xml)
{
static int testCompareXMLToXMLFiles(const char *xml) { char *xmlData = NULL;
char xmlData[MAX_FILE];
char *xmlPtr = &(xmlData[0]);
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virNodeDeviceDefPtr dev = NULL; virNodeDeviceDefPtr dev = NULL;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail; goto fail;
if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE))) if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE)))
@ -40,16 +38,26 @@ static int testCompareXMLToXMLFiles(const char *xml) {
ret = 0; ret = 0;
fail: fail:
free(xmlData);
free(actual); free(actual);
virNodeDeviceDefFree(dev); virNodeDeviceDefFree(dev);
return ret; return ret;
} }
static int testCompareXMLToXMLHelper(const void *data) { static int
char xml[PATH_MAX]; testCompareXMLToXMLHelper(const void *data)
snprintf(xml, PATH_MAX, "%s/nodedevschemadata/%s.xml", {
abs_srcdir, (const char*)data); int result = -1;
return testCompareXMLToXMLFiles(xml); char *xml = NULL;
if (virAsprintf(&xml, "%s/nodedevschemadata/%s.xml",
abs_srcdir, (const char*)data) < 0)
return -1;
result = testCompareXMLToXMLFiles(xml);
free(xml);
return result;
} }

View File

@ -21,24 +21,24 @@ mymain(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
#else #else
# define MAX_FILE 4096
extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, virNodeInfoPtr nodeinfo, extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, virNodeInfoPtr nodeinfo,
bool need_hyperthreads); bool need_hyperthreads);
static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) { static int
char actualData[MAX_FILE]; linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile)
char expectData[MAX_FILE]; {
char *expect = &expectData[0]; int ret = -1;
char *actualData = NULL;
char *expectData = NULL;
virNodeInfo nodeinfo; virNodeInfo nodeinfo;
FILE *cpuinfo; FILE *cpuinfo;
if (virtTestLoadFile(outputfile, &expect, MAX_FILE) < 0) if (virtTestLoadFile(outputfile, &expectData) < 0)
return -1; goto fail;
cpuinfo = fopen(cpuinfofile, "r"); cpuinfo = fopen(cpuinfofile, "r");
if (!cpuinfo) if (!cpuinfo)
return -1; goto fail;
memset(&nodeinfo, 0, sizeof(nodeinfo)); memset(&nodeinfo, 0, sizeof(nodeinfo));
if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo, false) < 0) { if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo, false) < 0) {
@ -49,7 +49,7 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
virFreeError(error); virFreeError(error);
} }
VIR_FORCE_FCLOSE(cpuinfo); VIR_FORCE_FCLOSE(cpuinfo);
return -1; goto fail;
} }
VIR_FORCE_FCLOSE(cpuinfo); VIR_FORCE_FCLOSE(cpuinfo);
@ -58,30 +58,49 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
* so blank it to a predictable value */ * so blank it to a predictable value */
nodeinfo.nodes = 1; nodeinfo.nodes = 1;
snprintf(actualData, MAX_FILE, if (virAsprintf(&actualData, "CPUs: %u, MHz: %u, Nodes: %u, Cores: %u\n",
"CPUs: %u, MHz: %u, Nodes: %u, Cores: %u\n", nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes,
nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes, nodeinfo.cores); nodeinfo.cores) < 0)
goto fail;
if (STRNEQ(actualData, expectData)) { if (STRNEQ(actualData, expectData)) {
if (getenv("DEBUG_TESTS")) { if (getenv("DEBUG_TESTS")) {
printf("Expect %d '%s'\n", (int)strlen(expectData), expectData); printf("Expect %d '%s'\n", (int)strlen(expectData), expectData);
printf("Actual %d '%s'\n", (int)strlen(actualData), actualData); printf("Actual %d '%s'\n", (int)strlen(actualData), actualData);
} }
return -1; goto fail;
} }
return 0; ret = 0;
fail:
free(expectData);
free(actualData);
return ret;
} }
static int linuxTestNodeInfo(const void *data) { static int
char cpuinfo[PATH_MAX]; linuxTestNodeInfo(const void *data)
char output[PATH_MAX]; {
snprintf(cpuinfo, PATH_MAX, "%s/nodeinfodata/linux-%s.cpuinfo", int result = -1;
abs_srcdir, (const char*)data); char *cpuinfo = NULL;
snprintf(output, PATH_MAX, "%s/nodeinfodata/linux-%s.txt", char *output = NULL;
abs_srcdir, (const char*)data);
return linuxTestCompareFiles(cpuinfo, output); if (virAsprintf(&cpuinfo, "%s/nodeinfodata/linux-%s.cpuinfo",
abs_srcdir, (const char*)data) < 0 ||
virAsprintf(&output, "%s/nodeinfodata/linux-%s.txt",
abs_srcdir, (const char*)data) < 0) {
goto cleanup;
}
result = linuxTestCompareFiles(cpuinfo, output);
cleanup:
free(cpuinfo);
free(output);
return result;
} }

View File

@ -16,23 +16,19 @@
#include "nwfilter_conf.h" #include "nwfilter_conf.h"
#include "testutilsqemu.h" #include "testutilsqemu.h"
#define MAX_FILE 4096 static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
bool expect_error)
static int testCompareXMLToXMLFiles(const char *inxml, {
const char *outxml, char *inXmlData = NULL;
bool expect_error) { char *outXmlData = NULL;
char inXmlData[MAX_FILE];
char *inXmlPtr = &(inXmlData[0]);
char outXmlData[MAX_FILE];
char *outXmlPtr = &(outXmlData[0]);
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virNWFilterDefPtr dev = NULL; virNWFilterDefPtr dev = NULL;
if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail; goto fail;
virResetLastError(); virResetLastError();
@ -59,6 +55,8 @@ static int testCompareXMLToXMLFiles(const char *inxml,
ret = 0; ret = 0;
fail: fail:
free(inXmlData);
free(outXmlData);
free(actual); free(actual);
virNWFilterDefFree(dev); virNWFilterDefFree(dev);
return ret; return ret;
@ -69,17 +67,29 @@ typedef struct test_parms {
bool expect_warning; bool expect_warning;
} test_parms; } test_parms;
static int testCompareXMLToXMLHelper(const void *data) { static int
testCompareXMLToXMLHelper(const void *data)
{
int result = -1;
const test_parms *tp = data; const test_parms *tp = data;
char inxml[PATH_MAX]; char *inxml = NULL;
char outxml[PATH_MAX]; char *outxml = NULL;
snprintf(inxml, PATH_MAX, "%s/nwfilterxml2xmlin/%s.xml",
abs_srcdir, tp->name);
snprintf(outxml, PATH_MAX, "%s/nwfilterxml2xmlout/%s.xml",
abs_srcdir, tp->name);
return testCompareXMLToXMLFiles(inxml, outxml, tp->expect_warning);
}
if (virAsprintf(&inxml, "%s/nwfilterxml2xmlin/%s.xml",
abs_srcdir, tp->name) < 0 ||
virAsprintf(&outxml, "%s/nwfilterxml2xmlout/%s.xml",
abs_srcdir, tp->name) < 0) {
goto cleanup;
}
result = testCompareXMLToXMLFiles(inxml, outxml, tp->expect_warning);
cleanup:
free(inxml);
free(outxml);
return result;
}
static int static int
mymain(void) mymain(void)

View File

@ -18,8 +18,6 @@
static struct qemud_driver driver; static struct qemud_driver driver;
# define MAX_FILE 4096
static int blankProblemElements(char *data) static int blankProblemElements(char *data)
{ {
if (virtTestClearLineRegex("<name>[[:alnum:]]+</name>", data) < 0 || if (virtTestClearLineRegex("<name>[[:alnum:]]+</name>", data) < 0 ||
@ -35,18 +33,16 @@ static int blankProblemElements(char *data)
static int testCompareXMLToArgvFiles(const char *xml, static int testCompareXMLToArgvFiles(const char *xml,
const char *cmdfile, const char *cmdfile,
bool expect_warning) { bool expect_warning) {
char xmlData[MAX_FILE]; char *expectxml = NULL;
char cmdData[MAX_FILE];
char *expectxml = &(xmlData[0]);
char *actualxml = NULL; char *actualxml = NULL;
char *cmd = &(cmdData[0]); char *cmd = NULL;
int ret = -1; int ret = -1;
virDomainDefPtr vmdef = NULL; virDomainDefPtr vmdef = NULL;
char *log; char *log;
if (virtTestLoadFile(cmdfile, &cmd, MAX_FILE) < 0) if (virtTestLoadFile(cmdfile, &cmd) < 0)
goto fail; goto fail;
if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0) if (virtTestLoadFile(xml, &expectxml) < 0)
goto fail; goto fail;
if (!(vmdef = qemuParseCommandLineString(driver.caps, cmd))) if (!(vmdef = qemuParseCommandLineString(driver.caps, cmd)))
@ -75,7 +71,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
ret = 0; ret = 0;
fail: fail:
free(expectxml);
free(actualxml); free(actualxml);
free(cmd);
virDomainDefFree(vmdef); virDomainDefFree(vmdef);
return ret; return ret;
} }
@ -87,15 +85,26 @@ struct testInfo {
const char *migrateFrom; const char *migrateFrom;
}; };
static int testCompareXMLToArgvHelper(const void *data) { static int
testCompareXMLToArgvHelper(const void *data)
{
int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char xml[PATH_MAX]; char *xml = NULL;
char args[PATH_MAX]; char *args = NULL;
snprintf(xml, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
abs_srcdir, info->name); if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
snprintf(args, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.args", abs_srcdir, info->name) < 0 ||
abs_srcdir, info->name); virAsprintf(&args, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
return testCompareXMLToArgvFiles(xml, args, !!info->extraFlags); abs_srcdir, info->name) < 0)
goto cleanup;
result = testCompareXMLToArgvFiles(xml, args, !!info->extraFlags);
cleanup:
free(xml);
free(args);
return result;
} }

View File

@ -9,8 +9,6 @@
# include "qemu/qemu_capabilities.h" # include "qemu/qemu_capabilities.h"
# include "memory.h" # include "memory.h"
# define MAX_HELP_OUTPUT_SIZE 1024*64
struct testInfo { struct testInfo {
const char *name; const char *name;
virBitmapPtr flags; virBitmapPtr flags;
@ -38,8 +36,7 @@ static int testHelpStrParsing(const void *data)
{ {
const struct testInfo *info = data; const struct testInfo *info = data;
char *path = NULL; char *path = NULL;
char helpStr[MAX_HELP_OUTPUT_SIZE]; char *help = NULL;
char *help = &(helpStr[0]);
unsigned int version, is_kvm, kvm_version; unsigned int version, is_kvm, kvm_version;
virBitmapPtr flags = NULL; virBitmapPtr flags = NULL;
int ret = -1; int ret = -1;
@ -49,7 +46,7 @@ static int testHelpStrParsing(const void *data)
if (virAsprintf(&path, "%s/qemuhelpdata/%s", abs_srcdir, info->name) < 0) if (virAsprintf(&path, "%s/qemuhelpdata/%s", abs_srcdir, info->name) < 0)
return -1; return -1;
if (virtTestLoadFile(path, &help, MAX_HELP_OUTPUT_SIZE) < 0) if (virtTestLoadFile(path, &help) < 0)
goto cleanup; goto cleanup;
if (!(flags = qemuCapsNew())) if (!(flags = qemuCapsNew()))
@ -61,11 +58,12 @@ static int testHelpStrParsing(const void *data)
if (qemuCapsGet(info->flags, QEMU_CAPS_DEVICE)) { if (qemuCapsGet(info->flags, QEMU_CAPS_DEVICE)) {
VIR_FREE(path); VIR_FREE(path);
VIR_FREE(help);
if (virAsprintf(&path, "%s/qemuhelpdata/%s-device", abs_srcdir, if (virAsprintf(&path, "%s/qemuhelpdata/%s-device", abs_srcdir,
info->name) < 0) info->name) < 0)
goto cleanup; goto cleanup;
if (virtTestLoadFile(path, &help, MAX_HELP_OUTPUT_SIZE) < 0) if (virtTestLoadFile(path, &help) < 0)
goto cleanup; goto cleanup;
if (qemuCapsParseDeviceStr(help, flags) < 0) if (qemuCapsParseDeviceStr(help, flags) < 0)
@ -111,6 +109,7 @@ static int testHelpStrParsing(const void *data)
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(path); VIR_FREE(path);
VIR_FREE(help);
qemuCapsFree(flags); qemuCapsFree(flags);
VIR_FREE(got); VIR_FREE(got);
VIR_FREE(expected); VIR_FREE(expected);

View File

@ -22,16 +22,14 @@
static const char *abs_top_srcdir; static const char *abs_top_srcdir;
static struct qemud_driver driver; static struct qemud_driver driver;
# define MAX_FILE 4096
static int testCompareXMLToArgvFiles(const char *xml, static int testCompareXMLToArgvFiles(const char *xml,
const char *cmdline, const char *cmdline,
virBitmapPtr extraFlags, virBitmapPtr extraFlags,
const char *migrateFrom, const char *migrateFrom,
int migrateFd, int migrateFd,
bool expectError) { bool expectError)
char argvData[MAX_FILE]; {
char *expectargv = &(argvData[0]); char *expectargv = NULL;
int len; int len;
char *actualargv = NULL; char *actualargv = NULL;
int ret = -1; int ret = -1;
@ -45,7 +43,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (!(conn = virGetConnect())) if (!(conn = virGetConnect()))
goto fail; goto fail;
len = virtTestLoadFile(cmdline, &expectargv, MAX_FILE); len = virtTestLoadFile(cmdline, &expectargv);
if (len < 0) if (len < 0)
goto fail; goto fail;
if (len && expectargv[len - 1] == '\n') if (len && expectargv[len - 1] == '\n')
@ -156,6 +154,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
fail: fail:
free(log); free(log);
free(emulator); free(emulator);
free(expectargv);
free(actualargv); free(actualargv);
virCommandFree(cmd); virCommandFree(cmd);
virDomainDefFree(vmdef); virDomainDefFree(vmdef);
@ -172,17 +171,28 @@ struct testInfo {
bool expectError; bool expectError;
}; };
static int testCompareXMLToArgvHelper(const void *data) { static int
testCompareXMLToArgvHelper(const void *data)
{
int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char xml[PATH_MAX]; char *xml = NULL;
char args[PATH_MAX]; char *args = NULL;
snprintf(xml, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
abs_srcdir, info->name); if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
snprintf(args, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.args", abs_srcdir, info->name) < 0 ||
abs_srcdir, info->name); virAsprintf(&args, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
return testCompareXMLToArgvFiles(xml, args, info->extraFlags, abs_srcdir, info->name) < 0)
info->migrateFrom, info->migrateFd, goto cleanup;
info->expectError);
result = testCompareXMLToArgvFiles(xml, args, info->extraFlags,
info->migrateFrom, info->migrateFd,
info->expectError);
cleanup:
free(xml);
free(args);
return result;
} }
@ -191,7 +201,7 @@ static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char map[PATH_MAX]; char *map = NULL;
abs_top_srcdir = getenv("abs_top_srcdir"); abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir) if (!abs_top_srcdir)
@ -210,10 +220,11 @@ mymain(void)
return EXIT_FAILURE; return EXIT_FAILURE;
if (!(driver.spicePassword = strdup("123456"))) if (!(driver.spicePassword = strdup("123456")))
return EXIT_FAILURE; return EXIT_FAILURE;
if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
snprintf(map, PATH_MAX, "%s/src/cpu/cpu_map.xml", abs_top_srcdir); cpuMapOverride(map) < 0) {
if (cpuMapOverride(map) < 0) free(map);
return EXIT_FAILURE; return EXIT_FAILURE;
}
# define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \ # define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \
do { \ do { \
@ -484,6 +495,7 @@ mymain(void)
free(driver.stateDir); free(driver.stateDir);
virCapabilitiesFree(driver.caps); virCapabilitiesFree(driver.caps);
free(map);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }

View File

@ -17,21 +17,18 @@
static struct qemud_driver driver; static struct qemud_driver driver;
# define MAX_FILE 4096 static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
{
static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { char *inXmlData = NULL;
char inXmlData[MAX_FILE]; char *outXmlData = NULL;
char *inXmlPtr = &(inXmlData[0]);
char outXmlData[MAX_FILE];
char *outXmlPtr = &(outXmlData[0]);
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail; goto fail;
if (!(def = virDomainDefParseString(driver.caps, inXmlData, if (!(def = virDomainDefParseString(driver.caps, inXmlData,
@ -49,6 +46,8 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0; ret = 0;
fail: fail:
free(inXmlData);
free(outXmlData);
free(actual); free(actual);
virDomainDefFree(def); virDomainDefFree(def);
return ret; return ret;
@ -59,16 +58,19 @@ struct testInfo {
int different; int different;
}; };
static int testCompareXMLToXMLHelper(const void *data) { static int
testCompareXMLToXMLHelper(const void *data)
{
const struct testInfo *info = data; const struct testInfo *info = data;
char xml_in[PATH_MAX]; char *xml_in = NULL;
char xml_out[PATH_MAX]; char *xml_out = NULL;
int ret; int ret = -1;
snprintf(xml_in, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml", if (virAsprintf(&xml_in, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
abs_srcdir, info->name); abs_srcdir, info->name) < 0 ||
snprintf(xml_out, PATH_MAX, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml", virAsprintf(&xml_out, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
abs_srcdir, info->name); abs_srcdir, info->name) < 0)
goto cleanup;
if (info->different) { if (info->different) {
ret = testCompareXMLToXMLFiles(xml_in, xml_out); ret = testCompareXMLToXMLFiles(xml_in, xml_out);
@ -76,6 +78,9 @@ static int testCompareXMLToXMLHelper(const void *data) {
ret = testCompareXMLToXMLFiles(xml_in, xml_in); ret = testCompareXMLToXMLFiles(xml_in, xml_in);
} }
cleanup:
free(xml_in);
free(xml_out);
return ret; return ret;
} }

View File

@ -15,15 +15,12 @@
static virCapsPtr caps; static virCapsPtr caps;
#define MAX_FILE 4096 static int
testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
static int testCompareFiles(const char *xml, const char *sexpr, {
int xendConfigVersion) { char *xmlData = NULL;
char xmlData[MAX_FILE]; char *sexprData = NULL;
char sexprData[MAX_FILE];
char *gotxml = NULL; char *gotxml = NULL;
char *xmlPtr = &(xmlData[0]);
char *sexprPtr = &(sexprData[0]);
int id; int id;
char * tty; char * tty;
int vncport; int vncport;
@ -36,10 +33,10 @@ static int testCompareFiles(const char *xml, const char *sexpr,
conn = virGetConnect(); conn = virGetConnect();
if (!conn) goto fail; if (!conn) goto fail;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0) if (virtTestLoadFile(sexpr, &sexprData) < 0)
goto fail; goto fail;
memset(&priv, 0, sizeof priv); memset(&priv, 0, sizeof priv);
@ -70,6 +67,8 @@ static int testCompareFiles(const char *xml, const char *sexpr,
ret = 0; ret = 0;
fail: fail:
free(xmlData);
free(sexprData);
free(gotxml); free(gotxml);
virDomainDefFree(def); virDomainDefFree(def);
if (conn) if (conn)
@ -84,17 +83,29 @@ struct testInfo {
int version; int version;
}; };
static int testCompareHelper(const void *data) { static int
testCompareHelper(const void *data)
{
int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char xml[PATH_MAX]; char *xml = NULL;
char args[PATH_MAX]; char *args = NULL;
snprintf(xml, PATH_MAX, "%s/sexpr2xmldata/sexpr2xml-%s.xml",
abs_srcdir, info->input);
snprintf(args, PATH_MAX, "%s/sexpr2xmldata/sexpr2xml-%s.sexpr",
abs_srcdir, info->output);
return testCompareFiles(xml, args, info->version);
}
if (virAsprintf(&xml, "%s/sexpr2xmldata/sexpr2xml-%s.xml",
abs_srcdir, info->input) < 0 ||
virAsprintf(&args, "%s/sexpr2xmldata/sexpr2xml-%s.sexpr",
abs_srcdir, info->output) < 0) {
goto cleanup;
}
result = testCompareFiles(xml, args, info->version);
cleanup:
free(xml);
free(args);
return result;
}
static int static int
mymain(void) mymain(void)

View File

@ -13,21 +13,18 @@
#include "storage_conf.h" #include "storage_conf.h"
#include "testutilsqemu.h" #include "testutilsqemu.h"
#define MAX_FILE 4096 static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
{
static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { char *inXmlData = NULL;
char inXmlData[MAX_FILE]; char *outXmlData = NULL;
char *inXmlPtr = &(inXmlData[0]);
char outXmlData[MAX_FILE];
char *outXmlPtr = &(outXmlData[0]);
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virStoragePoolDefPtr dev = NULL; virStoragePoolDefPtr dev = NULL;
if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail; goto fail;
if (!(dev = virStoragePoolDefParseString(inXmlData))) if (!(dev = virStoragePoolDefParseString(inXmlData)))
@ -44,21 +41,35 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0; ret = 0;
fail: fail:
free(inXmlData);
free(outXmlData);
free(actual); free(actual);
virStoragePoolDefFree(dev); virStoragePoolDefFree(dev);
return ret; return ret;
} }
static int testCompareXMLToXMLHelper(const void *data) { static int
char inxml[PATH_MAX]; testCompareXMLToXMLHelper(const void *data)
char outxml[PATH_MAX]; {
snprintf(inxml, PATH_MAX, "%s/storagepoolxml2xmlin/%s.xml", int result = -1;
abs_srcdir, (const char*)data); char *inxml = NULL;
snprintf(outxml, PATH_MAX, "%s/storagepoolxml2xmlout/%s.xml", char *outxml = NULL;
abs_srcdir, (const char*)data);
return testCompareXMLToXMLFiles(inxml, outxml);
}
if (virAsprintf(&inxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, (const char*)data) < 0 ||
virAsprintf(&outxml, "%s/storagepoolxml2xmlout/%s.xml",
abs_srcdir, (const char*)data) < 0) {
goto cleanup;
}
result = testCompareXMLToXMLFiles(inxml, outxml);
cleanup:
free(inxml);
free(outxml);
return result;
}
static int static int
mymain(void) mymain(void)

View File

@ -13,28 +13,23 @@
#include "storage_conf.h" #include "storage_conf.h"
#include "testutilsqemu.h" #include "testutilsqemu.h"
#define MAX_FILE 4096 static int
testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
const char *outxml)
static int testCompareXMLToXMLFiles(const char *poolxml, {
const char *inxml, char *poolXmlData = NULL;
const char *outxml) { char *inXmlData = NULL;
char poolXmlData[MAX_FILE]; char *outXmlData = NULL;
char *poolXmlPtr = &(poolXmlData[0]);
char inXmlData[MAX_FILE];
char *inXmlPtr = &(inXmlData[0]);
char outXmlData[MAX_FILE];
char *outXmlPtr = &(outXmlData[0]);
char *actual = NULL; char *actual = NULL;
int ret = -1; int ret = -1;
virStoragePoolDefPtr pool = NULL; virStoragePoolDefPtr pool = NULL;
virStorageVolDefPtr dev = NULL; virStorageVolDefPtr dev = NULL;
if (virtTestLoadFile(poolxml, &poolXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(poolxml, &poolXmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail; goto fail;
if (!(pool = virStoragePoolDefParseString(poolXmlData))) if (!(pool = virStoragePoolDefParseString(poolXmlData)))
@ -54,6 +49,9 @@ static int testCompareXMLToXMLFiles(const char *poolxml,
ret = 0; ret = 0;
fail: fail:
free(poolXmlData);
free(inXmlData);
free(outXmlData);
free(actual); free(actual);
virStoragePoolDefFree(pool); virStoragePoolDefFree(pool);
virStorageVolDefFree(dev); virStorageVolDefFree(dev);
@ -65,19 +63,32 @@ struct testInfo {
const char *name; const char *name;
}; };
static int testCompareXMLToXMLHelper(const void *data) { static int
char poolxml[PATH_MAX]; testCompareXMLToXMLHelper(const void *data)
char inxml[PATH_MAX]; {
char outxml[PATH_MAX]; int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char *poolxml = NULL;
char *inxml = NULL;
char *outxml = NULL;
snprintf(poolxml, PATH_MAX, "%s/storagepoolxml2xmlin/%s.xml", if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
abs_srcdir, (const char*)info->pool); abs_srcdir, info->pool) < 0 ||
snprintf(inxml, PATH_MAX, "%s/storagevolxml2xmlin/%s.xml", virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml",
abs_srcdir, (const char*)info->name); abs_srcdir, info->name) < 0 ||
snprintf(outxml, PATH_MAX, "%s/storagevolxml2xmlout/%s.xml", virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml",
abs_srcdir, (const char*)info->name); abs_srcdir, info->name) < 0) {
return testCompareXMLToXMLFiles(poolxml, inxml, outxml); goto cleanup;
}
result = testCompareXMLToXMLFiles(poolxml, inxml, outxml);
cleanup:
free(poolxml);
free(inxml);
free(outxml);
return result;
} }

View File

@ -173,17 +173,16 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
return ret; return ret;
} }
/* Read FILE into buffer BUF of length BUFLEN. /* Allocate BUF to the size of FILE. Read FILE into buffer BUF.
Upon any failure, or if FILE appears to contain more than BUFLEN bytes, Upon any failure, diagnose it and return -1, but don't bother trying
diagnose it and return -1, but don't bother trying to preserve errno. to preserve errno. Otherwise, return the number of bytes copied into BUF. */
Otherwise, return the number of bytes copied into BUF. */ int
int virtTestLoadFile(const char *file, virtTestLoadFile(const char *file, char **buf)
char **buf, {
int buflen) {
FILE *fp = fopen(file, "r"); FILE *fp = fopen(file, "r");
struct stat st; struct stat st;
char *tmp = *buf; char *tmp;
int len, tmplen = buflen; int len, tmplen, buflen;
if (!fp) { if (!fp) {
fprintf (stderr, "%s: failed to open: %s\n", file, strerror(errno)); fprintf (stderr, "%s: failed to open: %s\n", file, strerror(errno));
@ -196,17 +195,23 @@ int virtTestLoadFile(const char *file,
return -1; return -1;
} }
if (st.st_size > (buflen-1)) { tmplen = buflen = st.st_size + 1;
fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
if (VIR_ALLOC_N(*buf, buflen) < 0) {
fprintf (stderr, "%s: larger than available memory (> %d)\n", file, buflen);
VIR_FORCE_FCLOSE(fp); VIR_FORCE_FCLOSE(fp);
return -1; return -1;
} }
tmp = *buf;
(*buf)[0] = '\0'; (*buf)[0] = '\0';
if (st.st_size) { if (st.st_size) {
/* read the file line by line */ /* read the file line by line */
while (fgets(tmp, tmplen, fp) != NULL) { while (fgets(tmp, tmplen, fp) != NULL) {
len = strlen(tmp); len = strlen(tmp);
/* stop on an empty line */
if (len == 0)
break;
/* remove trailing backslash-newline pair */ /* remove trailing backslash-newline pair */
if (len >= 2 && tmp[len-2] == '\\' && tmp[len-1] == '\n') { if (len >= 2 && tmp[len-2] == '\\' && tmp[len-1] == '\n') {
len -= 2; len -= 2;
@ -219,6 +224,7 @@ int virtTestLoadFile(const char *file,
if (ferror(fp)) { if (ferror(fp)) {
fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno)); fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
VIR_FORCE_FCLOSE(fp); VIR_FORCE_FCLOSE(fp);
free(*buf);
return -1; return -1;
} }
} }
@ -268,10 +274,11 @@ void virtTestCaptureProgramExecChild(const char *const argv[],
VIR_FORCE_CLOSE(stdinfd); VIR_FORCE_CLOSE(stdinfd);
} }
int virtTestCaptureProgramOutput(const char *const argv[], int
char **buf, virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen)
int buflen) { {
int pipefd[2]; int pipefd[2];
int len;
if (pipe(pipefd) < 0) if (pipe(pipefd) < 0)
return -1; return -1;
@ -289,34 +296,20 @@ int virtTestCaptureProgramOutput(const char *const argv[],
return -1; return -1;
default: default:
{ VIR_FORCE_CLOSE(pipefd[1]);
int got = 0; len = virFileReadLimFD(pipefd[0], maxlen, buf);
int ret = -1; VIR_FORCE_CLOSE(pipefd[0]);
int want = buflen-1; waitpid(pid, NULL, 0);
VIR_FORCE_CLOSE(pipefd[1]); return len;
while (want) {
if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
break;
got += ret;
want -= ret;
}
VIR_FORCE_CLOSE(pipefd[0]);
if (!ret)
(*buf)[got] = '\0';
waitpid(pid, NULL, 0);
return ret;
}
} }
} }
#else /* !WIN32 */ #else /* !WIN32 */
int virtTestCaptureProgramOutput(const char *const argv[] ATTRIBUTE_UNUSED, int
char **buf ATTRIBUTE_UNUSED, virtTestCaptureProgramOutput(const char *const argv[] ATTRIBUTE_UNUSED,
int buflen ATTRIBUTE_UNUSED) { char **buf ATTRIBUTE_UNUSED,
int maxlen ATTRIBUTE_UNUSED)
{
return -1; return -1;
} }
#endif /* !WIN32 */ #endif /* !WIN32 */

View File

@ -27,12 +27,8 @@ int virtTestRun(const char *title,
int nloops, int nloops,
int (*body)(const void *data), int (*body)(const void *data),
const void *data); const void *data);
int virtTestLoadFile(const char *name, int virtTestLoadFile(const char *file, char **buf);
char **buf, int virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
int buflen);
int virtTestCaptureProgramOutput(const char *const argv[],
char **buf,
int buflen);
int virtTestClearLineRegex(const char *pattern, int virtTestClearLineRegex(const char *pattern,
char *string); char *string);

View File

@ -6,10 +6,9 @@
#include "internal.h" #include "internal.h"
#include "xml.h" #include "xml.h"
#include "util.h"
#include "testutils.h" #include "testutils.h"
#define MAX_FILE 4096
#define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493" #define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493"
static const char *dominfo_fc4 = "\ static const char *dominfo_fc4 = "\
@ -45,42 +44,32 @@ static int testFilterLine(char *buffer,
return 0; return 0;
} }
static int testCompareOutputLit(const char *expectData, static int
const char *filter, const char *const argv[]) { testCompareOutputLit(const char *expectData,
char actualData[MAX_FILE]; const char *filter, const char *const argv[])
char *actualPtr = &(actualData[0]); {
int result = -1;
char *actualData = NULL;
if (virtTestCaptureProgramOutput(argv, &actualPtr, MAX_FILE) < 0) if (virtTestCaptureProgramOutput(argv, &actualData, 4096) < 0)
return -1; goto cleanup;
if (filter) if (filter && testFilterLine(actualData, filter) < 0)
if (testFilterLine(actualData, filter) < 0) goto cleanup;
return -1;
if (STRNEQ(expectData, actualData)) { if (STRNEQ(expectData, actualData)) {
virtTestDifference(stderr, expectData, actualData); virtTestDifference(stderr, expectData, actualData);
return -1; goto cleanup;
} }
return 0; result = 0;
cleanup:
free(actualData);
return result;
} }
#if unused
static int testCompareOutput(const char *expect_rel, const char *filter,
const char *const argv[]) {
char expectData[MAX_FILE];
char *expectPtr = &(expectData[0]);
char expect[PATH_MAX];
snprintf(expect, sizeof expect - 1, "%s/%s", abs_srcdir, expect_rel);
if (virtTestLoadFile(expect, &expectPtr, MAX_FILE) < 0)
return -1;
return testCompareOutputLit(expectData, filter, argv);
}
#endif
#define VIRSH_DEFAULT "../tools/virsh", \ #define VIRSH_DEFAULT "../tools/virsh", \
"--connect", \ "--connect", \
"test:///default" "test:///default"
@ -233,16 +222,14 @@ static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
char buffer[PATH_MAX];
#ifdef WIN32 #ifdef WIN32
exit (EXIT_AM_SKIP); exit (EXIT_AM_SKIP);
#endif #endif
snprintf(buffer, PATH_MAX-1, if (virAsprintf(&custom_uri, "test://%s/../examples/xml/test/testnode.xml",
"test://%s/../examples/xml/test/testnode.xml", abs_srcdir); abs_srcdir) < 0)
buffer[PATH_MAX-1] = '\0'; return EXIT_FAILURE;
custom_uri = buffer;
if (virtTestRun("virsh list (default)", if (virtTestRun("virsh list (default)",
1, testCompareListDefault, NULL) != 0) 1, testCompareListDefault, NULL) != 0)
@ -394,6 +381,7 @@ mymain(void)
#undef DO_TEST #undef DO_TEST
free(custom_uri);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }

View File

@ -11,11 +11,9 @@
# include "testutils.h" # include "testutils.h"
# include "vmx/vmx.h" # include "vmx/vmx.h"
static virCapsPtr caps = NULL; static virCapsPtr caps;
static virVMXContext ctx; static virVMXContext ctx;
# define MAX_FILE 4096
static void static void
testCapsInit(void) testCapsInit(void)
{ {
@ -69,19 +67,17 @@ static int
testCompareFiles(const char *vmx, const char *xml) testCompareFiles(const char *vmx, const char *xml)
{ {
int result = -1; int result = -1;
char vmxData[MAX_FILE]; char *vmxData = NULL;
char xmlData[MAX_FILE]; char *xmlData = NULL;
char *formatted = NULL; char *formatted = NULL;
char *vmxPtr = &(vmxData[0]);
char *xmlPtr = &(xmlData[0]);
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
virErrorPtr err = NULL; virErrorPtr err = NULL;
if (virtTestLoadFile(vmx, &vmxPtr, MAX_FILE) < 0) { if (virtTestLoadFile(vmx, &vmxData) < 0) {
goto failure; goto failure;
} }
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) { if (virtTestLoadFile(xml, &xmlData) < 0) {
goto failure; goto failure;
} }
@ -109,6 +105,8 @@ testCompareFiles(const char *vmx, const char *xml)
result = 0; result = 0;
failure: failure:
VIR_FREE(vmxData);
VIR_FREE(xmlData);
VIR_FREE(formatted); VIR_FREE(formatted);
virDomainDefFree(def); virDomainDefFree(def);
@ -123,16 +121,25 @@ struct testInfo {
static int static int
testCompareHelper(const void *data) testCompareHelper(const void *data)
{ {
int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char vmx[PATH_MAX]; char *vmx = NULL;
char xml[PATH_MAX]; char *xml = NULL;
snprintf(vmx, PATH_MAX, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir, if (virAsprintf(&vmx, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir,
info->input); info->input) < 0 ||
snprintf(xml, PATH_MAX, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir, virAsprintf(&xml, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
info->output); info->output) < 0) {
goto cleanup;
}
return testCompareFiles(vmx, xml); result = testCompareFiles(vmx, xml);
cleanup:
VIR_FREE(vmx);
VIR_FREE(xml);
return result;
} }
static char * static char *

View File

@ -11,32 +11,27 @@
#include "xen/xen_hypervisor.h" #include "xen/xen_hypervisor.h"
#include "files.h" #include "files.h"
#define MAX_FILE 4096 static int
testCompareFiles(const char *hostmachine, const char *xml_rel,
static int testCompareFiles(const char *hostmachine, const char *cpuinfo_rel, const char *capabilities_rel)
const char *xml_rel, {
const char *cpuinfo_rel, char *expectxml = NULL;
const char *capabilities_rel) {
char xmlData[MAX_FILE];
char *expectxml = &(xmlData[0]);
char *actualxml = NULL; char *actualxml = NULL;
FILE *fp1 = NULL, *fp2 = NULL; FILE *fp1 = NULL, *fp2 = NULL;
virCapsPtr caps = NULL; virCapsPtr caps = NULL;
int ret = -1; int ret = -1;
char xml[PATH_MAX]; char *xml = NULL;
char cpuinfo[PATH_MAX]; char *cpuinfo = NULL;
char capabilities[PATH_MAX]; char *capabilities = NULL;
snprintf(xml, sizeof xml - 1, "%s/%s", if (virAsprintf(&xml, "%s/%s", abs_srcdir, xml_rel) < 0 ||
abs_srcdir, xml_rel); virAsprintf(&cpuinfo, "%s/%s", abs_srcdir, cpuinfo_rel) < 0 ||
snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/%s", virAsprintf(&capabilities, "%s/%s", abs_srcdir, capabilities_rel) < 0)
abs_srcdir, cpuinfo_rel); goto fail;
snprintf(capabilities, sizeof capabilities - 1, "%s/%s",
abs_srcdir, capabilities_rel);
if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0) if (virtTestLoadFile(xml, &expectxml) < 0)
goto fail; goto fail;
if (!(fp1 = fopen(cpuinfo, "r"))) if (!(fp1 = fopen(cpuinfo, "r")))
@ -59,8 +54,11 @@ static int testCompareFiles(const char *hostmachine,
ret = 0; ret = 0;
fail: fail:
free(expectxml);
free(actualxml); free(actualxml);
free(xml);
free(cpuinfo);
free(capabilities);
VIR_FORCE_FCLOSE(fp1); VIR_FORCE_FCLOSE(fp1);
VIR_FORCE_FCLOSE(fp2); VIR_FORCE_FCLOSE(fp2);

View File

@ -38,30 +38,29 @@
static virCapsPtr caps; static virCapsPtr caps;
#define MAX_FILE 4096 static int
testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
static int testCompareParseXML(const char *xmcfg, const char *xml, {
int xendConfigVersion) { char *xmlData = NULL;
char xmlData[MAX_FILE]; char *xmcfgData = NULL;
char xmcfgData[MAX_FILE]; char *gotxmcfgData = NULL;
char gotxmcfgData[MAX_FILE];
char *xmlPtr = &(xmlData[0]);
char *xmcfgPtr = &(xmcfgData[0]);
char *gotxmcfgPtr = &(gotxmcfgData[0]);
virConfPtr conf = NULL; virConfPtr conf = NULL;
int ret = -1; int ret = -1;
virConnectPtr conn; virConnectPtr conn;
int wrote = MAX_FILE; int wrote = 4096;
struct _xenUnifiedPrivate priv; struct _xenUnifiedPrivate priv;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
goto fail;
conn = virGetConnect(); conn = virGetConnect();
if (!conn) goto fail; if (!conn) goto fail;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0) if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
goto fail; goto fail;
/* Many puppies died to bring you this code. */ /* Many puppies died to bring you this code. */
@ -69,16 +68,16 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
priv.caps = caps; priv.caps = caps;
conn->privateData = &priv; conn->privateData = &priv;
if (!(def = virDomainDefParseString(caps, xmlPtr, if (!(def = virDomainDefParseString(caps, xmlData,
VIR_DOMAIN_XML_INACTIVE))) VIR_DOMAIN_XML_INACTIVE)))
goto fail; goto fail;
if (!(conf = xenFormatXM(conn, def, xendConfigVersion))) if (!(conf = xenFormatXM(conn, def, xendConfigVersion)))
goto fail; goto fail;
if (virConfWriteMem(gotxmcfgPtr, &wrote, conf) < 0) if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)
goto fail; goto fail;
gotxmcfgPtr[wrote] = '\0'; gotxmcfgData[wrote] = '\0';
if (STRNEQ(xmcfgData, gotxmcfgData)) { if (STRNEQ(xmcfgData, gotxmcfgData)) {
virtTestDifference(stderr, xmcfgData, gotxmcfgData); virtTestDifference(stderr, xmcfgData, gotxmcfgData);
@ -88,6 +87,9 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
ret = 0; ret = 0;
fail: fail:
free(xmlData);
free(xmcfgData);
free(gotxmcfgData);
if (conf) if (conf)
virConfFree(conf); virConfFree(conf);
virDomainDefFree(def); virDomainDefFree(def);
@ -96,12 +98,11 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
return ret; return ret;
} }
static int testCompareFormatXML(const char *xmcfg, const char *xml, static int
int xendConfigVersion) { testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
char xmlData[MAX_FILE]; {
char xmcfgData[MAX_FILE]; char *xmlData = NULL;
char *xmlPtr = &(xmlData[0]); char *xmcfgData = NULL;
char *xmcfgPtr = &(xmcfgData[0]);
char *gotxml = NULL; char *gotxml = NULL;
virConfPtr conf = NULL; virConfPtr conf = NULL;
int ret = -1; int ret = -1;
@ -112,10 +113,10 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
conn = virGetConnect(); conn = virGetConnect();
if (!conn) goto fail; if (!conn) goto fail;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0) if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
goto fail; goto fail;
/* Many puppies died to bring you this code. */ /* Many puppies died to bring you this code. */
@ -123,7 +124,7 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
priv.caps = caps; priv.caps = caps;
conn->privateData = &priv; conn->privateData = &priv;
if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr), 0))) if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0)))
goto fail; goto fail;
if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps))) if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps)))
@ -142,6 +143,8 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
fail: fail:
if (conf) if (conf)
virConfFree(conf); virConfFree(conf);
VIR_FREE(xmlData);
VIR_FREE(xmcfgData);
VIR_FREE(gotxml); VIR_FREE(gotxml);
virDomainDefFree(def); virDomainDefFree(def);
virUnrefConnect(conn); virUnrefConnect(conn);
@ -156,18 +159,30 @@ struct testInfo {
int mode; int mode;
}; };
static int testCompareHelper(const void *data) { static int
testCompareHelper(const void *data)
{
int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char xml[PATH_MAX]; char *xml = NULL;
char cfg[PATH_MAX]; char *cfg = NULL;
snprintf(xml, PATH_MAX, "%s/xmconfigdata/test-%s.xml",
abs_srcdir, info->name); if (virAsprintf(&xml, "%s/xmconfigdata/test-%s.xml",
snprintf(cfg, PATH_MAX, "%s/xmconfigdata/test-%s.cfg", abs_srcdir, info->name) < 0 ||
abs_srcdir, info->name); virAsprintf(&cfg, "%s/xmconfigdata/test-%s.cfg",
abs_srcdir, info->name) < 0)
goto cleanup;
if (info->mode == 0) if (info->mode == 0)
return testCompareParseXML(cfg, xml, info->version); result = testCompareParseXML(cfg, xml, info->version);
else else
return testCompareFormatXML(cfg, xml, info->version); result = testCompareFormatXML(cfg, xml, info->version);
cleanup:
free(xml);
free(cfg);
return result;
} }

View File

@ -16,22 +16,19 @@
static virCapsPtr caps; static virCapsPtr caps;
#define MAX_FILE 4096 static int
testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
static int testCompareFiles(const char *xml, const char *sexpr, {
int xendConfigVersion) { char *xmlData = NULL;
char xmlData[MAX_FILE]; char *sexprData = NULL;
char sexprData[MAX_FILE];
char *gotsexpr = NULL; char *gotsexpr = NULL;
char *xmlPtr = &(xmlData[0]);
char *sexprPtr = &(sexprData[0]);
int ret = -1; int ret = -1;
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail; goto fail;
if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0) if (virtTestLoadFile(sexpr, &sexprData) < 0)
goto fail; goto fail;
if (!(def = virDomainDefParseString(caps, xmlData, if (!(def = virDomainDefParseString(caps, xmlData,
@ -49,8 +46,10 @@ static int testCompareFiles(const char *xml, const char *sexpr,
ret = 0; ret = 0;
fail: fail:
virDomainDefFree(def); free(xmlData);
free(sexprData);
free(gotsexpr); free(gotsexpr);
virDomainDefFree(def);
return ret; return ret;
} }
@ -62,17 +61,29 @@ struct testInfo {
int version; int version;
}; };
static int testCompareHelper(const void *data) { static int
testCompareHelper(const void *data)
{
int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char xml[PATH_MAX]; char *xml = NULL;
char args[PATH_MAX]; char *args = NULL;
snprintf(xml, PATH_MAX, "%s/xml2sexprdata/xml2sexpr-%s.xml",
abs_srcdir, info->input);
snprintf(args, PATH_MAX, "%s/xml2sexprdata/xml2sexpr-%s.sexpr",
abs_srcdir, info->output);
return testCompareFiles(xml, args, info->version);
}
if (virAsprintf(&xml, "%s/xml2sexprdata/xml2sexpr-%s.xml",
abs_srcdir, info->input) < 0 ||
virAsprintf(&args, "%s/xml2sexprdata/xml2sexpr-%s.sexpr",
abs_srcdir, info->output) < 0) {
goto cleanup;
}
result = testCompareFiles(xml, args, info->version);
cleanup:
free(xml);
free(args);
return result;
}
static int static int
mymain(void) mymain(void)

View File

@ -11,11 +11,9 @@
# include "testutils.h" # include "testutils.h"
# include "vmx/vmx.h" # include "vmx/vmx.h"
static virCapsPtr caps = NULL; static virCapsPtr caps;
static virVMXContext ctx; static virVMXContext ctx;
# define MAX_FILE 4096
static void static void
testCapsInit(void) testCapsInit(void)
{ {
@ -69,18 +67,16 @@ static int
testCompareFiles(const char *xml, const char *vmx, int virtualHW_version) testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
{ {
int result = -1; int result = -1;
char xmlData[MAX_FILE]; char *xmlData = NULL;
char vmxData[MAX_FILE]; char *vmxData = NULL;
char *formatted = NULL; char *formatted = NULL;
char *xmlPtr = &(xmlData[0]);
char *vmxPtr = &(vmxData[0]);
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) { if (virtTestLoadFile(xml, &xmlData) < 0) {
goto failure; goto failure;
} }
if (virtTestLoadFile(vmx, &vmxPtr, MAX_FILE) < 0) { if (virtTestLoadFile(vmx, &vmxData) < 0) {
goto failure; goto failure;
} }
@ -104,6 +100,8 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
result = 0; result = 0;
failure: failure:
VIR_FREE(xmlData);
VIR_FREE(vmxData);
VIR_FREE(formatted); VIR_FREE(formatted);
virDomainDefFree(def); virDomainDefFree(def);
@ -119,16 +117,25 @@ struct testInfo {
static int static int
testCompareHelper(const void *data) testCompareHelper(const void *data)
{ {
int result = -1;
const struct testInfo *info = data; const struct testInfo *info = data;
char xml[PATH_MAX]; char *xml = NULL;
char vmx[PATH_MAX]; char *vmx = NULL;
snprintf(xml, PATH_MAX, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir, if (virAsprintf(&xml, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir,
info->input); info->input) < 0 ||
snprintf(vmx, PATH_MAX, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir, virAsprintf(&vmx, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
info->output); info->output) < 0) {
goto cleanup;
}
return testCompareFiles(xml, vmx, info->virtualHW_version); result = testCompareFiles(xml, vmx, info->virtualHW_version);
cleanup:
VIR_FREE(xml);
VIR_FREE(vmx);
return result;
} }
static int static int