]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: silence qemuargv2xmltest noise
authorEric Blake <eblake@redhat.com>
Fri, 10 Sep 2010 16:25:49 +0000 (10:25 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 16 Sep 2010 16:45:33 +0000 (10:45 -0600)
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.

tests/qemuargv2xmltest.c
tests/testutils.c
tests/testutils.h

index b75d2c52e05f5543f1c4bcdf20199eb5c32ecf7c..4f9ec8454dc991b72e53c9176196ee726b799813 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdbool.h>
 
 #include <sys/types.h>
 #include <fcntl.h>
@@ -35,7 +36,8 @@ static int blankProblemElements(char *data)
 }
 
 static int testCompareXMLToArgvFiles(const char *xml,
-                                     const char *cmdfile) {
+                                     const char *cmdfile,
+                                     bool expect_warning) {
     char xmlData[MAX_FILE];
     char cmdData[MAX_FILE];
     char *expectxml = &(xmlData[0]);
@@ -43,6 +45,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
     char *cmd = &(cmdData[0]);
     int ret = -1;
     virDomainDefPtr vmdef = NULL;
+    char *log;
 
     if (virtTestLoadFile(cmdfile, &cmd, MAX_FILE) < 0)
         goto fail;
@@ -52,6 +55,14 @@ static int testCompareXMLToArgvFiles(const char *xml,
     if (!(vmdef = qemuParseCommandLineString(driver.caps, cmd)))
         goto fail;
 
+    if ((log = virtTestLogContentAndReset()) == NULL)
+        goto fail;
+    if ((*log != '\0') != expect_warning) {
+        free(log);
+        goto fail;
+    }
+    free(log);
+
     if (!(actualxml = virDomainDefFormat(vmdef, 0)))
         goto fail;
 
@@ -87,7 +98,7 @@ static int testCompareXMLToArgvHelper(const void *data) {
              abs_srcdir, info->name);
     snprintf(args, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
              abs_srcdir, info->name);
-    return testCompareXMLToArgvFiles(xml, args);
+    return testCompareXMLToArgvFiles(xml, args, !!info->extraFlags);
 }
 
 
@@ -215,7 +226,7 @@ mymain(int argc, char **argv)
     DO_TEST_FULL("restore-v2", 0, "exec:cat");
     DO_TEST_FULL("migrate", 0, "tcp:10.0.0.1:5000");
 
-    DO_TEST("qemu-ns-no-env");
+    DO_TEST_FULL("qemu-ns-no-env", 1, NULL);
 
     free(driver.stateDir);
     virCapabilitiesFree(driver.caps);
index 2f61aadc84b65d54adaeeb8a93c2b4c5823e684b..8171f103b62bd371472b1b399ab0050fc72a86e9 100644 (file)
@@ -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) {
index 95f16804641a5f01db3791161542b28050513c5e..88603a1f0b8e54cd6dd20a74dfdb813a0020d291 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * utils.c: test utils
  *
- * Copyright (C) 2005, 2008-2009 Red Hat, Inc.
+ * Copyright (C) 2005, 2008-2010 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -40,6 +40,8 @@ int virtTestDifference(FILE *stream,
 unsigned int virTestGetDebug(void);
 unsigned int virTestGetVerbose(void);
 
+char *virtTestLogContentAndReset(void);
+
 int virtTestMain(int argc,
                  char **argv,
                  int (*func)(int, char **));