public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH]  [PATCH V6] syscalls: ipc: Add shmget hugepage test
@ 2026-03-11  7:02 Pavithra
  2026-03-23  7:20 ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 2+ messages in thread
From: Pavithra @ 2026-03-11  7:02 UTC (permalink / raw)
  To: ltp; +Cc: pavrampu

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 3248 bytes --]

Changes in v6:
- Added "tst_test.h" and "tst_hugepage.h" instead of hugetlb.h
- Modified code to use TEST() macro

Signed-off-by: Pavithra <pavrampu@linux.ibm.com>
---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/ipc/shmget/.gitignore     |  1 +
 .../kernel/syscalls/ipc/shmget/shmget07.c     | 75 +++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ipc/shmget/shmget07.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 2179e007c..1d5e0f214 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1547,6 +1547,7 @@ shmget03 shmget03
 shmget04 shmget04
 shmget05 shmget05
 shmget06 shmget06
+shmget07 shmget07
 
 shutdown01 shutdown01
 shutdown02 shutdown02
diff --git a/testcases/kernel/syscalls/ipc/shmget/.gitignore b/testcases/kernel/syscalls/ipc/shmget/.gitignore
index 768d1c69d..23ba002b5 100644
--- a/testcases/kernel/syscalls/ipc/shmget/.gitignore
+++ b/testcases/kernel/syscalls/ipc/shmget/.gitignore
@@ -3,3 +3,4 @@
 /shmget04
 /shmget05
 /shmget06
+/shmget07
diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget07.c b/testcases/kernel/syscalls/ipc/shmget/shmget07.c
new file mode 100644
index 000000000..c6e4068d8
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget07.c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
+ */
+
+/*\
+ * [Descripiton]
+ *
+ * Origin: https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/shm-getraw.c
+ *
+ * The test creates a shared memory segment, then attaches it to the process’s address space.
+ * It writes a string to the shared memory from raw device and detaches the shared memory
+ * segment and finally removes it.
+ * The purpose of this test is to ensure that the shared memory subsystem is working correctly
+ * with hugepages. It checks that shared memory segments can be created, attached, written to,
+ * read from, detached, and removed without errors
+ *
+ */
+
+#include "tst_test.h"
+#include "tst_hugepage.h"
+#include "tst_safe_sysv_ipc.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define NR_HUGEPAGES 2
+
+static int shmid = -1;
+static size_t size;
+static size_t i;
+
+static char *shmaddr;
+static int raw_fd;
+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 = hpage_size * NR_HUGEPAGES;
+	raw_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\n", shmaddr);
+
+	/* Read a page from device and write to shm segment */
+
+	for (i = 0; i < size; i += hpage_size) {
+		TEST(read(raw_fd, shmaddr, hpage_size));
+		if (TST_RET != hpage_size)
+			tst_res(TFAIL | TERRNO, "Can't read full page from raw device!");
+		else
+			tst_res(TPASS, "Read full page from raw device");
+	}
+
+	SAFE_SHMDT(shmaddr);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_test,
+	.hugepages = {2, TST_NEEDS},
+};
-- 
2.53.0


[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-23  7:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11  7:02 [LTP] [PATCH] [PATCH V6] syscalls: ipc: Add shmget hugepage test Pavithra
2026-03-23  7:20 ` Andrea Cervesato via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox