From 9ba4eb3c081027846637acf20b17ec801dc66b72 Mon Sep 17 00:00:00 2001 From: Matthias Bolte Date: Mon, 25 Apr 2011 00:25:10 +0200 Subject: tests: Lower stack usage below 4096 bytes Make virtTestLoadFile allocate the buffer to read the file into. Fix logic error in virtTestLoadFile, stop reading on the first empty line. Use virFileReadLimFD in virtTestCaptureProgramOutput to avoid manual buffer handling. --- tests/vmx2xmltest.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'tests/vmx2xmltest.c') diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 3b7e9be7c..e01e8ad03 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 * -- cgit v1.2.3-65-gdbad