summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2010-09-10 10:25:49 -0600
committerEric Blake <eblake@redhat.com>2010-09-16 10:45:33 -0600
commit9e3525df867ba1dbb3e5b1ff55f088f8287e9f9a (patch)
treeb2e776250e298a8cb0d0739da58c0a53b90d68ed /tests/testutils.c
parenttests: clean up qemuargv2xmltest (diff)
downloadlibvirt-9e3525df867ba1dbb3e5b1ff55f088f8287e9f9a.tar.gz
libvirt-9e3525df867ba1dbb3e5b1ff55f088f8287e9f9a.tar.bz2
libvirt-9e3525df867ba1dbb3e5b1ff55f088f8287e9f9a.zip
tests: silence qemuargv2xmltest noise
Before this patch, the testsuite was noisy: TEST: qemuargv2xmltest ........................................ 40 ................20:41:28.046: warning : qemuParseCommandLine:6565 : unknown QEMU argument '-unknown', adding to the qemu namespace 20:41:28.046: warning : qemuParseCommandLine:6565 : unknown QEMU argument 'parameter', adding to the qemu namespace . 57 OK PASS: qemuargv2xmltest It's not a real failure (which is why the test was completing successfully), so much as an intentional warning to the user that use of the qemu namespace has the potential for undefined effects that leaked through the default logging behavior. After this patch series, all tests can access any logged data, and this particular test can explicitly check for the presence or absence of the warning, such that the test output becomes: TEST: qemuargv2xmltest ........................................ 40 ................. 57 OK PASS: qemuargv2xmltest * tests/testutils.h (virtTestLogContentAndReset): New prototype. * tests/testutils.c (struct virtTestLogData): New struct. (virtTestLogOutput, virtTestLogClose, virtTestLogContentAndReset): New functions. (virtTestMain): Always capture log data emitted during tests. * tests/qemuargv2xmltest.c (testCompareXMLToArgvHelper, mymain): Use flag to mark which tests expect noisy stderr. (testCompareXMLToArgvFiles): Add parameter to test whether stderr was appropriately silent.
Diffstat (limited to 'tests/testutils.c')
-rw-r--r--tests/testutils.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/testutils.c b/tests/testutils.c
index 2f61aadc8..8171f103b 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -1,7 +1,7 @@
/*
* testutils.c: basic test utils
*
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * Copyright (C) 2005-2010 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
@@ -31,6 +31,8 @@
#include "util.h"
#include "threads.h"
#include "virterror_internal.h"
+#include "buf.h"
+#include "logging.h"
#if TEST_OOM_TRACE
# include <execinfo.h>
@@ -351,6 +353,45 @@ virtTestErrorFuncQuiet(void *data ATTRIBUTE_UNUSED,
{ }
#endif
+struct virtTestLogData {
+ virBuffer buf;
+};
+
+static struct virtTestLogData testLog = { VIR_BUFFER_INITIALIZER };
+
+static int
+virtTestLogOutput(const char *category ATTRIBUTE_UNUSED,
+ int priority ATTRIBUTE_UNUSED,
+ const char *funcname ATTRIBUTE_UNUSED,
+ long long lineno ATTRIBUTE_UNUSED,
+ const char *str, int len, void *data)
+{
+ struct virtTestLogData *log = data;
+ virBufferAdd(&log->buf, str, len);
+ return len;
+}
+
+static void
+virtTestLogClose(void *data)
+{
+ struct virtTestLogData *log = data;
+
+ virBufferFreeAndReset(&log->buf);
+}
+
+/* Return a malloc'd string (possibly with strlen of 0) of all data
+ * logged since the last call to this function, or NULL on failure. */
+char *
+virtTestLogContentAndReset(void)
+{
+ char *ret;
+
+ if (virBufferError(&testLog.buf))
+ return NULL;
+ ret = virBufferContentAndReset(&testLog.buf);
+ return ret ? ret : strdup("");
+}
+
#if TEST_OOM_TRACE
static void
virtTestErrorHook(int n, void *data ATTRIBUTE_UNUSED)
@@ -425,6 +466,9 @@ int virtTestMain(int argc,
virRandomInitialize(time(NULL) ^ getpid()))
return 1;
+ if (virLogDefineOutput(virtTestLogOutput, virtTestLogClose, &testLog,
+ 0, 0, NULL, 0) < 0)
+ return 1;
#if TEST_OOM
if ((oomStr = getenv("VIR_TEST_OOM")) != NULL) {