]> xenbits.xensource.com Git - libvirt.git/commitdiff
test: Refactor setting of dummy error handlers
authorPeter Krempa <pkrempa@redhat.com>
Tue, 17 Sep 2013 13:20:24 +0000 (15:20 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 17 Sep 2013 14:45:53 +0000 (16:45 +0200)
Multiple tests need to register a function to quiesce errors from
libvirt when using a connection and doing negative tests. Each of those
tests had a static function to do so. This can be replaced by a utility
function that enables the errors when debug is enabled.

This patch adds virtTestQuiesceLibvirtErrors() and refactors test that
use private handlers.

tests/esxutilstest.c
tests/reconnect.c
tests/sockettest.c
tests/statstest.c
tests/testutils.c
tests/testutils.h
tests/utiltest.c

index 221c46ac5a9a8e4b6e9317b7458aba3c87e6f50e..a60c7ecad74655e3fdf46e0ccfebbece9922fcfa 100644 (file)
 # include "esx/esx_util.h"
 # include "esx/esx_vi_types.h"
 
-
-static void
-testQuietError(void *userData ATTRIBUTE_UNUSED,
-               virErrorPtr error ATTRIBUTE_UNUSED)
-{
-    /* nothing */
-}
-
-
-
 struct testPath {
     const char *datastorePath;
     int result;
@@ -259,7 +249,7 @@ mymain(void)
 {
     int result = 0;
 
-    virSetErrorFunc(NULL, testQuietError);
+    virtTestQuiesceLibvirtErrors(true);
 
 # define DO_TEST(_name)                                                       \
         do {                                                                  \
index b446161fd083ec60177bf003839ff6733c0497e6..09deb5d106e3aac5b0561cfa685b40abb54eeda5 100644 (file)
@@ -8,10 +8,6 @@
 #include "testutils.h"
 #include "vircommand.h"
 
-static void errorHandler(void *userData ATTRIBUTE_UNUSED,
-                         virErrorPtr error ATTRIBUTE_UNUSED) {
-}
-
 static int
 mymain(void)
 {
@@ -36,7 +32,7 @@ mymain(void)
     }
     virCommandFree(cmd);
 
-    virSetErrorFunc(NULL, errorHandler);
+    virtTestQuiesceLibvirtErrors(true);
 
     conn = virConnectOpen(NULL);
     if (conn == NULL) {
index 092de88ba6902b5242d78423d593fbf79a977f0a..6842ba40dbe887d95c90b0ba311f2ea0013a463c 100644 (file)
 #include "virlog.h"
 #include "viralloc.h"
 
-static void testQuietError(void *userData ATTRIBUTE_UNUSED,
-                           virErrorPtr error ATTRIBUTE_UNUSED)
-{
-    /* nada */
-}
-
 static int testParse(virSocketAddr *addr, const char *addrstr, int family, bool pass)
 {
     int rc;
@@ -188,8 +182,7 @@ mymain(void)
      * register a handler to stop error messages cluttering
      * up display
      */
-    if (!virTestGetDebug())
-        virSetErrorFunc(NULL, testQuietError);
+    virtTestQuiesceLibvirtErrors(false);
 
 #define DO_TEST_PARSE(addrstr, family, pass)                            \
     do {                                                                \
index 30f9ab0d12e880b5cba5e3cf7e68c24670ef186b..94ccd4f30a84f9f3f256cef210cf1edfae4e1126 100644 (file)
 #include "testutils.h"
 #include "vircommand.h"
 
-static void testQuietError(void *userData ATTRIBUTE_UNUSED,
-                           virErrorPtr error ATTRIBUTE_UNUSED)
-{
-    /* nada */
-}
-
 static int testDevice(const char *path, int expect)
 {
     int actual = xenLinuxDomainDeviceID(1, path);
@@ -67,8 +61,7 @@ mymain(void)
      * register a handler to stop error messages cluttering
      * up display
      */
-    if (!virTestGetDebug())
-        virSetErrorFunc(NULL, testQuietError);
+    virtTestQuiesceLibvirtErrors(false);
 
 #define DO_TEST(dev, num)                                              \
     do {                                                               \
index c5215528b03294b527f6f97e2998dc47c60fa64f..a215f3f32c59f1eccc1f13b152b88c039eac194e 100644 (file)
@@ -478,12 +478,19 @@ int virtTestDifferenceBin(FILE *stream,
     return 0;
 }
 
-#if TEST_OOM
 static void
 virtTestErrorFuncQuiet(void *data ATTRIBUTE_UNUSED,
                        virErrorPtr err ATTRIBUTE_UNUSED)
 { }
-#endif
+
+
+/* register an error handler in tests when using connections */
+void
+virtTestQuiesceLibvirtErrors(bool always)
+{
+    if (always || !virTestGetVerbose())
+        virSetErrorFunc(NULL, virtTestErrorFuncQuiet);
+}
 
 struct virtTestLogData {
     virBuffer buf;
@@ -698,7 +705,7 @@ int virtTestMain(int argc,
     if (testOOM) {
         /* Makes next test runs quiet... */
         testOOM++;
-        virSetErrorFunc(NULL, virtTestErrorFuncQuiet);
+        virtTestQuiesceLibvirtErrors(true);
 
         virAllocTestInit();
 
index ef0ca3cf58aa2d0a56bd77e21ae3547fb860d1fe..2da6424236328ad1bcaee64c84b1d0342f7e691a 100644 (file)
@@ -69,6 +69,8 @@ unsigned int virTestGetExpensive(void);
 
 char *virtTestLogContentAndReset(void);
 
+void virtTestQuiesceLibvirtErrors(bool always);
+
 int virtTestMain(int argc,
                  char **argv,
                  int (*func)(void));
index 0cbf3f3dc9f8579bcfb83981ed11833606659213..422f4e81615162da49fb8baeee77027d3471808c 100644 (file)
 #include "testutils.h"
 #include "virutil.h"
 
-
-static void
-testQuietError(void *userData ATTRIBUTE_UNUSED,
-               virErrorPtr error ATTRIBUTE_UNUSED)
-{
-    /* nothing */
-}
-
-
-
 static const char* diskNames[] = {
     "sda",  "sdb",  "sdc",  "sdd",  "sde",  "sdf",  "sdg",  "sdh",  "sdi",  "sdj",  "sdk",  "sdl",  "sdm",  "sdn",  "sdo",  "sdp",  "sdq",  "sdr",  "sds",  "sdt",  "sdu",  "sdv",  "sdw",  "sdx",  "sdy",  "sdz",
     "sdaa", "sdab", "sdac", "sdad", "sdae", "sdaf", "sdag", "sdah", "sdai", "sdaj", "sdak", "sdal", "sdam", "sdan", "sdao", "sdap", "sdaq", "sdar", "sdas", "sdat", "sdau", "sdav", "sdaw", "sdax", "sday", "sdaz",
@@ -160,7 +150,7 @@ mymain(void)
 {
     int result = 0;
 
-    virSetErrorFunc(NULL, testQuietError);
+    virtTestQuiesceLibvirtErrors(true);
 
 #define DO_TEST(_name)                                                  \
         do {                                                                  \