tests/9pfs: Code refactoring
v2 cover tests/9pfs: Code refactoring
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
PATCH v2 1/5 tests/9pfs: Factor out do_version() helper
fs_version() is a top level test function. Factor out the reusable code to a separate helper instead of hijacking it in other tests.
--- tests/qtest/virtio-9p-test.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
tests/qtest/virtio-9p-test.c +9 -5
@@ -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);
PATCH v2 2/5 tests/9pfs: Turn fs_readdir_split() into a helper
In reply to Greg Kurzfs_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.
--- tests/qtest/virtio-9p-test.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
tests/qtest/virtio-9p-test.c +7 -7
@@ -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 ); }
PATCH v2 3/5 tests/9pfs: Set alloc in fs_create_dir()
In reply to Greg Kurzfs_create_dir() is a top level test function. It should set alloc.
--- tests/qtest/virtio-9p-test.c | 1 + 1 file changed, 1 insertion(+)
tests/qtest/virtio-9p-test.c +1 -0
@@ -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" );
PATCH v2 4/5 tests/9pfs: Factor out do_attach() helper
In reply to Greg Kurzfs_attach() is a top level test function. Factor out the reusable code to a separate helper instead of hijacking it in other tests.
--- tests/qtest/virtio-9p-test.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
tests/qtest/virtio-9p-test.c +16 -12
@@ -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 ... */
PATCH v2 5/5 tests/9pfs: Turn fs_mkdir() into a helper
In reply to Greg Kurzfs_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.
--- tests/qtest/virtio-9p-test.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
tests/qtest/virtio-9p-test.c +2 -5
@@ -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 );
Quoted 15 lines · 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 outdo_version()helper tests/9pfs: Turnfs_readdir_split()into a helper tests/9pfs: Set alloc infs_create_dir()tests/9pfs: Factor outdo_attach()helper tests/9pfs: Turnfs_mkdir()into a helper
Quoted 6 lines
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
Quoted 20 lines · On Tue, 20 Oct 2020 19:23:19 +0200 Christian Schoenebeck…
Quoted 19 lines · 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 outdo_version()helper tests/9pfs: Turnfs_readdir_split()into a helper tests/9pfs: Set alloc infs_create_dir()tests/9pfs: Factor outdo_attach()helper tests/9pfs: Turnfs_mkdir()into a helpertests/qtest/virtio-9p-test.c | 62+++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 28 deletions(-)
Quoted 9 lines
Quoted 2 lines
--
GregQueued on 9p.next:
https://github.com/cschoenebeck/qemu/commits/9p.nextI just tweaked the order of the patches to prevent intermediate compiler errors.
Oops, sorry... thanks ! :)
Quoted 6 lines
Thanks!
Best regards,
Christian Schoenebeck