提交 6bd9758e 编写于 作者: E Erik Skultety

tests: Add a new test for logging outputs parser

Test for parser's functionality.
上级 814b2ec6
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
struct testLogData { struct testLogData {
const char *str; const char *str;
int count;
bool pass; bool pass;
}; };
...@@ -42,29 +43,69 @@ testLogMatch(const void *opaque) ...@@ -42,29 +43,69 @@ testLogMatch(const void *opaque)
return 0; return 0;
} }
static int
testLogParseOutputs(const void *opaque)
{
int ret = -1;
const struct testLogData *data = opaque;
ret = virLogParseOutputs(data->str);
if (ret < 0) {
if (!data->pass) {
VIR_TEST_DEBUG("Got expected error: %s\n",
virGetLastErrorMessage());
virResetLastError();
ret = 0;
goto cleanup;
}
} else if (ret != data->count) {
VIR_TEST_DEBUG("Expected number of parsed outputs is %d, "
"but got %d\n", data->count, ret);
goto cleanup;
} else if (!data->pass) {
VIR_TEST_DEBUG("Test should have failed\n");
goto cleanup;
}
ret = 0;
cleanup:
virLogReset();
return ret;
}
static int static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
#define DO_TEST_FULL(name, test, str, pass) \ #define DO_TEST_FULL(name, test, str, count, pass) \
do { \ do { \
struct testLogData data = { \ struct testLogData data = { \
str, pass \ str, count, pass \
}; \ }; \
if (virtTestRun(name, test, &data) < 0) \ if (virtTestRun(name, test, &data) < 0) \
ret = -1; \ ret = -1; \
} while (0) } while (0)
#define TEST_LOG_MATCH_FAIL(str) \ #define TEST_LOG_MATCH_FAIL(str) \
DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, false) DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, 0, false)
#define TEST_LOG_MATCH(str) \ #define TEST_LOG_MATCH(str) \
DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, true) DO_TEST_FULL("testLogMatch " # str, testLogMatch, str, 0, true)
#define TEST_PARSE_OUTPUTS_FAIL(str, count) \
DO_TEST_FULL("testLogParseOutputs " # str, testLogParseOutputs, str, count, false)
#define TEST_PARSE_OUTPUTS(str, count) \
DO_TEST_FULL("testLogParseOutputs " # str, testLogParseOutputs, str, count, true)
TEST_LOG_MATCH("2013-10-11 15:43:43.866+0000: 28302: info : libvirt version: 1.1.3"); 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"); TEST_LOG_MATCH_FAIL("libvirt: error : cannot execute binary /usr/libexec/libvirt_lxc: No such file or directory");
TEST_PARSE_OUTPUTS("1:file:/dev/null", 1);
TEST_PARSE_OUTPUTS("1:file:/dev/null 2:stderr", 2);
TEST_PARSE_OUTPUTS_FAIL("foo:stderr", 1);
TEST_PARSE_OUTPUTS_FAIL("1:bar", 1);
TEST_PARSE_OUTPUTS_FAIL("1:stderr:foobar", 1);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册