qtest/virtio-9p-test.c: fix slow tests
v2 cover qtest/virtio-9p-test.c: fix slow tests
Hi,
In this new version I added a handful of patches to make it easier to review, as suggested by Greg in v1.
Thomas, the changes made aren't negligible so I didn't add your Tested-by. You're more than welcome to give this version a try :)
The first 2 patches are needed to ease the burden of individual test changes. It was really annoying to deal with changing the dir name every time a test was being removed. Parametrizing the dir name (and anything that has the dir in it) makes it trivial to change the dir name when needed.
I kept the slow revert patch (7) because this series is passing the Gitlab CI with it:
https://gitlab.com/danielhb/qemu/-/pipelines/1228813691
I'll leave to the 9p maintainers to decide whether we should go ahead with it or not.
Changes from v1:
- patches 1 and 2 from v1: dropped
- patches 1 and 2 (new):
- parametrize 'new_dir' name
- patches 3, 4, 5, 6 (new):
- individual test consolidation
- v1 link: https://mail.gnu.org/archive/html/qemu-devel/2024-03/msg06146.html
Daniel Henrique Barboza (7):
qtest/virtio-9p-test.c: add '_path' in path vars qtest/virtio-9p-test.c: parametrize 'dir' name in local tests qtest/virtio-9p-test.c: consolidate create dir tests qtest/virtio-9p-test.c: consolidate create file tests qtest/virtio-9p-test.c: consolidate create symlink tests qtest/virtio-9p-test.c: consolidate hardlink tests qtest/virtio-9p-test.c: remove g_test_slow() gate
tests/qtest/virtio-9p-test.c | 228 +++++++++++++++-------------------- 1 file changed, 96 insertions(+), 132 deletions(-)
Signature · 1 line
2.44.0
PATCH v2 1/7 qtest/virtio-9p-test.c: add '_path' in path vars
Add a '_path' call in all variables that are receiving a full path via virtio_9p_test_path().
Aside from being more accurate with what the variable represents, this will allow us to use 'new_dir' and 'real_path' and so on to parametrize test values in the next patch.
--- tests/qtest/virtio-9p-test.c | 64 ++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 29 deletions(-)
tests/qtest/virtio-9p-test.c +35 -29
@@ -512,7 +512,7 @@ static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)v9fs_set_allocator (t_alloc);struct stat st; g_autofree char *root_path = virtio_9p_test_path(""); - g_autofree char *new_dir = virtio_9p_test_path("01"); + g_autofree char *new_dir_path = virtio_9p_test_path("01");g_assert (root_path !=NULL );
@@ -520,7 +520,7 @@ static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc) tmkdir({ .client = v9p, .atPath = "/", .name = "01" });/* check if created directory really exists now ... */ -g_assert (stat (new_dir, &st) ==0 ); +g_assert (stat (new_dir_path, &st) ==0 );/* ... and is actually a directory */ g_assert ((st.st_mode &S_IFMT ) ==S_IFDIR ); }
@@ -531,7 +531,7 @@ static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc)v9fs_set_allocator (t_alloc);struct stat st; g_autofree char *root_path = virtio_9p_test_path(""); - g_autofree char *new_dir = virtio_9p_test_path("02"); + g_autofree char *new_dir_path = virtio_9p_test_path("02");g_assert (root_path !=NULL );
@@ -539,7 +539,7 @@ static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc) tmkdir({ .client = v9p, .atPath = "/", .name = "02" });/* check if created directory really exists now ... */ -g_assert (stat (new_dir, &st) ==0 ); +g_assert (stat (new_dir_path, &st) ==0 );/* ... and is actually a directory */ g_assert ((st.st_mode &S_IFMT ) ==S_IFDIR );
@@ -548,7 +548,7 @@ static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc) .flags = P9_DOTL_AT_REMOVEDIR });/* directory should be gone now */ -g_assert (stat (new_dir, &st) !=0 ); +g_assert (stat (new_dir_path, &st) !=0 ); }static void fs_create_file (void *obj,void *data,QGuestAllocator *t_alloc)
@@ -556,14 +556,14 @@ static void fs_create_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; - g_autofree char *new_file = virtio_9p_test_path("03/1st_file"); + g_autofree char *new_file_path = virtio_9p_test_path("03/1st_file"); tattach({ .client = v9p }); tmkdir({ .client = v9p, .atPath = "/", .name = "03" }); tlcreate({ .client = v9p, .atPath = "03", .name = "1st_file" });/* check if created file exists now ... */ -g_assert (stat (new_file, &st) ==0 ); +g_assert (stat (new_file_path, &st) ==0 );/* ... and is a regular file */ g_assert ((st.st_mode &S_IFMT ) ==S_IFREG ); }
@@ -573,20 +573,20 @@ static void fs_unlinkat_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; - g_autofree char *new_file = virtio_9p_test_path("04/doa_file"); + g_autofree char *new_file_path = virtio_9p_test_path("04/doa_file"); tattach({ .client = v9p }); tmkdir({ .client = v9p, .atPath = "/", .name = "04" }); tlcreate({ .client = v9p, .atPath = "04", .name = "doa_file" });/* check if created file exists now ... */ -g_assert (stat (new_file, &st) ==0 ); +g_assert (stat (new_file_path, &st) ==0 );/* ... and is a regular file */ g_assert ((st.st_mode &S_IFMT ) ==S_IFREG ); tunlinkat({ .client = v9p, .atPath = "04", .name = "doa_file" });/* file should be gone now */ -g_assert (stat (new_file, &st) !=0 ); +g_assert (stat (new_file_path, &st) !=0 ); }static void fs_symlink_file (void *obj,void *data,QGuestAllocator *t_alloc)
@@ -594,13 +594,13 @@ static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; - g_autofree char *real_file = virtio_9p_test_path("05/real_file"); - g_autofree char *symlink_file = virtio_9p_test_path("05/symlink_file"); + g_autofree char *real_file_path = virtio_9p_test_path("05/real_file"); + g_autofree char *symlink_file_path = virtio_9p_test_path("05/symlink_file"); tattach({ .client = v9p }); tmkdir({ .client = v9p, .atPath = "/", .name = "05" }); tlcreate({ .client = v9p, .atPath = "05", .name = "real_file" }); -g_assert (stat (real_file, &st) ==0 ); +g_assert (stat (real_file_path, &st) ==0 );g_assert ((st.st_mode &S_IFMT ) ==S_IFREG ); tsymlink({
@@ -609,7 +609,7 @@ static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_alloc) });/* check if created link exists now */ -g_assert (stat (symlink_file, &st) ==0 ); +g_assert (stat (symlink_file_path, &st) ==0 ); } static void fs_unlinkat_symlink(void *obj, void *data,
@@ -618,24 +618,24 @@ static void fs_unlinkat_symlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; - g_autofree char *real_file = virtio_9p_test_path("06/real_file"); - g_autofree char *symlink_file = virtio_9p_test_path("06/symlink_file"); + g_autofree char *real_file_path = virtio_9p_test_path("06/real_file"); + g_autofree char *symlink_file_path = virtio_9p_test_path("06/symlink_file"); tattach({ .client = v9p }); tmkdir({ .client = v9p, .atPath = "/", .name = "06" }); tlcreate({ .client = v9p, .atPath = "06", .name = "real_file" }); -g_assert (stat (real_file, &st) ==0 ); +g_assert (stat (real_file_path, &st) ==0 );g_assert ((st.st_mode &S_IFMT ) ==S_IFREG );tsymlink ({ .client = v9p, .atPath = "06", .name = "symlink_file", .symtgt = "real_file" }); -g_assert (stat (symlink_file, &st) ==0 ); +g_assert (stat (symlink_file_path, &st) ==0 ); tunlinkat({ .client = v9p, .atPath = "06", .name = "symlink_file" });/* symlink should be gone now */ -g_assert (stat (symlink_file, &st) !=0 ); +g_assert (stat (symlink_file_path, &st) !=0 ); }static void fs_hardlink_file (void *obj,void *data,QGuestAllocator *t_alloc)
@@ -643,13 +643,16 @@ static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; - g_autofree char *real_file = virtio_9p_test_path("07/real_file"); - g_autofree char *hardlink_file = virtio_9p_test_path("07/hardlink_file"); + g_autofree char *real_file_path = NULL; + g_autofree char *hardlink_file_path = NULL; + + real_file_path =virtio_9p_test_path ("07/real_file" ); + hardlink_file_path =virtio_9p_test_path ("07/hardlink_file" ); tattach({ .client = v9p }); tmkdir({ .client = v9p, .atPath = "/", .name = "07" }); tlcreate({ .client = v9p, .atPath = "07", .name = "real_file" }); -g_assert (stat (real_file, &st_real) ==0 ); +g_assert (stat (real_file_path, &st_real) ==0 );g_assert ((st_real.st_mode &S_IFMT ) ==S_IFREG ); tlink({
@@ -658,7 +661,7 @@ static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc) });/* check if link exists now ... */ -g_assert (stat (hardlink_file, &st_link) ==0 ); +g_assert (stat (hardlink_file_path, &st_link) ==0 );/* ... and it's a hard link, right? */ g_assert ((st_link.st_mode &S_IFMT ) ==S_IFREG );g_assert (st_link.st_dev == st_real.st_dev);
@@ -671,26 +674,29 @@ static void fs_unlinkat_hardlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; - g_autofree char *real_file = virtio_9p_test_path("08/real_file"); - g_autofree char *hardlink_file = virtio_9p_test_path("08/hardlink_file"); + g_autofree char *real_file_path = NULL; + g_autofree char *hardlink_file_path = NULL; + + real_file_path =virtio_9p_test_path ("08/real_file" ); + hardlink_file_path =virtio_9p_test_path ("08/hardlink_file" ); tattach({ .client = v9p }); tmkdir({ .client = v9p, .atPath = "/", .name = "08" }); tlcreate({ .client = v9p, .atPath = "08", .name = "real_file" }); -g_assert (stat (real_file, &st_real) ==0 ); +g_assert (stat (real_file_path, &st_real) ==0 );g_assert ((st_real.st_mode &S_IFMT ) ==S_IFREG );tlink ({ .client = v9p, .atPath = "08", .name = "hardlink_file", .toPath = "08/real_file" }); -g_assert (stat (hardlink_file, &st_link) ==0 ); +g_assert (stat (hardlink_file_path, &st_link) ==0 ); tunlinkat({ .client = v9p, .atPath = "08", .name = "hardlink_file" });/* symlink should be gone now */ -g_assert (stat (hardlink_file, &st_link) !=0 ); +g_assert (stat (hardlink_file_path, &st_link) !=0 );/* and old file should still exist */ -g_assert (stat (real_file, &st_real) ==0 ); +g_assert (stat (real_file_path, &st_real) ==0 ); }static void *assign_9p_local_driver (GString *cmd_line,void *arg)
Signature · 1 line
2.44.0
PATCH v2 2/7 qtest/virtio-9p-test.c: parametrize 'dir' name in local tests
In reply to Daniel Henrique BarbozaAll local 9p tests creates a different dir inside tempdir, where '01' is the dir for the first test, '02' the dir fot the second test and so on.
We want to make tests autoclean themselves while also consolidating them in fewer tests, but this will incur a lot of dir changes that will be unpleasant to deal with at it is today - the dir name is hard coded in every 9p API call.
Add a 'new_dir' var in each test that will hold the created dir name. If the test also creates new files/symlinks, parametrize them as well since they also use the dir name.
After these changes, changing the val of "new_dir" will change all dir references the test uses.
--- tests/qtest/virtio-9p-test.c | 108 +++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 36 deletions(-)
tests/qtest/virtio-9p-test.c +72 -36
@@ -511,13 +511,14 @@ static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; +const char *new_dir ="01" ; g_autofree char *root_path = virtio_9p_test_path(""); - g_autofree char *new_dir_path = virtio_9p_test_path("01"); + g_autofree char *new_dir_path = virtio_9p_test_path(new_dir);g_assert (root_path !=NULL ); tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = "01" }); + tmkdir({ .client = v9p, .atPath = "/", .name = new_dir });/* check if created directory really exists now ... */ g_assert (stat (new_dir_path, &st) ==0 );
@@ -530,13 +531,14 @@ static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; +const char *new_dir ="02" ; g_autofree char *root_path = virtio_9p_test_path(""); - g_autofree char *new_dir_path = virtio_9p_test_path("02"); + g_autofree char *new_dir_path = virtio_9p_test_path(new_dir);g_assert (root_path !=NULL ); tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = "02" }); + tmkdir({ .client = v9p, .atPath = "/", .name = new_dir });/* check if created directory really exists now ... */ g_assert (stat (new_dir_path, &st) ==0 );
@@ -544,7 +546,7 @@ static void fs_unlinkat_dir(void *obj, void *data, QGuestAllocator *t_alloc)g_assert ((st.st_mode &S_IFMT ) ==S_IFDIR );tunlinkat ({ - .client = v9p, .atPath = "/", .name = "02", + .client = v9p, .atPath = "/", .name = new_dir, .flags = P9_DOTL_AT_REMOVEDIR });/* directory should be gone now */
@@ -556,11 +558,13 @@ static void fs_create_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; - g_autofree char *new_file_path = virtio_9p_test_path("03/1st_file"); +const char *new_dir ="03" ; + g_autofree char *new_file = g_strdup_printf("%s/%s", new_dir, "1st_file"); + g_autofree char *new_file_path = virtio_9p_test_path(new_file); tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = "03" }); - tlcreate({ .client = v9p, .atPath = "03", .name = "1st_file" }); + tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); + tlcreate({ .client = v9p, .atPath = new_dir, .name = "1st_file" });/* check if created file exists now ... */ g_assert (stat (new_file_path, &st) ==0 );
@@ -573,18 +577,20 @@ static void fs_unlinkat_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; - g_autofree char *new_file_path = virtio_9p_test_path("04/doa_file"); +const char *new_dir ="04" ; + g_autofree char *new_file = g_strdup_printf("%s/%s", new_dir, "doa_file"); + g_autofree char *new_file_path = virtio_9p_test_path(new_file); tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = "04" }); - tlcreate({ .client = v9p, .atPath = "04", .name = "doa_file" }); + tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); + tlcreate({ .client = v9p, .atPath = new_dir, .name = "doa_file" });/* check if created file exists now ... */ g_assert (stat (new_file_path, &st) ==0 );/* ... and is a regular file */ g_assert ((st.st_mode &S_IFMT ) ==S_IFREG ); - tunlinkat({ .client = v9p, .atPath = "04", .name = "doa_file" }); + tunlinkat({ .client = v9p, .atPath = new_dir, .name = "doa_file" });/* file should be gone now */ g_assert (stat (new_file_path, &st) !=0 ); }
@@ -594,17 +600,26 @@ static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; - g_autofree char *real_file_path = virtio_9p_test_path("05/real_file"); - g_autofree char *symlink_file_path = virtio_9p_test_path("05/symlink_file"); +const char *new_dir ="05" ; + g_autofree char *real_file = NULL; + g_autofree char *real_file_path = NULL; + g_autofree char *symlink_file = NULL; + g_autofree char *symlink_file_path = NULL; + + real_file =g_strdup_printf ("%s/%s" , new_dir,"real_file" ); + real_file_path =virtio_9p_test_path (real_file); + + symlink_file =g_strdup_printf ("%s/%s" , new_dir,"symlink_file" ); + symlink_file_path =virtio_9p_test_path (symlink_file); tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = "05" }); - tlcreate({ .client = v9p, .atPath = "05", .name = "real_file" }); + tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); + tlcreate({ .client = v9p, .atPath = new_dir, .name = "real_file" });g_assert (stat (real_file_path, &st) ==0 );g_assert ((st.st_mode &S_IFMT ) ==S_IFREG );tsymlink ({ - .client = v9p, .atPath = "05", .name = "symlink_file", + .client = v9p, .atPath = new_dir, .name = "symlink_file", .symtgt = "real_file" });
@@ -618,22 +633,31 @@ static void fs_unlinkat_symlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; - g_autofree char *real_file_path = virtio_9p_test_path("06/real_file"); - g_autofree char *symlink_file_path = virtio_9p_test_path("06/symlink_file"); +const char *new_dir ="06" ; + g_autofree char *real_file = NULL; + g_autofree char *real_file_path = NULL; + g_autofree char *symlink_file = NULL; + g_autofree char *symlink_file_path = NULL; + + real_file =g_strdup_printf ("%s/%s" , new_dir,"real_file" ); + real_file_path =virtio_9p_test_path (real_file); + + symlink_file =g_strdup_printf ("%s/%s" , new_dir,"symlink_file" ); + symlink_file_path =virtio_9p_test_path (symlink_file); tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = "06" }); - tlcreate({ .client = v9p, .atPath = "06", .name = "real_file" }); + tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); + tlcreate({ .client = v9p, .atPath = new_dir, .name = "real_file" });g_assert (stat (real_file_path, &st) ==0 );g_assert ((st.st_mode &S_IFMT ) ==S_IFREG );tsymlink ({ - .client = v9p, .atPath = "06", .name = "symlink_file", + .client = v9p, .atPath = new_dir, .name = "symlink_file", .symtgt = "real_file" });g_assert (stat (symlink_file_path, &st) ==0 ); - tunlinkat({ .client = v9p, .atPath = "06", .name = "symlink_file" }); + tunlinkat({ .client = v9p, .atPath = new_dir, .name = "symlink_file" });/* symlink should be gone now */ g_assert (stat (symlink_file_path, &st) !=0 ); }
@@ -643,21 +667,27 @@ static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; +const char *new_dir ="07" ; + g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; + g_autofree char *hardlink_file = NULL; g_autofree char *hardlink_file_path = NULL; - real_file_path =virtio_9p_test_path ("07/real_file" ); - hardlink_file_path =virtio_9p_test_path ("07/hardlink_file" ); + real_file =g_strdup_printf ("%s/%s" , new_dir,"real_file" ); + real_file_path =virtio_9p_test_path (real_file); + + hardlink_file =g_strdup_printf ("%s/%s" , new_dir,"hardlink_file" ); + hardlink_file_path =virtio_9p_test_path (hardlink_file); tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = "07" }); - tlcreate({ .client = v9p, .atPath = "07", .name = "real_file" }); + tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); + tlcreate({ .client = v9p, .atPath = new_dir, .name = "real_file" });g_assert (stat (real_file_path, &st_real) ==0 );g_assert ((st_real.st_mode &S_IFMT ) ==S_IFREG );tlink ({ - .client = v9p, .atPath = "07", .name = "hardlink_file", - .toPath = "07/real_file" + .client = v9p, .atPath = new_dir, .name = "hardlink_file", + .toPath = real_file });/* check if link exists now ... */
@@ -674,25 +704,31 @@ static void fs_unlinkat_hardlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; +const char *new_dir ="08" ; + g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; + g_autofree char *hardlink_file = NULL; g_autofree char *hardlink_file_path = NULL; - real_file_path =virtio_9p_test_path ("08/real_file" ); - hardlink_file_path =virtio_9p_test_path ("08/hardlink_file" ); + real_file =g_strdup_printf ("%s/%s" , new_dir,"real_file" ); + real_file_path =virtio_9p_test_path (real_file); + + hardlink_file =g_strdup_printf ("%s/%s" , new_dir,"hardlink_file" ); + hardlink_file_path =virtio_9p_test_path (hardlink_file); tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = "08" }); - tlcreate({ .client = v9p, .atPath = "08", .name = "real_file" }); + tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); + tlcreate({ .client = v9p, .atPath = new_dir, .name = "real_file" });g_assert (stat (real_file_path, &st_real) ==0 );g_assert ((st_real.st_mode &S_IFMT ) ==S_IFREG );tlink ({ - .client = v9p, .atPath = "08", .name = "hardlink_file", - .toPath = "08/real_file" + .client = v9p, .atPath = new_dir, .name = "hardlink_file", + .toPath = real_file });g_assert (stat (hardlink_file_path, &st_link) ==0 ); - tunlinkat({ .client = v9p, .atPath = "08", .name = "hardlink_file" }); + tunlinkat({ .client = v9p, .atPath = new_dir, .name = "hardlink_file" });/* symlink should be gone now */ g_assert (stat (hardlink_file_path, &st_link) !=0 );/* and old file should still exist */
Signature · 1 line
2.44.0
PATCH v2 3/7 qtest/virtio-9p-test.c: consolidate create dir tests
In reply to Daniel Henrique BarbozaThe local 9p driver in virtio-9p-test.c its temporary dir right at the start of qos-test (via virtio_9p_create_local_test_dir()) and only deletes it after qos-test is finished (via virtio_9p_remove_local_test_dir()).
This means that any qos-test machine that ends up running virtio-9p-test local tests more than once will end up re-using the same temp dir. This is what's happening in [1] after we introduced the riscv machine nodes:
if we enable slow tests with the '-m slow' flag using qemu-system-riscv64, this is what happens:
- a temp dir is created;
- virtio-9p-device tests will run virtio-9p-test successfully;
- virtio-9p-pci tests will run virtio-9p-test, and fail right at the first slow test at fs_create_dir() because the "01" file was already created by fs_create_dir() test when running with the virtio-9p-device.
We can fix it by making every test clean up their changes in the filesystem after they're done. But we don't need every test either: what fs_create_file() does is already exercised in fs_unlinkat_dir(), i.e. a dir is created, verified to be created, and then removed. Fixing fs_create_file() would turn it into fs_unlinkat_dir(), so we don't need both.
The same idea applies to every test in virtio-9p-test.c, where the 'unlinkat' variant does the same thing the 'create' does but with some cleaning in the end. But we'll start with fs_create_dir() and fs_unlinkat_dir() only:
- fs_create_dir() is removed. s_unlinkat_dir() is renamed to fs_create_unlinkat_dir();
- update the dir names for every other test since we have 1 less test.
[1] https://mail.gnu.org/archive/html/qemu-devel/2024-03/msg05807.html
--- tests/qtest/virtio-9p-test.c | 39 +++++++++--------------------------- 1 file changed, 10 insertions(+), 29 deletions(-)
tests/qtest/virtio-9p-test.c +10 -29
@@ -506,7 +506,8 @@ static void fs_readdir_split_512(void *obj, void *data,/* tests using the 9pfs 'local' fs driver */ -static void fs_create_dir (void *obj,void *data,QGuestAllocator *t_alloc) +static void fs_create_unlinkat_dir (void *obj,void *data, +QGuestAllocator *t_alloc) {QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);
@@ -524,26 +525,6 @@ static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc)g_assert (stat (new_dir_path, &st) ==0 );/* ... and is actually a directory */ g_assert ((st.st_mode &S_IFMT ) ==S_IFDIR ); -} - -static void fs_unlinkat_dir (void *obj,void *data,QGuestAllocator *t_alloc) -{ -QVirtio9P *v9p = obj; -v9fs_set_allocator (t_alloc); -struct stat st; -const char *new_dir ="02" ; - g_autofree char *root_path = virtio_9p_test_path(""); - g_autofree char *new_dir_path = virtio_9p_test_path(new_dir); - -g_assert (root_path !=NULL ); - - tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); - -/* check if created directory really exists now ... */ -g_assert (stat (new_dir_path, &st) ==0 ); -/* ... and is actually a directory */ -g_assert ((st.st_mode &S_IFMT ) ==S_IFDIR ); tunlinkat({ .client = v9p, .atPath = "/", .name = new_dir,
@@ -558,7 +539,7 @@ static void fs_create_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; -const char *new_dir ="03" ; +const char *new_dir ="02" ; g_autofree char *new_file = g_strdup_printf("%s/%s", new_dir, "1st_file"); g_autofree char *new_file_path = virtio_9p_test_path(new_file);
@@ -577,7 +558,7 @@ static void fs_unlinkat_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; -const char *new_dir ="04" ; +const char *new_dir ="03" ; g_autofree char *new_file = g_strdup_printf("%s/%s", new_dir, "doa_file"); g_autofree char *new_file_path = virtio_9p_test_path(new_file);
@@ -600,7 +581,7 @@ static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; -const char *new_dir ="05" ; +const char *new_dir ="04" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *symlink_file = NULL;
@@ -633,7 +614,7 @@ static void fs_unlinkat_symlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; -const char *new_dir ="06" ; +const char *new_dir ="05" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *symlink_file = NULL;
@@ -667,7 +648,7 @@ static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; -const char *new_dir ="07" ; +const char *new_dir ="06" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *hardlink_file = NULL;
@@ -704,7 +685,7 @@ static void fs_unlinkat_hardlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; -const char *new_dir ="08" ; +const char *new_dir ="07" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *hardlink_file = NULL;
@@ -788,8 +769,8 @@ static void register_virtio_9p_test(void) opts.before = assign_9p_local_driver;qos_add_test ("local/config" ,"virtio-9p" , pci_config, &opts); -qos_add_test ("local/create_dir" ,"virtio-9p" , fs_create_dir, &opts); -qos_add_test ("local/unlinkat_dir" ,"virtio-9p" , fs_unlinkat_dir, &opts); +qos_add_test ("local/create_unlinkat_dir" ,"virtio-9p" , + fs_create_unlinkat_dir, &opts);qos_add_test ("local/create_file" ,"virtio-9p" , fs_create_file, &opts);qos_add_test ("local/unlinkat_file" ,"virtio-9p" , fs_unlinkat_file, &opts);qos_add_test ("local/symlink_file" ,"virtio-9p" , fs_symlink_file, &opts);
Signature · 1 line
2.44.0
PATCH v2 4/7 qtest/virtio-9p-test.c: consolidate create file tests
In reply to Daniel Henrique BarbozaSimilar to what was done with fs_create_dir() in the previous patch, and for the same reasons, let's consolidate fs_create_file() and fs_unlinkat_file() in a single test that has the same coverage:
- fs_create_file() is removed;
- rename fs_unlinkat_file() to fs_create_unlinkat_file();
- change fs_create_unlinkat_file() to also remove the created dir.
The remaining tests got their dir changed to reflect that we're now with one less test.
--- tests/qtest/virtio-9p-test.c | 42 ++++++++++++++---------------------- 1 file changed, 16 insertions(+), 26 deletions(-)
tests/qtest/virtio-9p-test.c +16 -26
@@ -534,31 +534,14 @@ static void fs_create_unlinkat_dir(void *obj, void *data,g_assert (stat (new_dir_path, &st) !=0 ); } -static void fs_create_file (void *obj,void *data,QGuestAllocator *t_alloc) +static void fs_create_unlinkat_file (void *obj,void *data, +QGuestAllocator *t_alloc) {QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st;const char *new_dir ="02" ; - g_autofree char *new_file = g_strdup_printf("%s/%s", new_dir, "1st_file"); - g_autofree char *new_file_path = virtio_9p_test_path(new_file); - - tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); - tlcreate({ .client = v9p, .atPath = new_dir, .name = "1st_file" }); - -/* check if created file exists now ... */ -g_assert (stat (new_file_path, &st) ==0 ); -/* ... and is a regular file */ -g_assert ((st.st_mode &S_IFMT ) ==S_IFREG ); -} - -static void fs_unlinkat_file (void *obj,void *data,QGuestAllocator *t_alloc) -{ -QVirtio9P *v9p = obj; -v9fs_set_allocator (t_alloc); -struct stat st; -const char *new_dir ="03" ; + g_autofree char *new_dir_path = virtio_9p_test_path(new_dir); g_autofree char *new_file = g_strdup_printf("%s/%s", new_dir, "doa_file"); g_autofree char *new_file_path = virtio_9p_test_path(new_file);
@@ -574,6 +557,13 @@ static void fs_unlinkat_file(void *obj, void *data, QGuestAllocator *t_alloc) tunlinkat({ .client = v9p, .atPath = new_dir, .name = "doa_file" });/* file should be gone now */ g_assert (stat (new_file_path, &st) !=0 ); + +/* cleanup: remove the created dir */ +tunlinkat ({ + .client = v9p, .atPath = "/", .name = new_dir, + .flags = P9_DOTL_AT_REMOVEDIR + }); +g_assert (stat (new_dir_path, &st) !=0 ); }static void fs_symlink_file (void *obj,void *data,QGuestAllocator *t_alloc)
@@ -581,7 +571,7 @@ static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; -const char *new_dir ="04" ; +const char *new_dir ="03" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *symlink_file = NULL;
@@ -614,7 +604,7 @@ static void fs_unlinkat_symlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st; -const char *new_dir ="05" ; +const char *new_dir ="04" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *symlink_file = NULL;
@@ -648,7 +638,7 @@ static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; -const char *new_dir ="06" ; +const char *new_dir ="05" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *hardlink_file = NULL;
@@ -685,7 +675,7 @@ static void fs_unlinkat_hardlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; -const char *new_dir ="07" ; +const char *new_dir ="06" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *hardlink_file = NULL;
@@ -771,8 +761,8 @@ static void register_virtio_9p_test(void)qos_add_test ("local/config" ,"virtio-9p" , pci_config, &opts);qos_add_test ("local/create_unlinkat_dir" ,"virtio-9p" , fs_create_unlinkat_dir, &opts); -qos_add_test ("local/create_file" ,"virtio-9p" , fs_create_file, &opts); -qos_add_test ("local/unlinkat_file" ,"virtio-9p" , fs_unlinkat_file, &opts); +qos_add_test ("local/create_unlinkat_file" ,"virtio-9p" , + fs_create_unlinkat_file, &opts);qos_add_test ("local/symlink_file" ,"virtio-9p" , fs_symlink_file, &opts);qos_add_test ("local/unlinkat_symlink" ,"virtio-9p" , fs_unlinkat_symlink, &opts);
Signature · 1 line
2.44.0
PATCH v2 5/7 qtest/virtio-9p-test.c: consolidate create symlink tests
In reply to Daniel Henrique Barbozafs_unlinkat_symlink() does the same thing as fs_symlink_file() while also removing the created symlink. We also want every test to not leave stuff behind after each run to avoid subsequential runs to fail.
We can achieve all that by:
- remove fs_unlinkat_symlink(). fs_unlinkat_symlink() is now named fs_create_unlinkat_symlink();
- remove 'real_file' and the created dir at the end of fs_create_unlinkat_symlink().
The hardlink tests dir names were updated because now we have one less test.
--- tests/qtest/virtio-9p-test.c | 54 ++++++++++++------------------------ 1 file changed, 17 insertions(+), 37 deletions(-)
tests/qtest/virtio-9p-test.c +17 -37
@@ -566,12 +566,14 @@ static void fs_create_unlinkat_file(void *obj, void *data,g_assert (stat (new_dir_path, &st) !=0 ); } -static void fs_symlink_file (void *obj,void *data,QGuestAllocator *t_alloc) +static void fs_create_unlinkat_symlink (void *obj,void *data, +QGuestAllocator *t_alloc) {QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st;const char *new_dir ="03" ; + g_autofree char *new_dir_path = virtio_9p_test_path(new_dir); g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *symlink_file = NULL;
@@ -596,41 +598,20 @@ static void fs_symlink_file(void *obj, void *data, QGuestAllocator *t_alloc)/* check if created link exists now */ g_assert (stat (symlink_file_path, &st) ==0 ); -} - -static void fs_unlinkat_symlink (void *obj,void *data, -QGuestAllocator *t_alloc) -{ -QVirtio9P *v9p = obj; -v9fs_set_allocator (t_alloc); -struct stat st; -const char *new_dir ="04" ; - g_autofree char *real_file = NULL; - g_autofree char *real_file_path = NULL; - g_autofree char *symlink_file = NULL; - g_autofree char *symlink_file_path = NULL; - - real_file =g_strdup_printf ("%s/%s" , new_dir,"real_file" ); - real_file_path =virtio_9p_test_path (real_file); - - symlink_file =g_strdup_printf ("%s/%s" , new_dir,"symlink_file" ); - symlink_file_path =virtio_9p_test_path (symlink_file); - - tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); - tlcreate({ .client = v9p, .atPath = new_dir, .name = "real_file" }); -g_assert (stat (real_file_path, &st) ==0 ); -g_assert ((st.st_mode &S_IFMT ) ==S_IFREG ); - -tsymlink ({ - .client = v9p, .atPath = new_dir, .name = "symlink_file", - .symtgt = "real_file" - }); -g_assert (stat (symlink_file_path, &st) ==0 ); tunlinkat({ .client = v9p, .atPath = new_dir, .name = "symlink_file" });/* symlink should be gone now */ g_assert (stat (symlink_file_path, &st) !=0 ); + +/* cleanup: remove created file and dir */ + tunlinkat({ .client = v9p, .atPath = new_dir, .name = "real_file" }); +g_assert (stat (real_file_path, &st) !=0 ); + +tunlinkat ({ + .client = v9p, .atPath = "/", .name = new_dir, + .flags = P9_DOTL_AT_REMOVEDIR + }); +g_assert (stat (new_dir_path, &st) !=0 ); }static void fs_hardlink_file (void *obj,void *data,QGuestAllocator *t_alloc)
@@ -638,7 +619,7 @@ static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; -const char *new_dir ="05" ; +const char *new_dir ="04" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *hardlink_file = NULL;
@@ -675,7 +656,7 @@ static void fs_unlinkat_hardlink(void *obj, void *data,QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc);struct stat st_real, st_link; -const char *new_dir ="06" ; +const char *new_dir ="05" ; g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *hardlink_file = NULL;
@@ -763,9 +744,8 @@ static void register_virtio_9p_test(void) fs_create_unlinkat_dir, &opts);qos_add_test ("local/create_unlinkat_file" ,"virtio-9p" , fs_create_unlinkat_file, &opts); -qos_add_test ("local/symlink_file" ,"virtio-9p" , fs_symlink_file, &opts); -qos_add_test ("local/unlinkat_symlink" ,"virtio-9p" , fs_unlinkat_symlink, - &opts); +qos_add_test ("local/create_unlinkat_symlink" ,"virtio-9p" , + fs_create_unlinkat_symlink, &opts);qos_add_test ("local/hardlink_file" ,"virtio-9p" , fs_hardlink_file, &opts);qos_add_test ("local/unlinkat_hardlink" ,"virtio-9p" , fs_unlinkat_hardlink, &opts);
Signature · 1 line
2.44.0
PATCH v2 6/7 qtest/virtio-9p-test.c: consolidate hardlink tests
In reply to Daniel Henrique BarbozaWe've consolidated all local 9p tests but the hardlink ones. To make fs_unlinkat_hardlink() to act exactly like fs_hardlink_file() we added the g_assert(st_link...) checks in fs_unlinkat_hardlink() as well.
After that:
- remove fs_hardlink_file(). Rename fs_unlinkat_hardlink() to fs_create_unlinkat_hardlink();
- remove the created dir and 'real_file' at the end of fs_create_unlinkat_hardlink().
After this patch all local 9p tests are now cleaning themselves up after execution and we shouldn't experience errors like the one reported in [1].
[1] https://mail.gnu.org/archive/html/qemu-devel/2024-03/msg05807.html
--- tests/qtest/virtio-9p-test.c | 52 +++++++++++------------------------- 1 file changed, 16 insertions(+), 36 deletions(-)
tests/qtest/virtio-9p-test.c +16 -36
@@ -614,12 +614,14 @@ static void fs_create_unlinkat_symlink(void *obj, void *data,g_assert (stat (new_dir_path, &st) !=0 ); } -static void fs_hardlink_file (void *obj,void *data,QGuestAllocator *t_alloc) +static void fs_create_unlinkat_hardlink (void *obj,void *data, +QGuestAllocator *t_alloc) {QVirtio9P *v9p = obj;v9fs_set_allocator (t_alloc); -struct stat st_real, st_link; +struct stat st_real, st_link, st;const char *new_dir ="04" ; + g_autofree char *new_dir_path = virtio_9p_test_path(new_dir); g_autofree char *real_file = NULL; g_autofree char *real_file_path = NULL; g_autofree char *hardlink_file = NULL;
@@ -648,43 +650,22 @@ static void fs_hardlink_file(void *obj, void *data, QGuestAllocator *t_alloc)g_assert ((st_link.st_mode &S_IFMT ) ==S_IFREG );g_assert (st_link.st_dev == st_real.st_dev);g_assert (st_link.st_ino == st_real.st_ino); -} - -static void fs_unlinkat_hardlink (void *obj,void *data, -QGuestAllocator *t_alloc) -{ -QVirtio9P *v9p = obj; -v9fs_set_allocator (t_alloc); -struct stat st_real, st_link; -const char *new_dir ="05" ; - g_autofree char *real_file = NULL; - g_autofree char *real_file_path = NULL; - g_autofree char *hardlink_file = NULL; - g_autofree char *hardlink_file_path = NULL; - - real_file =g_strdup_printf ("%s/%s" , new_dir,"real_file" ); - real_file_path =virtio_9p_test_path (real_file); - - hardlink_file =g_strdup_printf ("%s/%s" , new_dir,"hardlink_file" ); - hardlink_file_path =virtio_9p_test_path (hardlink_file); - - tattach({ .client = v9p }); - tmkdir({ .client = v9p, .atPath = "/", .name = new_dir }); - tlcreate({ .client = v9p, .atPath = new_dir, .name = "real_file" }); -g_assert (stat (real_file_path, &st_real) ==0 ); -g_assert ((st_real.st_mode &S_IFMT ) ==S_IFREG ); - -tlink ({ - .client = v9p, .atPath = new_dir, .name = "hardlink_file", - .toPath = real_file - }); -g_assert (stat (hardlink_file_path, &st_link) ==0 ); tunlinkat({ .client = v9p, .atPath = new_dir, .name = "hardlink_file" });/* symlink should be gone now */ g_assert (stat (hardlink_file_path, &st_link) !=0 );/* and old file should still exist */ g_assert (stat (real_file_path, &st_real) ==0 ); + +/* cleanup: remove created file and dir */ + tunlinkat({ .client = v9p, .atPath = new_dir, .name = "real_file" }); +g_assert (stat (real_file_path, &st_real) !=0 ); + +tunlinkat ({ + .client = v9p, .atPath = "/", .name = new_dir, + .flags = P9_DOTL_AT_REMOVEDIR + }); +g_assert (stat (new_dir_path, &st) !=0 ); }static void *assign_9p_local_driver (GString *cmd_line,void *arg)
@@ -746,9 +727,8 @@ static void register_virtio_9p_test(void) fs_create_unlinkat_file, &opts);qos_add_test ("local/create_unlinkat_symlink" ,"virtio-9p" , fs_create_unlinkat_symlink, &opts); -qos_add_test ("local/hardlink_file" ,"virtio-9p" , fs_hardlink_file, &opts); -qos_add_test ("local/unlinkat_hardlink" ,"virtio-9p" , fs_unlinkat_hardlink, - &opts); +qos_add_test ("local/create_unlinkat_hardlink" ,"virtio-9p" , + fs_create_unlinkat_hardlink, &opts); }libqos_init (register_virtio_9p_test);
Signature · 1 line
2.44.0
PATCH v2 7/7 qtest/virtio-9p-test.c: remove g_test_slow() gate
In reply to Daniel Henrique BarbozaCommit 558f5c42ef gated the local tests with g_test_slow() to skip them in 'make check'. The reported issue back then was this following CI problem:
https://lists.nongnu.org/archive/html/qemu-devel/2020-11/msg05510.html
This problem ended up being fixed when the recently added risc-v machine nodes faced the same issue [1]. We're now able to run these tests with 'make check' in the CI.
This reverts commit 558f5c42efded3e0d0b20a90bce2a9a14580d824.
[1] https://mail.gnu.org/archive/html/qemu-devel/2024-03/msg05807.html
--- tests/qtest/virtio-9p-test.c | 9 --------- 1 file changed, 9 deletions(-)
tests/qtest/virtio-9p-test.c +0 -9
@@ -710,15 +710,6 @@ static void register_virtio_9p_test(void)/* 9pfs test cases using the 'local' filesystem driver */ - -/* -* XXX: Until we are sure that these tests can run everywhere, -* keep them as "slow" so that they aren't run with "make check". -*/ -if (!g_test_slow ()) { -return ; - } - opts.before = assign_9p_local_driver;qos_add_test ("local/config" ,"virtio-9p" , pci_config, &opts); qos_add_test("local/create_unlinkat_dir", "virtio-9p",
Signature · 1 line
2.44.0