From: Andrea Cervesato <andrea.cervesato@suse.de>
To: Linux Test Project <ltp@lists.linux.it>
Subject: [LTP] [PATCH v3 2/2] Add process_mrelease02 test
Date: Mon, 07 Sep 2026 10:55:17 +0200 [thread overview]
Message-ID: <20260907-process_mrelease-v3-2-03bde3e5d77c@suse.com> (raw)
In-Reply-To: <20260907-process_mrelease-v3-0-03bde3e5d77c@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that process_mrelease() returns expected error codes on
invalid file descriptors, non-zero flags, alive processes without
pending exit, and terminated processes.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
.../kernel/syscalls/process_mrelease/.gitignore | 1 +
.../syscalls/process_mrelease/process_mrelease02.c | 90 ++++++++++++++++++++++
3 files changed, 92 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index cfe76efca..b456afe20 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1152,6 +1152,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..d48aba623
--- /dev/null
+++ b/testcases/kernel/syscalls/process_mrelease/process_mrelease02.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Test verifies error codes for :manpage:`process_mrelease(2)`:
+ *
+ * - EBADF when invalid file descriptor is passed
+ * - EINVAL when flags parameter is not zero
+ * - EINVAL when target process is still alive and not dying
+ * - ESRCH when target process has terminated
+ *
+ * [Algorithm]
+ *
+ * - Call process_mrelease() with bad fd (-1) to expect EBADF
+ * - Spawn child, call process_mrelease() with invalid flags (-1) to expect EINVAL
+ * - Call process_mrelease() on running child without pending exit to expect EINVAL
+ * - Wait for child exit, call process_mrelease() on dead child to expect ESRCH
+ */
+
+#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;
+ pid_t pid = -1;
+
+ if (tc->child_type != NO_CHILD) {
+ 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_WAITPID(pid, &status, 0);
+ }
+
+ SAFE_CLOSE(pidfd);
+ }
+}
+
+static struct tst_test test = {
+ .test = run,
+ .tcnt = ARRAY_SIZE(tcases),
+ .forks_child = 1,
+ .min_kver = "5.15",
+ .needs_checkpoints = 1,
+};
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2026-09-07 8:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-07 8:55 [LTP] [PATCH v3 0/2] Add process_mrelease testing suite Andrea Cervesato
2026-09-07 8:55 ` [LTP] [PATCH v3 1/2] Add process_mrelease01 test Andrea Cervesato
2026-09-07 12:06 ` [LTP] " linuxtestproject.agent
2026-09-07 8:55 ` Andrea Cervesato [this message]
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=20260907-process_mrelease-v3-2-03bde3e5d77c@suse.com \
--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 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.