[LTP] [PATCH v2 3/3] Add process_mrelease02 test

Andrea Cervesato andrea.cervesato@suse.de
Mon Aug 12 13:46:30 CEST 2024


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

This test verifies that process_mrelease() syscall correctly raises
the errors.

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 runtest/syscalls                                   |  1 +
 .../kernel/syscalls/process_mrelease/.gitignore    |  1 +
 .../syscalls/process_mrelease/process_mrelease02.c | 84 ++++++++++++++++++++++
 3 files changed, 86 insertions(+)

diff --git a/runtest/syscalls b/runtest/syscalls
index de90e9ba3..f3cb7d465 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1074,6 +1074,7 @@ preadv203_64 preadv203_64
 profil01 profil01
 
 process_mrelease01 process_mrelease01
+process_mrelease02 process_mrelease02
 
 process_vm_readv01 process_vm01 -r
 process_vm_readv02 process_vm_readv02
diff --git a/testcases/kernel/syscalls/process_mrelease/.gitignore b/testcases/kernel/syscalls/process_mrelease/.gitignore
index 673983858..f1e7a8fea 100644
--- a/testcases/kernel/syscalls/process_mrelease/.gitignore
+++ b/testcases/kernel/syscalls/process_mrelease/.gitignore
@@ -1 +1,2 @@
 /process_mrelease01
+/process_mrelease02
diff --git a/testcases/kernel/syscalls/process_mrelease/process_mrelease02.c b/testcases/kernel/syscalls/process_mrelease/process_mrelease02.c
new file mode 100644
index 000000000..ced556243
--- /dev/null
+++ b/testcases/kernel/syscalls/process_mrelease/process_mrelease02.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that process_mrelease() syscall is raising errors:
+ * * EBADF when a bad file descriptor is given
+ * * EINVAL when flags is not zero
+ * * EINVAL when memory of a task cannot be released because it's still running
+ * * ESRCH when child has been closed
+ */
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static int badfd = -1;
+static int pidfd;
+
+enum {
+	NO_CHILD,
+	EXIT_CHILD,
+	WAIT_CHILD,
+};
+
+static struct tcase {
+	int child_type;
+	int *fd;
+	int flags;
+	int exp_errno;
+	char *msg;
+} tcases[] = {
+	{NO_CHILD, &badfd, 0, EBADF, "bad file descriptor"},
+	{WAIT_CHILD, &pidfd, -1, EINVAL, "flags is not 0"},
+	{WAIT_CHILD, &pidfd, 0, EINVAL, "task memory cannot be released"},
+	{EXIT_CHILD, &pidfd, 0, ESRCH, "child is not running"},
+};
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int status;
+
+	if (tc->child_type != NO_CHILD) {
+		pid_t pid;
+
+		pid = SAFE_FORK();
+		if (!pid) {
+			if (tc->child_type == WAIT_CHILD)
+				TST_CHECKPOINT_WAIT(0);
+
+			exit(0);
+		}
+
+		tst_res(TINFO, "Spawned waiting child with pid=%d", pid);
+
+		pidfd = SAFE_PIDFD_OPEN(pid, 0);
+
+		if (tc->child_type == EXIT_CHILD)
+			SAFE_WAITPID(pid, &status, 0);
+	}
+
+	TST_EXP_FAIL(tst_syscall(__NR_process_mrelease, *tc->fd, tc->flags),
+		tc->exp_errno,
+		"%s", tc->msg);
+
+	if (tc->child_type != NO_CHILD) {
+		if (tc->child_type == WAIT_CHILD)
+			TST_CHECKPOINT_WAKE(0);
+
+		SAFE_CLOSE(pidfd);
+	}
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_root = 1,
+	.forks_child = 1,
+	.min_kver = "5.15",
+	.needs_checkpoints = 1,
+};

-- 
2.43.0



More information about the ltp mailing list