All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
To: qemu-devel@nongnu.org
Cc: thuth@redhat.com, alistair.francis@wdc.com, groug@kaod.org,
	peter.maydell@linaro.org, qemu_oss@crudebyte.com,
	Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Subject: [PATCH for-9.0 v2 2/7] qtest/virtio-9p-test.c: parametrize 'dir' name in local tests
Date: Wed, 27 Mar 2024 06:31:39 -0300	[thread overview]
Message-ID: <20240327093144.781701-3-dbarboza@ventanamicro.com> (raw)
In-Reply-To: <20240327093144.781701-1-dbarboza@ventanamicro.com>

All 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.

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
 tests/qtest/virtio-9p-test.c | 108 +++++++++++++++++++++++------------
 1 file changed, 72 insertions(+), 36 deletions(-)

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 23edca05c5..be031abc17 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -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 */
-- 
2.44.0



  parent reply	other threads:[~2024-03-27  9:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27  9:31 [PATCH for-9.0 v2 0/7] qtest/virtio-9p-test.c: fix slow tests Daniel Henrique Barboza
2024-03-27  9:31 ` [PATCH for-9.0 v2 1/7] qtest/virtio-9p-test.c: add '_path' in path vars Daniel Henrique Barboza
2024-03-27  9:31 ` Daniel Henrique Barboza [this message]
2024-03-27  9:31 ` [PATCH for-9.0 v2 3/7] qtest/virtio-9p-test.c: consolidate create dir tests Daniel Henrique Barboza
2024-03-27  9:31 ` [PATCH for-9.0 v2 4/7] qtest/virtio-9p-test.c: consolidate create file tests Daniel Henrique Barboza
2024-03-27  9:31 ` [PATCH for-9.0 v2 5/7] qtest/virtio-9p-test.c: consolidate create symlink tests Daniel Henrique Barboza
2024-03-27  9:31 ` [PATCH for-9.0 v2 6/7] qtest/virtio-9p-test.c: consolidate hardlink tests Daniel Henrique Barboza
2024-03-27  9:31 ` [PATCH for-9.0 v2 7/7] qtest/virtio-9p-test.c: remove g_test_slow() gate Daniel Henrique Barboza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240327093144.781701-3-dbarboza@ventanamicro.com \
    --to=dbarboza@ventanamicro.com \
    --cc=alistair.francis@wdc.com \
    --cc=groug@kaod.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.