[PATCH 1/2] test: Refactor setting of dummy error handlers

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

 



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 enabledd.

This patch adds virtTestQuiesceLibvirtErrors() and refactors test that
use private handlers.
---
 tests/esxutilstest.c | 12 +-----------
 tests/reconnect.c    |  6 +-----
 tests/sockettest.c   |  9 +--------
 tests/statstest.c    |  9 +--------
 tests/testutils.c    | 13 ++++++++++---
 tests/testutils.h    |  2 ++
 tests/utiltest.c     | 12 +-----------
 7 files changed, 17 insertions(+), 46 deletions(-)

diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index 221c46a..a60c7ec 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -14,16 +14,6 @@
 # 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 {                                                                  \
diff --git a/tests/reconnect.c b/tests/reconnect.c
index b446161..09deb5d 100644
--- a/tests/reconnect.c
+++ b/tests/reconnect.c
@@ -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) {
diff --git a/tests/sockettest.c b/tests/sockettest.c
index 092de88..6842ba4 100644
--- a/tests/sockettest.c
+++ b/tests/sockettest.c
@@ -30,12 +30,6 @@
 #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 {                                                                \
diff --git a/tests/statstest.c b/tests/statstest.c
index 30f9ab0..94ccd4f 100644
--- a/tests/statstest.c
+++ b/tests/statstest.c
@@ -11,12 +11,6 @@
 #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 {                                                               \
diff --git a/tests/testutils.c b/tests/testutils.c
index c521552..a215f3f 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -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();

diff --git a/tests/testutils.h b/tests/testutils.h
index ef0ca3c..2da6424 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -69,6 +69,8 @@ unsigned int virTestGetExpensive(void);

 char *virtTestLogContentAndReset(void);

+void virtTestQuiesceLibvirtErrors(bool always);
+
 int virtTestMain(int argc,
                  char **argv,
                  int (*func)(void));
diff --git a/tests/utiltest.c b/tests/utiltest.c
index 0cbf3f3..422f4e8 100644
--- a/tests/utiltest.c
+++ b/tests/utiltest.c
@@ -10,16 +10,6 @@
 #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 {                                                                  \
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]