Convert test suites over to new test infrastructure

This commit is contained in:
Daniel P. Berrange 2008-05-29 15:31:49 +00:00
parent b0bcffda3b
commit 4b23495509
10 changed files with 97 additions and 57 deletions

View File

@ -1,3 +1,13 @@
Thu May 29 11:29:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* tests/nodeinfotest.c, tests/qemuxml2argvtest.c,
tests/qemuxml2xmltest.c, tests/qparamtest.c,
tests/sexpr2xmltest.c, tests/statstest.c,
tests/xencapstest.c, tests/xmconfigtest.c,
tests/xml2sexprtest.c: Convert over to new test suite
infrastructure to enable OOM testing. Avoid use of
the abs_top_srcdir variable in favour of abs_srcdir
Thu May 29 11:23:00 EST 2008 Daniel P. Berrange <berrange@redhat.com> Thu May 29 11:23:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
Misc memory handling / cleanup fixes Misc memory handling / cleanup fixes

View File

@ -3,13 +3,14 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "testutils.h" #include "testutils.h"
#include "internal.h" #include "internal.h"
#include "nodeinfo.h" #include "nodeinfo.h"
static char *progname; static char *progname;
static char *abs_top_srcdir; static char *abs_srcdir;
#define MAX_FILE 4096 #define MAX_FILE 4096
@ -56,17 +57,17 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
static int linuxTestNodeInfo(const void *data) { static int linuxTestNodeInfo(const void *data) {
char cpuinfo[PATH_MAX]; char cpuinfo[PATH_MAX];
char output[PATH_MAX]; char output[PATH_MAX];
snprintf(cpuinfo, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.cpuinfo", snprintf(cpuinfo, PATH_MAX, "%s/nodeinfodata/linux-%s.cpuinfo",
abs_top_srcdir, (const char*)data); abs_srcdir, (const char*)data);
snprintf(output, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.txt", snprintf(output, PATH_MAX, "%s/nodeinfodata/linux-%s.txt",
abs_top_srcdir, (const char*)data); abs_srcdir, (const char*)data);
return linuxTestCompareFiles(cpuinfo, output); return linuxTestCompareFiles(cpuinfo, output);
} }
#endif #endif
int static int
main(int argc, char **argv) mymain(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
#ifdef __linux__ #ifdef __linux__
@ -79,16 +80,17 @@ main(int argc, char **argv)
"nodeinfo-5", "nodeinfo-5",
"nodeinfo-6", "nodeinfo-6",
}; };
char cwd[PATH_MAX];
abs_top_srcdir = getenv("abs_top_srcdir"); abs_srcdir = getenv("abs_srcdir");
if (!abs_top_srcdir) if (!abs_srcdir)
return EXIT_FAILURE; abs_srcdir = getcwd(cwd, sizeof(cwd));
progname = argv[0]; progname = argv[0];
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return(EXIT_FAILURE);
} }
virInitialize(); virInitialize();
@ -98,5 +100,7 @@ main(int argc, char **argv)
ret = -1; ret = -1;
#endif #endif
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)

View File

