[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/2] tests: simplify common setup



A few of the tests were missing basic sanity checks, while most
of them were doing copy-and-paste initialization (in fact, some
of them pasted the argc > 1 check more than once!).  It's much
nicer to do things in one common place, and minimizes the size of
the next patch that fixes getcwd usage.

* tests/testutils.h (EXIT_AM_HARDFAIL): New define.
(progname, abs_srcdir): Define for all tests.
(VIRT_TEST_MAIN): Change callback signature.
* tests/testutils.c (virtTestMain): Do more common init.
* tests/commandtest.c (mymain): Simplify.
* tests/cputest.c (mymain): Likewise.
* tests/esxutilstest.c (mymain): Likewise.
* tests/eventtest.c (mymain): Likewise.
* tests/hashtest.c (mymain): Likewise.
* tests/networkxml2xmltest.c (mymain): Likewise.
* tests/nodedevxml2xmltest.c (myname): Likewise.
* tests/nodeinfotest.c (mymain): Likewise.
* tests/nwfilterxml2xmltest.c (mymain): Likewise.
* tests/qemuargv2xmltest.c (mymain): Likewise.
* tests/qemuhelptest.c (mymain): Likewise.
* tests/qemuxml2argvtest.c (mymain): Likewise.
* tests/qemuxml2xmltest.c (mymain): Likewise.
* tests/qparamtest.c (mymain): Likewise.
* tests/sexpr2xmltest.c (mymain): Likewise.
* tests/sockettest.c (mymain): Likewise.
* tests/statstest.c (mymain): Likewise.
* tests/storagepoolxml2xmltest.c (mymain): Likewise.
* tests/storagevolxml2xmltest.c (mymain): Likewise.
* tests/virbuftest.c (mymain): Likewise.
* tests/virshtest.c (mymain): Likewise.
* tests/vmx2xmltest.c (mymain): Likewise.
* tests/xencapstest.c (mymain): Likewise.
* tests/xmconfigtest.c (mymain): Likewise.
* tests/xml2sexprtest.c (mymain): Likewise.
* tests/xml2vmxtest.c (mymain): Likewise.
---
 tests/commandtest.c            |   18 +-----------------
 tests/cputest.c                |   18 ++----------------
 tests/esxutilstest.c           |   17 +----------------
 tests/eventtest.c              |   11 +----------
 tests/hashtest.c               |    3 +--
 tests/interfacexml2xmltest.c   |   17 +----------------
 tests/networkxml2xmltest.c     |   17 +----------------
 tests/nodedevxml2xmltest.c     |   17 +----------------
 tests/nodeinfotest.c           |   17 +----------------
 tests/nwfilterxml2xmltest.c    |   17 +----------------
 tests/qemuargv2xmltest.c       |   16 +---------------
 tests/qemuhelptest.c           |   17 +----------------
 tests/qemuxml2argvtest.c       |   16 +---------------
 tests/qemuxml2xmltest.c        |   16 +---------------
 tests/qparamtest.c             |    3 +--
 tests/sexpr2xmltest.c          |   21 +--------------------
 tests/sockettest.c             |    5 ++---
 tests/statstest.c              |    3 +--
 tests/storagepoolxml2xmltest.c |   17 +----------------
 tests/storagevolxml2xmltest.c  |   17 +----------------
 tests/testutils.c              |   29 +++++++++++++++++++++++------
 tests/testutils.h              |   15 ++++++++++-----
 tests/virbuftest.c             |    3 +--
 tests/virshtest.c              |   18 +++---------------
 tests/vmx2xmltest.c            |   23 +----------------------
 tests/xencapstest.c            |   17 +----------------
 tests/xmconfigtest.c           |   18 ++----------------
 tests/xml2sexprtest.c          |   16 +---------------
 tests/xml2vmxtest.c            |   23 +----------------------
 29 files changed, 65 insertions(+), 380 deletions(-)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index c313a2c..509c888 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -46,10 +46,6 @@ mymain(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)

 #else

-static char *progname;
-static char *abs_srcdir;
-
-
 static int checkoutput(const char *testname)
 {
     int ret = -1;
@@ -754,23 +750,11 @@ cleanup:
 }

 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
     int fd;

-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return(EXIT_FAILURE);
-    }
-
     if (chdir("/tmp") < 0)
         return(EXIT_FAILURE);

