[LTP] [PATCH v4 13/13] Add statmount07 test

Andrea Cervesato
2024-09-09T10:04:56Z

From: Andrea Cervesato <andrea.cervesato@suse.com>

This test is verifying that statmount syscall is raising the correct
errors according with invalid input values.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/statmount/.gitignore | 1 +
testcases/kernel/syscalls/statmount/statmount07.c | 75 +++++++++++++++++++++++
3 files changed, 77 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index 209e04b79..125d8fb00 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1574,6 +1574,7 @@ statmount03 statmount03
statmount04 statmount04
statmount05 statmount05
statmount06 statmount06
+statmount07 statmount07

statfs01 statfs01
statfs01_64 statfs01_64
diff --git a/testcases/kernel/syscalls/statmount/.gitignore b/testcases/kernel/syscalls/statmount/.gitignore
index 03a75bd40..b2a55c077 100644
--- a/testcases/kernel/syscalls/statmount/.gitignore
+++ b/testcases/kernel/syscalls/statmount/.gitignore
@@ -4,3 +4,4 @@ statmount03
statmount04
statmount05
statmount06
+statmount07
diff --git a/testcases/kernel/syscalls/statmount/statmount07.c b/testcases/kernel/syscalls/statmount/statmount07.c
new file mode 100644
index 000000000..2746bf424
--- /dev/null
+++ b/testcases/kernel/syscalls/statmount/statmount07.c
@@ -0,0 +1,75 @@
+// 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 raising the correct errors according
+ * with invalid input values.
+ */
+
+#define _GNU_SOURCE
+
+#include "statmount.h"
+#include "lapi/stat.h"
+
+#define MNTPOINT "mntpoint"
+
+static struct statmount *st_mount;
+static struct statmount *st_mount_null;
+static uint64_t mnt_id;
+static uint64_t mnt_id_dont_exist = -1;
+static size_t buff_size;
+static size_t buff_size_invalid = -1;
+
+struct tcase {
+ int exp_errno;
+ char *msg;
+ uint64_t *mnt_id;
+ uint64_t mask;
+ unsigned int flags;
+ size_t *buff_size;
+ struct statmount **buff;
+} tcases[] = {
+ {ENOENT, "mount id doesn't exist'", &mnt_id_dont_exist, 0, 0, &buff_size, &st_mount},
+ {EOVERFLOW, "invalid mask", &mnt_id, -1, 0, &buff_size, &st_mount},
+ {EINVAL, "flags must be zero", &mnt_id, 0, 1, &buff_size, &st_mount},
+ {EFAULT, "invalid buffer size", &mnt_id, 0, 0, &buff_size_invalid, &st_mount},
+ {EFAULT, "invalid buffer pointer", &mnt_id, 0, 0, &buff_size, &st_mount_null},
+};
+
+static void run(unsigned int n)
+{
+ struct tcase *tc = &tcases[n];
+
+ memset(st_mount, 0, sizeof(struct statmount));
+
+ TST_EXP_FAIL(statmount(*tc->mnt_id, tc->mask,
+ *tc->buff, *tc->buff_size, tc->flags),
+ tc->exp_errno, "%s", tc->msg);
+}
+
+static void setup(void)
+{
+ struct ltp_statx sx;
+
+ SAFE_STATX(AT_FDCWD, MNTPOINT, 0, STATX_MNT_ID_UNIQUE, &sx);
+
+ mnt_id = sx.data.stx_mnt_id;
+ buff_size = sizeof(struct statmount);
+}
+static struct tst_test test = {
+ .test = run,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+ .min_kver = "6.8",
+ .mount_device = 1,
+ .mntpoint = MNTPOINT,
+ .format_device = 1,
+ .bufs = (struct tst_buffers []) {
+ {&st_mount, .size = sizeof(struct statmount)},
+ {}
+ }
+};

--
2.43.0