]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuxmlconftest: Add test cases for broken and missing XML files
authorPeter Krempa <pkrempa@redhat.com>
Thu, 8 Aug 2024 07:14:11 +0000 (09:14 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 9 Aug 2024 14:34:33 +0000 (16:34 +0200)
Add test cases for few edge cases which excercise the XML reporting from
libxml2 in anticipation of upcoming changes of behaviour.

'virschematest' must skip parsing of the broken file altogether so this
patch adds infrastructure to allow that.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err [new file with mode: 0644]
tests/qemuxmlconfdata/broken-xml-invalid.xml [new file with mode: 0644]
tests/qemuxmlconfdata/nonexistent-file.x86_64-latest.err [new file with mode: 0644]
tests/qemuxmlconftest.c
tests/testutilsqemu.h
tests/virschematest.c

diff --git a/tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err b/tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err
new file mode 100644 (file)
index 0000000..35a1801
--- /dev/null
@@ -0,0 +1,3 @@
+ABS_SRCDIR/qemuxmlconfdata/broken-xml-invalid.xml:2: Couldn't find end of Start Tag dom line 1
+(null)
+^
diff --git a/tests/qemuxmlconfdata/broken-xml-invalid.xml b/tests/qemuxmlconfdata/broken-xml-invalid.xml
new file mode 100644 (file)
index 0000000..9903e61
--- /dev/null
@@ -0,0 +1 @@
+<dom
diff --git a/tests/qemuxmlconfdata/nonexistent-file.x86_64-latest.err b/tests/qemuxmlconfdata/nonexistent-file.x86_64-latest.err
new file mode 100644 (file)
index 0000000..0ddf1ea
--- /dev/null
@@ -0,0 +1 @@
+XML error: failed to parse xml document 'ABS_SRCDIR/qemuxmlconfdata/nonexistent-file.xml'
index 6e882ca0a81748db056056593c75cba83abdb0a8..89292af3002fa61ce2d383a1dce67f2c4289ef3a 100644 (file)
@@ -372,6 +372,7 @@ testCheckExclusiveFlags(int flags)
                   FLAG_REAL_CAPS |
                   FLAG_SLIRP_HELPER |
                   FLAG_ALLOW_DUPLICATE_OUTPUT |
+                  FLAG_ALLOW_MISSING_INPUT |
                   0, -1);
 
     return 0;
@@ -671,7 +672,8 @@ testQemuConfXMLCommon(testQemuInfo *info,
     if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
         goto cleanup;
 
-    if (!virFileExists(info->infile)) {
+    if (!(info->flags & FLAG_ALLOW_MISSING_INPUT) &&
+        !virFileExists(info->infile)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "Input file '%s' not found", info->infile);
         goto cleanup;
@@ -1237,6 +1239,10 @@ mymain(void)
     g_unsetenv("PIPEWIRE_REMOTE");
     g_unsetenv("PIPEWIRE_RUNTIME_DIR");
 
+    DO_TEST_CAPS_ARCH_LATEST_FULL("nonexistent-file", "x86_64",
+                                  ARG_FLAGS, FLAG_EXPECT_PARSE_ERROR | FLAG_ALLOW_MISSING_INPUT);
+    DO_TEST_CAPS_LATEST_PARSE_ERROR("broken-xml-invalid");
+
     DO_TEST_CAPS_LATEST("x86_64-pc-minimal");
     DO_TEST_CAPS_LATEST_ABI_UPDATE("x86_64-pc-minimal");
     DO_TEST_CAPS_LATEST("x86_64-q35-minimal");
index a5806f244b1767eb8cb322c7638ca09b3b598979..90632031ff819c326d457b2ee7fc5f04cb951f82 100644 (file)
@@ -61,6 +61,7 @@ typedef enum {
     FLAG_REAL_CAPS          = 1 << 2,
     FLAG_SLIRP_HELPER       = 1 << 3,
     FLAG_ALLOW_DUPLICATE_OUTPUT = 1 << 4, /* allow multiple tests with the same output file */
+    FLAG_ALLOW_MISSING_INPUT = 1 << 5,
 } testQemuInfoFlags;
 
 struct testQemuConf {
index 9b6649a6cf2ddcdaa92bfe364b3cef34702b6862..20ac495f4a5cd3403e418199e2f9dcc40e6d2688 100644 (file)
@@ -36,6 +36,7 @@ struct testSchemaEntry {
     const char **exceptions; /* optional NULL terminated list of filenames inside
                                 directory where the expected validation result is
                                 inverted */
+    const char **skip; /* optional NULL terminated list of files to skip altogether */
     const char *dirRegex;
     const char *file;
 };
@@ -131,6 +132,10 @@ testSchemaDir(const char *schema,
             !g_regex_match(filter, ent->d_name, 0, NULL))
             continue;
 
+        if (entry->skip &&
+            g_strv_contains(entry->skip, ent->d_name))
+            continue;
+
         if (entry->exceptions)
             exception = g_strv_contains(entry->exceptions, ent->d_name);
 
@@ -237,10 +242,17 @@ static const char *exceptions_qemuxmlconfdata[] = {
     NULL
 };
 
+/* skip tests with completely broken XML */
+static const char *skip_qemuxmlconfdata[] = {
+    "broken-xml-invalid.xml",
+    NULL
+};
+
 static const struct testSchemaEntry schemaDomain[] = {
     { .dir = "tests/domainschemadata" },
     { .dir = "tests/qemuxmlconfdata",
       .exceptions = exceptions_qemuxmlconfdata,
+      .skip = skip_qemuxmlconfdata,
     },
     { .dir = "tests/xmconfigdata" },
     { .dir = "tests/lxcxml2xmldata" },