diff --git a/tests/cputest.c b/tests/cputest.c
index bd06958..a8d28dc 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -1,7 +1,7 @@
 /*
  * cputest.c: Test the libvirtd internal CPU APIs
  *
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -39,8 +39,6 @@
 #include "cpu/cpu.h"
 #include "cpu/cpu_map.h"

-static const char *progname;
-static const char *abs_srcdir;
 static const char *abs_top_srcdir;

 #define VIR_FROM_THIS VIR_FROM_CPU
@@ -494,23 +492,11 @@ static const char *nomodel[]    = { "nomodel" };
 static const char *models[]     = { "qemu64", "core2duo", "Nehalem" };

 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
     char map[PATH_MAX];

-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return EXIT_FAILURE;
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));
-
     abs_top_srcdir = getenv("abs_top_srcdir");
     if (!abs_top_srcdir)
         abs_top_srcdir = "..";
diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index b6bf87b..830f79c 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -14,9 +14,6 @@
 # include "esx/esx_util.h"
 # include "esx/esx_vi_types.h"

-static char *progname;
-
-

 static void
 testQuietError(void *userData ATTRIBUTE_UNUSED,
@@ -323,22 +320,10 @@ testConvertWindows1252ToUTF8(const void *data ATTRIBUTE_UNUSED)


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int result = 0;

-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return EXIT_FAILURE;
-    }
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return EXIT_FAILURE;
-    }
-
     virSetErrorFunc(NULL, testQuietError);

 # define DO_TEST(_name)                                                       \
diff --git a/tests/eventtest.c b/tests/eventtest.c
index eb4b755..4c45860 100644
--- a/tests/eventtest.c
+++ b/tests/eventtest.c
@@ -259,20 +259,12 @@ resetAll(void)
 }

 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
-    char *progname;
     int i;
     pthread_t eventThread;
     char one = '1';

-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return EXIT_FAILURE;
-    }
-
     for (i = 0 ; i < NUM_FDS ; i++) {
         if (pipe(handles[i].pipeFD) < 0) {
             fprintf(stderr, "Cannot create pipe: %d", errno);
@@ -483,5 +475,4 @@ mymain(int argc, char **argv)
     return EXIT_SUCCESS;
 }

-
 VIRT_TEST_MAIN(mymain)
diff --git a/tests/hashtest.c b/tests/hashtest.c
index bb3a812..525ae06 100644
--- a/tests/hashtest.c
+++ b/tests/hashtest.c
@@ -476,8 +476,7 @@ cleanup:


 static int
-mymain(int argc ATTRIBUTE_UNUSED,
-       char **argv ATTRIBUTE_UNUSED)
+mymain(void)
 {
     int ret = 0;

diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c
index 094ccf5..fb454c1 100644
--- a/tests/interfacexml2xmltest.c
+++ b/tests/interfacexml2xmltest.c
@@ -13,9 +13,6 @@
 #include "interface_conf.h"
 #include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
-
 #define MAX_FILE 4096


@@ -57,21 +54,9 @@ static int testCompareXMLToXMLHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

 #define DO_TEST(name) \
     if (virtTestRun("Interface XML-2-XML " name, \
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
index 7805548..f7489f5 100644
--- a/tests/networkxml2xmltest.c
+++ b/tests/networkxml2xmltest.c
@@ -13,9 +13,6 @@
 #include "network_conf.h"
 #include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
-
 #define MAX_FILE 4096


@@ -64,21 +61,9 @@ static int testCompareXMLToXMLHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

 #define DO_TEST(name) \
     if (virtTestRun("Network XML-2-XML " name, \
diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c
index 2bc6743..f6a1335 100644
--- a/tests/nodedevxml2xmltest.c
+++ b/tests/nodedevxml2xmltest.c
@@ -13,9 +13,6 @@
 #include "node_device_conf.h"
 #include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
-
 #define MAX_FILE 4096


@@ -57,21 +54,9 @@ static int testCompareXMLToXMLHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

 #define DO_TEST(name) \
     if (virtTestRun("Node device XML-2-XML " name, \
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index c690403..9a87dc0 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -21,9 +21,6 @@ mymain(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)

 #else

-static char *progname;
-static char *abs_srcdir;
-
 # define MAX_FILE 4096

 extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, virNodeInfoPtr nodeinfo,
@@ -89,7 +86,7 @@ static int linuxTestNodeInfo(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
     int i;
@@ -101,18 +98,6 @@ mymain(int argc, char **argv)
         "nodeinfo-5",
         "nodeinfo-6",
     };
-    char cwd[PATH_MAX];
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return(EXIT_FAILURE);
-    }

     if (virInitialize() < 0)
         return EXIT_FAILURE;
diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c
index 575177a..a1f57fa 100644
--- a/tests/nwfilterxml2xmltest.c
+++ b/tests/nwfilterxml2xmltest.c
@@ -16,9 +16,6 @@
 #include "nwfilter_conf.h"
 #include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
-
 #define MAX_FILE 4096


@@ -85,21 +82,9 @@ static int testCompareXMLToXMLHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

 #define DO_TEST(NAME, EXPECT_WARN)                                \
     do {                                                          \
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index 0214db0..60dce46 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -16,8 +16,6 @@

 # include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
 static struct qemud_driver driver;

 # define MAX_FILE 4096
@@ -103,21 +101,9 @@ static int testCompareXMLToArgvHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

     if ((driver.caps = testQemuCapsInit()) == NULL)
         return EXIT_FAILURE;
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index c86c578..792b5ab 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -19,9 +19,6 @@ struct testInfo {
     unsigned int kvm_version;
 };

-static char *progname;
-static char *abs_srcdir;
-
 static void printMismatchedFlags(virBitmapPtr got,
                                  virBitmapPtr expect)
 {
@@ -121,21 +118,9 @@ cleanup:
 }

 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

 # define DO_TEST(name, version, is_kvm, kvm_version, ...)                   \
     do {                                                                    \
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index c06bdf6..ebde3a1 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -19,8 +19,6 @@

 # include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
 static const char *abs_top_srcdir;
 static struct qemud_driver driver;

@@ -190,23 +188,11 @@ static int testCompareXMLToArgvHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
     char map[PATH_MAX];

-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));
-
     abs_top_srcdir = getenv("abs_top_srcdir");
     if (!abs_top_srcdir)
         abs_top_srcdir = "..";
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 27330a9..6f51d1e 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -15,8 +15,6 @@
 # include "qemu/qemu_conf.h"
 # include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
 static struct qemud_driver driver;

 # define MAX_FILE 4096
@@ -83,21 +81,9 @@ static int testCompareXMLToXMLHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

     if ((driver.caps = testQemuCapsInit()) == NULL)
         return (EXIT_FAILURE);
diff --git a/tests/qparamtest.c b/tests/qparamtest.c
index a4ed1fb..6dfac43 100644
--- a/tests/qparamtest.c
+++ b/tests/qparamtest.c
@@ -183,8 +183,7 @@ static const struct qparamParseDataEntry params5[] = { { "foo", "one two" } };
 static const struct qparamParseDataEntry params6[] = { { "foo", "one" } };

 static int
-mymain(int argc ATTRIBUTE_UNUSED,
-       char **argv ATTRIBUTE_UNUSED)
+mymain(void)
 {
     int ret = 0;

diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
index 9f74ece..0919435 100644
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -13,8 +13,6 @@
 #include "testutils.h"
 #include "testutilsxen.h"

-static char *progname;
-static char *abs_srcdir;
 static virCapsPtr caps;

 #define MAX_FILE 4096
@@ -99,26 +97,9 @@ static int testCompareHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return(EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return(EXIT_FAILURE);
-    }

     if (!(caps = testXenCapsInit()))
         return(EXIT_FAILURE);
diff --git a/tests/sockettest.c b/tests/sockettest.c
index 2c9ff03..b9e37ab 100644
--- a/tests/sockettest.c
+++ b/tests/sockettest.c
@@ -1,7 +1,7 @@
 /*
  * sockettest.c: Testing for src/util/network.c APIs
  *
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -159,8 +159,7 @@ static int testNetmaskHelper(const void *opaque)


 static int
-mymain(int argc ATTRIBUTE_UNUSED,
-       char **argv ATTRIBUTE_UNUSED)
+mymain(void)
 {
     int ret = 0;
     /* Some of our tests deliberately test failure cases, so
diff --git a/tests/statstest.c b/tests/statstest.c
index 36cbea4..d18bb0c 100644
--- a/tests/statstest.c
+++ b/tests/statstest.c
@@ -41,8 +41,7 @@ static int testDeviceHelper(const void *data)
 }

 static int
-mymain(int argc ATTRIBUTE_UNUSED,
-       char **argv ATTRIBUTE_UNUSED)
+mymain(void)
 {
     int ret = 0;
     /* Some of our tests delibrately test failure cases, so
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index 2ec29e3..6641153 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -13,9 +13,6 @@
 #include "storage_conf.h"
 #include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
-
 #define MAX_FILE 4096


@@ -64,21 +61,9 @@ static int testCompareXMLToXMLHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

 #define DO_TEST(name) \
     if (virtTestRun("Storage Pool XML-2-XML " name, \
diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c
index ffa5dfe..0cd57af 100644
--- a/tests/storagevolxml2xmltest.c
+++ b/tests/storagevolxml2xmltest.c
@@ -13,9 +13,6 @@
 #include "storage_conf.h"
 #include "testutilsqemu.h"

-static char *progname;
-static char *abs_srcdir;
-
 #define MAX_FILE 4096


@@ -85,21 +82,9 @@ static int testCompareXMLToXMLHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return (EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

 #define DO_TEST(pool, name) \
     do {                    \
diff --git a/tests/testutils.c b/tests/testutils.c
index 1f3b569..456a735 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -55,6 +55,9 @@ static unsigned int testVerbose = -1;
 static unsigned int testOOM = 0;
 static unsigned int testCounter = 0;

+char *progname;
+char *abs_srcdir;
+
 double
 virtTestCountAverage(double *items, int nitems)
 {
@@ -472,9 +475,10 @@ virTestGetVerbose(void) {

 int virtTestMain(int argc,
                  char **argv,
-                 int (*func)(int, char **))
+                 int (*func)(void))
 {
     int ret;
+    char cwd[PATH_MAX];
 #if TEST_OOM
     int approxAlloc = 0;
     int n;
@@ -485,7 +489,20 @@ int virtTestMain(int argc,
     int worker = 0;
 #endif

-    fprintf(stderr, "TEST: %s\n", STRPREFIX(argv[0], "./") ? argv[0] + 2 : argv[0]);
+    abs_srcdir = getenv("abs_srcdir");
+    if (!abs_srcdir)
+        abs_srcdir = getcwd(cwd, sizeof(cwd));
+    if (!abs_srcdir)
+        exit(EXIT_AM_HARDFAIL);
+
+    progname = argv[0];
+    if (STRPREFIX(progname, "./"))
+        progname += 2;
+    if (argc > 1) {
+        fprintf(stderr, "Usage: %s\n", argv[0]);
+        return EXIT_FAILURE;
+    }
+    fprintf(stderr, "TEST: %s\n", progname);
     if (!virTestGetVerbose())
         fprintf(stderr, "      ");

@@ -520,7 +537,7 @@ int virtTestMain(int argc,
     }

     /* Run once to prime any static allocations & ensure it passes */
-    ret = (func)(argc, argv);
+    ret = (func)();
     if (ret != EXIT_SUCCESS)
         goto cleanup;

@@ -537,7 +554,7 @@ int virtTestMain(int argc,
         virAllocTestInit();

         /* Run again to count allocs, and ensure it passes :-) */
-        ret = (func)(argc, argv);
+        ret = (func)();
         if (ret != EXIT_SUCCESS)
             goto cleanup;

@@ -574,7 +591,7 @@ int virtTestMain(int argc,
             }
             virAllocTestOOM(n+1, oomCount);

-            if (((func)(argc, argv)) != EXIT_FAILURE) {
+            if (((func)()) != EXIT_FAILURE) {
                 ret = EXIT_FAILURE;
                 break;
             }
@@ -604,7 +621,7 @@ int virtTestMain(int argc,
     }
 cleanup:
 #else
-    ret = (func)(argc, argv);
+    ret = (func)();
 #endif

     virResetLastError();
diff --git a/tests/testutils.h b/tests/testutils.h
index 88603a1..0ea70ee 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -1,7 +1,7 @@
 /*
  * utils.c: test utils
  *
- * Copyright (C) 2005, 2008-2010 Red Hat, Inc.
+ * Copyright (C) 2005, 2008-2011 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -14,6 +14,10 @@
 # include <stdio.h>

 # define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
+# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
+
+extern char *progname;
+extern char *abs_srcdir;

 double virtTestCountAverage(double *items,
                             int nitems);
@@ -44,11 +48,12 @@ char *virtTestLogContentAndReset(void);

 int virtTestMain(int argc,
                  char **argv,
-                 int (*func)(int, char **));
+                 int (*func)(void));

-# define VIRT_TEST_MAIN(func)                    \
-    int main(int argc, char **argv)  {          \
-        return virtTestMain(argc,argv, func);   \
+/* Setup, then call func() */
+# define VIRT_TEST_MAIN(func)                   \
+    int main(int argc, char **argv) {           \
+        return virtTestMain(argc, argv, func);  \
     }

 #endif /* __VIT_TEST_UTILS_H__ */
diff --git a/tests/virbuftest.c b/tests/virbuftest.c
index db08fc4..0094a16 100644
--- a/tests/virbuftest.c
+++ b/tests/virbuftest.c
@@ -64,8 +64,7 @@ out:
 }

 static int
-mymain(int argc ATTRIBUTE_UNUSED,
-       char **argv ATTRIBUTE_UNUSED)
+mymain(void)
 {
     int ret = 0;

diff --git a/tests/virshtest.c b/tests/virshtest.c
index 8ec97a8..465d5ea 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -8,8 +8,6 @@
 #include "xml.h"
 #include "testutils.h"

-static char *progname;
-static char *abs_srcdir;
 #define MAX_FILE 4096

 #define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493"
@@ -232,30 +230,20 @@ static int testCompareEcho(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
     char buffer[PATH_MAX];
-    char cwd[PATH_MAX];
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

 #ifdef WIN32
     exit (EXIT_AM_SKIP);
 #endif

-    snprintf(buffer, PATH_MAX-1, "test://%s/../examples/xml/test/testnode.xml", abs_srcdir);
+    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);
-    }
-
     if (virtTestRun("virsh list (default)",
                     1, testCompareListDefault, NULL) != 0)
         ret = -1;
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index 5fed1c4..3b7e9be 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -11,8 +11,6 @@
 # include "testutils.h"
 # include "vmx/vmx.h"

-static char *progname = NULL;
-static char *abs_srcdir = NULL;
 static virCapsPtr caps = NULL;
 static virVMXContext ctx;

@@ -181,28 +179,9 @@ testParseVMXFileName(const char *fileName, void *opaque ATTRIBUTE_UNUSED)
 }

 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int result = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return EXIT_FAILURE;
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-
-    if (abs_srcdir == NULL) {
-        abs_srcdir = getcwd(cwd, sizeof(cwd));
-    }
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return EXIT_FAILURE;
-    }

 # define DO_TEST(_in, _out)                                                   \
         do {                                                                  \
diff --git a/tests/xencapstest.c b/tests/xencapstest.c
index 7b48812..36946cf 100644
--- a/tests/xencapstest.c
+++ b/tests/xencapstest.c
@@ -11,9 +11,6 @@
 #include "xen/xen_hypervisor.h"
 #include "files.h"

-static char *progname;
-static char *abs_srcdir;
-
 #define MAX_FILE 4096

 static int testCompareFiles(const char *hostmachine,
@@ -151,21 +148,9 @@ static int testXenppc64(const void *data ATTRIBUTE_UNUSED) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return(EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

     virInitialize();

diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 7d418a5..62d3488 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -1,7 +1,7 @@
 /*
  * xmconfigtest.c: Test backend for xm_internal config file handling
  *
- * Copyright (C) 2007, 2010 Red Hat, Inc.
+ * Copyright (C) 2007, 2010-2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -36,8 +36,6 @@
 #include "testutilsxen.h"
 #include "memory.h"

-static char *progname;
-static char *abs_srcdir;
 static virCapsPtr caps;

 #define MAX_FILE 4096
@@ -174,21 +172,9 @@ static int testCompareHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return(EXIT_FAILURE);
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));

     if (!(caps = testXenCapsInit()))
         return(EXIT_FAILURE);
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index cf530b6..b258c3d 100644
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -14,8 +14,6 @@
 #include "testutils.h"
 #include "testutilsxen.h"

-static char *progname;
-static char *abs_srcdir;
 static virCapsPtr caps;

 #define MAX_FILE 4096
@@ -77,21 +75,9 @@ static int testCompareHelper(const void *data) {


 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int ret = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    abs_srcdir = getenv("abs_srcdir");
-    if (!abs_srcdir)
-        abs_srcdir = getcwd(cwd, sizeof(cwd));
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return(EXIT_FAILURE);
-    }

 #define DO_TEST(in, out, name, version)                                \
     do {                                                               \
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index a5fb4f7..6a4b795 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -11,8 +11,6 @@
 # include "testutils.h"
 # include "vmx/vmx.h"

-static char *progname = NULL;
-static char *abs_srcdir = NULL;
 static virCapsPtr caps = NULL;
 static virVMXContext ctx;

@@ -198,28 +196,9 @@ testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
 }

 static int
-mymain(int argc, char **argv)
+mymain(void)
 {
     int result = 0;
-    char cwd[PATH_MAX];
-
-    progname = argv[0];
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return EXIT_FAILURE;
-    }
-
-    abs_srcdir = getenv("abs_srcdir");
-
-    if (abs_srcdir == NULL) {
-        abs_srcdir = getcwd(cwd, sizeof(cwd));
-    }
-
-    if (argc > 1) {
-        fprintf(stderr, "Usage: %s\n", progname);
-        return EXIT_FAILURE;
-    }

 # define DO_TEST(_in, _out, _version)                                         \
         do {                                                                  \
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]