@ -43,6 +43,7 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd, int extra
if (!(vmdef = qemudParseVMDef(NULL, &driver, xmlData, "test"))) if (!(vmdef = qemudParseVMDef(NULL, &driver, xmlData, "test")))
goto fail; goto fail;
memset(&vm, 0, sizeof vm);
vm.def = vmdef; vm.def = vmdef;
vm.pid = -1; vm.pid = -1;
vm.id = -1; vm.id = -1;
@ -115,8 +116,8 @@ static int testCompareXMLToArgvHelper(const void *data) {
int static int
main(int argc, char **argv) mymain(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
char cwd[PATH_MAX]; char cwd[PATH_MAX];
@ -125,14 +126,15 @@ main(int argc, char **argv)
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return (EXIT_FAILURE);
} }
abs_srcdir = getenv("abs_srcdir"); abs_srcdir = getenv("abs_srcdir");
if (!abs_srcdir) if (!abs_srcdir)
abs_srcdir = getcwd(cwd, sizeof(cwd)); abs_srcdir = getcwd(cwd, sizeof(cwd));
driver.caps = testQemuCapsInit(); if ((driver.caps = testQemuCapsInit()) == NULL)
return EXIT_FAILURE;
#define DO_TEST(name, extraFlags) \ #define DO_TEST(name, extraFlags) \
do { \ do { \
@ -181,11 +183,13 @@ main(int argc, char **argv)
virCapabilitiesFree(driver.caps); virCapabilitiesFree(driver.caps);
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)
#else #else
int main (void) { exit (77); /* means 'test skipped' for automake */ } int main (void) { return (77); /* means 'test skipped' for automake */ }
#endif /* WITH_QEMU */ #endif /* WITH_QEMU */

View File

@ -70,8 +70,8 @@ static int testCompareXMLToXMLHelper(const void *data) {
} }
int static int
main(int argc, char **argv) mymain(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
char cwd[PATH_MAX]; char cwd[PATH_MAX];
@ -80,14 +80,15 @@ main(int argc, char **argv)
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return (EXIT_FAILURE);
} }
abs_srcdir = getenv("abs_srcdir"); abs_srcdir = getenv("abs_srcdir");
if (!abs_srcdir) if (!abs_srcdir)
abs_srcdir = getcwd(cwd, sizeof(cwd)); abs_srcdir = getcwd(cwd, sizeof(cwd));
driver.caps = testQemuCapsInit(); if ((driver.caps = testQemuCapsInit()) == NULL)
return (EXIT_FAILURE);
#define DO_TEST(name) \ #define DO_TEST(name) \
if (virtTestRun("QEMU XML-2-XML " name, \ if (virtTestRun("QEMU XML-2-XML " name, \
@ -129,9 +130,11 @@ main(int argc, char **argv)
virCapabilitiesFree(driver.caps); virCapabilitiesFree(driver.caps);
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)
#else #else
int main (void) { exit (77); /* means 'test skipped' to automake */ } int main (void) { exit (77); /* means 'test skipped' to automake */ }

View File

@ -8,6 +8,7 @@
#include "testutils.h" #include "testutils.h"
#include "qparams.h" #include "qparams.h"
#include "util.h" #include "util.h"
#include "memory.h"
struct qparamParseDataEntry { struct qparamParseDataEntry {
const char *name; const char *name;
@ -181,8 +182,9 @@ static const struct qparamParseDataEntry const params4[] = { { "foo", "" } };
static const struct qparamParseDataEntry const params5[] = { { "foo", "one two" } }; static const struct qparamParseDataEntry const params5[] = { { "foo", "one two" } };
static const struct qparamParseDataEntry const params6[] = { { "foo", "one" } }; static const struct qparamParseDataEntry const params6[] = { { "foo", "one" } };
int static int
main(void) mymain(int argc ATTRIBUTE_UNUSED,
char **argv ATTRIBUTE_UNUSED)
{ {
int ret = 0; int ret = 0;
@ -221,5 +223,7 @@ main(void)
if (virtTestRun("Add vargs", 1, qparamTestAddVargs, NULL) < 0) if (virtTestRun("Add vargs", 1, qparamTestAddVargs, NULL) < 0)
ret = -1; ret = -1;
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)

View File

@ -69,8 +69,8 @@ static int testCompareHelper(const void *data) {
} }
int static int
main(int argc, char **argv) mymain(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
char cwd[PATH_MAX]; char cwd[PATH_MAX];
@ -79,7 +79,7 @@ main(int argc, char **argv)
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return(EXIT_FAILURE);
} }
abs_srcdir = getenv("abs_srcdir"); abs_srcdir = getenv("abs_srcdir");
@ -88,7 +88,7 @@ main(int argc, char **argv)
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return(EXIT_FAILURE);
} }
#define DO_TEST(in, out, version) \ #define DO_TEST(in, out, version) \
@ -139,8 +139,11 @@ main(int argc, char **argv)
DO_TEST("fv-sound", "fv-sound", 1); DO_TEST("fv-sound", "fv-sound", 1);
DO_TEST("fv-sound-all", "fv-sound-all", 1); DO_TEST("fv-sound-all", "fv-sound-all", 1);
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)
#else /* WITHOUT_XEN */ #else /* WITHOUT_XEN */
int int
main(void) main(void)

View File

@ -45,8 +45,9 @@ static int testDeviceHelper(const void *data)
#endif #endif
int static int
main(void) mymain(int argc ATTRIBUTE_UNUSED,
char **argv ATTRIBUTE_UNUSED)
{ {
int ret = 0; int ret = 0;
#if __linux__ && WITH_XEN #if __linux__ && WITH_XEN
@ -54,7 +55,7 @@ main(void)
* register a handler to stop error messages cluttering * register a handler to stop error messages cluttering
* up display * up display
*/ */
if (!getenv("DEBUG_TESTS")) if (!getenv("VIR_TEST_DEBUG"))
virSetErrorFunc(NULL, testQuietError); virSetErrorFunc(NULL, testQuietError);
#define DO_TEST(dev, num) \ #define DO_TEST(dev, num) \
@ -177,5 +178,7 @@ main(void)
DO_TEST("/dev/xvda15", 51727); DO_TEST("/dev/xvda15", 51727);
#endif #endif
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)

View File

@ -3,6 +3,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#ifdef WITH_XEN #ifdef WITH_XEN
@ -12,7 +13,7 @@
#include "xen_internal.h" #include "xen_internal.h"
static char *progname; static char *progname;
static char *abs_top_srcdir; static char *abs_srcdir;
#define MAX_FILE 4096 #define MAX_FILE 4096
@ -31,12 +32,12 @@ static int testCompareFiles(const char *hostmachine,
char cpuinfo[PATH_MAX]; char cpuinfo[PATH_MAX];
char capabilities[PATH_MAX]; char capabilities[PATH_MAX];
snprintf(xml, sizeof xml - 1, "%s/tests/%s", snprintf(xml, sizeof xml - 1, "%s/%s",
abs_top_srcdir, xml_rel); abs_srcdir, xml_rel);
snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/tests/%s", snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/%s",
abs_top_srcdir, cpuinfo_rel); abs_srcdir, cpuinfo_rel);
snprintf(capabilities, sizeof capabilities - 1, "%s/tests/%s", snprintf(capabilities, sizeof capabilities - 1, "%s/%s",
abs_top_srcdir, capabilities_rel); abs_srcdir, capabilities_rel);
if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0) if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0)
goto fail; goto fail;
@ -147,21 +148,22 @@ static int testXenppc64(const void *data ATTRIBUTE_UNUSED) {
} }
int static int
main(int argc, char **argv) mymain(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
char cwd[PATH_MAX];
progname = argv[0]; progname = argv[0];
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return(EXIT_FAILURE);
} }
abs_top_srcdir = getenv("abs_top_srcdir"); abs_srcdir = getenv("abs_srcdir");
if (!abs_top_srcdir) if (!abs_srcdir)
return 1; abs_srcdir = getcwd(cwd, sizeof(cwd));
virInitialize(); virInitialize();
@ -213,9 +215,11 @@ main(int argc, char **argv)
ret = -1; ret = -1;
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)
#else /* !WITH_XEN */ #else /* !WITH_XEN */
int int

