mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
tests: Slightly tweak virlogtest
Patch adds a generic DO_TEST_FULL macro, some PASS/FAIL macros to better visually distinguish tests that should fail and tests that should pass. Also, some cosmetic changes like renames and direct call to fprintf is replaced with our VIR_TEST_DEBUG macro, as using testutils should be our preferred way of reporting errors in tests.
This commit is contained in:
parent
c1276177f8
commit
814b2ec625
@ -23,20 +23,20 @@
|
|||||||
|
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
|
|
||||||
struct testLogMatchData {
|
struct testLogData {
|
||||||
const char *str;
|
const char *str;
|
||||||
bool res;
|
bool pass;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testLogMatch(const void *opaque)
|
testLogMatch(const void *opaque)
|
||||||
{
|
{
|
||||||
const struct testLogMatchData *data = opaque;
|
const struct testLogData *data = opaque;
|
||||||
|
|
||||||
bool got = virLogProbablyLogMessage(data->str);
|
bool got = virLogProbablyLogMessage(data->str);
|
||||||
if (got != data->res) {
|
if (got != data->pass) {
|
||||||
fprintf(stderr, "Expected '%d' but got '%d' for '%s'\n",
|
VIR_TEST_DEBUG("Expected '%d' but got '%d' for '%s'\n",
|
||||||
data->res, got, data->str);
|
data->pass, got, data->str);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -48,18 +48,23 @@ mymain(void)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
#define TEST_LOG_MATCH(str, res) \
|
#define DO_TEST_FULL(name, test, str, pass) \
|
||||||
do { \
|
do { \
|
||||||
struct testLogMatchData data = { \
|
struct testLogData data = { \
|
||||||
str, res \
|
str, pass \
|
||||||
}; \
|
}; \
|
||||||
if (virtTestRun("testLogMatch " # str, testLogMatch, &data) < 0) \
|
if (virtTestRun(name, test, &data) < 0) \
|
||||||
ret = -1; \
|
ret = -1; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
TEST_LOG_MATCH("2013-10-11 15:43:43.866+0000: 28302: info : libvirt version: 1.1.3", true);
|
#define TEST_LOG_MATCH_FAIL(str) \
|
||||||
|
DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, false)
|
||||||
|
#define TEST_LOG_MATCH(str) \
|
||||||
|
DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, true)
|
||||||
|
|
||||||
TEST_LOG_MATCH("libvirt: error : cannot execute binary /usr/libexec/libvirt_lxc: No such file or directory", false);
|
TEST_LOG_MATCH("2013-10-11 15:43:43.866+0000: 28302: info : libvirt version: 1.1.3");
|
||||||
|
|
||||||
|
TEST_LOG_MATCH_FAIL("libvirt: error : cannot execute binary /usr/libexec/libvirt_lxc: No such file or directory");
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user