The exception is needed in qemuxml2xmltest which is in one instance testing update from an invalid config to a valid one. Currently the compliance with the test is achieved via a hack. As further patches will be simpler without the hack present we need a way to invert the expected output in specific cases. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- ...network-invalid-inactive.x86_64-latest.xml | 1 - ...m-empty-network-invalid.x86_64-latest.xml} | 0 tests/virschematest.c | 40 ++++++++++++++----- 3 files changed, 31 insertions(+), 10 deletions(-) delete mode 120000 tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid-inactive.x86_64-latest.xml rename tests/qemuxml2xmloutdata/{disk-cdrom-empty-network-invalid-active.x86_64-latest.xml => disk-cdrom-empty-network-invalid.x86_64-latest.xml} (100%) diff --git a/tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid-inactive.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid-inactive.x86_64-latest.xml deleted file mode 120000 index 9733ff06a7..0000000000 --- a/tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid-inactive.x86_64-latest.xml +++ /dev/null @@ -1 +0,0 @@ -disk-cdrom-empty-network-invalid-active.x86_64-latest.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid-active.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid.x86_64-latest.xml similarity index 100% rename from tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid-active.x86_64-latest.xml rename to tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid.x86_64-latest.xml diff --git a/tests/virschematest.c b/tests/virschematest.c index c7bfd372c9..24ddb042c1 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -33,6 +33,9 @@ struct testSchemaEntry { /* if dirRegex is non-NULL the provided regular expression is used to match * the file names in a directory (without path prefixed) and only matching * files are validated */ + const char **exceptions; /* optional NULL terminated list of filenames inside + directory where the expected validation result is + inverted */ const char *dirRegex; const char *file; }; @@ -40,6 +43,7 @@ struct testSchemaEntry { struct testSchemaData { virXMLValidator *validator; + bool exception; const char *xml_path; }; @@ -53,6 +57,9 @@ testSchemaValidateXML(const void *args) bool shouldFail = !!strstr(data->xml_path, "-invalid."); g_autoptr(xmlDoc) xml = NULL; + if (data->exception) + shouldFail = !shouldFail; + if (!(xml = virXMLParseFileCtxt(data->xml_path, NULL))) return -1; @@ -66,12 +73,14 @@ testSchemaValidateXML(const void *args) static int testSchemaFile(const char *schema, virXMLValidator *validator, - const char *path) + const char *path, + bool exception) { g_autofree char *test_name = NULL; struct testSchemaData data = { .validator = validator, .xml_path = path, + .exception = exception, }; test_name = g_strdup_printf("Checking %s against %s", path, schema); @@ -84,7 +93,7 @@ static int testSchemaDir(const char *schema, virXMLValidator *validator, const char *dir_path, - const char *filterstr) + const struct testSchemaEntry *entry) { g_autoptr(DIR) dir = NULL; struct dirent *ent; @@ -97,17 +106,18 @@ testSchemaDir(const char *schema, return -1; } - if (filterstr) { + if (entry->dirRegex) { g_autoptr(GError) err = NULL; - if (!(filter = g_regex_new(filterstr, 0, 0, &err))) { - VIR_TEST_VERBOSE("\nfailed to compile regex '%s': %s", filterstr, err->message); + if (!(filter = g_regex_new(entry->dirRegex, 0, 0, &err))) { + VIR_TEST_VERBOSE("\nfailed to compile regex '%s': %s", entry->dirRegex, err->message); return -1; } } while ((rc = virDirRead(dir, &ent, dir_path)) > 0) { g_autofree char *xml_path = NULL; + bool exception = false; if (!virStringHasSuffix(ent->d_name, ".xml")) continue; @@ -117,9 +127,12 @@ testSchemaDir(const char *schema, !g_regex_match(filter, ent->d_name, 0, NULL)) continue; + if (entry->exceptions) + exception = g_strv_contains(entry->exceptions, ent->d_name); + xml_path = g_strdup_printf("%s/%s", dir_path, ent->d_name); - if (testSchemaFile(schema, validator, xml_path) < 0) + if (testSchemaFile(schema, validator, xml_path, exception) < 0) ret = -1; } @@ -190,14 +203,14 @@ testSchemaEntries(const char *schema, if (entry->dir) { g_autofree char *path = g_strdup_printf("%s/%s", abs_top_srcdir, entry->dir); - if (testSchemaDir(schema, validator, path, entry->dirRegex) < 0) + if (testSchemaDir(schema, validator, path, entry) < 0) ret = -1; } if (entry->file) { g_autofree char *path = g_strdup_printf("%s/%s", abs_top_srcdir, entry->file); - if (testSchemaFile(schema, validator, path) < 0) + if (testSchemaFile(schema, validator, path, false) < 0) ret = -1; } } @@ -212,11 +225,20 @@ static const struct testSchemaEntry schemaCapability[] = { { .dir = "tests/qemucaps2xmloutdata" }, }; + +/* give exceptions for output files of invalid input XMLs */ +static const char *exceptions_qemuxml2xmloutdata[] = { + "disk-cdrom-empty-network-invalid.x86_64-latest.xml", + NULL +}; + static const struct testSchemaEntry schemaDomain[] = { { .dir = "tests/domainschemadata" }, { .dir = "tests/qemuxml2argvdata" }, { .dir = "tests/xmconfigdata" }, - { .dir = "tests/qemuxml2xmloutdata" }, + { .dir = "tests/qemuxml2xmloutdata", + .exceptions = exceptions_qemuxml2xmloutdata, + }, { .dir = "tests/lxcxml2xmldata" }, { .dir = "tests/lxcxml2xmloutdata" }, { .dir = "tests/bhyvexml2argvdata" }, -- 2.43.0 _______________________________________________ Devel mailing list -- devel@xxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx