Re: [libvirt] [libvirt-users] [Libvir] libvirt & vde_switch
by Laine Stump
On 04/28/2011 09:56 AM, Robert Šmol wrote:
> For my needs I would like to see either vdeswitch or openvswitch
> integrated in the project. Is there any preference from the
> users/developers on which one of those I should start looking into?
Are you volunteering to write some code? :-)
There have been requests for both, and both should eventually be done,
so I guess pick whichever one you like better :-) (since there's already
a patch for VDE, albeit with different XML than we'd like, that may be
quicker to finish.)
You may want to follow development of the work I'll point out below,
though, otherwise you could waste a lot of time.
>
> Also I would like to know how this should be integrated, from the
> mails I can see devs prefers to have virtual switch present as a
> network. Can someone describe how the integration should be done?
> Support for additional features like vlan, QoS?
Once we get into these kinds of questions, it's probably best to switch
to the developers' list (libvir-list(a)redhat.com) to get better exposure
to people writing the code. I'm Cc'ing this message there (and switching
the Reply-To: as well).
In particular, I recently send an RFC to libvir-list proposing an
expansion of the <network> XML to remove the hard-coded connection
between guest interface and host interface for macvtap (type='direct')
interfaces:
https://www.redhat.com/archives/libvir-list/2011-April/msg00591.html
and in a followup message showed how we could expand on this work to
provide support for openvswitch (or vde):
https://www.redhat.com/archives/libvir-list/2011-April/msg00640.html
I'm planning to have this code finished and tested within the next two
months at most (hopefully considerably earlier). If you're interested in
implementing a <network type='openvswitch'> or <network type='vde'> you
should subscribe to libvir-list (if you aren't already) so that you can
follow along.
>
> Robert
>
> On 04/06/2011 04:13 PM, Robert Šmol wrote:
>>
>>
>> On 04/06/2011 04:00 PM, Nicolas Sebrecht wrote:
>>> The 06/04/11, Robert Šmol wrote:
>>>> On 04/06/2011 10:34 AM, Nicolas Sebrecht wrote:
>>>>> The 05/04/11, Robert Šmol wrote:
>>>>>
>>>>>> I would like to ask about status of VDE and libvirt. I found a
>>>>>> thread from
>>>>>> http://www.redhat.com/archives/libvir-list/2008-February/msg00030.html.
>>>>>>
>>>>> AFAIK, vde_switch is still unsupported by libvirt and nobody seems to
>>>>> work on it these days.
>>>>>
>>>>> Most people wanting vde_switch (or open vswitch) enough leave
>>>>> libvirt.
>>>>>
>>>> On #IRC I got point to message:
>>>>
>>>> http://www.mail-archive.com/libvir-list@redhat.com/msg32081.html
>>>>
>>>> It seems there is a patch ready. I will test it against 0.9.0. What
>>>> is the procedure to get the patch reviewed and eventually get into
>>>> libvirt?
>>> The patch wasn't merged but the why is a question to the maintainers. I
>>> guess the way it was implemented did not convinced. This is what I
>>> understand from the whole thread, at least.
>>>
>> From the thread it seems the maintainers would like to have a network
>> based on VDE. To me it also looks like better idea (create vde
>> network and then just attach the domain to a network.
>>
>
13 years, 8 months
[libvirt] [PATCH v2] tests: Lower stack usage below 4096 bytes
by Matthias Bolte
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.
---
v2: rebased to current git head.
m4/virt-compile-warnings.m4 | 10 ++---
tests/conftest.c | 29 ++++++++++----
tests/cputest.c | 64 ++++++++++++++++++------------
tests/esxutilstest.c | 2 +
tests/interfacexml2xmltest.c | 31 ++++++++++-----
tests/networkxml2xmltest.c | 49 ++++++++++++++---------
tests/nodedevxml2xmltest.c | 32 ++++++++++------
tests/nodeinfotest.c | 65 ++++++++++++++++++++-----------
tests/nwfilterxml2xmltest.c | 52 +++++++++++++++----------
tests/qemuargv2xmltest.c | 41 ++++++++++++--------
tests/qemuhelptest.c | 11 ++---
tests/qemuxml2argvtest.c | 52 +++++++++++++++----------
tests/qemuxml2xmltest.c | 41 +++++++++++---------
tests/sexpr2xmltest.c | 49 ++++++++++++++---------
tests/storagepoolxml2xmltest.c | 49 ++++++++++++++---------
tests/storagevolxml2xmltest.c | 63 ++++++++++++++++++------------
tests/testutils.c | 69 +++++++++++++++------------------
tests/testutils.h | 8 +---
tests/virshtest.c | 58 +++++++++++-----------------
tests/vmx2xmltest.c | 39 +++++++++++--------
tests/xencapstest.c | 36 ++++++++---------
tests/xmconfigtest.c | 83 +++++++++++++++++++++++----------------
tests/xml2sexprtest.c | 51 +++++++++++++++----------
tests/xml2vmxtest.c | 39 +++++++++++--------
24 files changed, 588 insertions(+), 435 deletions(-)
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 295fd9b..305036f 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -88,12 +88,10 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
# that one off, so we need to manually enable this again
gl_WARN_ADD([-Wjump-misses-init])
- # This should be < 256 really, but with PATH_MAX everywhere
- # we have doom, even with 4096. In fact we have some functions
- # with several PATH_MAX sized variables :-( We should kill off
- # all PATH_MAX usage and then lower this limit
- gl_WARN_ADD([-Wframe-larger-than=65700])
- dnl gl_WARN_ADD([-Wframe-larger-than=4096])
+ # This should be < 256 really. Currently we're down to 4096,
+ # but using 1024 bytes sized buffers (mostly for virStrerror)
+ # stops us from going down further
+ gl_WARN_ADD([-Wframe-larger-than=4096])
dnl gl_WARN_ADD([-Wframe-larger-than=256])
# Extra special flags
diff --git a/tests/conftest.c b/tests/conftest.c
index a7977bb..6514f4d 100644
--- a/tests/conftest.c
+++ b/tests/conftest.c
@@ -6,32 +6,43 @@
#include <string.h>
#include <errno.h>
#include "conf.h"
+#include "memory.h"
-int main(int argc, char **argv) {
- int ret;
+int main(int argc, char **argv)
+{
+ int ret, exit_code = EXIT_FAILURE;
virConfPtr conf;
int len = 10000;
- char buffer[10000];
+ char *buffer = NULL;
if (argc != 2) {
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);
if (conf == NULL) {
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) {
fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
- exit(EXIT_FAILURE);
+ goto cleanup;
}
virConfFree(conf);
if (fwrite(buffer, 1, len, stdout) != len) {
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;
}
diff --git a/tests/cputest.c b/tests/cputest.c
index a8d28dc..b132ceb 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -42,7 +42,6 @@
static const char *abs_top_srcdir;
#define VIR_FROM_THIS VIR_FROM_CPU
-#define MAX_FILE 4096
enum compResultShadow {
ERROR = VIR_CPU_COMPARE_ERROR,
@@ -89,14 +88,13 @@ struct data {
static virCPUDefPtr
cpuTestLoadXML(const char *arch, const char *name)
{
- char xml[PATH_MAX];
+ char *xml = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
virCPUDefPtr cpu = NULL;
- snprintf(xml, PATH_MAX,
- "%s/cputestdata/%s-%s.xml",
- abs_srcdir, arch, name);
+ if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
+ goto cleanup;
if (!(doc = virXMLParseFile(xml)) ||
!(ctxt = xmlXPathNewContext(doc)))
@@ -108,6 +106,7 @@ cpuTestLoadXML(const char *arch, const char *name)
cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
+ free(xml);
return cpu;
}
@@ -117,7 +116,7 @@ cpuTestLoadMultiXML(const char *arch,
const char *name,
unsigned int *count)
{
- char xml[PATH_MAX];
+ char *xml = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL;
@@ -125,9 +124,8 @@ cpuTestLoadMultiXML(const char *arch,
int n;
int i;
- snprintf(xml, PATH_MAX,
- "%s/cputestdata/%s-%s.xml",
- abs_srcdir, arch, name);
+ if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
+ goto cleanup;
if (!(doc = virXMLParseFile(xml)) ||
!(ctxt = xmlXPathNewContext(doc)))
@@ -149,6 +147,7 @@ cpuTestLoadMultiXML(const char *arch,
*count = n;
cleanup:
+ free(xml);
free(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
@@ -170,17 +169,16 @@ cpuTestCompareXML(const char *arch,
const virCPUDefPtr cpu,
const char *name)
{
- char xml[PATH_MAX];
- char expected[MAX_FILE];
- char *expectedPtr = &(expected[0]);
+ char *xml = NULL;
+ char *expected = NULL;
char *actual = NULL;
int ret = -1;
- snprintf(xml, PATH_MAX,
- "%s/cputestdata/%s-%s.xml",
- abs_srcdir, arch, name);
+ if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
+ abs_srcdir, arch, name) < 0)
+ goto cleanup;
- if (virtTestLoadFile(xml, &expectedPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &expected) < 0)
goto cleanup;
if (!(actual = virCPUDefFormat(cpu, NULL, 0)))
@@ -194,6 +192,8 @@ cpuTestCompareXML(const char *arch,
ret = 0;
cleanup:
+ free(xml);
+ free(expected);
free(actual);
return ret;
}
@@ -333,7 +333,7 @@ cpuTestBaseline(const void *arg)
virCPUDefPtr *cpus = NULL;
virCPUDefPtr baseline = NULL;
unsigned int ncpus = 0;
- char result[PATH_MAX];
+ char *result = NULL;
unsigned int i;
if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
@@ -353,7 +353,9 @@ cpuTestBaseline(const void *arg)
if (!baseline)
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)
goto cleanup;
@@ -382,6 +384,7 @@ cleanup:
free(cpus);
}
virCPUDefFree(baseline);
+ free(result);
return ret;
}
@@ -393,7 +396,7 @@ cpuTestUpdate(const void *arg)
int ret = -1;
virCPUDefPtr host = NULL;
virCPUDefPtr cpu = NULL;
- char result[PATH_MAX];
+ char *result = NULL;
if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
!(cpu = cpuTestLoadXML(data->arch, data->name)))
@@ -402,12 +405,15 @@ cpuTestUpdate(const void *arg)
if (cpuUpdate(cpu, host) < 0)
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);
cleanup:
virCPUDefFree(host);
virCPUDefFree(cpu);
+ free(result);
return ret;
}
@@ -465,10 +471,10 @@ static int (*cpuTest[])(const void *) = {
static int
cpuTestRun(const char *name, const struct data *data)
{
- char label[PATH_MAX];
+ char *label = NULL;
- snprintf(label, PATH_MAX, "CPU %s(%s): %s",
- apis[data->api], data->arch, name);
+ if (virAsprintf(&label, "CPU %s(%s): %s", apis[data->api], data->arch, name) < 0)
+ return -1;
free(virtTestLogContentAndReset());
@@ -480,9 +486,12 @@ cpuTestRun(const char *name, const struct data *data)
fprintf(stderr, "\n%s\n", log);
free(log);
}
+
+ free(label);
return -1;
}
+ free(label);
return 0;
}
@@ -495,15 +504,17 @@ static int
mymain(void)
{
int ret = 0;
- char map[PATH_MAX];
+ char *map = NULL;
abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir)
abs_top_srcdir = "..";
- snprintf(map, PATH_MAX, "%s/src/cpu/cpu_map.xml", abs_top_srcdir);
- if (cpuMapOverride(map) < 0)
+ if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
+ cpuMapOverride(map) < 0) {
+ free(map);
return EXIT_FAILURE;
+ }
#define DO_TEST(arch, api, name, host, cpu, \
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", nomodel, NULL, -1);
+ free(map);
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index 830f79c..2b36535 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -273,6 +273,7 @@ testEscapeDatastoreItem(const void *data ATTRIBUTE_UNUSED)
}
}
+ VIR_FREE(escaped);
return 0;
}
@@ -314,6 +315,7 @@ testConvertWindows1252ToUTF8(const void *data ATTRIBUTE_UNUSED)
}
}
+ VIR_FREE(utf8);
return 0;
}
diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c
index fb454c1..dc08ea7 100644
--- a/tests/interfacexml2xmltest.c
+++ b/tests/interfacexml2xmltest.c
@@ -13,17 +13,16 @@
#include "interface_conf.h"
#include "testutilsqemu.h"
-#define MAX_FILE 4096
-
-static int testCompareXMLToXMLFiles(const char *xml) {
- char xmlData[MAX_FILE];
- char *xmlPtr = &(xmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *xml)
+{
+ char *xmlData = NULL;
char *actual = NULL;
int ret = -1;
virInterfaceDefPtr dev = NULL;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
if (!(dev = virInterfaceDefParseString(xmlData)))
@@ -40,16 +39,26 @@ static int testCompareXMLToXMLFiles(const char *xml) {
ret = 0;
fail:
+ free(xmlData);
free(actual);
virInterfaceDefFree(dev);
return ret;
}
-static int testCompareXMLToXMLHelper(const void *data) {
- char xml[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/interfaceschemadata/%s.xml",
- abs_srcdir, (const char*)data);
- return testCompareXMLToXMLFiles(xml);
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ 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;
}
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
index f7489f5..468785b 100644
--- a/tests/networkxml2xmltest.c
+++ b/tests/networkxml2xmltest.c
@@ -13,21 +13,18 @@
#include "network_conf.h"
#include "testutilsqemu.h"
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
+{
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virNetworkDefPtr dev = NULL;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
if (!(dev = virNetworkDefParseString(inXmlData)))
@@ -44,21 +41,35 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0;
fail:
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virNetworkDefFree(dev);
return ret;
}
-static int testCompareXMLToXMLHelper(const void *data) {
- char inxml[PATH_MAX];
- char outxml[PATH_MAX];
- snprintf(inxml, PATH_MAX, "%s/networkxml2xmlin/%s.xml",
- abs_srcdir, (const char*)data);
- snprintf(outxml, PATH_MAX, "%s/networkxml2xmlout/%s.xml",
- abs_srcdir, (const char*)data);
- return testCompareXMLToXMLFiles(inxml, outxml);
-}
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ 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
mymain(void)
diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c
index f6a1335..d0deaeb 100644
--- a/tests/nodedevxml2xmltest.c
+++ b/tests/nodedevxml2xmltest.c
@@ -13,17 +13,15 @@
#include "node_device_conf.h"
#include "testutilsqemu.h"
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *xml) {
- char xmlData[MAX_FILE];
- char *xmlPtr = &(xmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *xml)
+{
+ char *xmlData = NULL;
char *actual = NULL;
int ret = -1;
virNodeDeviceDefPtr dev = NULL;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE)))
@@ -40,16 +38,26 @@ static int testCompareXMLToXMLFiles(const char *xml) {
ret = 0;
fail:
+ free(xmlData);
free(actual);
virNodeDeviceDefFree(dev);
return ret;
}
-static int testCompareXMLToXMLHelper(const void *data) {
- char xml[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/nodedevschemadata/%s.xml",
- abs_srcdir, (const char*)data);
- return testCompareXMLToXMLFiles(xml);
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ 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;
}
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index 9a87dc0..b4e81b3 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -21,24 +21,24 @@ mymain(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
#else
-# define MAX_FILE 4096
-
extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, virNodeInfoPtr nodeinfo,
bool need_hyperthreads);
-static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) {
- char actualData[MAX_FILE];
- char expectData[MAX_FILE];
- char *expect = &expectData[0];
+static int
+linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile)
+{
+ int ret = -1;
+ char *actualData = NULL;
+ char *expectData = NULL;
virNodeInfo nodeinfo;
FILE *cpuinfo;
- if (virtTestLoadFile(outputfile, &expect, MAX_FILE) < 0)
- return -1;
+ if (virtTestLoadFile(outputfile, &expectData) < 0)
+ goto fail;
cpuinfo = fopen(cpuinfofile, "r");
if (!cpuinfo)
- return -1;
+ goto fail;
memset(&nodeinfo, 0, sizeof(nodeinfo));
if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo, false) < 0) {
@@ -49,7 +49,7 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
virFreeError(error);
}
VIR_FORCE_FCLOSE(cpuinfo);
- return -1;
+ goto fail;
}
VIR_FORCE_FCLOSE(cpuinfo);
@@ -58,30 +58,49 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
* so blank it to a predictable value */
nodeinfo.nodes = 1;
- snprintf(actualData, MAX_FILE,
- "CPUs: %u, MHz: %u, Nodes: %u, Cores: %u\n",
- nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes, nodeinfo.cores);
+ if (virAsprintf(&actualData, "CPUs: %u, MHz: %u, Nodes: %u, Cores: %u\n",
+ nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes,
+ nodeinfo.cores) < 0)
+ goto fail;
if (STRNEQ(actualData, expectData)) {
if (getenv("DEBUG_TESTS")) {
printf("Expect %d '%s'\n", (int)strlen(expectData), expectData);
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) {
- char cpuinfo[PATH_MAX];
- char output[PATH_MAX];
- snprintf(cpuinfo, PATH_MAX, "%s/nodeinfodata/linux-%s.cpuinfo",
- abs_srcdir, (const char*)data);
- snprintf(output, PATH_MAX, "%s/nodeinfodata/linux-%s.txt",
- abs_srcdir, (const char*)data);
- return linuxTestCompareFiles(cpuinfo, output);
+static int
+linuxTestNodeInfo(const void *data)
+{
+ int result = -1;
+ char *cpuinfo = NULL;
+ char *output = NULL;
+
+ 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;
}
diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c
index a1f57fa..49c6b99 100644
--- a/tests/nwfilterxml2xmltest.c
+++ b/tests/nwfilterxml2xmltest.c
@@ -16,23 +16,19 @@
#include "nwfilter_conf.h"
#include "testutilsqemu.h"
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *inxml,
- const char *outxml,
- bool expect_error) {
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
+ bool expect_error)
+{
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virNWFilterDefPtr dev = NULL;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
virResetLastError();
@@ -59,6 +55,8 @@ static int testCompareXMLToXMLFiles(const char *inxml,
ret = 0;
fail:
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virNWFilterDefFree(dev);
return ret;
@@ -69,17 +67,29 @@ typedef struct test_parms {
bool expect_warning;
} test_parms;
-static int testCompareXMLToXMLHelper(const void *data) {
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
const test_parms *tp = data;
- char inxml[PATH_MAX];
- char outxml[PATH_MAX];
- 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);
-}
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ 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
mymain(void)
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index 60dce46..db68b60 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -18,8 +18,6 @@
static struct qemud_driver driver;
-# define MAX_FILE 4096
-
static int blankProblemElements(char *data)
{
if (virtTestClearLineRegex("<name>[[:alnum:]]+</name>", data) < 0 ||
@@ -35,18 +33,16 @@ static int blankProblemElements(char *data)
static int testCompareXMLToArgvFiles(const char *xml,
const char *cmdfile,
bool expect_warning) {
- char xmlData[MAX_FILE];
- char cmdData[MAX_FILE];
- char *expectxml = &(xmlData[0]);
+ char *expectxml = NULL;
char *actualxml = NULL;
- char *cmd = &(cmdData[0]);
+ char *cmd = NULL;
int ret = -1;
virDomainDefPtr vmdef = NULL;
char *log;
- if (virtTestLoadFile(cmdfile, &cmd, MAX_FILE) < 0)
+ if (virtTestLoadFile(cmdfile, &cmd) < 0)
goto fail;
- if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &expectxml) < 0)
goto fail;
if (!(vmdef = qemuParseCommandLineString(driver.caps, cmd)))
@@ -75,7 +71,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
ret = 0;
fail:
+ free(expectxml);
free(actualxml);
+ free(cmd);
virDomainDefFree(vmdef);
return ret;
}
@@ -87,15 +85,26 @@ struct testInfo {
const char *migrateFrom;
};
-static int testCompareXMLToArgvHelper(const void *data) {
+static int
+testCompareXMLToArgvHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char args[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
- abs_srcdir, info->name);
- snprintf(args, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
- abs_srcdir, info->name);
- return testCompareXMLToArgvFiles(xml, args, !!info->extraFlags);
+ char *xml = NULL;
+ char *args = NULL;
+
+ if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&args, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
+
+ result = testCompareXMLToArgvFiles(xml, args, !!info->extraFlags);
+
+cleanup:
+ free(xml);
+ free(args);
+ return result;
}
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index 792b5ab..2522396 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -9,8 +9,6 @@
# include "qemu/qemu_capabilities.h"
# include "memory.h"
-# define MAX_HELP_OUTPUT_SIZE 1024*64
-
struct testInfo {
const char *name;
virBitmapPtr flags;
@@ -38,8 +36,7 @@ static int testHelpStrParsing(const void *data)
{
const struct testInfo *info = data;
char *path = NULL;
- char helpStr[MAX_HELP_OUTPUT_SIZE];
- char *help = &(helpStr[0]);
+ char *help = NULL;
unsigned int version, is_kvm, kvm_version;
virBitmapPtr flags = NULL;
int ret = -1;
@@ -49,7 +46,7 @@ static int testHelpStrParsing(const void *data)
if (virAsprintf(&path, "%s/qemuhelpdata/%s", abs_srcdir, info->name) < 0)
return -1;
- if (virtTestLoadFile(path, &help, MAX_HELP_OUTPUT_SIZE) < 0)
+ if (virtTestLoadFile(path, &help) < 0)
goto cleanup;
if (!(flags = qemuCapsNew()))
@@ -61,11 +58,12 @@ static int testHelpStrParsing(const void *data)
if (qemuCapsGet(info->flags, QEMU_CAPS_DEVICE)) {
VIR_FREE(path);
+ VIR_FREE(help);
if (virAsprintf(&path, "%s/qemuhelpdata/%s-device", abs_srcdir,
info->name) < 0)
goto cleanup;
- if (virtTestLoadFile(path, &help, MAX_HELP_OUTPUT_SIZE) < 0)
+ if (virtTestLoadFile(path, &help) < 0)
goto cleanup;
if (qemuCapsParseDeviceStr(help, flags) < 0)
@@ -111,6 +109,7 @@ static int testHelpStrParsing(const void *data)
ret = 0;
cleanup:
VIR_FREE(path);
+ VIR_FREE(help);
qemuCapsFree(flags);
VIR_FREE(got);
VIR_FREE(expected);
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index ebde3a1..a7e4cc0 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -22,16 +22,14 @@
static const char *abs_top_srcdir;
static struct qemud_driver driver;
-# define MAX_FILE 4096
-
static int testCompareXMLToArgvFiles(const char *xml,
const char *cmdline,
virBitmapPtr extraFlags,
const char *migrateFrom,
int migrateFd,
- bool expectError) {
- char argvData[MAX_FILE];
- char *expectargv = &(argvData[0]);
+ bool expectError)
+{
+ char *expectargv = NULL;
int len;
char *actualargv = NULL;
int ret = -1;
@@ -45,7 +43,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (!(conn = virGetConnect()))
goto fail;
- len = virtTestLoadFile(cmdline, &expectargv, MAX_FILE);
+ len = virtTestLoadFile(cmdline, &expectargv);
if (len < 0)
goto fail;
if (len && expectargv[len - 1] == '\n')
@@ -156,6 +154,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
fail:
free(log);
free(emulator);
+ free(expectargv);
free(actualargv);
virCommandFree(cmd);
virDomainDefFree(vmdef);
@@ -172,17 +171,28 @@ struct testInfo {
bool expectError;
};
-static int testCompareXMLToArgvHelper(const void *data) {
+static int
+testCompareXMLToArgvHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char args[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
- abs_srcdir, info->name);
- snprintf(args, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
- abs_srcdir, info->name);
- return testCompareXMLToArgvFiles(xml, args, info->extraFlags,
- info->migrateFrom, info->migrateFd,
- info->expectError);
+ char *xml = NULL;
+ char *args = NULL;
+
+ if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&args, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
+
+ 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)
{
int ret = 0;
- char map[PATH_MAX];
+ char *map = NULL;
abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir)
@@ -210,10 +220,11 @@ mymain(void)
return EXIT_FAILURE;
if (!(driver.spicePassword = strdup("123456")))
return EXIT_FAILURE;
-
- snprintf(map, PATH_MAX, "%s/src/cpu/cpu_map.xml", abs_top_srcdir);
- if (cpuMapOverride(map) < 0)
+ if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
+ cpuMapOverride(map) < 0) {
+ free(map);
return EXIT_FAILURE;
+ }
# define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \
do { \
@@ -484,6 +495,7 @@ mymain(void)
free(driver.stateDir);
virCapabilitiesFree(driver.caps);
+ free(map);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 6f51d1e..5bfbcab 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -17,21 +17,18 @@
static struct qemud_driver driver;
-# define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
+{
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virDomainDefPtr def = NULL;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
if (!(def = virDomainDefParseString(driver.caps, inXmlData,
@@ -49,6 +46,8 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0;
fail:
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virDomainDefFree(def);
return ret;
@@ -59,16 +58,19 @@ struct testInfo {
int different;
};
-static int testCompareXMLToXMLHelper(const void *data) {
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
const struct testInfo *info = data;
- char xml_in[PATH_MAX];
- char xml_out[PATH_MAX];
- int ret;
+ char *xml_in = NULL;
+ char *xml_out = NULL;
+ int ret = -1;
- snprintf(xml_in, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
- abs_srcdir, info->name);
- snprintf(xml_out, PATH_MAX, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
- abs_srcdir, info->name);
+ if (virAsprintf(&xml_in, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&xml_out, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
if (info->different) {
ret = testCompareXMLToXMLFiles(xml_in, xml_out);
@@ -76,6 +78,9 @@ static int testCompareXMLToXMLHelper(const void *data) {
ret = testCompareXMLToXMLFiles(xml_in, xml_in);
}
+cleanup:
+ free(xml_in);
+ free(xml_out);
return ret;
}
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
index 0919435..f465105 100644
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -15,15 +15,12 @@
static virCapsPtr caps;
-#define MAX_FILE 4096
-
-static int testCompareFiles(const char *xml, const char *sexpr,
- int xendConfigVersion) {
- char xmlData[MAX_FILE];
- char sexprData[MAX_FILE];
+static int
+testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *sexprData = NULL;
char *gotxml = NULL;
- char *xmlPtr = &(xmlData[0]);
- char *sexprPtr = &(sexprData[0]);
int id;
char * tty;
int vncport;
@@ -36,10 +33,10 @@ static int testCompareFiles(const char *xml, const char *sexpr,
conn = virGetConnect();
if (!conn) goto fail;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
- if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(sexpr, &sexprData) < 0)
goto fail;
memset(&priv, 0, sizeof priv);
@@ -70,6 +67,8 @@ static int testCompareFiles(const char *xml, const char *sexpr,
ret = 0;
fail:
+ free(xmlData);
+ free(sexprData);
free(gotxml);
virDomainDefFree(def);
if (conn)
@@ -84,17 +83,29 @@ struct testInfo {
int version;
};
-static int testCompareHelper(const void *data) {
+static int
+testCompareHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char args[PATH_MAX];
- 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);
-}
+ char *xml = NULL;
+ char *args = NULL;
+
+ 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
mymain(void)
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index 6641153..f2c1780 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -13,21 +13,18 @@
#include "storage_conf.h"
#include "testutilsqemu.h"
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
+{
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virStoragePoolDefPtr dev = NULL;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
if (!(dev = virStoragePoolDefParseString(inXmlData)))
@@ -44,21 +41,35 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0;
fail:
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virStoragePoolDefFree(dev);
return ret;
}
-static int testCompareXMLToXMLHelper(const void *data) {
- char inxml[PATH_MAX];
- char outxml[PATH_MAX];
- snprintf(inxml, PATH_MAX, "%s/storagepoolxml2xmlin/%s.xml",
- abs_srcdir, (const char*)data);
- snprintf(outxml, PATH_MAX, "%s/storagepoolxml2xmlout/%s.xml",
- abs_srcdir, (const char*)data);
- return testCompareXMLToXMLFiles(inxml, outxml);
-}
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ 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
mymain(void)
diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c
index 0cd57af..c8dddbb 100644
--- a/tests/storagevolxml2xmltest.c
+++ b/tests/storagevolxml2xmltest.c
@@ -13,28 +13,23 @@
#include "storage_conf.h"
#include "testutilsqemu.h"
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *poolxml,
- const char *inxml,
- const char *outxml) {
- char poolXmlData[MAX_FILE];
- char *poolXmlPtr = &(poolXmlData[0]);
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
+ const char *outxml)
+{
+ char *poolXmlData = NULL;
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virStoragePoolDefPtr pool = NULL;
virStorageVolDefPtr dev = NULL;
- if (virtTestLoadFile(poolxml, &poolXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(poolxml, &poolXmlData) < 0)
goto fail;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
if (!(pool = virStoragePoolDefParseString(poolXmlData)))
@@ -54,6 +49,9 @@ static int testCompareXMLToXMLFiles(const char *poolxml,
ret = 0;
fail:
+ free(poolXmlData);
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virStoragePoolDefFree(pool);
virStorageVolDefFree(dev);
@@ -65,19 +63,32 @@ struct testInfo {
const char *name;
};
-static int testCompareXMLToXMLHelper(const void *data) {
- char poolxml[PATH_MAX];
- char inxml[PATH_MAX];
- char outxml[PATH_MAX];
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
+ char *poolxml = NULL;
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
+ abs_srcdir, info->pool) < 0 ||
+ virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml",
+ abs_srcdir, info->name) < 0) {
+ goto cleanup;
+ }
+
+ result = testCompareXMLToXMLFiles(poolxml, inxml, outxml);
+
+cleanup:
+ free(poolxml);
+ free(inxml);
+ free(outxml);
- snprintf(poolxml, PATH_MAX, "%s/storagepoolxml2xmlin/%s.xml",
- abs_srcdir, (const char*)info->pool);
- snprintf(inxml, PATH_MAX, "%s/storagevolxml2xmlin/%s.xml",
- abs_srcdir, (const char*)info->name);
- snprintf(outxml, PATH_MAX, "%s/storagevolxml2xmlout/%s.xml",
- abs_srcdir, (const char*)info->name);
- return testCompareXMLToXMLFiles(poolxml, inxml, outxml);
+ return result;
}
diff --git a/tests/testutils.c b/tests/testutils.c
index 58b0275..bc89690 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -173,17 +173,16 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
return ret;
}
-/* Read FILE into buffer BUF of length BUFLEN.
- Upon any failure, or if FILE appears to contain more than BUFLEN bytes,
- diagnose it and return -1, but don't bother trying to preserve errno.
- Otherwise, return the number of bytes copied into BUF. */
-int virtTestLoadFile(const char *file,
- char **buf,
- int buflen) {
+/* Allocate BUF to the size of FILE. Read FILE into buffer BUF.
+ Upon any failure, diagnose it and return -1, but don't bother trying
+ to preserve errno. Otherwise, return the number of bytes copied into BUF. */
+int
+virtTestLoadFile(const char *file, char **buf)
+{
FILE *fp = fopen(file, "r");
struct stat st;
- char *tmp = *buf;
- int len, tmplen = buflen;
+ char *tmp;
+ int len, tmplen, buflen;
if (!fp) {
fprintf (stderr, "%s: failed to open: %s\n", file, strerror(errno));
@@ -196,17 +195,23 @@ int virtTestLoadFile(const char *file,
return -1;
}
- if (st.st_size > (buflen-1)) {
- fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
+ tmplen = buflen = st.st_size + 1;
+
+ if (VIR_ALLOC_N(*buf, buflen) < 0) {
+ fprintf (stderr, "%s: larger than available memory (> %d)\n", file, buflen);
VIR_FORCE_FCLOSE(fp);
return -1;
}
+ tmp = *buf;
(*buf)[0] = '\0';
if (st.st_size) {
/* read the file line by line */
while (fgets(tmp, tmplen, fp) != NULL) {
len = strlen(tmp);
+ /* stop on an empty line */
+ if (len == 0)
+ break;
/* remove trailing backslash-newline pair */
if (len >= 2 && tmp[len-2] == '\\' && tmp[len-1] == '\n') {
len -= 2;
@@ -219,6 +224,7 @@ int virtTestLoadFile(const char *file,
if (ferror(fp)) {
fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
VIR_FORCE_FCLOSE(fp);
+ free(*buf);
return -1;
}
}
@@ -268,10 +274,11 @@ void virtTestCaptureProgramExecChild(const char *const argv[],
VIR_FORCE_CLOSE(stdinfd);
}
-int virtTestCaptureProgramOutput(const char *const argv[],
- char **buf,
- int buflen) {
+int
+virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen)
+{
int pipefd[2];
+ int len;
if (pipe(pipefd) < 0)
return -1;
@@ -289,34 +296,20 @@ int virtTestCaptureProgramOutput(const char *const argv[],
return -1;
default:
- {
- int got = 0;
- int ret = -1;
- int want = buflen-1;
-
- VIR_FORCE_CLOSE(pipefd[1]);
-
- 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);
+ VIR_FORCE_CLOSE(pipefd[1]);
+ len = virFileReadLimFD(pipefd[0], maxlen, buf);
+ VIR_FORCE_CLOSE(pipefd[0]);
+ waitpid(pid, NULL, 0);
- return ret;
- }
+ return len;
}
}
#else /* !WIN32 */
-int virtTestCaptureProgramOutput(const char *const argv[] ATTRIBUTE_UNUSED,
- char **buf ATTRIBUTE_UNUSED,
- int buflen ATTRIBUTE_UNUSED) {
+int
+virtTestCaptureProgramOutput(const char *const argv[] ATTRIBUTE_UNUSED,
+ char **buf ATTRIBUTE_UNUSED,
+ int maxlen ATTRIBUTE_UNUSED)
+{
return -1;
}
#endif /* !WIN32 */
diff --git a/tests/testutils.h b/tests/testutils.h
index 0ea70ee..e8f4153 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -27,12 +27,8 @@ int virtTestRun(const char *title,
int nloops,
int (*body)(const void *data),
const void *data);
-int virtTestLoadFile(const char *name,
- char **buf,
- int buflen);
-int virtTestCaptureProgramOutput(const char *const argv[],
- char **buf,
- int buflen);
+int virtTestLoadFile(const char *file, char **buf);
+int virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
int virtTestClearLineRegex(const char *pattern,
char *string);
diff --git a/tests/virshtest.c b/tests/virshtest.c
index 465d5ea..0932efd 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -6,10 +6,9 @@
#include "internal.h"
#include "xml.h"
+#include "util.h"
#include "testutils.h"
-#define MAX_FILE 4096
-
#define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493"
static const char *dominfo_fc4 = "\
@@ -45,41 +44,31 @@ static int testFilterLine(char *buffer,
return 0;
}
-static int testCompareOutputLit(const char *expectData,
- const char *filter, const char *const argv[]) {
- char actualData[MAX_FILE];
- char *actualPtr = &(actualData[0]);
+static int
+testCompareOutputLit(const char *expectData,
+ const char *filter, const char *const argv[])
+{
+ int result = -1;
+ char *actualData = NULL;
- if (virtTestCaptureProgramOutput(argv, &actualPtr, MAX_FILE) < 0)
- return -1;
+ if (virtTestCaptureProgramOutput(argv, &actualData, 4096) < 0)
+ goto cleanup;
- if (filter)
- if (testFilterLine(actualData, filter) < 0)
- return -1;
+ if (filter && testFilterLine(actualData, filter) < 0)
+ goto cleanup;
- if (STRNEQ(expectData, actualData)) {
- virtTestDifference(stderr, expectData, actualData);
- return -1;
- }
+ if (STRNEQ(expectData, actualData)) {
+ virtTestDifference(stderr, expectData, actualData);
+ goto cleanup;
+ }
- return 0;
-}
-
-#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];
+ result = 0;
- snprintf(expect, sizeof expect - 1, "%s/%s", abs_srcdir, expect_rel);
+cleanup:
+ free(actualData);
- if (virtTestLoadFile(expect, &expectPtr, MAX_FILE) < 0)
- return -1;
-
- return testCompareOutputLit(expectData, filter, argv);
+ return result;
}
-#endif
#define VIRSH_DEFAULT "../tools/virsh", \
"--connect", \
@@ -233,16 +222,14 @@ static int
mymain(void)
{
int ret = 0;
- char buffer[PATH_MAX];
#ifdef WIN32
exit (EXIT_AM_SKIP);
#endif
- snprintf(buffer, PATH_MAX-1,
- "test://%s/../examples/xml/test/testnode.xml", abs_srcdir);
- buffer[PATH_MAX-1] = '\0';
- custom_uri = buffer;
+ if (virAsprintf(&custom_uri, "test://%s/../examples/xml/test/testnode.xml",
+ abs_srcdir) < 0)
+ return EXIT_FAILURE;
if (virtTestRun("virsh list (default)",
1, testCompareListDefault, NULL) != 0)
@@ -394,6 +381,7 @@ mymain(void)
#undef DO_TEST
+ free(custom_uri);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index 3b7e9be..e01e8ad 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -11,11 +11,9 @@
# include "testutils.h"
# include "vmx/vmx.h"
-static virCapsPtr caps = NULL;
+static virCapsPtr caps;
static virVMXContext ctx;
-# define MAX_FILE 4096
-
static void
testCapsInit(void)
{
@@ -69,19 +67,17 @@ static int
testCompareFiles(const char *vmx, const char *xml)
{
int result = -1;
- char vmxData[MAX_FILE];
- char xmlData[MAX_FILE];
+ char *vmxData = NULL;
+ char *xmlData = NULL;
char *formatted = NULL;
- char *vmxPtr = &(vmxData[0]);
- char *xmlPtr = &(xmlData[0]);
virDomainDefPtr def = NULL;
virErrorPtr err = NULL;
- if (virtTestLoadFile(vmx, &vmxPtr, MAX_FILE) < 0) {
+ if (virtTestLoadFile(vmx, &vmxData) < 0) {
goto failure;
}
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) {
+ if (virtTestLoadFile(xml, &xmlData) < 0) {
goto failure;
}
@@ -109,6 +105,8 @@ testCompareFiles(const char *vmx, const char *xml)
result = 0;
failure:
+ VIR_FREE(vmxData);
+ VIR_FREE(xmlData);
VIR_FREE(formatted);
virDomainDefFree(def);
@@ -123,16 +121,25 @@ struct testInfo {
static int
testCompareHelper(const void *data)
{
+ int result = -1;
const struct testInfo *info = data;
- char vmx[PATH_MAX];
- char xml[PATH_MAX];
+ char *vmx = NULL;
+ char *xml = NULL;
+
+ if (virAsprintf(&vmx, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir,
+ info->input) < 0 ||
+ virAsprintf(&xml, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
+ info->output) < 0) {
+ goto cleanup;
+ }
- snprintf(vmx, PATH_MAX, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir,
- info->input);
- snprintf(xml, PATH_MAX, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
- info->output);
+ result = testCompareFiles(vmx, xml);
- return testCompareFiles(vmx, xml);
+ cleanup:
+ VIR_FREE(vmx);
+ VIR_FREE(xml);
+
+ return result;
}
static char *
diff --git a/tests/xencapstest.c b/tests/xencapstest.c
index 36946cf..3f96cf2 100644
--- a/tests/xencapstest.c
+++ b/tests/xencapstest.c
@@ -11,32 +11,27 @@
#include "xen/xen_hypervisor.h"
#include "files.h"
-#define MAX_FILE 4096
-
-static int testCompareFiles(const char *hostmachine,
- const char *xml_rel,
- const char *cpuinfo_rel,
- const char *capabilities_rel) {
- char xmlData[MAX_FILE];
- char *expectxml = &(xmlData[0]);
+static int
+testCompareFiles(const char *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;
int ret = -1;
- char xml[PATH_MAX];
- char cpuinfo[PATH_MAX];
- char capabilities[PATH_MAX];
+ char *xml = NULL;
+ char *cpuinfo = NULL;
+ char *capabilities = NULL;
- snprintf(xml, sizeof xml - 1, "%s/%s",
- abs_srcdir, xml_rel);
- snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/%s",
- abs_srcdir, cpuinfo_rel);
- snprintf(capabilities, sizeof capabilities - 1, "%s/%s",
- abs_srcdir, capabilities_rel);
+ if (virAsprintf(&xml, "%s/%s", abs_srcdir, xml_rel) < 0 ||
+ virAsprintf(&cpuinfo, "%s/%s", abs_srcdir, cpuinfo_rel) < 0 ||
+ virAsprintf(&capabilities, "%s/%s", abs_srcdir, capabilities_rel) < 0)
+ goto fail;
- if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &expectxml) < 0)
goto fail;
if (!(fp1 = fopen(cpuinfo, "r")))
@@ -59,8 +54,11 @@ static int testCompareFiles(const char *hostmachine,
ret = 0;
fail:
-
+ free(expectxml);
free(actualxml);
+ free(xml);
+ free(cpuinfo);
+ free(capabilities);
VIR_FORCE_FCLOSE(fp1);
VIR_FORCE_FCLOSE(fp2);
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 62d3488..02a8900 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -38,30 +38,29 @@
static virCapsPtr caps;
-#define MAX_FILE 4096
-
-static int testCompareParseXML(const char *xmcfg, const char *xml,
- int xendConfigVersion) {
- char xmlData[MAX_FILE];
- char xmcfgData[MAX_FILE];
- char gotxmcfgData[MAX_FILE];
- char *xmlPtr = &(xmlData[0]);
- char *xmcfgPtr = &(xmcfgData[0]);
- char *gotxmcfgPtr = &(gotxmcfgData[0]);
+static int
+testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *xmcfgData = NULL;
+ char *gotxmcfgData = NULL;
virConfPtr conf = NULL;
int ret = -1;
virConnectPtr conn;
- int wrote = MAX_FILE;
+ int wrote = 4096;
struct _xenUnifiedPrivate priv;
virDomainDefPtr def = NULL;
+ if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
+ goto fail;
+
conn = virGetConnect();
if (!conn) goto fail;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
- if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
goto fail;
/* Many puppies died to bring you this code. */
@@ -69,16 +68,16 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
priv.caps = caps;
conn->privateData = &priv;
- if (!(def = virDomainDefParseString(caps, xmlPtr,
+ if (!(def = virDomainDefParseString(caps, xmlData,
VIR_DOMAIN_XML_INACTIVE)))
goto fail;
if (!(conf = xenFormatXM(conn, def, xendConfigVersion)))
goto fail;
- if (virConfWriteMem(gotxmcfgPtr, &wrote, conf) < 0)
+ if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)
goto fail;
- gotxmcfgPtr[wrote] = '\0';
+ gotxmcfgData[wrote] = '\0';
if (STRNEQ(xmcfgData, gotxmcfgData)) {
virtTestDifference(stderr, xmcfgData, gotxmcfgData);
@@ -88,6 +87,9 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
ret = 0;
fail:
+ free(xmlData);
+ free(xmcfgData);
+ free(gotxmcfgData);
if (conf)
virConfFree(conf);
virDomainDefFree(def);
@@ -96,12 +98,11 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
return ret;
}
-static int testCompareFormatXML(const char *xmcfg, const char *xml,
- int xendConfigVersion) {
- char xmlData[MAX_FILE];
- char xmcfgData[MAX_FILE];
- char *xmlPtr = &(xmlData[0]);
- char *xmcfgPtr = &(xmcfgData[0]);
+static int
+testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *xmcfgData = NULL;
char *gotxml = NULL;
virConfPtr conf = NULL;
int ret = -1;
@@ -112,10 +113,10 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
conn = virGetConnect();
if (!conn) goto fail;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
- if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
goto fail;
/* Many puppies died to bring you this code. */
@@ -123,7 +124,7 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
priv.caps = caps;
conn->privateData = &priv;
- if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr), 0)))
+ if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0)))
goto fail;
if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps)))
@@ -142,6 +143,8 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
fail:
if (conf)
virConfFree(conf);
+ VIR_FREE(xmlData);
+ VIR_FREE(xmcfgData);
VIR_FREE(gotxml);
virDomainDefFree(def);
virUnrefConnect(conn);
@@ -156,18 +159,30 @@ struct testInfo {
int mode;
};
-static int testCompareHelper(const void *data) {
+static int
+testCompareHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char cfg[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/xmconfigdata/test-%s.xml",
- abs_srcdir, info->name);
- snprintf(cfg, PATH_MAX, "%s/xmconfigdata/test-%s.cfg",
- abs_srcdir, info->name);
+ char *xml = NULL;
+ char *cfg = NULL;
+
+ if (virAsprintf(&xml, "%s/xmconfigdata/test-%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&cfg, "%s/xmconfigdata/test-%s.cfg",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
+
if (info->mode == 0)
- return testCompareParseXML(cfg, xml, info->version);
+ result = testCompareParseXML(cfg, xml, info->version);
else
- return testCompareFormatXML(cfg, xml, info->version);
+ result = testCompareFormatXML(cfg, xml, info->version);
+
+cleanup:
+ free(xml);
+ free(cfg);
+
+ return result;
}
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index b258c3d..dab8c84 100644
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -16,22 +16,19 @@
static virCapsPtr caps;
-#define MAX_FILE 4096
-
-static int testCompareFiles(const char *xml, const char *sexpr,
- int xendConfigVersion) {
- char xmlData[MAX_FILE];
- char sexprData[MAX_FILE];
+static int
+testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *sexprData = NULL;
char *gotsexpr = NULL;
- char *xmlPtr = &(xmlData[0]);
- char *sexprPtr = &(sexprData[0]);
int ret = -1;
virDomainDefPtr def = NULL;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
- if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(sexpr, &sexprData) < 0)
goto fail;
if (!(def = virDomainDefParseString(caps, xmlData,
@@ -49,8 +46,10 @@ static int testCompareFiles(const char *xml, const char *sexpr,
ret = 0;
fail:
- virDomainDefFree(def);
+ free(xmlData);
+ free(sexprData);
free(gotsexpr);
+ virDomainDefFree(def);
return ret;
}
@@ -62,17 +61,29 @@ struct testInfo {
int version;
};
-static int testCompareHelper(const void *data) {
+static int
+testCompareHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char args[PATH_MAX];
- 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);
-}
+ char *xml = NULL;
+ char *args = NULL;
+
+ 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
mymain(void)
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index 6a4b795..efd4d74 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -11,11 +11,9 @@
# include "testutils.h"
# include "vmx/vmx.h"
-static virCapsPtr caps = NULL;
+static virCapsPtr caps;
static virVMXContext ctx;
-# define MAX_FILE 4096
-
static void
testCapsInit(void)
{
@@ -69,18 +67,16 @@ static int
testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
{
int result = -1;
- char xmlData[MAX_FILE];
- char vmxData[MAX_FILE];
+ char *xmlData = NULL;
+ char *vmxData = NULL;
char *formatted = NULL;
- char *xmlPtr = &(xmlData[0]);
- char *vmxPtr = &(vmxData[0]);
virDomainDefPtr def = NULL;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) {
+ if (virtTestLoadFile(xml, &xmlData) < 0) {
goto failure;
}
- if (virtTestLoadFile(vmx, &vmxPtr, MAX_FILE) < 0) {
+ if (virtTestLoadFile(vmx, &vmxData) < 0) {
goto failure;
}
@@ -104,6 +100,8 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
result = 0;
failure:
+ VIR_FREE(xmlData);
+ VIR_FREE(vmxData);
VIR_FREE(formatted);
virDomainDefFree(def);
@@ -119,16 +117,25 @@ struct testInfo {
static int
testCompareHelper(const void *data)
{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char vmx[PATH_MAX];
+ char *xml = NULL;
+ char *vmx = NULL;
+
+ if (virAsprintf(&xml, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir,
+ info->input) < 0 ||
+ virAsprintf(&vmx, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
+ info->output) < 0) {
+ goto cleanup;
+ }
+
+ result = testCompareFiles(xml, vmx, info->virtualHW_version);
- snprintf(xml, PATH_MAX, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir,
- info->input);
- snprintf(vmx, PATH_MAX, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
- info->output);
+ cleanup:
+ VIR_FREE(xml);
+ VIR_FREE(vmx);
- return testCompareFiles(xml, vmx, info->virtualHW_version);
+ return result;
}
static int
--
1.7.0.4
13 years, 8 months
[libvirt] [PATCH] nwfilter: Fix memory leak in the ebtables subdriver
by Matthias Bolte
Call shutdown functions for all subcompontents in nwfilterDriverShutdown.
Make sure that this shutdown functions can safely be called multiple times
and independent from the actual subcompontents state.
---
src/conf/nwfilter_conf.c | 8 ++++++++
src/nwfilter/nwfilter_driver.c | 2 ++
src/nwfilter/nwfilter_learnipaddr.c | 5 ++++-
3 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 09dc32b..615c0f1 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -125,6 +125,7 @@ struct int_map {
* only one filter update allowed
*/
static virMutex updateMutex;
+static bool initialized = false;
void
virNWFilterLockFilterUpdates(void) {
@@ -2971,6 +2972,8 @@ int virNWFilterConfLayerInit(virHashIterator domUpdateCB)
{
virNWFilterDomainFWUpdateCB = domUpdateCB;
+ initialized = true;
+
if (virMutexInitRecursive(&updateMutex))
return 1;
@@ -2980,7 +2983,12 @@ int virNWFilterConfLayerInit(virHashIterator domUpdateCB)
void virNWFilterConfLayerShutdown(void)
{
+ if (!initialized)
+ return;
+
virMutexDestroy(&updateMutex);
+
+ initialized = false;
}
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index a579306..8af3f8a 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -199,6 +199,8 @@ nwfilterDriverShutdown(void) {
if (!driverState)
return -1;
+ virNWFilterConfLayerShutdown();
+ virNWFilterTechDriversShutdown();
virNWFilterLearnShutdown();
nwfilterDriverLock(driverState);
diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c
index 9ee439a..96d2a55 100644
--- a/src/nwfilter/nwfilter_learnipaddr.c
+++ b/src/nwfilter/nwfilter_learnipaddr.c
@@ -873,7 +873,10 @@ virNWFilterLearnThreadsTerminate(bool allowNewThreads) {
* Shutdown of this layer
*/
void
-virNWFilterLearnShutdown(void) {
+virNWFilterLearnShutdown(void)
+{
+ if (!pendingLearnReq)
+ return;
virNWFilterLearnThreadsTerminate(false);
--
1.7.0.4
13 years, 8 months
[libvirt] [PATCH] qemu: Fix qemuDomainModifyDeviceFlags leaking the caps bitmap
by Matthias Bolte
---
src/qemu/qemu_driver.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b277cc5..a19c4a7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4316,6 +4316,7 @@ endjob:
vm = NULL;
cleanup:
+ qemuCapsFree(qemuCaps);
virDomainDefFree(vmdef);
virDomainDeviceDefFree(dev);
if (vm)
--
1.7.0.4
13 years, 8 months
[libvirt] [PATCH] Fix memory leak in __virExec
by Matthias Bolte
Commit e0d014f2379dd made binary potentially allocated on the heap.
It was freed in the parent in the error path, but not in the success path
that doesn't goto the cleanup label.
Found by 'make -C tests valgrind'.
---
src/util/util.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c
index c337aa9..37472bb 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -568,6 +568,10 @@ __virExec(const char *const*argv,
}
*retpid = pid;
+
+ if (binary != argv[0])
+ VIR_FREE(binary);
+
return 0;
}
--
1.7.0.4
13 years, 8 months
[libvirt] [PATCH] hash: fix memory leak and regression
by Eric Blake
Commit 1671d1d introduced a memory leak in virHashFree, and
wholesale table corruption in virHashRemoveSet (elements not
requested to be freed are lost).
* src/util/hash.c (virHashFree): Free bucket array.
(virHashRemoveSet): Don't lose elements.
* tests/hashtest.c (testHashCheckForEachCount): New method.
(testHashCheckCount): Expose the bug.
---
src/util/hash.c | 6 +++---
tests/hashtest.c | 15 +++++++++++++++
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/util/hash.c b/src/util/hash.c
index a9b09b0..5366dd6 100644
--- a/src/util/hash.c
+++ b/src/util/hash.c
@@ -269,6 +269,7 @@ virHashFree(virHashTablePtr table)
}
}
+ VIR_FREE(table->table);
VIR_FREE(table);
}
@@ -532,13 +533,12 @@ int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data)
* virHashRemoveSet
* @table: the hash table to process
* @iter: callback to identify elements for removal
- * @f: callback to free memory from element payload
* @data: opaque data to pass to the iterator
*
* Iterates over all elements in the hash table, invoking the 'iter'
* callback. If the callback returns a non-zero value, the element
* will be removed from the hash table & its payload passed to the
- * callback 'f' for de-allocation.
+ * data freer callback registered at creation.
*
* Returns number of items removed on success, -1 on failure
*/
@@ -562,7 +562,7 @@ int virHashRemoveSet(virHashTablePtr table,
while (*nextptr) {
virHashEntryPtr entry = *nextptr;
if (!iter(entry->payload, entry->name, data)) {
- *nextptr = entry->next;
+ nextptr = &entry->next;
} else {
count++;
if (table->dataFree)
diff --git a/tests/hashtest.c b/tests/hashtest.c
index 525ae06..f02b3a9 100644
--- a/tests/hashtest.c
+++ b/tests/hashtest.c
@@ -61,16 +61,31 @@ testHashInit(int size)
return hash;
}
+static void
+testHashCheckForEachCount(void *payload ATTRIBUTE_UNUSED,
+ const void *name ATTRIBUTE_UNUSED,
+ void *data ATTRIBUTE_UNUSED)
+{
+}
static int
testHashCheckCount(virHashTablePtr hash, int count)
{
+ int iter_count = 0;
+
if (virHashSize(hash) != count) {
testError("\nhash contains %d instead of %d elements\n",
virHashSize(hash), count);
return -1;
}
+ iter_count = virHashForEach(hash, testHashCheckForEachCount, NULL);
+ if (count != iter_count) {
+ testError("\nhash claims to have %d elements but iteration finds %d\n",
+ count, iter_count);
+ return -1;
+ }
+
return 0;
}
--
1.7.4.4
13 years, 8 months
[libvirt] [PATCH v2] util: Simplify hash implementation
by Jiri Denemark
So far first entries for each hash key are stored directly in the hash
table while other entries mapped to the same key are linked through
pointers. As a result of that, the code is cluttered with special
handling for the first items.
This patch makes all entries (even the first ones) linked through
pointers, which significantly simplifies the code and makes it more
maintainable.
---
src/util/hash.c | 294 +++++++++++++++++--------------------------------------
1 files changed, 92 insertions(+), 202 deletions(-)
diff --git a/src/util/hash.c b/src/util/hash.c
index fc7652d..dbb34ec 100644
--- a/src/util/hash.c
+++ b/src/util/hash.c
@@ -50,14 +50,13 @@ struct _virHashEntry {
struct _virHashEntry *next;
void *name;
void *payload;
- int valid;
};
/*
* The entire hash table
*/
struct _virHashTable {
- struct _virHashEntry *table;
+ virHashEntryPtr *table;
int size;
int nbElems;
/* True iff we are iterating over hash entries. */
@@ -165,7 +164,7 @@ virHashTablePtr virHashCreateFull(int size,
*
* Create a new virHashTablePtr.
*
- * Returns the newly created object, or NULL if an error occured.
+ * Returns the newly created object, or NULL if an error occurred.
*/
virHashTablePtr virHashCreate(int size, virHashDataFree dataFree)
{
@@ -189,10 +188,8 @@ virHashTablePtr virHashCreate(int size, virHashDataFree dataFree)
static int
virHashGrow(virHashTablePtr table, int size)
{
- unsigned long key;
int oldsize, i;
- virHashEntryPtr iter, next;
- struct _virHashEntry *oldtable;
+ virHashEntryPtr *oldtable;
#ifdef DEBUG_GROW
unsigned long nbElem = 0;
@@ -217,43 +214,18 @@ virHashGrow(virHashTablePtr table, int size)
}
table->size = size;
- /* If the two loops are merged, there would be situations where
- * a new entry needs to allocated and data copied into it from
- * the main table. So instead, we run through the array twice, first
- * copying all the elements in the main array (where we can't get
- * conflicts) and then the rest, so we only free (and don't allocate)
- */
- for (i = 0; i < oldsize; i++) {
- if (oldtable[i].valid == 0)
- continue;
- key = virHashComputeKey(table, oldtable[i].name);
- memcpy(&(table->table[key]), &(oldtable[i]), sizeof(virHashEntry));
- table->table[key].next = NULL;
- }
-
for (i = 0; i < oldsize; i++) {
- iter = oldtable[i].next;
+ virHashEntryPtr iter = oldtable[i];
while (iter) {
- next = iter->next;
-
- /*
- * put back the entry in the new table
- */
+ virHashEntryPtr next = iter->next;
+ unsigned long key = virHashComputeKey(table, iter->name);
- key = virHashComputeKey(table, iter->name);
- if (table->table[key].valid == 0) {
- memcpy(&(table->table[key]), iter, sizeof(virHashEntry));
- table->table[key].next = NULL;
- VIR_FREE(iter);
- } else {
- iter->next = table->table[key].next;
- table->table[key].next = iter;
- }
+ iter->next = table->table[key];
+ table->table[key] = iter;
#ifdef DEBUG_GROW
nbElem++;
#endif
-
iter = next;
}
}
@@ -279,36 +251,24 @@ void
virHashFree(virHashTablePtr table)
{
int i;
- virHashEntryPtr iter;
- virHashEntryPtr next;
- int inside_table = 0;
- int nbElems;
if (table == NULL)
return;
- if (table->table) {
- nbElems = table->nbElems;
- for (i = 0; (i < table->size) && (nbElems > 0); i++) {
- iter = &(table->table[i]);
- if (iter->valid == 0)
- continue;
- inside_table = 1;
- while (iter) {
- next = iter->next;
- if ((table->dataFree != NULL) && (iter->payload != NULL))
- table->dataFree(iter->payload, iter->name);
- if (table->keyFree)
- table->keyFree(iter->name);
- iter->payload = NULL;
- if (!inside_table)
- VIR_FREE(iter);
- nbElems--;
- inside_table = 0;
- iter = next;
- }
+
+ for (i = 0; i < table->size; i++) {
+ virHashEntryPtr iter = table->table[i];
+ while (iter) {
+ virHashEntryPtr next = iter->next;
+
+ if (table->dataFree)
+ table->dataFree(iter->payload, iter->name);
+ if (table->keyFree)
+ table->keyFree(iter->name);
+ VIR_FREE(iter);
+ iter = next;
}
- VIR_FREE(table->table);
}
+
VIR_FREE(table);
}
@@ -319,9 +279,7 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const void *name,
{
unsigned long key, len = 0;
virHashEntryPtr entry;
- virHashEntryPtr insert;
char *new_name;
- bool found;
if ((table == NULL) || (name == NULL))
return (-1);
@@ -329,67 +287,40 @@ virHashAddOrUpdateEntry(virHashTablePtr table, const void *name,
if (table->iterating)
virHashIterationError(-1);
- /*
- * Check for duplicate and insertion location.
- */
- found = false;
key = virHashComputeKey(table, name);
- if (table->table[key].valid == 0) {
- insert = NULL;
- } else {
- for (insert = &(table->table[key]); insert->next != NULL;
- insert = insert->next) {
- if (table->keyEqual(insert->name, name)) {
- found = true;
- break;
- }
- len++;
- }
- if (table->keyEqual(insert->name, name))
- found = true;
- }
-
- if (found) {
- if (is_update) {
- if (table->dataFree)
- table->dataFree(insert->payload, insert->name);
- insert->payload = userdata;
- return (0);
- } else {
- return (-1);
- }
- }
- if (insert == NULL) {
- entry = &(table->table[key]);
- } else {
- if (VIR_ALLOC(entry) < 0) {
- virReportOOMError();
- return (-1);
+ /* Check for duplicate entry */
+ for (entry = table->table[key]; entry; entry = entry->next) {
+ if (table->keyEqual(entry->name, name)) {
+ if (is_update) {
+ if (table->dataFree)
+ table->dataFree(entry->payload, entry->name);
+ entry->payload = userdata;
+ return 0;
+ } else {
+ return -1;
+ }
}
+ len++;
}
- new_name = table->keyCopy(name);
- if (new_name == NULL) {
+ if (VIR_ALLOC(entry) < 0 || !(new_name = table->keyCopy(name))) {
virReportOOMError();
- if (insert != NULL)
- VIR_FREE(entry);
- return (-1);
+ VIR_FREE(entry);
+ return -1;
}
+
entry->name = new_name;
entry->payload = userdata;
- entry->next = NULL;
- entry->valid = 1;
-
- if (insert != NULL)
- insert->next = entry;
+ entry->next = table->table[key];
+ table->table[key] = entry;
table->nbElems++;
if (len > MAX_HASH_LEN)
virHashGrow(table, MAX_HASH_LEN * table->size);
- return (0);
+ return 0;
}
/**
@@ -443,18 +374,15 @@ virHashLookup(virHashTablePtr table, const void *name)
unsigned long key;
virHashEntryPtr entry;
- if (table == NULL)
- return (NULL);
- if (name == NULL)
- return (NULL);
+ if (!table || !name)
+ return NULL;
+
key = virHashComputeKey(table, name);
- if (table->table[key].valid == 0)
- return (NULL);
- for (entry = &(table->table[key]); entry != NULL; entry = entry->next) {
+ for (entry = table->table[key]; entry; entry = entry->next) {
if (table->keyEqual(entry->name, name))
- return (entry->payload);
+ return entry->payload;
}
- return (NULL);
+ return NULL;
}
@@ -512,47 +440,31 @@ virHashSize(virHashTablePtr table)
int
virHashRemoveEntry(virHashTablePtr table, const void *name)
{
- unsigned long key;
virHashEntryPtr entry;
- virHashEntryPtr prev = NULL;
+ virHashEntryPtr *nextptr;
if (table == NULL || name == NULL)
return (-1);
- key = virHashComputeKey(table, name);
- if (table->table[key].valid == 0) {
- return (-1);
- } else {
- for (entry = &(table->table[key]); entry != NULL;
- entry = entry->next) {
- if (table->keyEqual(entry->name, name)) {
- if (table->iterating && table->current != entry)
- virHashIterationError(-1);
- if (table->dataFree && (entry->payload != NULL))
- table->dataFree(entry->payload, entry->name);
- entry->payload = NULL;
- if (table->keyFree)
- table->keyFree(entry->name);
- if (prev) {
- prev->next = entry->next;
- VIR_FREE(entry);
- } else {
- if (entry->next == NULL) {
- entry->valid = 0;
- } else {
- entry = entry->next;
- memcpy(&(table->table[key]), entry,
- sizeof(virHashEntry));
- VIR_FREE(entry);
- }
- }
- table->nbElems--;
- return (0);
- }
- prev = entry;
+ nextptr = table->table + virHashComputeKey(table, name);
+ for (entry = *nextptr; entry; entry = entry->next) {
+ if (table->keyEqual(entry->name, name)) {
+ if (table->iterating && table->current != entry)
+ virHashIterationError(-1);
+
+ if (table->dataFree)
+ table->dataFree(entry->payload, entry->name);
+ if (table->keyFree)
+ table->keyFree(entry->name);
+ *nextptr = entry->next;
+ VIR_FREE(entry);
+ table->nbElems--;
+ return 0;
}
- return (-1);
+ nextptr = &entry->next;
}
+
+ return -1;
}
@@ -581,23 +493,15 @@ int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data)
table->iterating = true;
table->current = NULL;
for (i = 0 ; i < table->size ; i++) {
- virHashEntryPtr entry = table->table + i;
+ virHashEntryPtr entry = table->table[i];
while (entry) {
virHashEntryPtr next = entry->next;
- if (entry->valid) {
- void *name = (entry == table->table + i) ? entry->name : NULL;
- table->current = entry;
- iter(entry->payload, entry->name, data);
- table->current = NULL;
- count++;
+ table->current = entry;
+ iter(entry->payload, entry->name, data);
+ table->current = NULL;
- /* revisit current entry if it was the first one in collision
- * list and its content changed, i.e. it was deleted by iter()
- */
- if (name && name != entry->name)
- continue;
- }
+ count++;
entry = next;
}
}
@@ -620,7 +524,10 @@ int virHashForEach(virHashTablePtr table, virHashIterator iter, void *data)
*
* Returns number of items removed on success, -1 on failure
*/
-int virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, const void *data) {
+int virHashRemoveSet(virHashTablePtr table,
+ virHashSearcher iter,
+ const void *data)
+{
int i, count = 0;
if (table == NULL || iter == NULL)
@@ -632,44 +539,27 @@ int virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, const void *da
table->iterating = true;
table->current = NULL;
for (i = 0 ; i < table->size ; i++) {
- virHashEntryPtr prev = NULL;
- virHashEntryPtr entry = &(table->table[i]);
+ virHashEntryPtr *nextptr = table->table + i;
- while (entry && entry->valid) {
- if (iter(entry->payload, entry->name, data)) {
+ while (*nextptr) {
+ virHashEntryPtr entry = *nextptr;
+ if (!iter(entry->payload, entry->name, data)) {
+ *nextptr = entry->next;
+ } else {
count++;
if (table->dataFree)
table->dataFree(entry->payload, entry->name);
if (table->keyFree)
table->keyFree(entry->name);
+ *nextptr = entry->next;
+ VIR_FREE(entry);
table->nbElems--;
- if (prev) {
- prev->next = entry->next;
- VIR_FREE(entry);
- entry = prev;
- } else {
- if (entry->next == NULL) {
- entry->valid = 0;
- entry->name = NULL;
- } else {
- entry = entry->next;
- memcpy(&(table->table[i]), entry,
- sizeof(virHashEntry));
- VIR_FREE(entry);
- entry = &(table->table[i]);
- continue;
- }
- }
- }
- prev = entry;
- if (entry) {
- entry = entry->next;
}
}
}
table->iterating = false;
- return (count);
+ return count;
}
/**
@@ -683,7 +573,10 @@ int virHashRemoveSet(virHashTablePtr table, virHashSearcher iter, const void *da
* returns non-zero will be returned by this function.
* The elements are processed in a undefined order
*/
-void *virHashSearch(virHashTablePtr table, virHashSearcher iter, const void *data) {
+void *virHashSearch(virHashTablePtr table,
+ virHashSearcher iter,
+ const void *data)
+{
int i;
if (table == NULL || iter == NULL)
@@ -695,18 +588,15 @@ void *virHashSearch(virHashTablePtr table, virHashSearcher iter, const void *dat
table->iterating = true;
table->current = NULL;
for (i = 0 ; i < table->size ; i++) {
- virHashEntryPtr entry = table->table + i;
- while (entry) {
- if (entry->valid) {
- if (iter(entry->payload, entry->name, data)) {
- table->iterating = false;
- return entry->payload;
- }
+ virHashEntryPtr entry;
+ for (entry = table->table[i]; entry; entry = entry->next) {
+ if (iter(entry->payload, entry->name, data)) {
+ table->iterating = false;
+ return entry->payload;
}
- entry = entry->next;
}
}
table->iterating = false;
- return (NULL);
+ return NULL;
}
--
1.7.5.rc1
13 years, 8 months
[libvirt] [PATCH] docs: Document <filesystem> device
by Cole Robinson
Tried to dredge through old changelogs and commits to come up with it, so
may not be completely accurate.
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
docs/formatdomain.html.in | 107 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 107 insertions(+), 0 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a055b38..eafb983 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -903,6 +903,113 @@
</dd>
</dl>
+ <h4><a name="elementsFilesystems">Filesystems</a></h4>
+
+ <p>
+ A directory on the host that can be accessed directly from the guest.
+ <span class="since">since 0.3.3 for containers, since 0.8.5 for QEMU/KVM</span>
+ </p>
+
+<pre>
+ ...
+ <devices>
+ <filesystem type='template'>
+ <source name='my-vm-template'/>
+ <target dir='/'/>
+ </filesystem>
+ <filesystem type='mount' >
+ <source dir='/export/to/guest'/>
+ <target dir='/import/from/host'/>
+ <readonly/>
+ </filesystem>
+ ...
+ </devices>
+ ...</pre>
+
+ <dl>
+ <dt><code>filesystem</code></dt>
+ <dd>
+
+ The filesystem attribute <code>type</code> specifies the type of the
+ <code>source</code>. The possible values are:
+
+ <dl>
+ <dt><code>type='mount'</code></dt>
+ <dd>
+ A host directory to mount in the guest. Used by LXC,
+ OpenVZ <span class="since">(since 0.6.2)</span>
+ and QEMU/KVM <span class="since">(since 0.8.5)</span>.
+ This is the default <code>mode</code> if one is not specified.
+ </dd>
+ <dt><code>type='template'</code></dt>
+ <dd>
+ OpenVZ filesystem template. Only used by OpenVZ driver.
+ </dd>
+ <dt><code>type='file'</code></dt>
+ <dd>
+ Currently unused.
+ </dd>
+ <dt><code>type='block'</code></dt>
+ <dd>
+ Currently unused.
+ </dd>
+ </dl>
+
+ The filesystem block has an optional attribute <code>mode</code>
+ which specifies the security mode for accessing the source
+ <span class="since">(since 0.8.5)</span>. Currently this only works
+ with <code>type='mount'</code> for the QEMU/KVM driver. The possible
+ values are:
+
+ <dl>
+ <dt><code>mode='passthrough'</code></dt>
+ <dd>
+ The <code>source</code> is accessed with the permissions of the
+ user inside the guest. This is the default <code>mode</code> if
+ one is not specified.
+ <a href="http://lists.gnu.org/archive/html/qemu-devel/2010-05/msg02673.html">More info</a>
+ </dd>
+ <dt><code>mode='mapped'</code></dt>
+ <dd>
+ The <code>source</code> is accessed with the permissions of the
+ hypervisor (QEMU process).
+ <a href="http://lists.gnu.org/archive/html/qemu-devel/2010-05/msg02673.html">More info</a>
+ </dd>
+ <dt><code>mode='squash'</code></dt>
+ <dd>
+ Similar to 'passthrough', the exception is that failure of
+ privileged operations like 'chown' are ignored. This makes a
+ passthrough-like mode usable for people who run the hypervisor
+ as non-root.
+ <a href="http://www.mail-archive.com/qemu-devel@nongnu.org/msg41096.html">More info</a>
+ </dd>
+ </dl>
+
+ </dd>
+
+ <dt><code>source</code></dt>
+ <dd>
+ The resource on the host that is being accessed in the guest. The
+ <code>name</code> attribute must be used with
+ <code>type='template'</code>, and the <code>dir</code> attribute must
+ be used with <code>type='mount'</code>
+ </dd>
+
+ <dt><code>target</code></dt>
+ <dd>
+ Where the <code>source</code> can be accessed in the guest. For
+ most drivers this is an automatic mount point, but for QEMU/KVM
+ this is merely an arbitrary string tag that is exported to the
+ guest as a hint for where to mount.
+ </dd>
+
+ <dt><code>readonly</code></dt>
+ <dd>
+ An optional <code>readonly</code> attribute is available but currently
+ unused.
+ </dd>
+ </dl>
+
<h4><a name="elementsControllers">Controllers</a></h4>
<p>
--
1.7.4
13 years, 8 months
[libvirt] [PATCH] build: avoid test warnings on mingw
by Eric Blake
* .gnulib: Update to latest, for getaddrinfo fixes.
Reported by Matthias Bolte.
---
As promised, I've done the gnulib side of the mingw cleanups
affecting the issues Matthias found with 0.9.1-rc1.
Oh, and now that gnulib getcwd-lgpl exists, we could use it
to fix our uses of getcwd(NULL,0), followup coming later.
* .gnulib 7d06b32...74175b9 (29):
> getaddrinfo: fix gai_strerror signature
> getsockopt: avoid compiler warning
> tests: drop unused link dependency
> hash, mgetgroups: drop xalloc dependency
> xalloc-oversized: new module
> utimecmp: drop dependency on xmalloc
> getcwd: fix mingw bugs
> Typo in comment.
> mkstemps: Ensure declaration on MacOS X 10.5.
> mkstemp: More documentation.
> mkstemp: Tweak configure message when cross-compiling.
> clean-temp: Clarify what it does.
> fchdir: avoid extra chdir and fix test
> filenamecat-lgpl: fix licence
> linkat, renameat: add missing dependency
> tests: reduce dependencies
> save-cwd: reduce default dependency
> getcwd: enhance tests
> getcwd-lgpl: new module
> getcwd: tweak comments
> mkstemp: replace if system version uses wrong permissions
> passfd: avoid compiler warning
> Change gnulib-tool to support NetBSD's join
> mkstemp: mention clean-temp module
> inttypes: also provide default values for 32-bit tests
> strtoumax: remove dependency on strtoimax
> inttypes-incomplete: new module
> inttypes: omit now-redundant strtoimax and strtoumax work
> strtoimax, strtoumax: simplify, port to HP-UX 11.00 64-bit
.gnulib | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/.gnulib b/.gnulib
index 7d06b32..74175b9 160000
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit 7d06b32684363a39fae65c616b84bc7589768106
+Subproject commit 74175b903b1716c1677658e45fa69ef1fbc99015
--
1.7.4.4
13 years, 8 months
[libvirt] [PATCH] tests: Lower stack usage below 4096 bytes
by Matthias Bolte
Make virtTestLoadFile allocate the buffer to read the file into.
Fix logic error in virtTestLoadFile, stop reading on the an empty line.
Use virFileReadLimFD in virtTestCaptureProgramOutput.
---
m4/virt-compile-warnings.m4 | 10 ++---
tests/commandhelper.c | 5 +-
tests/commandtest.c | 14 ++----
tests/conftest.c | 29 +++++++++----
tests/cputest.c | 66 ++++++++++++++++++-------------
tests/esxutilstest.c | 2 +
tests/interfacexml2xmltest.c | 33 ++++++++++------
tests/networkxml2xmltest.c | 51 ++++++++++++++---------
tests/nodedevxml2xmltest.c | 34 ++++++++++------
tests/nodeinfotest.c | 67 ++++++++++++++++++++-----------
tests/nwfilterxml2xmltest.c | 54 +++++++++++++++----------
tests/qemuargv2xmltest.c | 43 ++++++++++++--------
tests/qemuhelptest.c | 13 +++---
tests/qemuxml2argvtest.c | 56 ++++++++++++++++----------
tests/qemuxml2xmltest.c | 43 +++++++++++---------
tests/sexpr2xmltest.c | 51 ++++++++++++++---------
tests/storagepoolxml2xmltest.c | 51 ++++++++++++++---------
tests/storagevolxml2xmltest.c | 65 ++++++++++++++++++-------------
tests/testutils.c | 69 ++++++++++++++------------------
tests/testutils.h | 8 +---
tests/virshtest.c | 65 +++++++++++++-----------------
tests/vmx2xmltest.c | 45 ++++++++++++---------
tests/xencapstest.c | 38 ++++++++---------
tests/xmconfigtest.c | 85 +++++++++++++++++++++++----------------
tests/xml2sexprtest.c | 53 +++++++++++++++----------
tests/xml2vmxtest.c | 45 ++++++++++++---------
26 files changed, 624 insertions(+), 471 deletions(-)
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4
index 295fd9b..305036f 100644
--- a/m4/virt-compile-warnings.m4
+++ b/m4/virt-compile-warnings.m4
@@ -88,12 +88,10 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
# that one off, so we need to manually enable this again
gl_WARN_ADD([-Wjump-misses-init])
- # This should be < 256 really, but with PATH_MAX everywhere
- # we have doom, even with 4096. In fact we have some functions
- # with several PATH_MAX sized variables :-( We should kill off
- # all PATH_MAX usage and then lower this limit
- gl_WARN_ADD([-Wframe-larger-than=65700])
- dnl gl_WARN_ADD([-Wframe-larger-than=4096])
+ # This should be < 256 really. Currently we're down to 4096,
+ # but using 1024 bytes sized buffers (mostly for virStrerror)
+ # stops us from going down further
+ gl_WARN_ADD([-Wframe-larger-than=4096])
dnl gl_WARN_ADD([-Wframe-larger-than=256])
# Extra special flags
diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 46c00f4..99ba22e 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -99,8 +99,8 @@ int main(int argc, char **argv) {
}
fprintf(log, "DAEMON:%s\n", getpgrp() == getsid(0) ? "yes" : "no");
- char cwd[1024];
- if (!getcwd(cwd, sizeof(cwd)))
+ char *cwd = NULL;
+ if (!(cwd = getcwd(NULL, 0)))
return EXIT_FAILURE;
if (strlen(cwd) > strlen("/commanddata") &&
STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata"))
@@ -137,5 +137,6 @@ int main(int argc, char **argv) {
return EXIT_SUCCESS;
error:
+ free(cwd);
return EXIT_FAILURE;
}
diff --git a/tests/commandtest.c b/tests/commandtest.c
index c313a2c..a728d10 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -47,21 +47,18 @@ mymain(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
#else
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
static int checkoutput(const char *testname)
{
int ret = -1;
- char cwd[1024];
char *expectname = NULL;
char *expectlog = NULL;
char *actualname = NULL;
char *actuallog = NULL;
- if (!getcwd(cwd, sizeof(cwd)))
- return -1;
-
if (virAsprintf(&expectname, "%s/commanddata/%s.log", abs_srcdir,
testname) < 0)
goto cleanup;
@@ -545,12 +542,12 @@ cleanup:
static int test15(const void *unused ATTRIBUTE_UNUSED)
{
virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
- char *cwd = NULL;
+ char *wd = NULL;
int ret = -1;
- if (virAsprintf(&cwd, "%s/commanddata", abs_srcdir) < 0)
+ if (virAsprintf(&wd, "%s/commanddata", abs_srcdir) < 0)
goto cleanup;
- virCommandSetWorkingDirectory(cmd, cwd);
+ virCommandSetWorkingDirectory(cmd, wd);
if (virCommandRun(cmd, NULL) < 0) {
virErrorPtr err = virGetLastError();
@@ -561,7 +558,7 @@ static int test15(const void *unused ATTRIBUTE_UNUSED)
ret = checkoutput("test15");
cleanup:
- VIR_FREE(cwd);
+ VIR_FREE(wd);
virCommandFree(cmd);
return ret;
@@ -757,7 +754,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
int fd;
abs_srcdir = getenv("abs_srcdir");
diff --git a/tests/conftest.c b/tests/conftest.c
index a7977bb..6514f4d 100644
--- a/tests/conftest.c
+++ b/tests/conftest.c
@@ -6,32 +6,43 @@
#include <string.h>
#include <errno.h>
#include "conf.h"
+#include "memory.h"
-int main(int argc, char **argv) {
- int ret;
+int main(int argc, char **argv)
+{
+ int ret, exit_code = EXIT_FAILURE;
virConfPtr conf;
int len = 10000;
- char buffer[10000];
+ char *buffer = NULL;
if (argc != 2) {
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);
if (conf == NULL) {
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) {
fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
- exit(EXIT_FAILURE);
+ goto cleanup;
}
virConfFree(conf);
if (fwrite(buffer, 1, len, stdout) != len) {
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;
}
diff --git a/tests/cputest.c b/tests/cputest.c
index bd06958..831fa81 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -40,11 +40,11 @@
#include "cpu/cpu_map.h"
static const char *progname;
+static char cwd[PATH_MAX];
static const char *abs_srcdir;
static const char *abs_top_srcdir;
#define VIR_FROM_THIS VIR_FROM_CPU
-#define MAX_FILE 4096
enum compResultShadow {
ERROR = VIR_CPU_COMPARE_ERROR,
@@ -91,14 +91,13 @@ struct data {
static virCPUDefPtr
cpuTestLoadXML(const char *arch, const char *name)
{
- char xml[PATH_MAX];
+ char *xml = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
virCPUDefPtr cpu = NULL;
- snprintf(xml, PATH_MAX,
- "%s/cputestdata/%s-%s.xml",
- abs_srcdir, arch, name);
+ if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
+ goto cleanup;
if (!(doc = virXMLParseFile(xml)) ||
!(ctxt = xmlXPathNewContext(doc)))
@@ -110,6 +109,7 @@ cpuTestLoadXML(const char *arch, const char *name)
cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
+ free(xml);
return cpu;
}
@@ -119,7 +119,7 @@ cpuTestLoadMultiXML(const char *arch,
const char *name,
unsigned int *count)
{
- char xml[PATH_MAX];
+ char *xml = NULL;
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL;
@@ -127,9 +127,8 @@ cpuTestLoadMultiXML(const char *arch,
int n;
int i;
- snprintf(xml, PATH_MAX,
- "%s/cputestdata/%s-%s.xml",
- abs_srcdir, arch, name);
+ if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) < 0)
+ goto cleanup;
if (!(doc = virXMLParseFile(xml)) ||
!(ctxt = xmlXPathNewContext(doc)))
@@ -151,6 +150,7 @@ cpuTestLoadMultiXML(const char *arch,
*count = n;
cleanup:
+ free(xml);
free(nodes);
xmlXPathFreeContext(ctxt);
xmlFreeDoc(doc);
@@ -172,17 +172,16 @@ cpuTestCompareXML(const char *arch,
const virCPUDefPtr cpu,
const char *name)
{
- char xml[PATH_MAX];
- char expected[MAX_FILE];
- char *expectedPtr = &(expected[0]);
+ char *xml = NULL;
+ char *expected = NULL;
char *actual = NULL;
int ret = -1;
- snprintf(xml, PATH_MAX,
- "%s/cputestdata/%s-%s.xml",
- abs_srcdir, arch, name);
+ if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml",
+ abs_srcdir, arch, name) < 0)
+ goto cleanup;
- if (virtTestLoadFile(xml, &expectedPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &expected) < 0)
goto cleanup;
if (!(actual = virCPUDefFormat(cpu, NULL, 0)))
@@ -196,6 +195,8 @@ cpuTestCompareXML(const char *arch,
ret = 0;
cleanup:
+ free(xml);
+ free(expected);
free(actual);
return ret;
}
@@ -335,7 +336,7 @@ cpuTestBaseline(const void *arg)
virCPUDefPtr *cpus = NULL;
virCPUDefPtr baseline = NULL;
unsigned int ncpus = 0;
- char result[PATH_MAX];
+ char *result = NULL;
unsigned int i;
if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
@@ -355,7 +356,9 @@ cpuTestBaseline(const void *arg)
if (!baseline)
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)
goto cleanup;
@@ -384,6 +387,7 @@ cleanup:
free(cpus);
}
virCPUDefFree(baseline);
+ free(result);
return ret;
}
@@ -395,7 +399,7 @@ cpuTestUpdate(const void *arg)
int ret = -1;
virCPUDefPtr host = NULL;
virCPUDefPtr cpu = NULL;
- char result[PATH_MAX];
+ char *result = NULL;
if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
!(cpu = cpuTestLoadXML(data->arch, data->name)))
@@ -404,12 +408,15 @@ cpuTestUpdate(const void *arg)
if (cpuUpdate(cpu, host) < 0)
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);
cleanup:
virCPUDefFree(host);
virCPUDefFree(cpu);
+ free(result);
return ret;
}
@@ -467,10 +474,10 @@ static int (*cpuTest[])(const void *) = {
static int
cpuTestRun(const char *name, const struct data *data)
{
- char label[PATH_MAX];
+ char *label = NULL;
- snprintf(label, PATH_MAX, "CPU %s(%s): %s",
- apis[data->api], data->arch, name);
+ if (virAsprintf(&label, "CPU %s(%s): %s", apis[data->api], data->arch, name) < 0)
+ return -1;
free(virtTestLogContentAndReset());
@@ -482,9 +489,12 @@ cpuTestRun(const char *name, const struct data *data)
fprintf(stderr, "\n%s\n", log);
free(log);
}
+
+ free(label);
return -1;
}
+ free(label);
return 0;
}
@@ -497,8 +507,7 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
- char map[PATH_MAX];
+ char *map = NULL;
progname = argv[0];
@@ -515,9 +524,11 @@ mymain(int argc, char **argv)
if (!abs_top_srcdir)
abs_top_srcdir = "..";
- snprintf(map, PATH_MAX, "%s/src/cpu/cpu_map.xml", abs_top_srcdir);
- if (cpuMapOverride(map) < 0)
+ if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
+ cpuMapOverride(map) < 0) {
+ free(map);
return EXIT_FAILURE;
+ }
#define DO_TEST(arch, api, name, host, cpu, \
models, nmodels, preferred, result) \
@@ -627,6 +638,7 @@ mymain(int argc, char **argv)
DO_TEST_GUESTDATA("x86", "host", "guest", models, "qemu64", 0);
DO_TEST_GUESTDATA("x86", "host", "guest", nomodel, NULL, -1);
+ free(map);
return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index b6bf87b..78761a1 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -276,6 +276,7 @@ testEscapeDatastoreItem(const void *data ATTRIBUTE_UNUSED)
}
}
+ VIR_FREE(escaped);
return 0;
}
@@ -317,6 +318,7 @@ testConvertWindows1252ToUTF8(const void *data ATTRIBUTE_UNUSED)
}
}
+ VIR_FREE(utf8);
return 0;
}
diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c
index 094ccf5..26a19ab 100644
--- a/tests/interfacexml2xmltest.c
+++ b/tests/interfacexml2xmltest.c
@@ -14,19 +14,19 @@
#include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-#define MAX_FILE 4096
-
-static int testCompareXMLToXMLFiles(const char *xml) {
- char xmlData[MAX_FILE];
- char *xmlPtr = &(xmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *xml)
+{
+ char *xmlData = NULL;
char *actual = NULL;
int ret = -1;
virInterfaceDefPtr dev = NULL;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
if (!(dev = virInterfaceDefParseString(xmlData)))
@@ -43,16 +43,26 @@ static int testCompareXMLToXMLFiles(const char *xml) {
ret = 0;
fail:
+ free(xmlData);
free(actual);
virInterfaceDefFree(dev);
return ret;
}
-static int testCompareXMLToXMLHelper(const void *data) {
- char xml[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/interfaceschemadata/%s.xml",
- abs_srcdir, (const char*)data);
- return testCompareXMLToXMLFiles(xml);
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ 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;
}
@@ -60,7 +70,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
index 7805548..6faeab2 100644
--- a/tests/networkxml2xmltest.c
+++ b/tests/networkxml2xmltest.c
@@ -14,23 +14,21 @@
#include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
+{
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virNetworkDefPtr dev = NULL;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
if (!(dev = virNetworkDefParseString(inXmlData)))
@@ -47,27 +45,40 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0;
fail:
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virNetworkDefFree(dev);
return ret;
}
-static int testCompareXMLToXMLHelper(const void *data) {
- char inxml[PATH_MAX];
- char outxml[PATH_MAX];
- snprintf(inxml, PATH_MAX, "%s/networkxml2xmlin/%s.xml",
- abs_srcdir, (const char*)data);
- snprintf(outxml, PATH_MAX, "%s/networkxml2xmlout/%s.xml",
- abs_srcdir, (const char*)data);
- return testCompareXMLToXMLFiles(inxml, outxml);
-}
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ 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
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c
index 2bc6743..e58883b 100644
--- a/tests/nodedevxml2xmltest.c
+++ b/tests/nodedevxml2xmltest.c
@@ -14,19 +14,18 @@
#include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *xml) {
- char xmlData[MAX_FILE];
- char *xmlPtr = &(xmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *xml)
+{
+ char *xmlData = NULL;
char *actual = NULL;
int ret = -1;
virNodeDeviceDefPtr dev = NULL;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
if (!(dev = virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE)))
@@ -43,16 +42,26 @@ static int testCompareXMLToXMLFiles(const char *xml) {
ret = 0;
fail:
+ free(xmlData);
free(actual);
virNodeDeviceDefFree(dev);
return ret;
}
-static int testCompareXMLToXMLHelper(const void *data) {
- char xml[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/nodedevschemadata/%s.xml",
- abs_srcdir, (const char*)data);
- return testCompareXMLToXMLFiles(xml);
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ 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;
}
@@ -60,7 +69,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index c690403..0d8c13b 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -22,26 +22,27 @@ mymain(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
#else
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-# define MAX_FILE 4096
-
extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, virNodeInfoPtr nodeinfo,
bool need_hyperthreads);
-static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) {
- char actualData[MAX_FILE];
- char expectData[MAX_FILE];
- char *expect = &expectData[0];
+static int
+linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile)
+{
+ int ret = -1;
+ char *actualData = NULL;
+ char *expectData = NULL;
virNodeInfo nodeinfo;
FILE *cpuinfo;
- if (virtTestLoadFile(outputfile, &expect, MAX_FILE) < 0)
- return -1;
+ if (virtTestLoadFile(outputfile, &expectData) < 0)
+ goto fail;
cpuinfo = fopen(cpuinfofile, "r");
if (!cpuinfo)
- return -1;
+ goto fail;
memset(&nodeinfo, 0, sizeof(nodeinfo));
if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo, false) < 0) {
@@ -52,7 +53,7 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
virFreeError(error);
}
VIR_FORCE_FCLOSE(cpuinfo);
- return -1;
+ goto fail;
}
VIR_FORCE_FCLOSE(cpuinfo);
@@ -61,30 +62,49 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
* so blank it to a predictable value */
nodeinfo.nodes = 1;
- snprintf(actualData, MAX_FILE,
- "CPUs: %u, MHz: %u, Nodes: %u, Cores: %u\n",
- nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes, nodeinfo.cores);
+ if (virAsprintf(&actualData, "CPUs: %u, MHz: %u, Nodes: %u, Cores: %u\n",
+ nodeinfo.cpus, nodeinfo.mhz, nodeinfo.nodes,
+ nodeinfo.cores) < 0)
+ goto fail;
if (STRNEQ(actualData, expectData)) {
if (getenv("DEBUG_TESTS")) {
printf("Expect %d '%s'\n", (int)strlen(expectData), expectData);
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) {
- char cpuinfo[PATH_MAX];
- char output[PATH_MAX];
- snprintf(cpuinfo, PATH_MAX, "%s/nodeinfodata/linux-%s.cpuinfo",
- abs_srcdir, (const char*)data);
- snprintf(output, PATH_MAX, "%s/nodeinfodata/linux-%s.txt",
- abs_srcdir, (const char*)data);
- return linuxTestCompareFiles(cpuinfo, output);
+static int
+linuxTestNodeInfo(const void *data)
+{
+ int result = -1;
+ char *cpuinfo = NULL;
+ char *output = NULL;
+
+ 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;
}
@@ -101,7 +121,6 @@ mymain(int argc, char **argv)
"nodeinfo-5",
"nodeinfo-6",
};
- char cwd[PATH_MAX];
abs_srcdir = getenv("abs_srcdir");
if (!abs_srcdir)
diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c
index 575177a..0463a79 100644
--- a/tests/nwfilterxml2xmltest.c
+++ b/tests/nwfilterxml2xmltest.c
@@ -17,25 +17,22 @@
#include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *inxml,
- const char *outxml,
- bool expect_error) {
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
+ bool expect_error)
+{
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virNWFilterDefPtr dev = NULL;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
virResetLastError();
@@ -62,6 +59,8 @@ static int testCompareXMLToXMLFiles(const char *inxml,
ret = 0;
fail:
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virNWFilterDefFree(dev);
return ret;
@@ -72,23 +71,34 @@ typedef struct test_parms {
bool expect_warning;
} test_parms;
-static int testCompareXMLToXMLHelper(const void *data) {
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
const test_parms *tp = data;
- char inxml[PATH_MAX];
- char outxml[PATH_MAX];
- 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);
-}
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ 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
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index 0214db0..47e452e 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -17,11 +17,10 @@
# include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
static struct qemud_driver driver;
-# define MAX_FILE 4096
-
static int blankProblemElements(char *data)
{
if (virtTestClearLineRegex("<name>[[:alnum:]]+</name>", data) < 0 ||
@@ -37,18 +36,16 @@ static int blankProblemElements(char *data)
static int testCompareXMLToArgvFiles(const char *xml,
const char *cmdfile,
bool expect_warning) {
- char xmlData[MAX_FILE];
- char cmdData[MAX_FILE];
- char *expectxml = &(xmlData[0]);
+ char *expectxml = NULL;
char *actualxml = NULL;
- char *cmd = &(cmdData[0]);
+ char *cmd = NULL;
int ret = -1;
virDomainDefPtr vmdef = NULL;
char *log;
- if (virtTestLoadFile(cmdfile, &cmd, MAX_FILE) < 0)
+ if (virtTestLoadFile(cmdfile, &cmd) < 0)
goto fail;
- if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &expectxml) < 0)
goto fail;
if (!(vmdef = qemuParseCommandLineString(driver.caps, cmd)))
@@ -77,7 +74,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
ret = 0;
fail:
+ free(expectxml);
free(actualxml);
+ free(cmd);
virDomainDefFree(vmdef);
return ret;
}
@@ -89,15 +88,26 @@ struct testInfo {
const char *migrateFrom;
};
-static int testCompareXMLToArgvHelper(const void *data) {
+static int
+testCompareXMLToArgvHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char args[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
- abs_srcdir, info->name);
- snprintf(args, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
- abs_srcdir, info->name);
- return testCompareXMLToArgvFiles(xml, args, !!info->extraFlags);
+ char *xml = NULL;
+ char *args = NULL;
+
+ if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&args, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
+
+ result = testCompareXMLToArgvFiles(xml, args, !!info->extraFlags);
+
+cleanup:
+ free(xml);
+ free(args);
+ return result;
}
@@ -106,7 +116,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index c86c578..4838e9a 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -9,8 +9,6 @@
# include "qemu/qemu_capabilities.h"
# include "memory.h"
-# define MAX_HELP_OUTPUT_SIZE 1024*64
-
struct testInfo {
const char *name;
virBitmapPtr flags;
@@ -20,6 +18,7 @@ struct testInfo {
};
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
static void printMismatchedFlags(virBitmapPtr got,
@@ -41,8 +40,7 @@ static int testHelpStrParsing(const void *data)
{
const struct testInfo *info = data;
char *path = NULL;
- char helpStr[MAX_HELP_OUTPUT_SIZE];
- char *help = &(helpStr[0]);
+ char *help = NULL;
unsigned int version, is_kvm, kvm_version;
virBitmapPtr flags = NULL;
int ret = -1;
@@ -52,7 +50,7 @@ static int testHelpStrParsing(const void *data)
if (virAsprintf(&path, "%s/qemuhelpdata/%s", abs_srcdir, info->name) < 0)
return -1;
- if (virtTestLoadFile(path, &help, MAX_HELP_OUTPUT_SIZE) < 0)
+ if (virtTestLoadFile(path, &help) < 0)
goto cleanup;
if (!(flags = qemuCapsNew()))
@@ -64,11 +62,12 @@ static int testHelpStrParsing(const void *data)
if (qemuCapsGet(info->flags, QEMU_CAPS_DEVICE)) {
VIR_FREE(path);
+ VIR_FREE(help);
if (virAsprintf(&path, "%s/qemuhelpdata/%s-device", abs_srcdir,
info->name) < 0)
goto cleanup;
- if (virtTestLoadFile(path, &help, MAX_HELP_OUTPUT_SIZE) < 0)
+ if (virtTestLoadFile(path, &help) < 0)
goto cleanup;
if (qemuCapsParseDeviceStr(help, flags) < 0)
@@ -114,6 +113,7 @@ static int testHelpStrParsing(const void *data)
ret = 0;
cleanup:
VIR_FREE(path);
+ VIR_FREE(help);
qemuCapsFree(flags);
VIR_FREE(got);
VIR_FREE(expected);
@@ -124,7 +124,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index c06bdf6..023f5df 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -20,20 +20,19 @@
# include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
static const char *abs_top_srcdir;
static struct qemud_driver driver;
-# define MAX_FILE 4096
-
static int testCompareXMLToArgvFiles(const char *xml,
const char *cmdline,
virBitmapPtr extraFlags,
const char *migrateFrom,
int migrateFd,
- bool expectError) {
- char argvData[MAX_FILE];
- char *expectargv = &(argvData[0]);
+ bool expectError)
+{
+ char *expectargv = NULL;
int len;
char *actualargv = NULL;
int ret = -1;
@@ -47,7 +46,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
if (!(conn = virGetConnect()))
goto fail;
- len = virtTestLoadFile(cmdline, &expectargv, MAX_FILE);
+ len = virtTestLoadFile(cmdline, &expectargv);
if (len < 0)
goto fail;
if (len && expectargv[len - 1] == '\n')
@@ -158,6 +157,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
fail:
free(log);
free(emulator);
+ free(expectargv);
free(actualargv);
virCommandFree(cmd);
virDomainDefFree(vmdef);
@@ -174,17 +174,28 @@ struct testInfo {
bool expectError;
};
-static int testCompareXMLToArgvHelper(const void *data) {
+static int
+testCompareXMLToArgvHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char args[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
- abs_srcdir, info->name);
- snprintf(args, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
- abs_srcdir, info->name);
- return testCompareXMLToArgvFiles(xml, args, info->extraFlags,
- info->migrateFrom, info->migrateFd,
- info->expectError);
+ char *xml = NULL;
+ char *args = NULL;
+
+ if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&args, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
+
+ result = testCompareXMLToArgvFiles(xml, args, info->extraFlags,
+ info->migrateFrom, info->migrateFd,
+ info->expectError);
+
+cleanup:
+ free(xml);
+ free(args);
+ return result;
}
@@ -193,14 +204,13 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
- char map[PATH_MAX];
+ char *map = NULL;
progname = argv[0];
if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname);
- return (EXIT_FAILURE);
+ return EXIT_FAILURE;
}
abs_srcdir = getenv("abs_srcdir");
@@ -224,10 +234,11 @@ mymain(int argc, char **argv)
return EXIT_FAILURE;
if (!(driver.spicePassword = strdup("123456")))
return EXIT_FAILURE;
-
- snprintf(map, PATH_MAX, "%s/src/cpu/cpu_map.xml", abs_top_srcdir);
- if (cpuMapOverride(map) < 0)
+ if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0 ||
+ cpuMapOverride(map) < 0) {
+ free(map);
return EXIT_FAILURE;
+ }
# define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \
do { \
@@ -498,6 +509,7 @@ mymain(int argc, char **argv)
free(driver.stateDir);
virCapabilitiesFree(driver.caps);
+ free(map);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 27330a9..9d8beeb 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -16,24 +16,22 @@
# include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
static struct qemud_driver driver;
-# define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
+{
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virDomainDefPtr def = NULL;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
if (!(def = virDomainDefParseString(driver.caps, inXmlData,
@@ -51,6 +49,8 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0;
fail:
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virDomainDefFree(def);
return ret;
@@ -61,16 +61,19 @@ struct testInfo {
int different;
};
-static int testCompareXMLToXMLHelper(const void *data) {
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
const struct testInfo *info = data;
- char xml_in[PATH_MAX];
- char xml_out[PATH_MAX];
- int ret;
+ char *xml_in = NULL;
+ char *xml_out = NULL;
+ int ret = -1;
- snprintf(xml_in, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
- abs_srcdir, info->name);
- snprintf(xml_out, PATH_MAX, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
- abs_srcdir, info->name);
+ if (virAsprintf(&xml_in, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&xml_out, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
if (info->different) {
ret = testCompareXMLToXMLFiles(xml_in, xml_out);
@@ -78,6 +81,9 @@ static int testCompareXMLToXMLHelper(const void *data) {
ret = testCompareXMLToXMLFiles(xml_in, xml_in);
}
+cleanup:
+ free(xml_in);
+ free(xml_out);
return ret;
}
@@ -86,7 +92,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
index 9f74ece..4df0fd5 100644
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -14,18 +14,16 @@
#include "testutilsxen.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
static virCapsPtr caps;
-#define MAX_FILE 4096
-
-static int testCompareFiles(const char *xml, const char *sexpr,
- int xendConfigVersion) {
- char xmlData[MAX_FILE];
- char sexprData[MAX_FILE];
+static int
+testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *sexprData = NULL;
char *gotxml = NULL;
- char *xmlPtr = &(xmlData[0]);
- char *sexprPtr = &(sexprData[0]);
int id;
char * tty;
int vncport;
@@ -38,10 +36,10 @@ static int testCompareFiles(const char *xml, const char *sexpr,
conn = virGetConnect();
if (!conn) goto fail;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
- if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(sexpr, &sexprData) < 0)
goto fail;
memset(&priv, 0, sizeof priv);
@@ -72,6 +70,8 @@ static int testCompareFiles(const char *xml, const char *sexpr,
ret = 0;
fail:
+ free(xmlData);
+ free(sexprData);
free(gotxml);
virDomainDefFree(def);
if (conn)
@@ -86,23 +86,34 @@ struct testInfo {
int version;
};
-static int testCompareHelper(const void *data) {
+static int
+testCompareHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char args[PATH_MAX];
- 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);
-}
+ char *xml = NULL;
+ char *args = NULL;
+
+ 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
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index 2ec29e3..e947100 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -14,23 +14,21 @@
#include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
+{
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virStoragePoolDefPtr dev = NULL;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
if (!(dev = virStoragePoolDefParseString(inXmlData)))
@@ -47,27 +45,40 @@ static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
ret = 0;
fail:
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virStoragePoolDefFree(dev);
return ret;
}
-static int testCompareXMLToXMLHelper(const void *data) {
- char inxml[PATH_MAX];
- char outxml[PATH_MAX];
- snprintf(inxml, PATH_MAX, "%s/storagepoolxml2xmlin/%s.xml",
- abs_srcdir, (const char*)data);
- snprintf(outxml, PATH_MAX, "%s/storagepoolxml2xmlout/%s.xml",
- abs_srcdir, (const char*)data);
- return testCompareXMLToXMLFiles(inxml, outxml);
-}
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ 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
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c
index ffa5dfe..c57b7a8 100644
--- a/tests/storagevolxml2xmltest.c
+++ b/tests/storagevolxml2xmltest.c
@@ -14,30 +14,26 @@
#include "testutilsqemu.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-#define MAX_FILE 4096
-
-
-static int testCompareXMLToXMLFiles(const char *poolxml,
- const char *inxml,
- const char *outxml) {
- char poolXmlData[MAX_FILE];
- char *poolXmlPtr = &(poolXmlData[0]);
- char inXmlData[MAX_FILE];
- char *inXmlPtr = &(inXmlData[0]);
- char outXmlData[MAX_FILE];
- char *outXmlPtr = &(outXmlData[0]);
+static int
+testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
+ const char *outxml)
+{
+ char *poolXmlData = NULL;
+ char *inXmlData = NULL;
+ char *outXmlData = NULL;
char *actual = NULL;
int ret = -1;
virStoragePoolDefPtr pool = NULL;
virStorageVolDefPtr dev = NULL;
- if (virtTestLoadFile(poolxml, &poolXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(poolxml, &poolXmlData) < 0)
goto fail;
- if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(inxml, &inXmlData) < 0)
goto fail;
- if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
goto fail;
if (!(pool = virStoragePoolDefParseString(poolXmlData)))
@@ -57,6 +53,9 @@ static int testCompareXMLToXMLFiles(const char *poolxml,
ret = 0;
fail:
+ free(poolXmlData);
+ free(inXmlData);
+ free(outXmlData);
free(actual);
virStoragePoolDefFree(pool);
virStorageVolDefFree(dev);
@@ -68,19 +67,32 @@ struct testInfo {
const char *name;
};
-static int testCompareXMLToXMLHelper(const void *data) {
- char poolxml[PATH_MAX];
- char inxml[PATH_MAX];
- char outxml[PATH_MAX];
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
+ char *poolxml = NULL;
+ char *inxml = NULL;
+ char *outxml = NULL;
+
+ if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
+ abs_srcdir, info->pool) < 0 ||
+ virAsprintf(&inxml, "%s/storagevolxml2xmlin/%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&outxml, "%s/storagevolxml2xmlout/%s.xml",
+ abs_srcdir, info->name) < 0) {
+ goto cleanup;
+ }
+
+ result = testCompareXMLToXMLFiles(poolxml, inxml, outxml);
+
+cleanup:
+ free(poolxml);
+ free(inxml);
+ free(outxml);
- snprintf(poolxml, PATH_MAX, "%s/storagepoolxml2xmlin/%s.xml",
- abs_srcdir, (const char*)info->pool);
- snprintf(inxml, PATH_MAX, "%s/storagevolxml2xmlin/%s.xml",
- abs_srcdir, (const char*)info->name);
- snprintf(outxml, PATH_MAX, "%s/storagevolxml2xmlout/%s.xml",
- abs_srcdir, (const char*)info->name);
- return testCompareXMLToXMLFiles(poolxml, inxml, outxml);
+ return result;
}
@@ -88,7 +100,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/testutils.c b/tests/testutils.c
index 1f3b569..aaee337 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -170,17 +170,16 @@ virtTestRun(const char *title, int nloops, int (*body)(const void *data), const
return ret;
}
-/* Read FILE into buffer BUF of length BUFLEN.
- Upon any failure, or if FILE appears to contain more than BUFLEN bytes,
- diagnose it and return -1, but don't bother trying to preserve errno.
- Otherwise, return the number of bytes copied into BUF. */
-int virtTestLoadFile(const char *file,
- char **buf,
- int buflen) {
+/* Allocate BUF to the size of FILE. Read FILE into buffer BUF.
+ Upon any failure, diagnose it and return -1, but don't bother trying
+ to preserve errno. Otherwise, return the number of bytes copied into BUF. */
+int
+virtTestLoadFile(const char *file, char **buf)
+{
FILE *fp = fopen(file, "r");
struct stat st;
- char *tmp = *buf;
- int len, tmplen = buflen;
+ char *tmp;
+ int len, tmplen, buflen;
if (!fp) {
fprintf (stderr, "%s: failed to open: %s\n", file, strerror(errno));
@@ -193,17 +192,23 @@ int virtTestLoadFile(const char *file,
return -1;
}
- if (st.st_size > (buflen-1)) {
- fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
+ tmplen = buflen = st.st_size + 1;
+
+ if (VIR_ALLOC_N(*buf, buflen) < 0) {
+ fprintf (stderr, "%s: larger than available memory (> %d)\n", file, buflen);
VIR_FORCE_FCLOSE(fp);
return -1;
}
+ tmp = *buf;
(*buf)[0] = '\0';
if (st.st_size) {
/* read the file line by line */
while (fgets(tmp, tmplen, fp) != NULL) {
len = strlen(tmp);
+ /* stop on an empty line */
+ if (len == 0)
+ break;
/* remove trailing backslash-newline pair */
if (len >= 2 && tmp[len-2] == '\\' && tmp[len-1] == '\n') {
len -= 2;
@@ -216,6 +221,7 @@ int virtTestLoadFile(const char *file,
if (ferror(fp)) {
fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
VIR_FORCE_FCLOSE(fp);
+ free(*buf);
return -1;
}
}
@@ -265,10 +271,11 @@ void virtTestCaptureProgramExecChild(const char *const argv[],
VIR_FORCE_CLOSE(stdinfd);
}
-int virtTestCaptureProgramOutput(const char *const argv[],
- char **buf,
- int buflen) {
+int
+virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen)
+{
int pipefd[2];
+ int len;
if (pipe(pipefd) < 0)
return -1;
@@ -286,34 +293,20 @@ int virtTestCaptureProgramOutput(const char *const argv[],
return -1;
default:
- {
- int got = 0;
- int ret = -1;
- int want = buflen-1;
-
- VIR_FORCE_CLOSE(pipefd[1]);
-
- 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);
+ VIR_FORCE_CLOSE(pipefd[1]);
+ len = virFileReadLimFD(pipefd[0], maxlen, buf);
+ VIR_FORCE_CLOSE(pipefd[0]);
+ waitpid(pid, NULL, 0);
- return ret;
- }
+ return len;
}
}
#else /* !WIN32 */
-int virtTestCaptureProgramOutput(const char *const argv[] ATTRIBUTE_UNUSED,
- char **buf ATTRIBUTE_UNUSED,
- int buflen ATTRIBUTE_UNUSED) {
+int
+virtTestCaptureProgramOutput(const char *const argv[] ATTRIBUTE_UNUSED,
+ char **buf ATTRIBUTE_UNUSED,
+ int maxlen ATTRIBUTE_UNUSED)
+{
return -1;
}
#endif /* !WIN32 */
diff --git a/tests/testutils.h b/tests/testutils.h
index 88603a1..6adc0a0 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -23,12 +23,8 @@ int virtTestRun(const char *title,
int nloops,
int (*body)(const void *data),
const void *data);
-int virtTestLoadFile(const char *name,
- char **buf,
- int buflen);
-int virtTestCaptureProgramOutput(const char *const argv[],
- char **buf,
- int buflen);
+int virtTestLoadFile(const char *file, char **buf);
+int virtTestCaptureProgramOutput(const char *const argv[], char **buf, int maxlen);
int virtTestClearLineRegex(const char *pattern,
char *string);
diff --git a/tests/virshtest.c b/tests/virshtest.c
index 8ec97a8..e6743d7 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -6,11 +6,12 @@
#include "internal.h"
#include "xml.h"
+#include "util.h"
#include "testutils.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-#define MAX_FILE 4096
#define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493"
@@ -47,41 +48,31 @@ static int testFilterLine(char *buffer,
return 0;
}
-static int testCompareOutputLit(const char *expectData,
- const char *filter, const char *const argv[]) {
- char actualData[MAX_FILE];
- char *actualPtr = &(actualData[0]);
-
- if (virtTestCaptureProgramOutput(argv, &actualPtr, MAX_FILE) < 0)
- return -1;
-
- if (filter)
- if (testFilterLine(actualData, filter) < 0)
- return -1;
+static int
+testCompareOutputLit(const char *expectData,
+ const char *filter, const char *const argv[])
+{
+ int result = -1;
+ char *actualData = NULL;
- if (STRNEQ(expectData, actualData)) {
- virtTestDifference(stderr, expectData, actualData);
- return -1;
- }
+ if (virtTestCaptureProgramOutput(argv, &actualData, 4096) < 0)
+ goto cleanup;
- return 0;
-}
+ if (filter && testFilterLine(actualData, filter) < 0)
+ goto cleanup;
-#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];
+ if (STRNEQ(expectData, actualData)) {
+ virtTestDifference(stderr, expectData, actualData);
+ goto cleanup;
+ }
- snprintf(expect, sizeof expect - 1, "%s/%s", abs_srcdir, expect_rel);
+ result = 0;
- if (virtTestLoadFile(expect, &expectPtr, MAX_FILE) < 0)
- return -1;
+cleanup:
+ free(actualData);
- return testCompareOutputLit(expectData, filter, argv);
+ return result;
}
-#endif
#define VIRSH_DEFAULT "../tools/virsh", \
"--connect", \
@@ -235,8 +226,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char buffer[PATH_MAX];
- char cwd[PATH_MAX];
abs_srcdir = getenv("abs_srcdir");
if (!abs_srcdir)
@@ -246,16 +235,17 @@ mymain(int argc, char **argv)
exit (EXIT_AM_SKIP);
#endif
- snprintf(buffer, PATH_MAX-1, "test://%s/../examples/xml/test/testnode.xml", abs_srcdir);
- buffer[PATH_MAX-1] = '\0';
- progname = argv[0];
- custom_uri = buffer;
-
if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname);
- return(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
+ if (virAsprintf(&custom_uri, "test://%s/../examples/xml/test/testnode.xml",
+ abs_srcdir) < 0)
+ return EXIT_FAILURE;
+
+ progname = argv[0];
+
if (virtTestRun("virsh list (default)",
1, testCompareListDefault, NULL) != 0)
ret = -1;
@@ -406,6 +396,7 @@ mymain(int argc, char **argv)
#undef DO_TEST
+ free(custom_uri);
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index 5fed1c4..53d66c5 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -11,13 +11,12 @@
# include "testutils.h"
# include "vmx/vmx.h"
-static char *progname = NULL;
-static char *abs_srcdir = NULL;
-static virCapsPtr caps = NULL;
+static char *progname;
+static char cwd[PATH_MAX];
+static char *abs_srcdir;
+static virCapsPtr caps;
static virVMXContext ctx;
-# define MAX_FILE 4096
-
static void
testCapsInit(void)
{
@@ -71,19 +70,17 @@ static int
testCompareFiles(const char *vmx, const char *xml)
{
int result = -1;
- char vmxData[MAX_FILE];
- char xmlData[MAX_FILE];
+ char *vmxData = NULL;
+ char *xmlData = NULL;
char *formatted = NULL;
- char *vmxPtr = &(vmxData[0]);
- char *xmlPtr = &(xmlData[0]);
virDomainDefPtr def = NULL;
virErrorPtr err = NULL;
- if (virtTestLoadFile(vmx, &vmxPtr, MAX_FILE) < 0) {
+ if (virtTestLoadFile(vmx, &vmxData) < 0) {
goto failure;
}
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) {
+ if (virtTestLoadFile(xml, &xmlData) < 0) {
goto failure;
}
@@ -111,6 +108,8 @@ testCompareFiles(const char *vmx, const char *xml)
result = 0;
failure:
+ VIR_FREE(vmxData);
+ VIR_FREE(xmlData);
VIR_FREE(formatted);
virDomainDefFree(def);
@@ -125,16 +124,25 @@ struct testInfo {
static int
testCompareHelper(const void *data)
{
+ int result = -1;
const struct testInfo *info = data;
- char vmx[PATH_MAX];
- char xml[PATH_MAX];
+ char *vmx = NULL;
+ char *xml = NULL;
+
+ if (virAsprintf(&vmx, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir,
+ info->input) < 0 ||
+ virAsprintf(&xml, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
+ info->output) < 0) {
+ goto cleanup;
+ }
- snprintf(vmx, PATH_MAX, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir,
- info->input);
- snprintf(xml, PATH_MAX, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
- info->output);
+ result = testCompareFiles(vmx, xml);
- return testCompareFiles(vmx, xml);
+ cleanup:
+ VIR_FREE(vmx);
+ VIR_FREE(xml);
+
+ return result;
}
static char *
@@ -184,7 +192,6 @@ static int
mymain(int argc, char **argv)
{
int result = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/xencapstest.c b/tests/xencapstest.c
index 7b48812..a00b30b 100644
--- a/tests/xencapstest.c
+++ b/tests/xencapstest.c
@@ -12,34 +12,30 @@
#include "files.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
-#define MAX_FILE 4096
-
-static int testCompareFiles(const char *hostmachine,
- const char *xml_rel,
- const char *cpuinfo_rel,
- const char *capabilities_rel) {
- char xmlData[MAX_FILE];
- char *expectxml = &(xmlData[0]);
+static int
+testCompareFiles(const char *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;
int ret = -1;
- char xml[PATH_MAX];
- char cpuinfo[PATH_MAX];
- char capabilities[PATH_MAX];
+ char *xml = NULL;
+ char *cpuinfo = NULL;
+ char *capabilities = NULL;
- snprintf(xml, sizeof xml - 1, "%s/%s",
- abs_srcdir, xml_rel);
- snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/%s",
- abs_srcdir, cpuinfo_rel);
- snprintf(capabilities, sizeof capabilities - 1, "%s/%s",
- abs_srcdir, capabilities_rel);
+ if (virAsprintf(&xml, "%s/%s", abs_srcdir, xml_rel) < 0 ||
+ virAsprintf(&cpuinfo, "%s/%s", abs_srcdir, cpuinfo_rel) < 0 ||
+ virAsprintf(&capabilities, "%s/%s", abs_srcdir, capabilities_rel) < 0)
+ goto fail;
- if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &expectxml) < 0)
goto fail;
if (!(fp1 = fopen(cpuinfo, "r")))
@@ -62,8 +58,11 @@ static int testCompareFiles(const char *hostmachine,
ret = 0;
fail:
-
+ free(expectxml);
free(actualxml);
+ free(xml);
+ free(cpuinfo);
+ free(capabilities);
VIR_FORCE_FCLOSE(fp1);
VIR_FORCE_FCLOSE(fp2);
@@ -154,7 +153,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 7d418a5..41ea0c8 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -37,33 +37,33 @@
#include "memory.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
static virCapsPtr caps;
-#define MAX_FILE 4096
-
-static int testCompareParseXML(const char *xmcfg, const char *xml,
- int xendConfigVersion) {
- char xmlData[MAX_FILE];
- char xmcfgData[MAX_FILE];
- char gotxmcfgData[MAX_FILE];
- char *xmlPtr = &(xmlData[0]);
- char *xmcfgPtr = &(xmcfgData[0]);
- char *gotxmcfgPtr = &(gotxmcfgData[0]);
+static int
+testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *xmcfgData = NULL;
+ char *gotxmcfgData = NULL;
virConfPtr conf = NULL;
int ret = -1;
virConnectPtr conn;
- int wrote = MAX_FILE;
+ int wrote = 4096;
struct _xenUnifiedPrivate priv;
virDomainDefPtr def = NULL;
+ if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
+ goto fail;
+
conn = virGetConnect();
if (!conn) goto fail;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
- if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
goto fail;
/* Many puppies died to bring you this code. */
@@ -71,16 +71,16 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
priv.caps = caps;
conn->privateData = &priv;
- if (!(def = virDomainDefParseString(caps, xmlPtr,
+ if (!(def = virDomainDefParseString(caps, xmlData,
VIR_DOMAIN_XML_INACTIVE)))
goto fail;
if (!(conf = xenFormatXM(conn, def, xendConfigVersion)))
goto fail;
- if (virConfWriteMem(gotxmcfgPtr, &wrote, conf) < 0)
+ if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)
goto fail;
- gotxmcfgPtr[wrote] = '\0';
+ gotxmcfgData[wrote] = '\0';
if (STRNEQ(xmcfgData, gotxmcfgData)) {
virtTestDifference(stderr, xmcfgData, gotxmcfgData);
@@ -90,6 +90,9 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
ret = 0;
fail:
+ free(xmlData);
+ free(xmcfgData);
+ free(gotxmcfgData);
if (conf)
virConfFree(conf);
virDomainDefFree(def);
@@ -98,12 +101,11 @@ static int testCompareParseXML(const char *xmcfg, const char *xml,
return ret;
}
-static int testCompareFormatXML(const char *xmcfg, const char *xml,
- int xendConfigVersion) {
- char xmlData[MAX_FILE];
- char xmcfgData[MAX_FILE];
- char *xmlPtr = &(xmlData[0]);
- char *xmcfgPtr = &(xmcfgData[0]);
+static int
+testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *xmcfgData = NULL;
char *gotxml = NULL;
virConfPtr conf = NULL;
int ret = -1;
@@ -114,10 +116,10 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
conn = virGetConnect();
if (!conn) goto fail;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
- if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
goto fail;
/* Many puppies died to bring you this code. */
@@ -125,7 +127,7 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
priv.caps = caps;
conn->privateData = &priv;
- if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr), 0)))
+ if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0)))
goto fail;
if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps)))
@@ -144,6 +146,8 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
fail:
if (conf)
virConfFree(conf);
+ VIR_FREE(xmlData);
+ VIR_FREE(xmcfgData);
VIR_FREE(gotxml);
virDomainDefFree(def);
virUnrefConnect(conn);
@@ -158,18 +162,30 @@ struct testInfo {
int mode;
};
-static int testCompareHelper(const void *data) {
+static int
+testCompareHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char cfg[PATH_MAX];
- snprintf(xml, PATH_MAX, "%s/xmconfigdata/test-%s.xml",
- abs_srcdir, info->name);
- snprintf(cfg, PATH_MAX, "%s/xmconfigdata/test-%s.cfg",
- abs_srcdir, info->name);
+ char *xml = NULL;
+ char *cfg = NULL;
+
+ if (virAsprintf(&xml, "%s/xmconfigdata/test-%s.xml",
+ abs_srcdir, info->name) < 0 ||
+ virAsprintf(&cfg, "%s/xmconfigdata/test-%s.cfg",
+ abs_srcdir, info->name) < 0)
+ goto cleanup;
+
if (info->mode == 0)
- return testCompareParseXML(cfg, xml, info->version);
+ result = testCompareParseXML(cfg, xml, info->version);
else
- return testCompareFormatXML(cfg, xml, info->version);
+ result = testCompareFormatXML(cfg, xml, info->version);
+
+cleanup:
+ free(xml);
+ free(cfg);
+
+ return result;
}
@@ -177,7 +193,6 @@ static int
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index cf530b6..b6d8c00 100644
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -15,25 +15,23 @@
#include "testutilsxen.h"
static char *progname;
+static char cwd[PATH_MAX];
static char *abs_srcdir;
static virCapsPtr caps;
-#define MAX_FILE 4096
-
-static int testCompareFiles(const char *xml, const char *sexpr,
- int xendConfigVersion) {
- char xmlData[MAX_FILE];
- char sexprData[MAX_FILE];
+static int
+testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *sexprData = NULL;
char *gotsexpr = NULL;
- char *xmlPtr = &(xmlData[0]);
- char *sexprPtr = &(sexprData[0]);
int ret = -1;
virDomainDefPtr def = NULL;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
- if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
+ if (virtTestLoadFile(sexpr, &sexprData) < 0)
goto fail;
if (!(def = virDomainDefParseString(caps, xmlData,
@@ -51,8 +49,10 @@ static int testCompareFiles(const char *xml, const char *sexpr,
ret = 0;
fail:
- virDomainDefFree(def);
+ free(xmlData);
+ free(sexprData);
free(gotsexpr);
+ virDomainDefFree(def);
return ret;
}
@@ -64,23 +64,34 @@ struct testInfo {
int version;
};
-static int testCompareHelper(const void *data) {
+static int
+testCompareHelper(const void *data)
+{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char args[PATH_MAX];
- 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);
-}
+ char *xml = NULL;
+ char *args = NULL;
+
+ 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
mymain(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
progname = argv[0];
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index a5fb4f7..1b58db8 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -11,13 +11,12 @@
# include "testutils.h"
# include "vmx/vmx.h"
-static char *progname = NULL;
-static char *abs_srcdir = NULL;
-static virCapsPtr caps = NULL;
+static char *progname;
+static char cwd[PATH_MAX];
+static char *abs_srcdir;
+static virCapsPtr caps;
static virVMXContext ctx;
-# define MAX_FILE 4096
-
static void
testCapsInit(void)
{
@@ -71,18 +70,16 @@ static int
testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
{
int result = -1;
- char xmlData[MAX_FILE];
- char vmxData[MAX_FILE];
+ char *xmlData = NULL;
+ char *vmxData = NULL;
char *formatted = NULL;
- char *xmlPtr = &(xmlData[0]);
- char *vmxPtr = &(vmxData[0]);
virDomainDefPtr def = NULL;
- if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) {
+ if (virtTestLoadFile(xml, &xmlData) < 0) {
goto failure;
}
- if (virtTestLoadFile(vmx, &vmxPtr, MAX_FILE) < 0) {
+ if (virtTestLoadFile(vmx, &vmxData) < 0) {
goto failure;
}
@@ -106,6 +103,8 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
result = 0;
failure:
+ VIR_FREE(xmlData);
+ VIR_FREE(vmxData);
VIR_FREE(formatted);
virDomainDefFree(def);
@@ -121,16 +120,25 @@ struct testInfo {
static int
testCompareHelper(const void *data)
{
+ int result = -1;
const struct testInfo *info = data;
- char xml[PATH_MAX];
- char vmx[PATH_MAX];
+ char *xml = NULL;
+ char *vmx = NULL;
+
+ if (virAsprintf(&xml, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir,
+ info->input) < 0 ||
+ virAsprintf(&vmx, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
+ info->output) < 0) {
+ goto cleanup;
+ }
+
+ result = testCompareFiles(xml, vmx, info->virtualHW_version);
- snprintf(xml, PATH_MAX, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir,
- info->input);
- snprintf(vmx, PATH_MAX, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
- info->output);
+ cleanup:
+ VIR_FREE(xml);
+ VIR_FREE(vmx);
- return testCompareFiles(xml, vmx, info->virtualHW_version);
+ return result;
}
static int
@@ -201,7 +209,6 @@ static int
mymain(int argc, char **argv)
{
int result = 0;
- char cwd[PATH_MAX];
progname = argv[0];
--
1.7.0.4
13 years, 8 months