All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] tests/9pfs: Code refactoring
@ 2020-10-20 16:09 Greg Kurz
  2020-10-20 16:09 ` [PATCH v2 1/5] tests/9pfs: Factor out do_version() helper Greg Kurz
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Greg Kurz @ 2020-10-20 16:09 UTC (permalink / raw)
  To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz

Some code refactoring to have a clear distinction between top level
test functions and helper functions.

v2: - use "do_" prefix instead of "do_fs_"

---

Greg Kurz (5):
      tests/9pfs: Factor out do_version() helper
      tests/9pfs: Turn fs_readdir_split() into a helper
      tests/9pfs: Set alloc in fs_create_dir()
      tests/9pfs: Factor out do_attach() helper
      tests/9pfs: Turn fs_mkdir() into a helper


 tests/qtest/virtio-9p-test.c |   62 +++++++++++++++++++++++-------------------
 1 file changed, 34 insertions(+), 28 deletions(-)

--
Greg



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/5] tests/9pfs: Factor out do_version() helper
  2020-10-20 16:09 [PATCH v2 0/5] tests/9pfs: Code refactoring Greg Kurz
@ 2020-10-20 16:09 ` Greg Kurz
  2020-10-20 16:09 ` [PATCH v2 2/5] tests/9pfs: Turn fs_readdir_split() into a helper Greg Kurz
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2020-10-20 16:09 UTC (permalink / raw)
  To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz

fs_version() is a top level test function. Factor out the reusable
code to a separate helper instead of hijacking it in other tests.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 tests/qtest/virtio-9p-test.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index c15908f27b3d..59bcea4c3091 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -567,10 +567,8 @@ static void v9fs_rflush(P9Req *req)
     v9fs_req_free(req);
 }
 
-static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc)
+static void do_version(QVirtio9P *v9p)
 {
-    QVirtio9P *v9p = obj;
-    alloc = t_alloc;
     const char *version = "9P2000.L";
     uint16_t server_len;
     char *server_version;
@@ -585,13 +583,19 @@ static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc)
     g_free(server_version);
 }
 
+static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+    alloc = t_alloc;
+    do_version(obj);
+}
+
 static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtio9P *v9p = obj;
     alloc = t_alloc;
     P9Req *req;
 
-    fs_version(v9p, NULL, t_alloc);
+    do_version(v9p);
     req = v9fs_tattach(v9p, 0, getuid(), 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rattach(req, NULL);
@@ -831,7 +835,7 @@ static void fs_walk_dotdot(void *obj, void *data, QGuestAllocator *t_alloc)
     v9fs_qid root_qid, *wqid;
     P9Req *req;
 
-    fs_version(v9p, NULL, t_alloc);
+    do_version(v9p);
     req = v9fs_tattach(v9p, 0, getuid(), 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rattach(req, &root_qid);




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/5] tests/9pfs: Turn fs_readdir_split() into a helper
  2020-10-20 16:09 [PATCH v2 0/5] tests/9pfs: Code refactoring Greg Kurz
  2020-10-20 16:09 ` [PATCH v2 1/5] tests/9pfs: Factor out do_version() helper Greg Kurz
@ 2020-10-20 16:09 ` Greg Kurz
  2020-10-20 16:09 ` [PATCH v2 3/5] tests/9pfs: Set alloc in fs_create_dir() Greg Kurz
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2020-10-20 16:09 UTC (permalink / raw)
  To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz

fs_readdir_split() isn't a top level test function and thus shouldn't
take the "void *obj, void *data, QGuestAllocator *t_alloc" arguments.
Turn it into a helper to be used by test functions.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 tests/qtest/virtio-9p-test.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 59bcea4c3091..52d102a3fc9f 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -727,11 +727,8 @@ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
 }
 
 /* readdir test where overall request is split over several messages */
-static void fs_readdir_split(void *obj, void *data, QGuestAllocator *t_alloc,
-                             uint32_t count)
+static void do_readdir_split(QVirtio9P *v9p, uint32_t count)
 {
-    QVirtio9P *v9p = obj;
-    alloc = t_alloc;
     char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_READDIR_DIR) };
     uint16_t nqid;
     v9fs_qid qid;
