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@xxxxxxxxxx> --- This patch is meant as an addendum to my review of: [PATCH] util: open XML files before calling libxml2 .../broken-xml-invalid.x86_64-latest.err | 3 +++ tests/qemuxmlconfdata/broken-xml-invalid.xml | 1 + .../nonexistent-file.x86_64-latest.err | 1 + tests/qemuxmlconftest.c | 8 +++++++- tests/testutilsqemu.h | 1 + tests/virschematest.c | 11 +++++++++++ 6 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err create mode 100644 tests/qemuxmlconfdata/broken-xml-invalid.xml create mode 100644 tests/qemuxmlconfdata/nonexistent-file.x86_64-latest.err 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 index 0000000000..601f547cc6 --- /dev/null +++ b/tests/qemuxmlconfdata/broken-xml-invalid.x86_64-latest.err @@ -0,0 +1,3 @@ +/home/pipo/libvirt/tests/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 index 0000000000..9903e61ead --- /dev/null +++ b/tests/qemuxmlconfdata/broken-xml-invalid.xml @@ -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 index 0000000000..59e92917f9 --- /dev/null +++ b/tests/qemuxmlconfdata/nonexistent-file.x86_64-latest.err @@ -0,0 +1 @@ +XML error: failed to parse xml document '/home/pipo/libvirt/tests/qemuxmlconfdata/nonexistent-file.xml' diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c index 8aa8efea13..9e6d40fe33 100644 --- a/tests/qemuxmlconftest.c +++ b/tests/qemuxmlconftest.c @@ -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; @@ -1233,6 +1235,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"); diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index a5806f244b..90632031ff 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -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 { diff --git a/tests/virschematest.c b/tests/virschematest.c index 9b6649a6cf..b4113619e2 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -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; /* 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,16 @@ static const char *exceptions_qemuxmlconfdata[] = { NULL }; +/* skip tests with completely broken XML */ +static const char *skip_qemuxmlconfdata[] = { + "broken-xml-invalid.xml" +}; + static const struct testSchemaEntry schemaDomain[] = { { .dir = "tests/domainschemadata" }, { .dir = "tests/qemuxmlconfdata", .exceptions = exceptions_qemuxmlconfdata, + .skip = skip_qemuxmlconfdata, }, { .dir = "tests/xmconfigdata" }, { .dir = "tests/lxcxml2xmldata" }, -- 2.45.2