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

Re: [libvirt] PATCH: 4/4: Switch many testcases to OOM checking APIs



This switches over a number of the test cases to make use of the new
virTestMain() function and thus gain support for allocation checking

So you can now actually see some checks when running
   

   VIR_TEST_OOM=1 make check

Oh, and for added fun you can check if there are any leaks in the cleanup
paths by layering in valgrind 


    VIR_TEST_OOM=1 make valgrind

which is superbly slow but finds a few things :-)

 nodeinfotest.c     |   28 ++++++++++++++++------------
 qemuxml2argvtest.c |   16 ++++++++++------
 qemuxml2xmltest.c  |   13 ++++++++-----
 qparamtest.c       |    8 ++++++--
 sexpr2xmltest.c    |   13 ++++++++-----
 statstest.c        |   11 +++++++----
 xencapstest.c      |   32 ++++++++++++++++++--------------
 xmconfigtest.c     |   11 +++++++----
 xml2sexprtest.c    |   10 ++++++----
 9 files changed, 86 insertions(+), 56 deletions(-)

Regards,
Daniel

diff -r 7713868fe647 tests/nodeinfotest.c
--- a/tests/nodeinfotest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/nodeinfotest.c	Thu May 22 13:01:25 2008 -0400
@@ -3,13 +3,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "testutils.h"
 #include "internal.h"
 #include "nodeinfo.h"
 
 static char *progname;
-static char *abs_top_srcdir;
+static char *abs_srcdir;
 
 #define MAX_FILE 4096
 
@@ -56,17 +57,17 @@
 static int linuxTestNodeInfo(const void *data) {
     char cpuinfo[PATH_MAX];
     char output[PATH_MAX];
-    snprintf(cpuinfo, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.cpuinfo",
-             abs_top_srcdir, (const char*)data);
-    snprintf(output, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.txt",
-             abs_top_srcdir, (const char*)data);
+    snprintf(cpuinfo, PATH_MAX, "%s/nodeinfodata/linux-%s.cpuinfo",
+             abs_srcdir, (const char*)data);
+    snprintf(output, PATH_MAX, "%s/nodeinfodata/linux-%s.txt",
+             abs_srcdir, (const char*)data);
     return linuxTestCompareFiles(cpuinfo, output);
 }
 #endif
 
 
-int
-main(int argc, char **argv)
+static int
+mymain(int argc, char **argv)
 {
     int ret = 0;
 #ifdef __linux__
@@ -79,16 +80,17 @@
         "nodeinfo-5",
         "nodeinfo-6",
     };
+    char cwd[PATH_MAX];
 
-    abs_top_srcdir = getenv("abs_top_srcdir");
-    if (!abs_top_srcdir)
-      return EXIT_FAILURE;
+    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);
-        exit(EXIT_FAILURE);
+        return(EXIT_FAILURE);
     }
 
     virInitialize();
@@ -98,5 +100,7 @@
         ret = -1;
 #endif
 
-    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+    return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+
+VIRT_TEST_MAIN(mymain)
diff -r 7713868fe647 tests/qemuxml2argvtest.c
--- a/tests/qemuxml2argvtest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/qemuxml2argvtest.c	Thu May 22 13:01:25 2008 -0400
@@ -43,6 +43,7 @@
     if (!(vmdef = qemudParseVMDef(NULL, &driver, xmlData, "test")))
         goto fail;
 
+    memset(&vm, 0, sizeof vm);
     vm.def = vmdef;
     vm.pid = -1;
     vm.id = -1;
@@ -115,8 +116,8 @@
 
 
 
