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 2/3] qtest/virtio-9p-test.c: consolidate hardlink tests
Date: Tue, 26 Mar 2024 10:26:05 -0300 [thread overview]
Message-ID: <20240326132606.686025-3-dbarboza@ventanamicro.com> (raw)
In-Reply-To: <20240326132606.686025-1-dbarboza@ventanamicro.com>
We need all virtio-9p-test.c tests to clean themselves up after being
executed to avoid an issue where multiple test runs of this same test
will find remains of the previous run. See [1] to see the side effects
of that.
Previous patch dealt with most tests in this file. We're now
consolidating the 'hardlink' tests:
- copy the asserts that checks if the created link is a hard link from
fs_hardlink_file() to fs_unlinkat_hardlink(). This will make
fs_unlinkat_hardlink() do exactly what fs_hardlink_file() is doing;
- remove fs_hardlink_file();
- fs_unlinkat_hardlink() is renamed to fs_create_unlinkat_hardlink().
We'll also remove 'real_file' and the '08' dir it creates.
With this last change all local 9p tests of the file are not leaving
files or dirs behind in the temporary dir, allowing multiple runs in the
same session to succeed.
[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 | 55 +++++++++++++++---------------------
1 file changed, 22 insertions(+), 33 deletions(-)
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index cdbe3e78ea..9938516fe7 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -600,39 +600,13 @@ static void fs_create_unlinkat_symlink(void *obj, void *data,
g_assert(stat(new_dir, &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;
- g_autofree char *real_file = virtio_9p_test_path("07/real_file");
- g_autofree char *hardlink_file = 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((st_real.st_mode & S_IFMT) == S_IFREG);
-
- tlink({
- .client = v9p, .atPath = "07", .name = "hardlink_file",
- .toPath = "07/real_file"
- });
-
- /* check if link exists now ... */
- g_assert(stat(hardlink_file, &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);
- 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;
+ struct stat st_real, st_link, st;
+ g_autofree char *new_dir = virtio_9p_test_path("08");
g_autofree char *real_file = virtio_9p_test_path("08/real_file");
g_autofree char *hardlink_file = virtio_9p_test_path("08/hardlink_file");
@@ -646,13 +620,29 @@ static void fs_unlinkat_hardlink(void *obj, void *data,
.client = v9p, .atPath = "08", .name = "hardlink_file",
.toPath = "08/real_file"
});
+
+ /* check if link exists now ... */
g_assert(stat(hardlink_file, &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);
+ g_assert(st_link.st_ino == st_real.st_ino);
tunlinkat({ .client = v9p, .atPath = "08", .name = "hardlink_file" });
/* symlink should be gone now */
g_assert(stat(hardlink_file, &st_link) != 0);
/* and old file should still exist */
g_assert(stat(real_file, &st_real) == 0);
+
+ /* cleanup: remove old file and dir */
+ tunlinkat({ .client = v9p, .atPath = "08", .name = "real_file" });
+ g_assert(stat(real_file, &st_real) != 0);
+
+ tunlinkat({
+ .client = v9p, .atPath = "/", .name = "08",
+ .flags = P9_DOTL_AT_REMOVEDIR
+ });
+ g_assert(stat(new_dir, &st) != 0);
}
static void *assign_9p_local_driver(GString *cmd_line, void *arg)
@@ -714,9 +704,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);
--
2.44.0
next prev parent reply other threads:[~2024-03-26 13:26 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-26 13:26 [PATCH for-9.0 0/3] qtest/virtio-9p-test.c: fix slow tests Daniel Henrique Barboza
2024-03-26 13:26 ` [PATCH for-9.0 1/3] qtest/virtio-9p-test.c: consolidate create dir, file and symlink tests Daniel Henrique Barboza
2024-03-26 17:05 ` Greg Kurz
2024-03-26 17:47 ` Daniel Henrique Barboza
2024-03-27 8:47 ` Christian Schoenebeck
2024-03-27 9:33 ` Daniel Henrique Barboza
2024-03-27 10:14 ` Christian Schoenebeck
2024-03-27 11:28 ` Daniel Henrique Barboza
2024-03-27 12:26 ` Christian Schoenebeck
2024-03-27 12:32 ` Greg Kurz
2024-03-27 12:40 ` Daniel Henrique Barboza
2024-03-26 13:26 ` Daniel Henrique Barboza [this message]
2024-03-26 13:26 ` [PATCH for-9.0 3/3] qtest/virtio-9p-test.c: remove g_test_slow() gate Daniel Henrique Barboza
2024-03-26 15:55 ` [PATCH for-9.0 0/3] qtest/virtio-9p-test.c: fix slow tests Greg Kurz
2024-03-26 16:07 ` Daniel Henrique Barboza
2024-03-27 8:52 ` Christian Schoenebeck
2024-03-26 16:23 ` Thomas Huth
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=20240326132606.686025-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.