Now that we can override the post-parse handling, let's update the
testsuite to provide the desired timestamp/name rather than ignoring
the non-deterministic one that was previously being generated. A few
output files need timestamps added now that they are no longer
ignored.

Signed-off-by: Eric Blake <ebl...@redhat.com>
---
 .../disk_driver_name_null.xml                 |   1 +
 .../disk_snapshot.xml                         |   1 +
 .../domainsnapshotxml2xmlout/external_vm.xml  |   1 +
 tests/domainsnapshotxml2xmltest.c             | 142 ++++++------------
 4 files changed, 52 insertions(+), 93 deletions(-)

diff --git a/tests/domainsnapshotxml2xmlout/disk_driver_name_null.xml 
b/tests/domainsnapshotxml2xmlout/disk_driver_name_null.xml
index ddd350de65..b0b27fd7e0 100644
--- a/tests/domainsnapshotxml2xmlout/disk_driver_name_null.xml
+++ b/tests/domainsnapshotxml2xmlout/disk_driver_name_null.xml
@@ -1,6 +1,7 @@
 <domainsnapshot>
   <name>asdf</name>
   <description>adsf</description>
+  <creationTime>1555419243</creationTime>
   <disks>
     <disk name='vda' snapshot='external' type='file'>
       <source file='/tmp/foo'/>
diff --git a/tests/domainsnapshotxml2xmlout/disk_snapshot.xml 
b/tests/domainsnapshotxml2xmlout/disk_snapshot.xml
index 0e81f35c69..76c543d25c 100644
--- a/tests/domainsnapshotxml2xmlout/disk_snapshot.xml
+++ b/tests/domainsnapshotxml2xmlout/disk_snapshot.xml
@@ -1,6 +1,7 @@
 <domainsnapshot>
   <name>my snap name</name>
   <description>!@#$%^</description>
+  <creationTime>1555419243</creationTime>
   <disks>
     <disk name='/dev/HostVG/QEMUGuest1'/>
     <disk name='hdb' snapshot='no'/>
diff --git a/tests/domainsnapshotxml2xmlout/external_vm.xml 
b/tests/domainsnapshotxml2xmlout/external_vm.xml
index 9da369b1e5..03c2e703b5 100644
--- a/tests/domainsnapshotxml2xmlout/external_vm.xml
+++ b/tests/domainsnapshotxml2xmlout/external_vm.xml
@@ -1,5 +1,6 @@
 <domainsnapshot>
   <name>my snap name</name>
   <description>!@#$%^</description>
+  <creationTime>1555419243</creationTime>
   <memory snapshot='external' file='/dev/HostVG/GuestMemory'/>
 </domainsnapshot>
diff --git a/tests/domainsnapshotxml2xmltest.c 
b/tests/domainsnapshotxml2xmltest.c
index a35edf18fb..daceac34e6 100644
--- a/tests/domainsnapshotxml2xmltest.c
+++ b/tests/domainsnapshotxml2xmltest.c
@@ -21,55 +21,12 @@

 static virQEMUDriver driver;

-/* This regex will skip the following XML constructs in test files
- * that are dynamically generated and thus problematic to test:
- * <name>1234352345</name> if the snapshot has no name,
- * <creationTime>23523452345</creationTime>
- */
-static const char *testSnapshotXMLVariableLineRegexStr =
-    "<(name|creationTime)>[0-9]+</(name|creationTime)>";
-
-regex_t *testSnapshotXMLVariableLineRegex = NULL;
-
 enum {
     TEST_INTERNAL = 1 << 0,
     TEST_REDEFINE = 1 << 1,
     TEST_RUNNING = 1 << 2,
 };

-static char *
-testFilterXML(char *xml)
-{
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-    char **xmlLines = NULL;
-    char **xmlLine;
-    char *ret = NULL;
-
-    if (!(xmlLines = virStringSplit(xml, "\n", 0))) {
-        VIR_FREE(xml);
-        goto cleanup;
-    }
-    VIR_FREE(xml);
-
-    for (xmlLine = xmlLines; *xmlLine; xmlLine++) {
-        if (regexec(testSnapshotXMLVariableLineRegex,
-                    *xmlLine, 0, NULL, 0) == 0)
-            continue;
-
-        virBufferStrcat(&buf, *xmlLine, "\n", NULL);
-    }
-
-    if (virBufferCheckError(&buf) < 0)
-        goto cleanup;
-
-    ret = virBufferContentAndReset(&buf);
-
- cleanup:
-    virBufferFreeAndReset(&buf);
-    virStringListFree(xmlLines);
-    return ret;
-}
-
 static int
 testCompareXMLToXMLFiles(const char *inxml,
                          const char *outxml,
@@ -116,14 +73,6 @@ testCompareXMLToXMLFiles(const char *inxml,
                                               formatflags)))
         goto cleanup;

-    if (!(flags & TEST_REDEFINE)) {
-        if (!(actual = testFilterXML(actual)))
-            goto cleanup;
-
-        if (!(outXmlData = testFilterXML(outXmlData)))
-            goto cleanup;
-    }
-
     if (STRNEQ(outXmlData, actual)) {
         virTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml);
         goto cleanup;
@@ -143,15 +92,33 @@ struct testInfo {
     const char *inxml;
     const char *outxml;
     const char *uuid;
+    long long creationTime;
     unsigned int flags;
 };
+static long long timeptr;