@@ -998,19 +995,22 @@ static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc,
 static void fs_readdir_split_128(void *obj, void *data,
                                  QGuestAllocator *t_alloc)
 {
-    fs_readdir_split(obj, data, t_alloc, 128);
+    alloc = t_alloc;
+    do_readdir_split(obj, 128);
 }
 
 static void fs_readdir_split_256(void *obj, void *data,
                                  QGuestAllocator *t_alloc)
 {
-    fs_readdir_split(obj, data, t_alloc, 256);
+    alloc = t_alloc;
+    do_readdir_split(obj, 256);
 }
 
 static void fs_readdir_split_512(void *obj, void *data,
                                  QGuestAllocator *t_alloc)
 {
-    fs_readdir_split(obj, data, t_alloc, 512);
+    alloc = t_alloc;
+    do_readdir_split(obj, 512);
 }
 
 




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/5] tests/9pfs: Set alloc in fs_create_dir()
  2020-10-20 16:09 [PATCH v2 0/5] tests/9pfs: Code refactoring Greg Kurz
  2020-10-20 16:09 ` [PATCH v2 1/5] tests/9pfs: Factor out do_version() helper Greg Kurz
  2020-10-20 16:09 ` [PATCH v2 2/5] tests/9pfs: Turn fs_readdir_split() into a helper Greg Kurz
@ 2020-10-20 16:09 ` Greg Kurz
  2020-10-20 16:09 ` [PATCH v2 4/5] tests/9pfs: Factor out do_attach() helper Greg Kurz
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2020-10-20 16:09 UTC (permalink / raw)
  To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz

fs_create_dir() is a top level test function. It should set alloc.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 tests/qtest/virtio-9p-test.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 52d102a3fc9f..cc52ae9a77b3 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -1019,6 +1019,7 @@ static void fs_readdir_split_512(void *obj, void *data,
 static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtio9P *v9p = obj;
+    alloc = t_alloc;
     struct stat st;
     char *root_path = virtio_9p_test_path("");
     char *new_dir = virtio_9p_test_path("01");




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/5] tests/9pfs: Factor out do_attach() helper
  2020-10-20 16:09 [PATCH v2 0/5] tests/9pfs: Code refactoring Greg Kurz
                   ` (2 preceding siblings ...)
  2020-10-20 16:09 ` [PATCH v2 3/5] tests/9pfs: Set alloc in fs_create_dir() Greg Kurz
