diff mbox series

[for-9.0,v2,5/7] qtest/virtio-9p-test.c: consolidate create symlink tests

Message ID 20240327093144.781701-6-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
fs_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.

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

Patch

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