diff mbox series

[v2,5/9] tests/virtio-9p: check file names of R_readdir response

Message ID 2a40095340d9536575af8fd214a7ac647b4603c9.1576678644.git.qemu_oss@crudebyte.com (mailing list archive)
State New, archived
Headers show
Series 9pfs: readdir optimization | expand

Commit Message

Christian Schoenebeck Dec. 18, 2019, 1:35 p.m. UTC
Additionally to the already existing check for expected amount
of directory entries returned by R_readdir response, also check
whether all directory entries have the expected file names (as
created on 9pfs synth driver side), ignoring their precise order
in result list though.

Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
 tests/virtio-9p-test.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Greg Kurz Jan. 6, 2020, 5:07 p.m. UTC | #1
On Wed, 18 Dec 2019 14:35:56 +0100
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:

> Additionally to the already existing check for expected amount
> of directory entries returned by R_readdir response, also check
> whether all directory entries have the expected file names (as
> created on 9pfs synth driver side), ignoring their precise order
> in result list though.
> 
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---

LGTM and trivial enough that it can be folded in the previous
patch.

>  tests/virtio-9p-test.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
> index 48c0eca292..cb5c9fb420 100644
> --- a/tests/virtio-9p-test.c
> +++ b/tests/virtio-9p-test.c
> @@ -565,6 +565,16 @@ static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc)
>      g_free(wqid);
>  }
>  
> +static bool fs_dirents_contain_name(struct v9fs_dirent *e, const char* name)
> +{
> +    for (; e; e = e->next) {
> +        if (!strcmp(e->name, name)) {
> +            return true;
> +        }
> +    }
> +    return false;
> +}
> +
>  static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
>  {
>      QVirtio9P *v9p = obj;
> @@ -599,6 +609,18 @@ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
>          QTEST_V9FS_SYNTH_READDIR_NFILES + 2 /* "." and ".." */
>      );
>  
> +    /*
> +     * Check all file names exist in returned entries, ignore their order
> +     * though.
> +     */
> +    g_assert_cmpint(fs_dirents_contain_name(entries, "."), ==, true);
> +    g_assert_cmpint(fs_dirents_contain_name(entries, ".."), ==, true);
> +    for (int i = 0; i < QTEST_V9FS_SYNTH_READDIR_NFILES; ++i) {
> +        char *name = g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE, i);
> +        g_assert_cmpint(fs_dirents_contain_name(entries, name), ==, true);
> +        g_free(name);
> +    }
> +
>      v9fs_free_dirents(entries);
>      g_free(wnames[0]);
>  }
Christian Schoenebeck Jan. 7, 2020, 12:28 p.m. UTC | #2
On Montag, 6. Januar 2020 18:07:11 CET Greg Kurz wrote:
> On Wed, 18 Dec 2019 14:35:56 +0100
> 
> Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:
> > Additionally to the already existing check for expected amount
> > of directory entries returned by R_readdir response, also check
> > whether all directory entries have the expected file names (as
> > created on 9pfs synth driver side), ignoring their precise order
> > in result list though.
> > 
> > Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> > ---
> 
> LGTM and trivial enough that it can be folded in the previous
> patch.

So you want that patch to be squashed. Np.

Best regards,
Christian Schoenebeck
Greg Kurz Jan. 7, 2020, 3:29 p.m. UTC | #3
On Tue, 07 Jan 2020 13:28:38 +0100
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:

> On Montag, 6. Januar 2020 18:07:11 CET Greg Kurz wrote:
> > On Wed, 18 Dec 2019 14:35:56 +0100
> > 
> > Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:
> > > Additionally to the already existing check for expected amount
> > > of directory entries returned by R_readdir response, also check
> > > whether all directory entries have the expected file names (as
> > > created on 9pfs synth driver side), ignoring their precise order
> > > in result list though.
> > > 
> > > Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> > > ---
> > 
> > LGTM and trivial enough that it can be folded in the previous
> > patch.
> 
> So you want that patch to be squashed. Np.
> 

Yes. Thanks.

> Best regards,
> Christian Schoenebeck
> 
>
diff mbox series

Patch

diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c
index 48c0eca292..cb5c9fb420 100644
--- a/tests/virtio-9p-test.c
+++ b/tests/virtio-9p-test.c
@@ -565,6 +565,16 @@  static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc)
     g_free(wqid);
 }
 
+static bool fs_dirents_contain_name(struct v9fs_dirent *e, const char* name)
+{
+    for (; e; e = e->next) {
+        if (!strcmp(e->name, name)) {
+            return true;
+        }
+    }
+    return false;
+}
+
 static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtio9P *v9p = obj;
@@ -599,6 +609,18 @@  static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
         QTEST_V9FS_SYNTH_READDIR_NFILES + 2 /* "." and ".." */
     );
 
+    /*
+     * Check all file names exist in returned entries, ignore their order
+     * though.
+     */
+    g_assert_cmpint(fs_dirents_contain_name(entries, "."), ==, true);
+    g_assert_cmpint(fs_dirents_contain_name(entries, ".."), ==, true);
+    for (int i = 0; i < QTEST_V9FS_SYNTH_READDIR_NFILES; ++i) {
+        char *name = g_strdup_printf(QTEST_V9FS_SYNTH_READDIR_FILE, i);
+        g_assert_cmpint(fs_dirents_contain_name(entries, name), ==, true);
+        g_free(name);
+    }
+
     v9fs_free_dirents(entries);
     g_free(wnames[0]);
 }