@ 2020-10-20 16:09 ` Greg Kurz
  2020-10-20 16:09 ` [PATCH v2 5/5] tests/9pfs: Turn fs_mkdir() into a helper Greg Kurz
  2020-10-20 17:23 ` [PATCH v2 0/5] tests/9pfs: Code refactoring Christian Schoenebeck
  5 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2020-10-20 16:09 UTC (permalink / raw)
  To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz

fs_attach() is a top level test function. Factor out the reusable
code to a separate helper instead of hijacking it in other tests.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 tests/qtest/virtio-9p-test.c |   28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index cc52ae9a77b3..3c187cdc08b7 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -589,10 +589,8 @@ static void fs_version(void *obj, void *data, QGuestAllocator *t_alloc)
     do_version(obj);
 }
 
-static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc)
+static void do_attach(QVirtio9P *v9p)
 {
-    QVirtio9P *v9p = obj;
-    alloc = t_alloc;
     P9Req *req;
 
     do_version(v9p);
@@ -601,6 +599,12 @@ static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc)
     v9fs_rattach(req, NULL);
 }
 
+static void fs_attach(void *obj, void *data, QGuestAllocator *t_alloc)
+{
+    alloc = t_alloc;
+    do_attach(obj);
+}
+
 static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc)
 {
     QVirtio9P *v9p = obj;
@@ -615,7 +619,7 @@ static void fs_walk(void *obj, void *data, QGuestAllocator *t_alloc)
         wnames[i] = g_strdup_printf(QTEST_V9FS_SYNTH_WALK_FILE, i);
     }
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
     req = v9fs_twalk(v9p, 0, 1, P9_MAXWELEM, wnames, 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rwalk(req, &nwqid, &wqid);
@@ -684,7 +688,7 @@ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc)
     struct V9fsDirent *entries = NULL;
     P9Req *req;
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
     req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rwalk(req, &nqid, NULL);
@@ -738,7 +742,7 @@ static void do_readdir_split(QVirtio9P *v9p, uint32_t count)
     int fid;
     uint64_t offset;
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
 
     fid = 1;
     offset = 0;
@@ -814,7 +818,7 @@ static void fs_walk_no_slash(void *obj, void *data, QGuestAllocator *t_alloc)
     P9Req *req;
     uint32_t err;
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
     req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rlerror(req, &err);
@@ -854,7 +858,7 @@ static void fs_lopen(void *obj, void *data, QGuestAllocator *t_alloc)
     char *const wnames[] = { g_strdup(QTEST_V9FS_SYNTH_LOPEN_FILE) };
     P9Req *req;
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
     req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rwalk(req, NULL, NULL);
@@ -876,7 +880,7 @@ static void fs_write(void *obj, void *data, QGuestAllocator *t_alloc)
     uint32_t count;
     P9Req *req;
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
     req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rwalk(req, NULL, NULL);
@@ -903,7 +907,7 @@ static void fs_flush_success(void *obj, void *data, QGuestAllocator *t_alloc)
     uint32_t reply_len;
     uint8_t should_block;
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
     req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rwalk(req, NULL, NULL);
@@ -940,7 +944,7 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc)
     uint32_t count;
     uint8_t should_block;
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
     req = v9fs_twalk(v9p, 0, 1, 1, wnames, 0);
     v9fs_req_wait_for_reply(req, NULL);
     v9fs_rwalk(req, NULL, NULL);
@@ -1026,7 +1030,7 @@ static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)
 
     g_assert(root_path != NULL);
 
-    fs_attach(v9p, NULL, t_alloc);
+    do_attach(v9p);
     fs_mkdir(v9p, data, t_alloc, "/", "01");
 
     /* check if created directory really exists now ... */




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 5/5] tests/9pfs: Turn fs_mkdir() into a helper
  2020-10-20 16:09 [PATCH v2 0/5] tests/9pfs: Code refactoring Greg Kurz
                   ` (3 preceding siblings ...)
  2020-10-20 16:09 ` [PATCH v2 4/5] tests/9pfs: Factor out do_attach() helper Greg Kurz
@ 2020-10-20 16:09 ` Greg Kurz
  2020-10-20 17:23 ` [PATCH v2 0/5] tests/9pfs: Code refactoring Christian Schoenebeck
  5 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2020-10-20 16:09 UTC (permalink / raw)
  To: Christian Schoenebeck; +Cc: qemu-devel, Greg Kurz

fs_mkdir() isn't a top level test function and thus shouldn't take
the "void *obj, void *data, QGuestAllocator *t_alloc" arguments.
Turn it into a helper to be used by test functions.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 tests/qtest/virtio-9p-test.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 3c187cdc08b7..2ea555fa045a 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -972,11 +972,8 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc)
     g_free(wnames[0]);
 }
 
-static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc,
-                     const char *path, const char *cname)
+static void do_mkdir(QVirtio9P *v9p, const char *path, const char *cname)
 {
-    QVirtio9P *v9p = obj;
-    alloc = t_alloc;
     char **wnames;
     char *const name = g_strdup(cname);
     P9Req *req;
@@ -1031,7 +1028,7 @@ static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)
     g_assert(root_path != NULL);
 
     do_attach(v9p);
-    fs_mkdir(v9p, data, t_alloc, "/", "01");
+    do_mkdir(v9p, "/", "01");
 
     /* check if created directory really exists now ... */
     g_assert(stat(new_dir, &st) == 0);




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/5] tests/9pfs: Code refactoring
  2020-10-20 16:09 [PATCH v2 0/5] tests/9pfs: Code refactoring Greg Kurz
                   ` (4 preceding siblings ...)
  2020-10-20 16:09 ` [PATCH v2 5/5] tests/9pfs: Turn fs_mkdir() into a helper Greg Kurz
@ 2020-10-20 17:23 ` Christian Schoenebeck
  2020-10-20 18:00   ` Greg Kurz
  5 siblings, 1 reply; 8+ messages in thread
From: Christian Schoenebeck @ 2020-10-20 17:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz

On Dienstag, 20. Oktober 2020 18:09:07 CEST Greg Kurz wrote:
> Some code refactoring to have a clear distinction between top level
> test functions and helper functions.
> 
> v2: - use "do_" prefix instead of "do_fs_"
> 
> ---
> 
> Greg Kurz (5):
>       tests/9pfs: Factor out do_version() helper
>       tests/9pfs: Turn fs_readdir_split() into a helper
>       tests/9pfs: Set alloc in fs_create_dir()
>       tests/9pfs: Factor out do_attach() helper
>       tests/9pfs: Turn fs_mkdir() into a helper
> 
> 
>  tests/qtest/virtio-9p-test.c |   62
> +++++++++++++++++++++++------------------- 1 file changed, 34
> insertions(+), 28 deletions(-)
> 
> --
> Greg

Queued on 9p.next:
https://github.com/cschoenebeck/qemu/commits/9p.next

I just tweaked the order of the patches to prevent intermediate compiler 
errors.

Thanks!

Best regards,
Christian Schoenebeck




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/5] tests/9pfs: Code refactoring
  2020-10-20 17:23 ` [PATCH v2 0/5] tests/9pfs: Code refactoring Christian Schoenebeck