-int
-main(int argc, char **argv)
+static int
+mymain(int argc, char **argv)
 {
     int ret = 0;
     char cwd[PATH_MAX];
@@ -125,14 +126,15 @@
 
     if (argc > 1) {
         fprintf(stderr, "Usage: %s\n", progname);
-        exit(EXIT_FAILURE);
+        return (EXIT_FAILURE);
     }
 
     abs_srcdir = getenv("abs_srcdir");
     if (!abs_srcdir)
         abs_srcdir = getcwd(cwd, sizeof(cwd));
 
-    driver.caps = testQemuCapsInit();
+    if ((driver.caps = testQemuCapsInit()) == NULL)
+        return EXIT_FAILURE;
 
 #define DO_TEST(name, extraFlags)                                       \
     do {                                                                \
@@ -181,11 +183,13 @@
 
     virCapabilitiesFree(driver.caps);
 
-    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+    return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+
+VIRT_TEST_MAIN(mymain)
 
 #else
 
-int main (void) { exit (77); /* means 'test skipped' for automake */ }
+int main (void) { return (77); /* means 'test skipped' for automake */ }
 
 #endif /* WITH_QEMU */
diff -r 7713868fe647 tests/qemuxml2xmltest.c
--- a/tests/qemuxml2xmltest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/qemuxml2xmltest.c	Thu May 22 13:01:25 2008 -0400
@@ -70,8 +70,8 @@
 }
 
 
-int
-main(int argc, char **argv)
+static int
+mymain(int argc, char **argv)
 {
     int ret = 0;
     char cwd[PATH_MAX];
@@ -80,14 +80,15 @@
 
     if (argc > 1) {
         fprintf(stderr, "Usage: %s\n", progname);
-        exit(EXIT_FAILURE);
+        return (EXIT_FAILURE);
     }
 
     abs_srcdir = getenv("abs_srcdir");
     if (!abs_srcdir)
         abs_srcdir = getcwd(cwd, sizeof(cwd));
 
-    driver.caps = testQemuCapsInit();
+    if ((driver.caps = testQemuCapsInit()) == NULL)
+        return (EXIT_FAILURE);
 
 #define DO_TEST(name) \
     if (virtTestRun("QEMU XML-2-XML " name, \
@@ -129,8 +130,10 @@
 
     virCapabilitiesFree(driver.caps);
 
-    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+
+VIRT_TEST_MAIN(mymain)
 
 #else
 
diff -r 7713868fe647 tests/qparamtest.c
--- a/tests/qparamtest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/qparamtest.c	Thu May 22 13:01:25 2008 -0400
@@ -7,6 +7,7 @@
 #include "testutils.h"
 #include "qparams.h"
 #include "util.h"
+#include "memory.h"
 
 struct qparamParseDataEntry {
     const char *name;
@@ -181,7 +182,8 @@
 static const struct qparamParseDataEntry const params6[] = { { "foo", "one" } };
 
 int
-main(void)
+mymain(int argc ATTRIBUTE_UNUSED,
+       char **argv ATTRIBUTE_UNUSED)
 {
     int ret = 0;
 
@@ -220,5 +222,7 @@
     if (virtTestRun("Add vargs", 1, qparamTestAddVargs, NULL) < 0)
         ret = -1;
 
-    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+    return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+
+VIRT_TEST_MAIN(mymain)
diff -r 7713868fe647 tests/sexpr2xmltest.c
--- a/tests/sexpr2xmltest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/sexpr2xmltest.c	Thu May 22 13:01:25 2008 -0400
@@ -69,8 +69,8 @@
 }
 
 
-int
-main(int argc, char **argv)
+static int
+mymain(int argc, char **argv)
 {
     int ret = 0;
     char cwd[PATH_MAX];
@@ -79,7 +79,7 @@
 
     if (argc > 1) {
         fprintf(stderr, "Usage: %s\n", progname);
-        exit(EXIT_FAILURE);
+        return(EXIT_FAILURE);
     }
 
     abs_srcdir = getenv("abs_srcdir");
@@ -88,7 +88,7 @@
 
     if (argc > 1) {
         fprintf(stderr, "Usage: %s\n", progname);
-        exit(EXIT_FAILURE);
+        return(EXIT_FAILURE);
     }
 
 #define DO_TEST(in, out, version)                                      \
@@ -139,8 +139,11 @@
     DO_TEST("fv-sound", "fv-sound", 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 */
 int
 main(void)
diff -r 7713868fe647 tests/statstest.c
--- a/tests/statstest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/statstest.c	Thu May 22 13:01:25 2008 -0400
@@ -45,8 +45,9 @@
 
 #endif
 
-int
-main(void)
+static int
+mymain(int argc ATTRIBUTE_UNUSED,
+       char **argv ATTRIBUTE_UNUSED)
 {
     int ret = 0;
 #if __linux__ && WITH_XEN
@@ -54,7 +55,7 @@
      * register a handler to stop error messages cluttering
      * up display
      */
-    if (!getenv("DEBUG_TESTS"))
+    if (!getenv("VIR_TEST_DEBUG"))
         virSetErrorFunc(NULL, testQuietError);
 
 #define DO_TEST(dev, num)                                              \
@@ -177,5 +178,7 @@
     DO_TEST("/dev/xvda15", 51727);
 
 #endif
-    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+    return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+
+VIRT_TEST_MAIN(mymain)
diff -r 7713868fe647 tests/xencapstest.c
--- a/tests/xencapstest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/xencapstest.c	Thu May 22 13:01:25 2008 -0400
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #ifdef WITH_XEN
 
@@ -12,7 +13,7 @@
 #include "xen_internal.h"
 
 static char *progname;
-static char *abs_top_srcdir;
+static char *abs_srcdir;
 
 #define MAX_FILE 4096
 
@@ -31,12 +32,12 @@
   char cpuinfo[PATH_MAX];
   char capabilities[PATH_MAX];
 
-  snprintf(xml, sizeof xml - 1, "%s/tests/%s",
-           abs_top_srcdir, xml_rel);
-  snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/tests/%s",
-           abs_top_srcdir, cpuinfo_rel);
-  snprintf(capabilities, sizeof capabilities - 1, "%s/tests/%s",
-           abs_top_srcdir, capabilities_rel);
+  snprintf(xml, sizeof xml - 1, "%s/%s",
+           abs_srcdir, xml_rel);
+  snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/%s",
+           abs_srcdir, cpuinfo_rel);
+  snprintf(capabilities, sizeof capabilities - 1, "%s/%s",
+           abs_srcdir, capabilities_rel);
 
   if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0)
     goto fail;
@@ -147,21 +148,22 @@
 }
 
 
-int
-main(int argc, char **argv)
+static int
+mymain(int argc, char **argv)
 {
     int ret = 0;
+    char cwd[PATH_MAX];
 
     progname = argv[0];
 
     if (argc > 1) {
         fprintf(stderr, "Usage: %s\n", progname);
-        exit(EXIT_FAILURE);
+        return(EXIT_FAILURE);
     }
 
-    abs_top_srcdir = getenv("abs_top_srcdir");
-    if (!abs_top_srcdir)
-      return 1;
+    abs_srcdir = getenv("abs_srcdir");
+    if (!abs_srcdir)
+        abs_srcdir = getcwd(cwd, sizeof(cwd));
 
     virInitialize();
 
@@ -213,8 +215,10 @@
         ret = -1;
 
 
-    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+    return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
 }
+
+VIRT_TEST_MAIN(mymain)
 
 #else /* !WITH_XEN */
 
diff -r 7713868fe647 tests/xmconfigtest.c
--- a/tests/xmconfigtest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/xmconfigtest.c	Thu May 22 13:01:25 2008 -0400
@@ -170,8 +170,8 @@
 }
 
 
-int
-main(int argc, char **argv)
+static int
+mymain(int argc, char **argv)
 {
     int ret = 0;
     char cwd[PATH_MAX];
@@ -180,7 +180,7 @@
 
     if (argc > 1) {
         fprintf(stderr, "Usage: %s\n", progname);
-        exit(EXIT_FAILURE);
+        return(EXIT_FAILURE);
     }
 
     abs_srcdir = getenv("abs_srcdir");
@@ -223,8 +223,11 @@
 
     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 */
 int
 main(void)
diff -r 7713868fe647 tests/xml2sexprtest.c
--- a/tests/xml2sexprtest.c	Thu May 22 12:59:37 2008 -0400
+++ b/tests/xml2sexprtest.c	Thu May 22 13:01:25 2008 -0400
@@ -77,8 +77,8 @@
 }
 
 
-int
-main(int argc, char **argv)
+static int
+mymain(int argc, char **argv)
 {
     int ret = 0;
     char cwd[PATH_MAX];
@@ -91,7 +91,7 @@
 
     if (argc > 1) {
         fprintf(stderr, "Usage: %s\n", progname);
-        exit(EXIT_FAILURE);
+        return(EXIT_FAILURE);
     }
 
 #define DO_TEST(in, out, name, version)                                \
@@ -145,8 +145,10 @@
 
     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 */
 

-- 
|: Red Hat, Engineering, Boston   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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