diff mbox series

[for-9.0,v2,6/7] qtest/virtio-9p-test.c: consolidate hardlink tests

Message ID 20240327093144.781701-7-dbarboza@ventanamicro.com
State New
Headers show
Series qtest/virtio-9p-test.c: fix slow tests | expand

Commit Message

Daniel Henrique Barboza March 27, 2024, 9:31 a.m. UTC
We'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

Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
 tests/qtest/virtio-9p-test.c | 52 +++++++++++-------------------------
 1 file changed, 16 insertions(+), 36 deletions(-)
diff mbox series

Patch

diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 222d11037d..f85f4ef407 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -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);