From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 09/10] Add statmount05 test
Date: Wed, 15 May 2024 13:33:37 +0200 [thread overview]
Message-ID: <20240515113338.554-10-andrea.cervesato@suse.de> (raw)
In-Reply-To: <20240515113338.554-1-andrea.cervesato@suse.de>
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies STATMOUNT_MNT_ROOT and STATMOUNT_MNT_POINT
functionalities of statmount().
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
.../kernel/syscalls/statmount/.gitignore | 1 +
.../kernel/syscalls/statmount/statmount05.c | 138 ++++++++++++++++++
3 files changed, 140 insertions(+)
create mode 100644 testcases/kernel/syscalls/statmount/statmount05.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 3c262ca3e..2984117e6 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1541,6 +1541,7 @@ statmount01 statmount01
statmount02 statmount02
statmount03 statmount03
statmount04 statmount04
+statmount05 statmount05
statfs01 statfs01
statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index e720050b5..f64763242 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -2,3 +2,4 @@ statmount01
statmount02
statmount03
statmount04
+statmount05
diff --git a/testcases/kernel/syscalls/statmount/statmount05.c b/testcases/kernel/syscalls/statmount/statmount05.c
new file mode 100644
index 000000000..9882719f5
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount05.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/**
+ * [Description]
+ *
+ * This test verifies STATMOUNT_MNT_ROOT and STATMOUNT_MNT_POINT functionalities
+ * of statmount(). In particular, STATMOUNT_MNT_ROOT will give the mount root
+ * (i.e. mount --bind /mnt /bla -> /mnt) and STATMOUNT_MNT_POINT will
+ * give the mount point (i.e. mount --bind /mnt /bla -> /bla).
+ *
+ * [Algorithm]
+ *
+ * * create a mount point
+ * * mount a folder inside the mount point
+ * * run statmount() on the mounted folder using STATMOUNT_MNT_ROOT
+ * * read results and check if contain the mount root path
+ * * run statmount() on the mounted folder using STATMOUNT_MNT_POINT
+ * * read results and check if contain the mount point path
+ */
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+
+#define MNTPOINT "mntpoint"
+#define DIRA MNTPOINT "/LTP_DIR_A"
+#define DIRB MNTPOINT "/LTP_DIR_B"
+#define SM_SIZE (1 << 10)
+
+static uint64_t root_id;
+static struct statmount *st_mount;
+static char mnt_root[PATH_MAX];
+static char mnt_point[PATH_MAX];
+
+static void test_mount_root(void)
+{
+ tst_res(TINFO, "Testing STATMOUNT_MNT_ROOT");
+
+ char *last_root;
+
+ memset(st_mount, 0, SM_SIZE);
+
+ TST_EXP_PASS(statmount(
+ root_id,
+ STATMOUNT_MNT_ROOT,
+ st_mount,
+ SM_SIZE,
+ 0));
+
+ if (TST_RET == -1)
+ return;
+
+ last_root = strrchr(mnt_root, '/');
+
+ TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_ROOT);
+ TST_EXP_EXPR(strcmp(st_mount->str + st_mount->mnt_root, last_root) == 0,
+ "statmount() read '%s', expected '%s'",
+ st_mount->str + st_mount->mnt_root,
+ last_root);
+}
+
+static void test_mount_point(void)
+{
+ tst_res(TINFO, "Testing STATMOUNT_MNT_POINT");
+
+ memset(st_mount, 0, SM_SIZE);
+
+ TST_EXP_POSITIVE(statmount(
+ root_id,
+ STATMOUNT_MNT_POINT,
+ st_mount,
+ SM_SIZE,
+ 0));
+
+ if (TST_RET == -1)
+ return;
+
+ TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_MNT_POINT);
+ TST_EXP_EXPR(strcmp(st_mount->str + st_mount->mnt_point, mnt_point) == 0,
+ "mount point is '%s'",
+ st_mount->str + st_mount->mnt_point);
+}
+
+static void run(void)
+{
+ test_mount_root();
+ test_mount_point();
+}
+
+static void setup(void)
+{
+ char *tmpdir;
+ struct statx sx;
+
+ tmpdir = tst_get_tmpdir();
+ snprintf(mnt_root, PATH_MAX, "%s/%s", tmpdir, DIRA);
+ snprintf(mnt_point, PATH_MAX, "%s/%s", tmpdir, DIRB);
+ free(tmpdir);
+
+ SAFE_MKDIR(mnt_root, 0700);
+ SAFE_MKDIR(mnt_point, 0700);
+ SAFE_MOUNT(mnt_root, mnt_point, "none", MS_BIND, NULL);
+
+ SAFE_STATX(AT_FDCWD, mnt_point, 0, STATX_MNT_ID_UNIQUE, &sx);
+ root_id = sx.stx_mnt_id;
+}
+
+static void cleanup(void)
+{
+ if (tst_is_mounted(DIRB))
+ SAFE_UMOUNT(DIRB);
+
+ if (tst_is_mounted(DIRA))
+ SAFE_UMOUNT(DIRA);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .min_kver = "6.8",
+ .needs_tmpdir = 1,
+ .format_device = 1,
+ .mount_device = 1,
+ .mntpoint = MNTPOINT,
+ .all_filesystems = 1,
+ .skip_filesystems = (const char *const []) {
+ "fuse",
+ NULL
+ },
+ .bufs = (struct tst_buffers []) {
+ {&st_mount, .size = SM_SIZE},
+ {}
+ }
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-05-15 11:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-15 11:33 [LTP] [PATCH v1 00/10] statmount/listmount testing suites Andrea Cervesato
2024-05-15 11:33 ` [LTP] [PATCH v2 01/10] Add SAFE_STATX macro Andrea Cervesato
2024-05-15 11:33 ` [LTP] [PATCH v2 02/10] Add listmount/statmount fallback declarations Andrea Cervesato
2024-05-15 11:33 ` [LTP] [PATCH v2 03/10] Add listmount01 test Andrea Cervesato
2024-05-16 1:47 ` Petr Vorel
2024-05-15 11:33 ` [LTP] [PATCH v2 04/10] Add listmount02 test Andrea Cervesato
2024-05-15 11:33 ` [LTP] [PATCH v2 05/10] Add stamount01 test Andrea Cervesato
2024-05-15 11:33 ` [LTP] [PATCH v2 06/10] Add statmount02 test Andrea Cervesato
2024-05-15 11:33 ` [LTP] [PATCH v2 07/10] Add statmount03 test Andrea Cervesato
2024-05-15 11:33 ` [LTP] [PATCH v2 08/10] Add statmount04 test Andrea Cervesato
2024-05-15 11:33 ` Andrea Cervesato [this message]
2024-05-15 11:33 ` [LTP] [PATCH v2 10/10] Add statmount06 test Andrea Cervesato
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=20240515113338.554-10-andrea.cervesato@suse.de \
--to=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).