[PATCH 2/3] tests: utils: Introduce helper for dispatching libvirt errors

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

 



In cases when we call a libvirt helper which reports an error the error
would be hidden unless libvirt library debug is on. This produces a lot
of output and is hard to debug.

The helper provides a way to dispatch the libvirt error in specific
cases sice we do already dispatch it in case when virTestRun is used.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/testutils.c | 29 +++++++++++++++++++++++++----
 tests/testutils.h |  1 +
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/tests/testutils.c b/tests/testutils.c
index f5d8487736..d9c0d5abbe 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -81,6 +81,30 @@ virTestGetFlag(const char *name)
 }


+/**
+ * virTestPropagateLibvirtError:
+ *
+ * In cases when a libvirt utility function which reports libvirt errors is
+ * used in the test suite outside of the virTestRun call and the failure of such
+ * a function would cause an test failure the error message reported by that
+ * function will not be propagated to the user as the error callback is not
+ * invoked.
+ *
+ * In cases when the error message may be beneficial in debugging this helper
+ * provides means to dispatch the errors including invocation of the error
+ * callback.
+ */
+void
+virTestPropagateLibvirtError(void)
+{
+    if (virGetLastErrorCode() == VIR_ERR_OK)
+        return;
+
+    if (virTestGetVerbose() || virTestGetDebug())
+        virDispatchError(NULL);
+}
+
+
 /*
  * Runs test
  *
@@ -112,10 +136,7 @@ virTestRun(const char *title,

     virResetLastError();
     ret = body(data);
-    if (virGetLastErrorCode()) {
-        if (virTestGetVerbose() || virTestGetDebug())
-            virDispatchError(NULL);
-    }
+    virTestPropagateLibvirtError();

     if (virTestGetVerbose()) {
         if (ret == 0)
diff --git a/tests/testutils.h b/tests/testutils.h
index 0088251dca..76090c5522 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -84,6 +84,7 @@ unsigned int virTestGetDebug(void);
 unsigned int virTestGetVerbose(void);
 unsigned int virTestGetExpensive(void);
 unsigned int virTestGetRegenerate(void);
+void virTestPropagateLibvirtError(void);

 #define VIR_TEST_DEBUG(fmt, ...) \
     do { \
-- 
2.23.0

--
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]

  Powered by Linux