* [LTP] [PATCH v8] hugetlb/hugeshmget: Add hugeshmget07 to test SHM_HUGETLB with /dev/zero read
@ 2026-09-23 8:33 Pavithra
2026-09-23 9:59 ` [LTP] " linuxtestproject.agent
0 siblings, 1 reply; 2+ messages in thread
From: Pavithra @ 2026-09-23 8:33 UTC (permalink / raw)
To: ltp; +Cc: pavrampu
Test that a hugepage-backed shared memory segment can be created,
attached, read into via /dev/zero, detached and removed without
errors.
Signed-off-by: Pavithra <pavrampu@linux.ibm.com>
---
v7 -> v8:
- Move test from syscalls/shmget/shmget07.c to hugetlb/hugeshmget/hugeshmget07.c
- Remove redundant #include "tst_hugepage.h"
- Rename raw_fd to zero_fd
- Replace TEST()/if/tst_res() block with TST_EXP_VAL()
Link to v7: https://lore.kernel.org/ltp/20260919151602.1039825-1-pavrampu@linux.ibm.com/
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
.../mem/hugetlb/hugeshmget/hugeshmget07.c | 69 +++++++++++++++++++
3 files changed, 71 insertions(+)
create mode 100644 testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget07.c
diff --git a/runtest/hugetlb b/runtest/hugetlb
index 621c9718a..d090cddec 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -62,3 +62,4 @@ hugeshmget02 hugeshmget02 -i 10
hugeshmget03 hugeshmget03 -i 10
hugeshmget05 hugeshmget05 -i 10
hugeshmget06 hugeshmget06 -i 10
+hugeshmget07 hugeshmget07 -i 10
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 9e706e1c8..67f9c23a5 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -55,6 +55,7 @@
/hugetlb/hugeshmget/hugeshmget03
/hugetlb/hugeshmget/hugeshmget05
/hugetlb/hugeshmget/hugeshmget06
+/hugetlb/hugeshmget/hugeshmget07
/ksm/ksm01
/ksm/ksm02
/ksm/ksm03
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget07.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget07.c
new file mode 100644
index 000000000..1a85b87e4
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget07.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ * Copyright (c) 2026 Pavithra <pavrampu@linux.ibm.com>
+ */
+
+/*\
+ * Test :manpage:`shmget(2)` shared memory segment with hugepages.
+ *
+ * A hugepage-backed shared memory segment is created and attached to
+ * the process address space. The test reads one hugepage at a time
+ * from ``/dev/zero`` directly into the shared memory region,
+ * verifying that each read delivers the full hugepage worth of data.
+ * The segment is then detached and removed.
+ *
+ * Requires root for :manpage:`shmget(2)` with ``SHM_HUGETLB``.
+ */
+
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+
+#define NR_HUGEPAGES 2
+
+static int shmid = -1;
+static long hpage_size;
+
+static void setup(void)
+{
+ hpage_size = tst_get_hugepage_size();
+}
+
+static void cleanup(void)
+{
+ if (shmid >= 0)
+ SAFE_SHMCTL(shmid, IPC_RMID, NULL);
+}
+
+static void run_test(void)
+{
+ size_t i;
+ size_t size = hpage_size * NR_HUGEPAGES;
+ char *shmaddr;
+ int zero_fd;
+
+ zero_fd = SAFE_OPEN("/dev/zero", O_RDONLY);
+
+ shmid = SAFE_SHMGET(IPC_PRIVATE, size, SHM_HUGETLB | SHM_R | SHM_W);
+
+ shmaddr = SAFE_SHMAT(shmid, 0, SHM_RND);
+ tst_res(TINFO, "shmaddr: %p", shmaddr);
+
+ for (i = 0; i < size; i += hpage_size) {
+ TST_EXP_VAL(read(zero_fd, shmaddr + i, hpage_size),
+ (ssize_t)hpage_size);
+ }
+
+ SAFE_CLOSE(zero_fd);
+ SAFE_SHMDT(shmaddr);
+ SAFE_SHMCTL(shmid, IPC_RMID, NULL);
+ shmid = -1;
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {NR_HUGEPAGES, TST_NEEDS},
+};
--
2.55.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [LTP] hugetlb/hugeshmget: Add hugeshmget07 to test SHM_HUGETLB with /dev/zero read
2026-09-23 8:33 [LTP] [PATCH v8] hugetlb/hugeshmget: Add hugeshmget07 to test SHM_HUGETLB with /dev/zero read Pavithra
@ 2026-09-23 9:59 ` linuxtestproject.agent
0 siblings, 0 replies; 2+ messages in thread
From: linuxtestproject.agent @ 2026-09-23 9:59 UTC (permalink / raw)
To: Pavithra; +Cc: ltp
Hi Pavithra,
On Wed, 23 Sep 2026 14:03:00 +0530, Pavithra <pavrampu@linux.ibm.com> wrote:
> hugetlb/hugeshmget: Add hugeshmget07 to test SHM_HUGETLB with /dev/zero read
>+ zero_fd = SAFE_OPEN("/dev/zero", O_RDONLY);
>+
>+ shmid = SAFE_SHMGET(IPC_PRIVATE, size, SHM_HUGETLB | SHM_R | SHM_W);
>+
>+ shmaddr = SAFE_SHMAT(shmid, 0, SHM_RND);
>+ tst_res(TINFO, "shmaddr: %p", shmaddr);
>+
>+ for (i = 0; i < size; i += hpage_size) {
>+ TST_EXP_VAL(read(zero_fd, shmaddr + i, hpage_size),
>+ (ssize_t)hpage_size);
>+ }
>+
>+ SAFE_CLOSE(zero_fd);
File descriptors must be initialized to -1 and closed in cleanup() with an
fd != -1 guard. If SAFE_SHMGET() or SAFE_SHMAT() aborts, zero_fd is not
closed. Define static int zero_fd = -1 at file scope, open it in setup(),
and close it in cleanup().
>+ SAFE_SHMCTL(shmid, IPC_RMID, NULL);
>+ shmid = -1;
SAFE_SHMCTL() sets shmid to -1 when called with IPC_RMID. The subsequent
shmid = -1 assignment is redundant.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-23 9:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 8:33 [LTP] [PATCH v8] hugetlb/hugeshmget: Add hugeshmget07 to test SHM_HUGETLB with /dev/zero read Pavithra
2026-09-23 9:59 ` [LTP] " linuxtestproject.agent
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.