View File

@ -170,8 +170,8 @@ static int testCompareHelper(const void *data) {
} }
int static int
main(int argc, char **argv) mymain(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
char cwd[PATH_MAX]; char cwd[PATH_MAX];
@ -180,7 +180,7 @@ main(int argc, char **argv)
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return(EXIT_FAILURE);
} }
abs_srcdir = getenv("abs_srcdir"); abs_srcdir = getenv("abs_srcdir");
@ -223,8 +223,11 @@ main(int argc, char **argv)
DO_TEST("fullvirt-sound", 2); DO_TEST("fullvirt-sound", 2);
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)
#else /* WITHOUT_XEN */ #else /* WITHOUT_XEN */
int int
main(void) main(void)

View File

@ -77,8 +77,8 @@ static int testCompareHelper(const void *data) {
} }
int static int
main(int argc, char **argv) mymain(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
char cwd[PATH_MAX]; char cwd[PATH_MAX];
@ -91,7 +91,7 @@ main(int argc, char **argv)
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return(EXIT_FAILURE);
} }
#define DO_TEST(in, out, name, version) \ #define DO_TEST(in, out, name, version) \
@ -145,9 +145,11 @@ main(int argc, char **argv)
DO_TEST("fv-sound", "fv-sound", "fvtest", 1); DO_TEST("fv-sound", "fv-sound", "fvtest", 1);
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)
#else /* WITH_XEN */ #else /* WITH_XEN */
int main (void) { exit (77); /* means 'test skipped' for automake */ } int main (void) { exit (77); /* means 'test skipped' for automake */ }