* [LTP] [PATCH v3] Migrating the libhugetlbfs/testcases/shm-gettest.c test
@ 2024-03-07 8:45 Sachin P Bappalige
2024-05-10 10:44 ` Cyril Hrubis
0 siblings, 1 reply; 2+ messages in thread
From: Sachin P Bappalige @ 2024-03-07 8:45 UTC (permalink / raw)
To: ltp; +Cc: sachinpb
Test Description: This testcase creates shared memory segments
backed by hugepages, writes specific patterns to each segment,
verifies pattern and detaches a shared memory segments in a loop.
This looping test was added to verify the functionality of
large page backed shared memory segments. A segment is created,
written, verified, and detached a specified number of times.
-Updated 'kernel/mem/.gitignore'
-Updated 'runtest/hugetlb' for number of iterations with -i 5
Signed-off-by: Sachin P Bappalige <sachinpb@linux.vnet.ibm.com>
---
v3:
-Addressed v2 comments
-Updated 'runtest/hugetlb' for number of iterations with -i 5
v2:
-Fixed coding style errors as per 'make check'
-Reporting TPASS moved inside do_shmtest() function
-Moved testcase file from folder hugemmap to hugeshmget
-Renamed testcase 'hugepage35.c' to hugeshmget06.c
-Updated 'kernel/mem/.gitignore'
-Updated 'runtest/hugetlb' for number of iterations with -i 10
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
.../mem/hugetlb/hugeshmget/hugeshmget06.c | 84 +++++++++++++++++++
3 files changed, 86 insertions(+)
create mode 100644 testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget06.c
diff --git a/runtest/hugetlb b/runtest/hugetlb
index 299c07ac9..7d8715922 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 -i 5
hugeshmctl01 hugeshmctl01 -i 5
hugeshmctl02 hugeshmctl02 -i 5
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index c96fe8bfc..d88484fa1 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -47,6 +47,7 @@
/hugetlb/hugeshmget/hugeshmget02
/hugetlb/hugeshmget/hugeshmget03
/hugetlb/hugeshmget/hugeshmget05
+/hugetlb/hugeshmget/hugeshmget06
/ksm/ksm01
/ksm/ksm02
/ksm/ksm03
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget06.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget06.c
new file mode 100644
index 000000000..3491df868
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget06.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2005-2006, IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+
+/*\
+ * DESCRIPTION
+ * hugeshmget06 -
+ * This testcase creates shared memory segments backed by hugepages,
+ * writes specific patterns to each segment, verifies pattern,
+ * and detaches a shared memory segments in a loop.
+ * It ensures that the hugepage backed shared memory functionalities
+ * works correctly by validating the data written to segment.
+ */
+
+#include "hugetlb.h"
+#include "tst_safe_sysv_ipc.h"
+
+#define MNTPOINT "hugetlbfs/"
+#define NR_HUGEPAGES 4
+
+static long hpage_size;
+static int shmid = -1, key = -1;
+
+static void do_shmtest(void)
+{
+ size_t i, j;
+ char pattern;
+ char *shmaddr;
+
+ shmaddr = SAFE_SHMAT(shmid, 0, SHM_RND);
+ tst_res(TINFO, "shmaddr: %p\n", shmaddr);
+
+ for (i = 0; i < NR_HUGEPAGES; i++) {
+ pattern = 65 + (i % 26);
+ tst_res(TINFO, "Touching %p with %c\n",
+ shmaddr + (i * hpage_size), pattern);
+ memset(shmaddr + (i * hpage_size), pattern, hpage_size);
+ }
+
+ for (i = 0; i < NR_HUGEPAGES; i++) {
+ pattern = 65 + (i % 26);
+ tst_res(TINFO, "Verifying %p\n", (shmaddr + (i * hpage_size)));
+ for (j = 0; j < (size_t)hpage_size; j++)
+ if (*(shmaddr + (i * hpage_size) + j) != pattern) {
+ tst_res(TFAIL, "Got wrong byte 0x%02x expected 0x%02x",
+ *(shmaddr + (i * hpage_size) + j),
+ pattern);
+ return;
+ }
+ }
+ SAFE_SHMDT((const void *)shmaddr);
+ tst_res(TPASS, "shm hugepages works correctly");
+}
+
+static void run_test(void)
+{
+ do_shmtest();
+}
+
+static void setup(void)
+{
+ hpage_size = tst_get_hugepage_size();
+ tst_res(TINFO, "hugepage size is %ld", hpage_size);
+ shmid = SAFE_SHMGET(key, NR_HUGEPAGES * hpage_size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
+ tst_res(TINFO, "shmid: 0x%x\n", shmid);
+}
+
+static void cleanup(void)
+{
+ if (shmid >= 0)
+ SAFE_SHMCTL(shmid, IPC_RMID, NULL);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .mntpoint = MNTPOINT,
+ .needs_hugetlbfs = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run_test,
+ .hugepages = {NR_HUGEPAGES, TST_NEEDS},
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH v3] Migrating the libhugetlbfs/testcases/shm-gettest.c test
2024-03-07 8:45 [LTP] [PATCH v3] Migrating the libhugetlbfs/testcases/shm-gettest.c test Sachin P Bappalige
@ 2024-05-10 10:44 ` Cyril Hrubis
0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2024-05-10 10:44 UTC (permalink / raw)
To: Sachin P Bappalige; +Cc: ltp
Hi!
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget06.c
> @@ -0,0 +1,84 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2005-2006, IBM Corporation.
> + * Author: David Gibson & Adam Litke
> + */
> +
> +/*\
> + * DESCRIPTION
This should be [Description]
> + * hugeshmget06 -
This shouldn't be there.
> + * This testcase creates shared memory segments backed by hugepages,
> + * writes specific patterns to each segment, verifies pattern,
> + * and detaches a shared memory segments in a loop.
> + * It ensures that the hugepage backed shared memory functionalities
> + * works correctly by validating the data written to segment.
> + */
> +
> +#include "hugetlb.h"
> +#include "tst_safe_sysv_ipc.h"
> +
> +#define MNTPOINT "hugetlbfs/"
> +#define NR_HUGEPAGES 4
> +
> +static long hpage_size;
> +static int shmid = -1, key = -1;
> +
> +static void do_shmtest(void)
> +{
> + size_t i, j;
> + char pattern;
> + char *shmaddr;
> +
> + shmaddr = SAFE_SHMAT(shmid, 0, SHM_RND);
> + tst_res(TINFO, "shmaddr: %p\n", shmaddr);
> +
> + for (i = 0; i < NR_HUGEPAGES; i++) {
> + pattern = 65 + (i % 26);
> + tst_res(TINFO, "Touching %p with %c\n",
> + shmaddr + (i * hpage_size), pattern);
Please do not add newlines in the tst_res() format strings. Also this
> + memset(shmaddr + (i * hpage_size), pattern, hpage_size);
> + }
> +
> + for (i = 0; i < NR_HUGEPAGES; i++) {
> + pattern = 65 + (i % 26);
> + tst_res(TINFO, "Verifying %p\n", (shmaddr + (i * hpage_size)));
Here as well.
> + for (j = 0; j < (size_t)hpage_size; j++)
> + if (*(shmaddr + (i * hpage_size) + j) != pattern) {
> + tst_res(TFAIL, "Got wrong byte 0x%02x expected 0x%02x",
> + *(shmaddr + (i * hpage_size) + j),
> + pattern);
> + return;
> + }
> + }
> + SAFE_SHMDT((const void *)shmaddr);
> + tst_res(TPASS, "shm hugepages works correctly");
> +}
> +
> +static void run_test(void)
> +{
> + do_shmtest();
What is the point of this indirection?
Just put the test code in the do_test() function instead.
> +}
> +
> +static void setup(void)
> +{
> + hpage_size = tst_get_hugepage_size();
> + tst_res(TINFO, "hugepage size is %ld", hpage_size);
^
Just one space here.
> + shmid = SAFE_SHMGET(key, NR_HUGEPAGES * hpage_size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
> + tst_res(TINFO, "shmid: 0x%x\n", shmid);
^
Here as well, no newlines.
> +}
> +
> +static void cleanup(void)
> +{
> + if (shmid >= 0)
> + SAFE_SHMCTL(shmid, IPC_RMID, NULL);
> +}
> +
> +static struct tst_test test = {
> + .needs_root = 1,
> + .mntpoint = MNTPOINT,
> + .needs_hugetlbfs = 1,
The test does not use the hugetlbfs, no need to mount it at all.
> + .setup = setup,
> + .cleanup = cleanup,
> + .test_all = run_test,
> + .hugepages = {NR_HUGEPAGES, TST_NEEDS},
> +};
> --
> 2.43.0
>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-10 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07 8:45 [LTP] [PATCH v3] Migrating the libhugetlbfs/testcases/shm-gettest.c test Sachin P Bappalige
2024-05-10 10:44 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox