]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: simplify common setup
authorEric Blake <eblake@redhat.com>
Fri, 29 Apr 2011 16:21:20 +0000 (10:21 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 29 Apr 2011 16:21:20 +0000 (10:21 -0600)
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.

29 files changed:
tests/commandtest.c
tests/cputest.c
tests/esxutilstest.c
tests/eventtest.c
tests/hashtest.c
tests/interfacexml2xmltest.c
tests/networkxml2xmltest.c
tests/nodedevxml2xmltest.c
tests/nodeinfotest.c
tests/nwfilterxml2xmltest.c
tests/qemuargv2xmltest.c
tests/qemuhelptest.c
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c
tests/qparamtest.c
tests/sexpr2xmltest.c
tests/sockettest.c
tests/statstest.c
tests/storagepoolxml2xmltest.c
tests/storagevolxml2xmltest.c
tests/testutils.c
tests/testutils.h
tests/virbuftest.c
tests/virshtest.c
tests/vmx2xmltest.c
tests/xencapstest.c
tests/xmconfigtest.c
tests/xml2sexprtest.c
tests/xml2vmxtest.c

index c313a2cec348e0f08ffe9c635b7dfb4c04180828..509c88842336f333c366595dc095200f4ec03b29 100644 (file)
@@ -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);
 
index bd06958a8a4d3f45562bd9f6b92f17a44ec8bca4..a8d28dc5959d4461331fa3143ee16429f3efd3ab 100644 (file)
@@ -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 = "..";
index b6bf87bd05c42f01192cb4ecd58d0baec21a1e46..830f79c861d6d11ef1624885fac32b5b10ad6efb 100644 (file)
@@ -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)                                                       \
index eb4b7552a915ab8c386f08c2ead7843f3db6e358..4c458602b5d26d390e8731e0f6ede31e5c2dcc96 100644 (file)
@@ -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)
index bb3a8128df227a8f1d554839828e55d3245b9e6c..525ae06903031c60a060060cb13a648918a60f1a 100644 (file)
@@ -476,8 +476,7 @@ cleanup:
 
 
 static int
-mymain(int argc ATTRIBUTE_UNUSED,
-       char **argv ATTRIBUTE_UNUSED)
+mymain(void)
 {
     int ret = 0;
 
index 094ccf511ae603972bee47764225f245943dcc80..fb454c1d9add283ba1cbd0191f6c18be3a51875e 100644 (file)
@@ -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, \
index 78055486306a07ce7ebfe2b65f55134ad73fcad1..f7489f5dbd6e8d20a2b3a8012eed720612d17304 100644 (file)
@@ -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, \
index 2bc67436baa31f9f2fc9669fae7b0b616e61743c..f6a1335a593f897c355d33f9ad34b9579d8e8b31 100644 (file)
@@ -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, \
index c690403503db2f00ff3440148214e2de74f0a4d7..9a87dc09cbea9889b3d8542ac8a7d0cbab199f44 100644 (file)
@@ -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;
index 575177af89a8d1565153ae7c6683f1a78dc21655..a1f57fab5757071184037decaf7b76b00931146c 100644 (file)
@@ -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 {                                                          \
index 0214db09866fca826b827ce0b576223df3c8f4e5..60dce460f58730ab39d152e11cabb51d8a13d5f7 100644 (file)
@@ -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;
index c86c5782c578bf1f1f4292eed97b6c48e9a31020..792b5ab7f7adff163221765738963d106131134e 100644 (file)
@@ -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 {                                                                    \
index c06bdf6c907c04a11c4e14624408e31120c13691..ebde3a1b8d5ffd5adaca836d78864fda6dfb2527 100644 (file)
@@ -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 = "..";
index 27330a97bc9c811b40db95c39af0747c1ccb9abd..6f51d1e06556b87a0331395e264f0a1c47ee2e40 100644 (file)
@@ -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);
index a4ed1fb8a2e7831ee1796cab7022fb0a23e0bad2..6dfac43615a1adcaf0b53162b0dbf68606afe701 100644 (file)
@@ -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;
 
index 9f74ece1b32a4331b3646593a2459cb8bd3a02df..091943553e81ada5abd9ab57f83ebdbd888c514a 100644 (file)
@@ -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);
index 2c9ff03d921f4c7ab1d68cbe9ef3a7951439b74c..b9e37ab407d08895bc5bed83c2f63281f88c239e 100644 (file)
@@ -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
index 36cbea4ff3f810722b64ada74663543661721338..d18bb0c06d19573ecc5b62e30903375556191489 100644 (file)
@@ -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
index 2ec29e3260e51b22c2a36e1c68f638606d9d90c1..6641153f5156f27839878702c789938581686470 100644 (file)
@@ -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, \
index ffa5dfef38eefbfb76737a49bdfeb0e91defb762..0cd57af26fd5b11e85a6150ed7dad1b490c8a8f2 100644 (file)
@@ -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 {                    \
index 1f3b5693d49251e1d9cea9b4e66d1b0bcfd95d0a..456a73540a613a1df8b0c5a5d7aac8da372d0b91 100644 (file)
@@ -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();
index 88603a1f0b8e54cd6dd20a74dfdb813a0020d291..0ea70ee82b0dae68af4033325fdc670c99ba8b21 100644 (file)
@@ -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
  *
 # 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__ */
index db08fc462a405005fb57299073266b0cf09d5add..0094a16ecaa920777206dfb4bda24705e2c8ed66 100644 (file)
@@ -64,8 +64,7 @@ out:
 }
 
 static int
-mymain(int argc ATTRIBUTE_UNUSED,
-       char **argv ATTRIBUTE_UNUSED)
+mymain(void)
 {
     int ret = 0;
 
index 8ec97a84e9a52c4d326b81c64775fbd7e0dd6157..465d5eac52360490c8ea73a1ac495e8132c0f75f 100644 (file)
@@ -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;
index 5fed1c4b58956e57f143c2e5bcb862e73cf8fff9..3b7e9be7c4948e0a309e9e605a7d31ad48340c3c 100644 (file)
@@ -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 {                                                                  \
index 7b4881252ceb925f5311616c1fba91e5dc1f3ee2..36946cf10cd88f1091fc0899ea5a94cb0adca7a8 100644 (file)
@@ -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();
 
index 7d418a50a9e5218ad9d23f6d43f904c31b535105..62d34880c858cb18651ccd101059082f48184c37 100644 (file)
@@ -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);
index cf530b68d9f6d925d3cf737905da3494d0238684..b258c3d58dd6ad7fd20d29294b9045d7ee138755 100644 (file)
@@ -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 {                                                               \
index a5fb4f7e6287184648707cc74bcacbae4915b03f..6a4b795d1d49f8902985d21b0f32516287835fab 100644 (file)
@@ -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 {                                                                  \