@ 2020-10-20 18:00   ` Greg Kurz
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Kurz @ 2020-10-20 18:00 UTC (permalink / raw)
  To: Christian Schoenebeck; +Cc: qemu-devel

On Tue, 20 Oct 2020 19:23:19 +0200
Christian Schoenebeck <qemu_oss@crudebyte.com> wrote:

> On Dienstag, 20. Oktober 2020 18:09:07 CEST Greg Kurz wrote:
> > Some code refactoring to have a clear distinction between top level
> > test functions and helper functions.
> > 
> > v2: - use "do_" prefix instead of "do_fs_"
> > 
> > ---
> > 
> > Greg Kurz (5):
> >       tests/9pfs: Factor out do_version() helper
> >       tests/9pfs: Turn fs_readdir_split() into a helper
> >       tests/9pfs: Set alloc in fs_create_dir()
> >       tests/9pfs: Factor out do_attach() helper
> >       tests/9pfs: Turn fs_mkdir() into a helper
> > 
> > 
> >  tests/qtest/virtio-9p-test.c |   62
> > +++++++++++++++++++++++------------------- 1 file changed, 34
> > insertions(+), 28 deletions(-)
> > 
> > --
> > Greg
> 
> Queued on 9p.next:
> https://github.com/cschoenebeck/qemu/commits/9p.next
> 
> I just tweaked the order of the patches to prevent intermediate compiler 
> errors.
> 

Oops, sorry... thanks ! :)

> Thanks!
> 
> Best regards,
> Christian Schoenebeck
> 
> 



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-10-20 18:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-20 16:09 [PATCH v2 0/5] tests/9pfs: Code refactoring Greg Kurz
2020-10-20 16:09 ` [PATCH v2 1/5] tests/9pfs: Factor out do_version() helper Greg Kurz
2020-10-20 16:09 ` [PATCH v2 2/5] tests/9pfs: Turn fs_readdir_split() into a helper Greg Kurz
2020-10-20 16:09 ` [PATCH v2 3/5] tests/9pfs: Set alloc in fs_create_dir() Greg Kurz
2020-10-20 16:09 ` [PATCH v2 4/5] tests/9pfs: Factor out do_attach() helper Greg Kurz
2020-10-20 16:09 ` [PATCH v2 5/5] tests/9pfs: Turn fs_mkdir() into a helper Greg Kurz
2020-10-20 17:23 ` [PATCH v2 0/5] tests/9pfs: Code refactoring Christian Schoenebeck
2020-10-20 18:00   ` Greg Kurz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.