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: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2019-11-19 11:52:40 +01:00
parent 5f5542b44e
commit d154807d5b
2 changed files with 26 additions and 4 deletions

View 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)

View 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 { \