From: Spoorthy <spoorthy@linux.ibm.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] Hugetlb: Migrating libhugetlbfs shm-perms
Date: Tue, 12 Sep 2023 17:42:38 +0530 [thread overview]
Message-ID: <20230912121238.64692-1-spoorthy@linux.ibm.com> (raw)
Migrating the libhugetlbfs/tests/shm-perms.c test
Test Description: Test shared memory behavior when multiple threads are attached
to a segment with different permissions. A segment is created
and children attach read-only to check reservation accounting.
Signed-off-by: Spoorthy <spoorthy@linux.ibm.com>
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
.../mem/hugetlb/hugeshmat/hugeshmat06.c | 86 +++++++++++++++++++
3 files changed, 88 insertions(+)
create mode 100644 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat06.c
diff --git a/runtest/hugetlb b/runtest/hugetlb
index 299c07ac9..240701b2b 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -44,6 +44,7 @@ hugeshmat02 hugeshmat02 -i 5
hugeshmat03 hugeshmat03 -i 5
hugeshmat04 hugeshmat04 -i 5
hugeshmat05 hugeshmat05 -i 5
+hugeshmat06 hugeshmat06
hugeshmctl01 hugeshmctl01 -i 5
hugeshmctl02 hugeshmctl02 -i 5
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 7258489ed..9f7fb1e76 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -39,6 +39,7 @@
/hugetlb/hugeshmat/hugeshmat03
/hugetlb/hugeshmat/hugeshmat04
/hugetlb/hugeshmat/hugeshmat05
+/hugetlb/hugeshmat/hugeshmat06
/hugetlb/hugeshmctl/hugeshmctl01
/hugetlb/hugeshmctl/hugeshmctl02
/hugetlb/hugeshmctl/hugeshmctl03
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat06.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat06.c
new file mode 100644
index 000000000..ca36ae2f4
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat06.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+/*
+ * Copyright (C) 2005-2006 IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+
+/*\
+ * [Description]
+ *
+ * Test shared memory behavior when multiple threads are attached
+ * to a segment with different permissions. A segment is created
+ * and children attach read-only to check reservation accounting.
+ */
+
+
+#include "tst_safe_sysv_ipc.h"
+#include "hugetlb.h"
+
+#define SEGMENT_SIZE ((size_t) 0x4000000)
+#define SEGMENT_KEY (0x82ba15ff)
+#define STRIDE (0x200000)
+#define MNTPOINT "hugetlbfs/"
+
+static int global_shmid = -1;
+
+void *shm_addr = NULL;
+static long hpage_size;
+
+int attach_segment(size_t segsize, int shmflags, int shmperms)
+{
+ int shmid;
+ shmid = SAFE_SHMGET(SEGMENT_KEY, segsize, shmflags);
+ shm_addr = SAFE_SHMAT(shmid, shm_addr, shmperms);
+ global_shmid = shmid;
+ return shmid;
+}
+
+static void setup(void)
+{
+ hpage_size = tst_get_hugepage_size();
+}
+
+static void run_test(void)
+{
+ char *p;
+ int i, iterations;
+ long total_hpages = SAFE_READ_MEMINFO(MEMINFO_HPAGE_TOTAL);
+ if (hpage_size > SEGMENT_SIZE)
+ tst_res(TCONF,"Page size is too large for configured SEGMENT_SIZE");
+
+ iterations = (total_hpages * hpage_size) / SEGMENT_SIZE + 1;
+ SAFE_MALLOC(sizeof(pid_t) * iterations);
+ attach_segment(SEGMENT_SIZE, IPC_CREAT | SHM_HUGETLB | 0640, 0);
+ p = (char *)shm_addr;
+ for (i = 0; i < 4; i++, p += STRIDE)
+ memset(p, 0x55, STRIDE);
+
+ SAFE_SHMDT((const void *)shm_addr);
+ for (i = 0; i < iterations; i++)
+ {
+ SAFE_FORK();
+ attach_segment(0, 0, SHM_RDONLY);
+ SAFE_SHMDT((const void *)shm_addr);
+ }
+ tst_reap_children();
+ tst_res(TPASS, "Successfully tested shared memory behavior when multiple threads are attached");
+}
+
+static void cleanup(void)
+{
+ if (global_shmid >= 0)
+ SAFE_SHMCTL(global_shmid, IPC_RMID, NULL);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .needs_tmpdir = 1,
+ .forks_child = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {32, TST_NEEDS},
+};
+
--
2.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2023-09-14 12:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 12:12 Spoorthy [this message]
2023-10-30 16:12 ` [LTP] [PATCH] Hugetlb: Migrating libhugetlbfs shm-perms Cyril Hrubis
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=20230912121238.64692-1-spoorthy@linux.ibm.com \
--to=spoorthy@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.