[PATCH 5/5] virschematest: Don't skip all "directory" tests

Peter Krempa posted 5 patches 4 weeks ago
[PATCH 5/5] virschematest: Don't skip all "directory" tests
Posted by Peter Krempa 4 weeks ago
Due to a bug in the optimization to avoid testing symlinked tests
multiple times all tests were skipped.

In commit f997fcca71a16b102e6ee663 I made an attempt to optimize the
tests by avoiding testing symlinks. This optimization was buggy as I've
passed the 'd_name' field of 'struct dirent' which is just the filename
to 'g_lstat()'. 'g_lstat()' obviously always failed with ENOENT. As the
logic checked only for successful return of 'g_lstat()' the optimizatio
was a dud.

Now in 4d8ebbfee83edb2 the 'g_lstat()' call was replaced by
'virFileIsLink()' checking all non-zero values. This meant that if
'virFileIsLink()' failed the test was skipped. Now since a bad argument
was passed this failed always and thus was always skipped making
'virschematest' useless.

Fix it by passing the full path of the test and also explicitly check
for '1' return value instead of any non-zero.

Fixes: f997fcca71a16b102e6ee663a3fb86bed8de9d7d
Fixes: 4d8ebbfee83edb26b19a62465b9f98d0126db991
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tests/virschematest.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tests/virschematest.c b/tests/virschematest.c
index 5d3fa32de4..e08ae21738 100644
--- a/tests/virschematest.c
+++ b/tests/virschematest.c
@@ -124,8 +124,6 @@ testSchemaDir(const char *schema,
             continue;
         if (ent->d_name[0] == '.')
             continue;
-        if (virFileIsLink(ent->d_name))
-            continue;
         if (filter &&
             !g_regex_match(filter, ent->d_name, 0, NULL))
             continue;
@@ -134,11 +132,14 @@ testSchemaDir(const char *schema,
             g_strv_contains(entry->skip, ent->d_name))
             continue;

+        xml_path = g_strdup_printf("%s/%s", dir_path, ent->d_name);
+
+        if (virFileIsLink(xml_path) == 1)
+            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, exception) < 0)
             ret = -1;
     }
-- 
2.47.0
Re: [PATCH 5/5] virschematest: Don't skip all "directory" tests
Posted by Michal Prívozník 4 weeks ago
On 11/28/24 09:32, Peter Krempa wrote:
> Due to a bug in the optimization to avoid testing symlinked tests
> multiple times all tests were skipped.
> 
> In commit f997fcca71a16b102e6ee663 I made an attempt to optimize the
> tests by avoiding testing symlinks. This optimization was buggy as I've
> passed the 'd_name' field of 'struct dirent' which is just the filename
> to 'g_lstat()'. 'g_lstat()' obviously always failed with ENOENT. As the
> logic checked only for successful return of 'g_lstat()' the optimizatio
> was a dud.
> 
> Now in 4d8ebbfee83edb2 the 'g_lstat()' call was replaced by
> 'virFileIsLink()' checking all non-zero values. This meant that if
> 'virFileIsLink()' failed the test was skipped. Now since a bad argument
> was passed this failed always and thus was always skipped making
> 'virschematest' useless.
> 
> Fix it by passing the full path of the test and also explicitly check
> for '1' return value instead of any non-zero.
> 
> Fixes: f997fcca71a16b102e6ee663a3fb86bed8de9d7d
> Fixes: 4d8ebbfee83edb26b19a62465b9f98d0126db991

Collaboration works! :-D

Michal