[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH for-9.0 v2 4/7] qtest/virtio-9p-test.c: consolidate create file t
From: |
Daniel Henrique Barboza |
Subject: |
[PATCH for-9.0 v2 4/7] qtest/virtio-9p-test.c: consolidate create file tests |
Date: |
Wed, 27 Mar 2024 06:31:41 -0300 |
Similar 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.
Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
tests/qtest/virtio-9p-test.c | 42 ++++++++++++++----------------------
1 file changed, 16 insertions(+), 26 deletions(-)
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 2cea1b4189..75d4d1cf4b 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -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);
--
2.44.0
- [PATCH for-9.0 v2 0/7] qtest/virtio-9p-test.c: fix slow tests, Daniel Henrique Barboza, 2024/03/27
- [PATCH for-9.0 v2 2/7] qtest/virtio-9p-test.c: parametrize 'dir' name in local tests, Daniel Henrique Barboza, 2024/03/27
- [PATCH for-9.0 v2 5/7] qtest/virtio-9p-test.c: consolidate create symlink tests, Daniel Henrique Barboza, 2024/03/27
- [PATCH for-9.0 v2 1/7] qtest/virtio-9p-test.c: add '_path' in path vars, Daniel Henrique Barboza, 2024/03/27
- [PATCH for-9.0 v2 3/7] qtest/virtio-9p-test.c: consolidate create dir tests, Daniel Henrique Barboza, 2024/03/27
- [PATCH for-9.0 v2 4/7] qtest/virtio-9p-test.c: consolidate create file tests,
Daniel Henrique Barboza <=
- [PATCH for-9.0 v2 6/7] qtest/virtio-9p-test.c: consolidate hardlink tests, Daniel Henrique Barboza, 2024/03/27
- [PATCH for-9.0 v2 7/7] qtest/virtio-9p-test.c: remove g_test_slow() gate, Daniel Henrique Barboza, 2024/03/27