|
|
c401cc |
From 9b71e87bc50debbc83586d044eecdd0eeb2d66c8 Mon Sep 17 00:00:00 2001
|
|
|
c401cc |
Message-Id: <9b71e87bc50debbc83586d044eecdd0eeb2d66c8@dist-git>
|
|
|
c401cc |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
c401cc |
Date: Wed, 26 Feb 2014 14:55:05 +0100
|
|
|
c401cc |
Subject: [PATCH] domainsnapshotxml2xmltest: Allow for better testing of
|
|
|
c401cc |
snapshots
|
|
|
c401cc |
|
|
|
c401cc |
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
|
|
|
c401cc |
|
|
|
c401cc |
Until now the test was only testing redefinition of snapshot XMLs stored
|
|
|
c401cc |
in tests/domainsnapshotxml2xmlout. This patch adds new infrastructure to
|
|
|
c401cc |
allow testing of files that may differ and will allow to utilize files
|
|
|
c401cc |
in tests/domainsnapshotxml2xmlin as new tests too.
|
|
|
c401cc |
|
|
|
c401cc |
(cherry picked from commit 11daad9a24077bf233c503c6538b9d55abd37ad7)
|
|
|
c401cc |
|
|
|
c401cc |
Conflicts:
|
|
|
c401cc |
tests/domainsnapshotxml2xmltest.c - test counter removal not
|
|
|
c401cc |
backported
|
|
|
c401cc |
|
|
|
c401cc |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c401cc |
---
|
|
|
c401cc |
tests/domainsnapshotxml2xmltest.c | 161 ++++++++++++++++++++++++++++++--------
|
|
|
c401cc |
1 file changed, 128 insertions(+), 33 deletions(-)
|
|
|
c401cc |
|
|
|
c401cc |
diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c
|
|
|
c401cc |
index ea33688..3140029 100644
|
|
|
c401cc |
--- a/tests/domainsnapshotxml2xmltest.c
|
|
|
c401cc |
+++ b/tests/domainsnapshotxml2xmltest.c
|
|
|
c401cc |
@@ -8,6 +8,8 @@
|
|
|
c401cc |
#include <sys/types.h>
|
|
|
c401cc |
#include <fcntl.h>
|
|
|
c401cc |
|
|
|
c401cc |
+#include <regex.h>
|
|
|
c401cc |
+
|
|
|
c401cc |
#include "testutils.h"
|
|
|
c401cc |
|
|
|
c401cc |
#ifdef WITH_QEMU
|
|
|
c401cc |
@@ -22,21 +24,79 @@
|
|
|
c401cc |
|
|
|
c401cc |
static virQEMUDriver driver;
|
|
|
c401cc |
|
|
|
c401cc |
+/* This regex will skip the following XML constructs in test files
|
|
|
c401cc |
+ * that are dynamically generated and thus problematic to test:
|
|
|
c401cc |
+ * <name>1234352345</name> if the snapshot has no name,
|
|
|
c401cc |
+ * <creationTime>23523452345</creationTime>,
|
|
|
c401cc |
+ * <state>nostate</state> as the backend code doesn't fill this
|
|
|
c401cc |
+ */
|
|
|
c401cc |
+static const char *testSnapshotXMLVariableLineRegexStr =
|
|
|
c401cc |
+ "(<(name|creationTime)>[0-9]+</(name|creationTime)>|"
|
|
|
c401cc |
+ "<state>nostate</state>)";
|
|
|
c401cc |
+
|
|
|
c401cc |
+regex_t *testSnapshotXMLVariableLineRegex = NULL;
|
|
|
c401cc |
+
|
|
|
c401cc |
+static char *
|
|
|
c401cc |
+testFilterXML(char *xml)
|
|
|
c401cc |
+{
|
|
|
c401cc |
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
c401cc |
+ char **xmlLines = NULL;
|
|
|
c401cc |
+ char **xmlLine;
|
|
|
c401cc |
+ char *ret = NULL;
|
|
|
c401cc |
+
|
|
|
c401cc |
+ if (!(xmlLines = virStringSplit(xml, "\n", 0))) {
|
|
|
c401cc |
+ VIR_FREE(xml);
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+ }
|
|
|
c401cc |
+ VIR_FREE(xml);
|
|
|
c401cc |
+
|
|
|
c401cc |
+ for (xmlLine = xmlLines; *xmlLine; xmlLine++) {
|
|
|
c401cc |
+ if (regexec(testSnapshotXMLVariableLineRegex,
|
|
|
c401cc |
+ *xmlLine, 0, NULL, 0) == 0)
|
|
|
c401cc |
+ continue;
|
|
|
c401cc |
+
|
|
|
c401cc |
+ virBufferStrcat(&buf, *xmlLine, "\n", NULL);
|
|
|
c401cc |
+ }
|
|
|
c401cc |
+
|
|
|
c401cc |
+ if (virBufferError(&buf)) {
|
|
|
c401cc |
+ virReportOOMError();
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+ }
|
|
|
c401cc |
+
|
|
|
c401cc |
+ ret = virBufferContentAndReset(&buf;;
|
|
|
c401cc |
+
|
|
|
c401cc |
+cleanup:
|
|
|
c401cc |
+ virBufferFreeAndReset(&buf;;
|
|
|
c401cc |
+ virStringFreeList(xmlLines);
|
|
|
c401cc |
+ return ret;
|
|
|
c401cc |
+}
|
|
|
c401cc |
+
|
|
|
c401cc |
static int
|
|
|
c401cc |
-testCompareXMLToXMLFiles(const char *inxml, const char *uuid, bool internal)
|
|
|
c401cc |
+testCompareXMLToXMLFiles(const char *inxml,
|
|
|
c401cc |
+ const char *outxml,
|
|
|
c401cc |
+ const char *uuid,
|
|
|
c401cc |
+ bool internal,
|
|
|
c401cc |
+ bool redefine)
|
|
|
c401cc |
{
|
|
|
c401cc |
char *inXmlData = NULL;
|
|
|
c401cc |
+ char *outXmlData = NULL;
|
|
|
c401cc |
char *actual = NULL;
|
|
|
c401cc |
int ret = -1;
|
|
|
c401cc |
virDomainSnapshotDefPtr def = NULL;
|
|
|
c401cc |
- unsigned int flags = (VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE |
|
|
|
c401cc |
- VIR_DOMAIN_SNAPSHOT_PARSE_DISKS);
|
|
|
c401cc |
+ unsigned int flags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
|
|
|
c401cc |
+
|
|
|
c401cc |
+ if (internal)
|
|
|
c401cc |
+ flags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
|
|
|
c401cc |
+
|
|
|
c401cc |
+ if (redefine)
|
|
|
c401cc |
+ flags |= VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE;
|
|
|
c401cc |
|
|
|
c401cc |
if (virtTestLoadFile(inxml, &inXmlData) < 0)
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
|
|
|
c401cc |
- if (internal)
|
|
|
c401cc |
- flags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
|
|
|
c401cc |
+ if (virtTestLoadFile(outxml, &outXmlData) < 0)
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+
|
|
|
c401cc |
if (!(def = virDomainSnapshotDefParseString(inXmlData, driver.caps,
|
|
|
c401cc |
driver.xmlopt,
|
|
|
c401cc |
QEMU_EXPECTED_VIRT_TYPES,
|
|
|
c401cc |
@@ -48,9 +108,16 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, bool internal)
|
|
|
c401cc |
internal)))
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
|
|
|
c401cc |
+ if (!redefine) {
|
|
|
c401cc |
+ if (!(actual = testFilterXML(actual)))
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+
|
|
|
c401cc |
+ if (!(outXmlData = testFilterXML(outXmlData)))
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+ }
|
|
|
c401cc |
|
|
|
c401cc |
- if (STRNEQ(inXmlData, actual)) {
|
|
|
c401cc |
- virtTestDifference(stderr, inXmlData, actual);
|
|
|
c401cc |
+ if (STRNEQ(outXmlData, actual)) {
|
|
|
c401cc |
+ virtTestDifference(stderr, outXmlData, actual);
|
|
|
c401cc |
goto cleanup;
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
@@ -58,15 +125,18 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, bool internal)
|
|
|
c401cc |
|
|
|
c401cc |
cleanup:
|
|
|
c401cc |
VIR_FREE(inXmlData);
|
|
|
c401cc |
+ VIR_FREE(outXmlData);
|
|
|
c401cc |
VIR_FREE(actual);
|
|
|
c401cc |
virDomainSnapshotDefFree(def);
|
|
|
c401cc |
return ret;
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
struct testInfo {
|
|
|
c401cc |
- const char *name;
|
|
|
c401cc |
+ const char *inxml;
|
|
|
c401cc |
+ const char *outxml;
|
|
|
c401cc |
const char *uuid;
|
|
|
c401cc |
bool internal;
|
|
|
c401cc |
+ bool redefine;
|
|
|
c401cc |
};
|
|
|
c401cc |
|
|
|
c401cc |
|
|
|
c401cc |
@@ -74,18 +144,9 @@ static int
|
|
|
c401cc |
testCompareXMLToXMLHelper(const void *data)
|
|
|
c401cc |
{
|
|
|
c401cc |
const struct testInfo *info = data;
|
|
|
c401cc |
- char *xml_in = NULL;
|
|
|
c401cc |
- int ret = -1;
|
|
|
c401cc |
-
|
|
|
c401cc |
- if (virAsprintf(&xml_in, "%s/domainsnapshotxml2xmlout/%s.xml",
|
|
|
c401cc |
- abs_srcdir, info->name) < 0)
|
|
|
c401cc |
- goto cleanup;
|
|
|
c401cc |
|
|
|
c401cc |
- ret = testCompareXMLToXMLFiles(xml_in, info->uuid, info->internal);
|
|
|
c401cc |
-
|
|
|
c401cc |
-cleanup:
|
|
|
c401cc |
- VIR_FREE(xml_in);
|
|
|
c401cc |
- return ret;
|
|
|
c401cc |
+ return testCompareXMLToXMLFiles(info->inxml, info->outxml, info->uuid,
|
|
|
c401cc |
+ info->internal, info->redefine);
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
|
|
|
c401cc |
@@ -102,28 +163,62 @@ mymain(void)
|
|
|
c401cc |
return EXIT_FAILURE;
|
|
|
c401cc |
}
|
|
|
c401cc |
|
|
|
c401cc |
-# define DO_TEST(name, uuid, internal) \
|
|
|
c401cc |
- do { \
|
|
|
c401cc |
- const struct testInfo info = {name, uuid, internal}; \
|
|
|
c401cc |
- if (virtTestRun("SNAPSHOT XML-2-XML " name, \
|
|
|
c401cc |
- 1, testCompareXMLToXMLHelper, &info) < 0) \
|
|
|
c401cc |
- ret = -1; \
|
|
|
c401cc |
+ if (VIR_ALLOC(testSnapshotXMLVariableLineRegex) < 0)
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+
|
|
|
c401cc |
+ if (regcomp(testSnapshotXMLVariableLineRegex,
|
|
|
c401cc |
+ testSnapshotXMLVariableLineRegexStr,
|
|
|
c401cc |
+ REG_EXTENDED | REG_NOSUB) != 0) {
|
|
|
c401cc |
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
c401cc |
+ "failed to compile test regex");
|
|
|
c401cc |
+ goto cleanup;
|
|
|
c401cc |
+ }
|
|
|
c401cc |
+
|
|
|
c401cc |
+
|
|
|
c401cc |
+# define DO_TEST(prefix, name, inpath, outpath, uuid, internal, redefine) \
|
|
|
c401cc |
+ do { \
|
|
|
c401cc |
+ const struct testInfo info = {abs_srcdir "/" inpath "/" name ".xml", \
|
|
|
c401cc |
+ abs_srcdir "/" outpath "/" name ".xml", \
|
|
|
c401cc |
+ uuid, internal, redefine}; \
|
|
|
c401cc |
+ if (virtTestRun("SNAPSHOT XML-2-XML " prefix " " name, 1, \
|
|
|
c401cc |
+ testCompareXMLToXMLHelper, &info) < 0) \
|
|
|
c401cc |
+ ret = -1; \
|
|
|
c401cc |
} while (0)
|
|
|
c401cc |
|
|
|
c401cc |
+# define DO_TEST_IN(name, uuid) DO_TEST("in->in", name,\
|
|
|
c401cc |
+ "domainsnapshotxml2xmlin",\
|
|
|
c401cc |
+ "domainsnapshotxml2xmlin",\
|
|
|
c401cc |
+ uuid, false, false)
|
|
|
c401cc |
+
|
|
|
c401cc |
+# define DO_TEST_OUT(name, uuid, internal) DO_TEST("out->out", name,\
|
|
|
c401cc |
+ "domainsnapshotxml2xmlout",\
|
|
|
c401cc |
+ "domainsnapshotxml2xmlout",\
|
|
|
c401cc |
+ uuid, internal, true)
|
|
|
c401cc |
+
|
|
|
c401cc |
+# define DO_TEST_INOUT(name, uuid, internal, redefine) \
|
|
|
c401cc |
+ DO_TEST("in->out", name,\
|
|
|
c401cc |
+ "domainsnapshotxml2xmlin",\
|
|
|
c401cc |
+ "domainsnapshotxml2xmlout",\
|
|
|
c401cc |
+ uuid, internal, redefine)
|
|
|
c401cc |
+
|
|
|
c401cc |
/* Unset or set all envvars here that are copied in qemudBuildCommandLine
|
|
|
c401cc |
* using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
|
|
|
c401cc |
* values for these envvars */
|
|
|
c401cc |
setenv("PATH", "/bin", 1);
|
|
|
c401cc |
|
|
|
c401cc |
- DO_TEST("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", true);
|
|
|
c401cc |
- DO_TEST("disk_snapshot", "c7a5fdbd-edaf-9455-926a-d65c16db1809", true);
|
|
|
c401cc |
- DO_TEST("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", true);
|
|
|
c401cc |
- DO_TEST("noparent_nodescription_noactive", NULL, false);
|
|
|
c401cc |
- DO_TEST("noparent_nodescription", NULL, true);
|
|
|
c401cc |
- DO_TEST("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false);
|
|
|
c401cc |
- DO_TEST("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
|
|
|
c401cc |
- DO_TEST("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
|
|
|
c401cc |
+ DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", true);
|
|
|
c401cc |
+ DO_TEST_OUT("disk_snapshot", "c7a5fdbd-edaf-9455-926a-d65c16db1809", true);
|
|
|
c401cc |
+ DO_TEST_OUT("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", true);
|
|
|
c401cc |
+ DO_TEST_OUT("noparent_nodescription_noactive", NULL, false);
|
|
|
c401cc |
+ DO_TEST_OUT("noparent_nodescription", NULL, true);
|
|
|
c401cc |
+ DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false);
|
|
|
c401cc |
+ DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
|
|
|
c401cc |
+ DO_TEST_OUT("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
|
|
|
c401cc |
|
|
|
c401cc |
+cleanup:
|
|
|
c401cc |
+ if (testSnapshotXMLVariableLineRegex)
|
|
|
c401cc |
+ regfree(testSnapshotXMLVariableLineRegex);
|
|
|
c401cc |
+ VIR_FREE(testSnapshotXMLVariableLineRegex);
|
|
|
c401cc |
virObjectUnref(driver.caps);
|
|
|
c401cc |
virObjectUnref(driver.xmlopt);
|
|
|
c401cc |
|
|
|
c401cc |
--
|
|
|
c401cc |
1.9.0
|
|
|
c401cc |
|