mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virschematest: Add regex filtering for directory contents
In some cases we have directories with mixed XML files in the test suite. Adding regex filtering will allow testing subsets of the XML files against schema. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
837633afb9
commit
873d484190
@ -32,6 +32,10 @@ VIR_LOG_INIT("tests.schematest");
|
|||||||
|
|
||||||
struct testSchemaEntry {
|
struct testSchemaEntry {
|
||||||
const char *dir;
|
const char *dir;
|
||||||
|
/* 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 *dirRegex;
|
||||||
const char *file;
|
const char *file;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,18 +83,29 @@ testSchemaFile(const char *schema,
|
|||||||
static int
|
static int
|
||||||
testSchemaDir(const char *schema,
|
testSchemaDir(const char *schema,
|
||||||
virXMLValidatorPtr validator,
|
virXMLValidatorPtr validator,
|
||||||
const char *dir_path)
|
const char *dir_path,
|
||||||
|
const char *filterstr)
|
||||||
{
|
{
|
||||||
DIR *dir = NULL;
|
DIR *dir = NULL;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int rc;
|
int rc;
|
||||||
|
g_autoptr(GRegex) filter = NULL;
|
||||||
|
|
||||||
if (virDirOpen(&dir, dir_path) < 0) {
|
if (virDirOpen(&dir, dir_path) < 0) {
|
||||||
virTestPropagateLibvirtError();
|
virTestPropagateLibvirtError();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filterstr) {
|
||||||
|
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);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
|
while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
|
||||||
g_autofree char *xml_path = NULL;
|
g_autofree char *xml_path = NULL;
|
||||||
|
|
||||||
@ -98,6 +113,9 @@ testSchemaDir(const char *schema,
|
|||||||
continue;
|
continue;
|
||||||
if (ent->d_name[0] == '.')
|
if (ent->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
|
if (filter &&
|
||||||
|
!g_regex_match(filter, ent->d_name, 0, NULL))
|
||||||
|
continue;
|
||||||
|
|
||||||
xml_path = g_strdup_printf("%s/%s", dir_path, ent->d_name);
|
xml_path = g_strdup_printf("%s/%s", dir_path, ent->d_name);
|
||||||
|
|
||||||
@ -176,7 +194,7 @@ testSchemaEntries(const char *schema,
|
|||||||
if (entry->dir) {
|
if (entry->dir) {
|
||||||
g_autofree char *path = g_strdup_printf("%s/%s", abs_top_srcdir, entry->dir);
|
g_autofree char *path = g_strdup_printf("%s/%s", abs_top_srcdir, entry->dir);
|
||||||
|
|
||||||
if (testSchemaDir(schema, validator, path) < 0)
|
if (testSchemaDir(schema, validator, path, entry->dirRegex) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user