diff mbox series

[v3,07/11] Add statmount02 test

Message ID 20240516-listmount_statmount-v3-7-2ff4ba29bba7@suse.com
State Accepted
Headers show
Series statmount/listmount testing suites | expand

Commit Message

Andrea Cervesato May 16, 2024, 12:29 p.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

This test verifies that statmount() is correctly reading basic
filesystem info using STATMOUNT_SB_BASIC.
---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/statmount/.gitignore    |  1 +
 testcases/kernel/syscalls/statmount/statmount02.c | 76 +++++++++++++++++++++++
 3 files changed, 78 insertions(+)

Comments

Cyril Hrubis July 10, 2024, 8:03 a.m. UTC | #1
Hi!
> +	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_SB_BASIC);
> +	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
> +	TST_EXP_EQ_LI(st_mount->sb_dev_major, sx_mount->stx_dev_major);
> +	TST_EXP_EQ_LI(st_mount->sb_dev_minor, sx_mount->stx_dev_minor);
> +	TST_EXP_EQ_LI(st_mount->sb_magic, sf_mount->f_type);

The basic operation also sets sb_flags, I suppose that we can pass
"readonly" flag for the mount in the tst_test structure then we should
see it in the sb_flags here.
diff mbox series

Patch

diff --git a/runtest/syscalls b/runtest/syscalls
index d36aebfd5..ac6ebb51d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1539,6 +1539,7 @@  stat04 symlink01 -T stat04
 stat04_64 symlink01 -T stat04_64
 
 statmount01 statmount01
+statmount02 statmount02
 
 statfs01 statfs01
 statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index f1529eb29..a30b9565f 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -1 +1,2 @@ 
 statmount01
+statmount02
diff --git a/testcases/kernel/syscalls/statmount/statmount02.c b/testcases/kernel/syscalls/statmount/statmount02.c
new file mode 100644
index 000000000..77cd88469
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount02.c
@@ -0,0 +1,76 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that statmount() is correctly reading basic filesystem
+ * info using STATMOUNT_SB_BASIC.
+ * The btrfs validation is currently skipped due to the lack of support for VFS.
+ *
+ * [Algorithm]
+ *
+ * * create a mount point and read its mount info
+ * * run statmount() on the mount point using STATMOUNT_SB_BASIC
+ * * read results and check if mount info are correct
+ */
+
+#include "statmount.h"
+#include "lapi/stat.h"
+#include "lapi/sched.h"
+#include <linux/btrfs.h>
+
+#define MNTPOINT "mntpoint"
+
+static struct statmount *st_mount;
+static struct statx *sx_mount;
+static struct statfs *sf_mount;
+
+static void run(void)
+{
+	memset(st_mount, 0, sizeof(struct statmount));
+
+	TST_EXP_PASS(statmount(
+		sx_mount->stx_mnt_id,
+		STATMOUNT_SB_BASIC,
+		st_mount,
+		sizeof(struct statmount),
+		0));
+
+	if (TST_RET == -1)
+		return;
+
+	TST_EXP_EQ_LI(st_mount->mask, STATMOUNT_SB_BASIC);
+	TST_EXP_EQ_LI(st_mount->size, sizeof(struct statmount));
+	TST_EXP_EQ_LI(st_mount->sb_dev_major, sx_mount->stx_dev_major);
+	TST_EXP_EQ_LI(st_mount->sb_dev_minor, sx_mount->stx_dev_minor);
+	TST_EXP_EQ_LI(st_mount->sb_magic, sf_mount->f_type);
+}
+
+static void setup(void)
+{
+	SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, sx_mount);
+	SAFE_STATFS(MNTPOINT, sf_mount);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.min_kver = "6.8",
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []) {
+		"fuse",
+		"btrfs",
+		NULL
+	},
+	.bufs = (struct tst_buffers []) {
+		{&st_mount, .size = sizeof(struct statmount)},
+		{&sx_mount, .size = sizeof(struct statx)},
+		{&sf_mount, .size = sizeof(struct statfs)},
+		{}
+	}
+};