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/sexpr2xmltest.c | |
parent | 88823ec90a1b1f2d9f39fb77812088142326e56c (diff) | |
download | libvirt-9ba4eb3c081027846637acf20b17ec801dc66b72.tar.gz |
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/sexpr2xmltest.c')
-rw-r--r-- | tests/sexpr2xmltest.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c index 091943553e..f465105660 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) |