+static int
+testSnapshotPostParse(virDomainMomentDefPtr def, void *opaque)
+{
+    long long *ptr = opaque;
+
+    if (!*ptr)
+        return 0;
+    if (def->creationTime)
+        return -1;
+    def->creationTime = *ptr;
+    if (!def->name &&
+        virAsprintf(&def->name, "%lld", def->creationTime) < 0)
+        return -1;
+    return 0;
+}

 static int
 testCompareXMLToXMLHelper(const void *data)
 {
     const struct testInfo *info = data;

+    timeptr = info->creationTime;
     return testCompareXMLToXMLFiles(info->inxml, info->outxml, info->uuid,
                                     info->flags);
 }
@@ -165,44 +132,34 @@ mymain(void)
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;

-    if (VIR_ALLOC(testSnapshotXMLVariableLineRegex) < 0)
-        goto cleanup;
+    virDomainXMLOptionSetMomentPostParse(driver.xmlopt,
+                                         testSnapshotPostParse,
+                                         &timeptr);

-    if (regcomp(testSnapshotXMLVariableLineRegex,
-                testSnapshotXMLVariableLineRegexStr,
-                REG_EXTENDED | REG_NOSUB) != 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       "failed to compile test regex");
-        goto cleanup;
-    }
-
-
-# define DO_TEST(prefix, name, inpath, outpath, uuid, flags) \
+# define DO_TEST(prefix, name, inpath, outpath, uuid, time, flags) \
     do { \
         const struct testInfo info = {abs_srcdir "/" inpath "/" name ".xml", \
                                       abs_srcdir "/" outpath "/" name ".xml", \
-                                      uuid, flags}; \
+                                      uuid, time, flags}; \
         if (virTestRun("SNAPSHOT XML-2-XML " prefix " " name, \
                        testCompareXMLToXMLHelper, &info) < 0) \
             ret = -1; \
     } while (0)

-# define DO_TEST_IN(name, uuid) DO_TEST("in->in", name,\
-                                        "domainsnapshotxml2xmlin",\
-                                        "domainsnapshotxml2xmlin",\
-                                        uuid, 0)
+# define DO_TEST_IN(name, uuid) DO_TEST("in->in", name, \
+                                        "domainsnapshotxml2xmlin", \
+                                        "domainsnapshotxml2xmlin", \
+                                        uuid, 0, 0)

-# define DO_TEST_OUT(name, uuid, internal) DO_TEST("out->out", name,\
-                                                   "domainsnapshotxml2xmlout",\
-                                                   "domainsnapshotxml2xmlout",\
-                                                   uuid, \
-                                                   internal | TEST_REDEFINE)
+# define DO_TEST_OUT(name, uuid, time, internal) \
+    DO_TEST("out->out", name, "domainsnapshotxml2xmlout", \
+            "domainsnapshotxml2xmlout", uuid, time, internal | TEST_REDEFINE)

-# define DO_TEST_INOUT(name, uuid, flags) \
-    DO_TEST("in->out", name,\
+# define DO_TEST_INOUT(name, uuid, time, flags) \
+    DO_TEST("in->out", name, \
             "domainsnapshotxml2xmlin",\
             "domainsnapshotxml2xmlout",\
-            uuid, flags)
+            uuid, time, flags)

     /* Unset or set all envvars here that are copied in qemudBuildCommandLine
      * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
@@ -210,33 +167,32 @@ mymain(void)
     setenv("PATH", "/bin", 1);

     DO_TEST_OUT("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
-                TEST_INTERNAL);
+                1272917631, TEST_INTERNAL);
     DO_TEST_OUT("disk_snapshot_redefine", 
"c7a5fdbd-edaf-9455-926a-d65c16db1809",
-                TEST_INTERNAL);
+                1272917631, TEST_INTERNAL);
     DO_TEST_OUT("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
-                TEST_INTERNAL);
-    DO_TEST_OUT("noparent_nodescription_noactive", NULL, 0);
-    DO_TEST_OUT("noparent_nodescription", NULL, TEST_INTERNAL);
-    DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0);
-    DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
+                1272917631, TEST_INTERNAL);
+    DO_TEST_OUT("noparent_nodescription_noactive", NULL, 1272917631, 0);
+    DO_TEST_OUT("noparent_nodescription", NULL, 1272917631, TEST_INTERNAL);
+    DO_TEST_OUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
+                1272917631, 0);
+    DO_TEST_OUT("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
+                1272917631, 0);
     DO_TEST_OUT("external_vm_redefine", "c7a5fdbd-edaf-9455-926a-d65c16db1809",
-                0);
+                1272917631, 0);

-    DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0);
+    DO_TEST_INOUT("empty", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
+                  1386166249, 0);
     DO_TEST_INOUT("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8",
-                  TEST_RUNNING);
-    DO_TEST_INOUT("external_vm", NULL, 0);
-    DO_TEST_INOUT("disk_snapshot", NULL, 0);
-    DO_TEST_INOUT("disk_driver_name_null", NULL, 0);
+                  1272917631, TEST_RUNNING);
+    DO_TEST_INOUT("external_vm", NULL, 1555419243, 0);
+    DO_TEST_INOUT("disk_snapshot", NULL, 1555419243, 0);
+    DO_TEST_INOUT("disk_driver_name_null", NULL, 1555419243, 0);

     DO_TEST_IN("name_and_description", NULL);
     DO_TEST_IN("description_only", NULL);
     DO_TEST_IN("name_only", NULL);

- cleanup:
-    if (testSnapshotXMLVariableLineRegex)
-        regfree(testSnapshotXMLVariableLineRegex);
-    VIR_FREE(testSnapshotXMLVariableLineRegex);
     qemuTestDriverFree(&driver);

     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to