* tests/qemuargv2xmltest.c (testCompareXMLToArgvHelper, mymain):
Use flag to mark which tests expect noisy stderr.
(testCompareXMLToArgvFiles): Add parameter to test whether stderr
was appropriately silent.
---
This doesn't actually validate the contents of the warning put to
stderr, but it's better than nothing as it tightens the test and
reduces the noise.
tests/qemuargv2xmltest.c | 53 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index b75d2c5..8acf89f 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -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_stderr) {
char xmlData[MAX_FILE];
char cmdData[MAX_FILE];
char *expectxml = &(xmlData[0]);
@@ -43,15 +45,52 @@ static int testCompareXMLToArgvFiles(const char *xml,
char *cmd = &(cmdData[0]);
int ret = -1;
virDomainDefPtr vmdef = NULL;
+ int err_fd = -1;
+ int orig_stderr = -1;
+ const char *file = NULL;
+ off_t offset;
if (virtTestLoadFile(cmdfile, &cmd, MAX_FILE) < 0)
goto fail;
if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0)
goto fail;
+ /* Redirect stderr for the duration of qemuParseCommandLineString,
+ * to check if there were any warnings. */
+ file = "qemuargv2xmltest.err";
+ if (fflush(stderr) ||
+ (err_fd = open(file, O_CREAT | O_RDWR, 0600)) < 0 ||
+ (orig_stderr = dup(STDERR_FILENO)) < 0 ||
+ dup2(err_fd, STDERR_FILENO) != STDERR_FILENO)
+ goto fail;
+
if (!(vmdef = qemuParseCommandLineString(driver.caps, cmd)))
goto fail;
+ if (dup2(orig_stderr, STDERR_FILENO) != STDERR_FILENO)
+ goto fail;
+ if (close(orig_stderr)) {
+ orig_stderr = -1;
+ goto fail;
+ }
+ orig_stderr = -1;
+
+ if ((offset = lseek(err_fd, 0, SEEK_CUR)) < 0 ||
+ expect_stderr != !!offset)
+ goto fail;
+
+ if (close(err_fd)) {
+ err_fd = -1;
+ goto fail;
+ }
+ err_fd = -1;
+ if (unlink(file)) {
+ file = NULL;
+ goto fail;
+ }
+ file = NULL;
+
+ /* Proceed with remainder of test. */
if (!(actualxml = virDomainDefFormat(vmdef, 0)))
goto fail;
@@ -67,6 +106,14 @@ static int testCompareXMLToArgvFiles(const char *xml,
ret = 0;
fail:
+ if (err_fd >= 0)
+ close(err_fd);
+ if (file)
+ unlink(file);
+ if (orig_stderr >= 0) {
+ dup2(orig_stderr, STDERR_FILENO);
+ close(orig_stderr);
+ }
free(actualxml);
virDomainDefFree(vmdef);
return ret;
@@ -87,7 +134,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 +262,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);
--
1.7.2.2