From: Pavithra <pavrampu@linux.ibm.com>
To: ltp@lists.linux.it
Cc: pavrampu@linux.ibm.com
Subject: [LTP] [PATCH v8] hugetlb/hugeshmget: Add hugeshmget07 to test SHM_HUGETLB with /dev/zero read
Date: Wed, 23 Sep 2026 14:03:00 +0530 [thread overview]
Message-ID: <20260923083300.54026-1-pavrampu@linux.ibm.com> (raw)
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
next reply other threads:[~2026-09-23 8:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 8:33 Pavithra [this message]
2026-09-23 9:59 ` [LTP] hugetlb/hugeshmget: Add hugeshmget07 to test SHM_HUGETLB with /dev/zero read linuxtestproject.agent
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=20260923083300.54026-1-pavrampu@linux.ibm.com \
--to=pavrampu@linux.ibm.com \
--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.