mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00: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_util.h"
|
||||||
# include "esx/esx_vi_types.h"
|
# include "esx/esx_vi_types.h"
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
testQuietError(void *userData ATTRIBUTE_UNUSED,
|
|
||||||
virErrorPtr error ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
/* nothing */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct testPath {
|
struct testPath {
|
||||||
const char *datastorePath;
|
const char *datastorePath;
|
||||||
int result;
|
int result;
|
||||||
@ -259,7 +249,7 @@ mymain(void)
|
|||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
virSetErrorFunc(NULL, testQuietError);
|
virtTestQuiesceLibvirtErrors(true);
|
||||||
|
|
||||||
# define DO_TEST(_name) \
|
# define DO_TEST(_name) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -8,10 +8,6 @@
|
|||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
#include "vircommand.h"
|
#include "vircommand.h"
|
||||||
|
|
||||||
static void errorHandler(void *userData ATTRIBUTE_UNUSED,
|
|
||||||
virErrorPtr error ATTRIBUTE_UNUSED) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mymain(void)
|
mymain(void)
|
||||||
{
|
{
|
||||||
@ -36,7 +32,7 @@ mymain(void)
|
|||||||
}
|
}
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
|
|
||||||
virSetErrorFunc(NULL, errorHandler);
|
virtTestQuiesceLibvirtErrors(true);
|
||||||
|
|
||||||
conn = virConnectOpen(NULL);
|
conn = virConnectOpen(NULL);
|
||||||
if (conn == NULL) {
|
if (conn == NULL) {
|
||||||
|
@ -30,12 +30,6 @@
|
|||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "viralloc.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)
|
static int testParse(virSocketAddr *addr, const char *addrstr, int family, bool pass)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -188,8 +182,7 @@ mymain(void)
|
|||||||
* register a handler to stop error messages cluttering
|
* register a handler to stop error messages cluttering
|
||||||
* up display
|
* up display
|
||||||
*/
|
*/
|
||||||
if (!virTestGetDebug())
|
virtTestQuiesceLibvirtErrors(false);
|
||||||
virSetErrorFunc(NULL, testQuietError);
|
|
||||||
|
|
||||||
#define DO_TEST_PARSE(addrstr, family, pass) \
|
#define DO_TEST_PARSE(addrstr, family, pass) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -11,12 +11,6 @@
|
|||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
#include "vircommand.h"
|
#include "vircommand.h"
|
||||||
|
|
||||||
static void testQuietError(void *userData ATTRIBUTE_UNUSED,
|
|
||||||
virErrorPtr error ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
/* nada */
|
|
||||||
}
|
|
||||||
|
|
||||||
static int testDevice(const char *path, int expect)
|
static int testDevice(const char *path, int expect)
|
||||||
{
|
{
|
||||||
int actual = xenLinuxDomainDeviceID(1, path);
|
int actual = xenLinuxDomainDeviceID(1, path);
|
||||||
@ -67,8 +61,7 @@ mymain(void)
|
|||||||
* register a handler to stop error messages cluttering
|
* register a handler to stop error messages cluttering
|
||||||
* up display
|
* up display
|
||||||
*/
|
*/
|
||||||
if (!virTestGetDebug())
|
virtTestQuiesceLibvirtErrors(false);
|
||||||
virSetErrorFunc(NULL, testQuietError);
|
|
||||||
|
|
||||||
#define DO_TEST(dev, num) \
|
#define DO_TEST(dev, num) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -478,12 +478,19 @@ int virtTestDifferenceBin(FILE *stream,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TEST_OOM
|
|
||||||
static void
|
static void
|
||||||
virtTestErrorFuncQuiet(void *data ATTRIBUTE_UNUSED,
|
virtTestErrorFuncQuiet(void *data ATTRIBUTE_UNUSED,
|
||||||
virErrorPtr err 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 {
|
struct virtTestLogData {
|
||||||
virBuffer buf;
|
virBuffer buf;
|
||||||
@ -698,7 +705,7 @@ int virtTestMain(int argc,
|
|||||||
if (testOOM) {
|
if (testOOM) {
|
||||||
/* Makes next test runs quiet... */
|
/* Makes next test runs quiet... */
|
||||||
testOOM++;
|
testOOM++;
|
||||||
virSetErrorFunc(NULL, virtTestErrorFuncQuiet);
|
virtTestQuiesceLibvirtErrors(true);
|
||||||
|
|
||||||
virAllocTestInit();
|
virAllocTestInit();
|
||||||
|
|
||||||
|
@ -69,6 +69,8 @@ unsigned int virTestGetExpensive(void);
|
|||||||
|
|
||||||
char *virtTestLogContentAndReset(void);
|
char *virtTestLogContentAndReset(void);
|
||||||
|
|
||||||
|
void virtTestQuiesceLibvirtErrors(bool always);
|
||||||
|
|
||||||
int virtTestMain(int argc,
|
int virtTestMain(int argc,
|
||||||
char **argv,
|
char **argv,
|
||||||
int (*func)(void));
|
int (*func)(void));
|
||||||
|
@ -10,16 +10,6 @@
|
|||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
#include "virutil.h"
|
#include "virutil.h"
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
testQuietError(void *userData ATTRIBUTE_UNUSED,
|
|
||||||
virErrorPtr error ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
/* nothing */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const char* diskNames[] = {
|
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",
|
"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",
|
"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;
|
int result = 0;
|
||||||
|
|
||||||
virSetErrorFunc(NULL, testQuietError);
|
virtTestQuiesceLibvirtErrors(true);
|
||||||
|
|
||||||
#define DO_TEST(_name) \
|
#define DO_TEST(_name) \
|
||||||
do { \
|
do { \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user