提交 d154807d 编写于 作者: P Peter Krempa

tests: utils: Introduce helper for dispatching libvirt errors

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 5f5542b4
...@@ -81,6 +81,30 @@ virTestGetFlag(const char *name) ...@@ -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 * Runs test
* *
...@@ -112,10 +136,7 @@ virTestRun(const char *title, ...@@ -112,10 +136,7 @@ virTestRun(const char *title,
virResetLastError(); virResetLastError();
ret = body(data); ret = body(data);
if (virGetLastErrorCode()) { virTestPropagateLibvirtError();
if (virTestGetVerbose() || virTestGetDebug())
virDispatchError(NULL);
}
if (virTestGetVerbose()) { if (virTestGetVerbose()) {
if (ret == 0) if (ret == 0)
......
...@@ -84,6 +84,7 @@ unsigned int virTestGetDebug(void); ...@@ -84,6 +84,7 @@ unsigned int virTestGetDebug(void);
unsigned int virTestGetVerbose(void); unsigned int virTestGetVerbose(void);
unsigned int virTestGetExpensive(void); unsigned int virTestGetExpensive(void);
unsigned int virTestGetRegenerate(void); unsigned int virTestGetRegenerate(void);
void virTestPropagateLibvirtError(void);
#define VIR_TEST_DEBUG(fmt, ...) \ #define VIR_TEST_DEBUG(fmt, ...) \
do { \ do { \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册