]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: utils: Introduce helper for dispatching libvirt errors
authorPeter Krempa <pkrempa@redhat.com>
Tue, 19 Nov 2019 10:52:40 +0000 (11:52 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 20 Nov 2019 11:57:50 +0000 (12:57 +0100)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/testutils.c
tests/testutils.h

index f5d8487736a8f768c5add2644dc5ddf06041f9bc..d9c0d5abbe4b07a4f24a1690bcefc1b3297e1ece 100644 (file)
@@ -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)
index 0088251dcaf253a43ceb64429914df4ef6bbed40..76090c5522bf1bf3e680facae75d4e34601f8941 100644 (file)
@@ -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 { \