diff options
author | Matthias Bolte <matthias.bolte@googlemail.com> | 2011-04-25 00:25:10 +0200 |
---|---|---|
committer | Matthias Bolte <matthias.bolte@googlemail.com> | 2011-04-30 19:59:52 +0200 |
commit | 9ba4eb3c081027846637acf20b17ec801dc66b72 (patch) | |
tree | 12eaeebaeeb298f17c8f009d1c08c43a590eda27 /tests/vmx2xmltest.c | |
parent | tests: Update valgrind suppressions file (diff) | |
download | libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.tar.gz libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.tar.bz2 libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.zip |
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.
Diffstat (limited to 'tests/vmx2xmltest.c')
-rw-r--r-- | tests/vmx2xmltest.c | 39 |
1 files changed, 23 insertions, 16 deletions
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 * |