mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-16 18:25:08 -06:00
test: Refactor setting of dummy error handlers
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 enabled. This patch adds virtTestQuiesceLibvirtErrors() and refactors test that use private handlers.
This commit is contained in:
parent
8ffe1d0c46
commit
43f68a4f9e
@ -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 { \
|
||||
|
@ -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) {
|
||||
|
@ -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 { \
|
||||
|
@ -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 { \
|
||||
|
@ -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();
|
||||
|
||||
|
@ -69,6 +69,8 @@ unsigned int virTestGetExpensive(void);
|
||||
|
||||
char *virtTestLogContentAndReset(void);
|
||||
|
||||
void virtTestQuiesceLibvirtErrors(bool always);
|
||||
|
||||
int virtTestMain(int argc,
|
||||
char **argv,
|
||||
int (*func)(void));
|
||||
|
@ -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 { \
|
||||
|
Loading…
Reference in New Issue
Block a user