* [LTP] [PATCH] Migrating the libhugetlbfs/testcases/shm-gettest.c test
@ 2023-09-08 12:11 Sachin P Bappalige
2023-09-08 12:35 ` Cyril Hrubis
2023-09-09 3:29 ` Geetika M
0 siblings, 2 replies; 4+ messages in thread
From: Sachin P Bappalige @ 2023-09-08 12:11 UTC (permalink / raw)
To: ltp; +Cc: geetika, Sachin P Bappalige
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.
Signed-off-by: Sachin P Bappalige <sachinpb@linux.vnet.ibm.com>
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
.../kernel/mem/hugetlb/hugemmap/hugepage35.c | 93 +++++++++++++++++++
3 files changed, 95 insertions(+)
create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
diff --git a/runtest/hugetlb b/runtest/hugetlb
index 299c07ac9..6bebc706c 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29
hugemmap30 hugemmap30
hugemmap31 hugemmap31
hugemmap32 hugemmap32
+hugemmap35 hugemmap35
hugemmap05_1 hugemmap05 -m
hugemmap05_2 hugemmap05 -s
hugemmap05_3 hugemmap05 -s -m
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index 7258489ed..bbc029716 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -34,6 +34,7 @@
/hugetlb/hugemmap/hugemmap30
/hugetlb/hugemmap/hugemmap31
/hugetlb/hugemmap/hugemmap32
+/hugetlb/hugemmap/hugemmap35
/hugetlb/hugeshmat/hugeshmat01
/hugetlb/hugeshmat/hugeshmat02
/hugetlb/hugeshmat/hugeshmat03
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c b/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
new file mode 100644
index 000000000..fb603b4ef
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2005-2006, IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+
+/*\
+ * [Description]
+ *
+ * Test Name: shm-gettest.c
+ *
+ * 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 unsigned int iter;
+static int shmid = -1, key = -1;
+
+static void do_shmtest(size_t size) {
+ size_t i, j;
+ char pattern;
+ char *shmaddr;
+
+ shmid = SAFE_SHMGET(key, size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
+ tst_res(TINFO, "shmid: 0x%x\n", shmid);
+
+ 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, "Verifying the segment failed."
+ "Got %c, expected %c",
+ *(shmaddr + (i * hpage_size) + j),
+ pattern);
+ }
+ SAFE_SHMDT((const void *)shmaddr);
+}
+
+static void run_test(void)
+{
+ int i;
+ iter = 2;
+ size_t size;
+ size = NR_HUGEPAGES * hpage_size;
+ for (i=0; i < (int)iter; i++)
+ do_shmtest(size);
+ tst_res(TPASS, "Successfully tested shared memory segment operations "
+ "backed by hugepages");
+}
+
+static void setup(void)
+{
+ hpage_size = tst_get_hugepage_size();
+ tst_res(TINFO, "hugepage size is %ld", hpage_size);
+}
+
+static void cleanup(void)
+{
+ if (shmid >= 0)
+ // Remove the shared memory segment
+ 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.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH] Migrating the libhugetlbfs/testcases/shm-gettest.c test
2023-09-08 12:11 [LTP] [PATCH] Migrating the libhugetlbfs/testcases/shm-gettest.c test Sachin P Bappalige
@ 2023-09-08 12:35 ` Cyril Hrubis
2023-09-09 3:29 ` Geetika M
1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2023-09-08 12:35 UTC (permalink / raw)
To: Sachin P Bappalige; +Cc: geetika, ltp
Hi!
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c b/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
> new file mode 100644
> index 000000000..fb603b4ef
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
> @@ -0,0 +1,93 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2005-2006, IBM Corporation.
> + * Author: David Gibson & Adam Litke
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Test Name: shm-gettest.c
> + *
> + * This testcase creates shared memory segments backed by hugepages,
^
Trailing
space.
There are a few in the source and other coding style errors, please run
'make check' and fix all the reported problems.
> + * 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 unsigned int iter;
> +static int shmid = -1, key = -1;
> +
> +static void do_shmtest(size_t size) {
> + size_t i, j;
> + char pattern;
> + char *shmaddr;
> +
> + shmid = SAFE_SHMGET(key, size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
> + tst_res(TINFO, "shmid: 0x%x\n", shmid);
> +
> + 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, "Verifying the segment failed."
> + "Got %c, expected %c",
> + *(shmaddr + (i * hpage_size) + j),
> + pattern);
> + }
> + SAFE_SHMDT((const void *)shmaddr);
> +}
> +
> +static void run_test(void)
> +{
> + int i;
> + iter = 2;
> + size_t size;
> + size = NR_HUGEPAGES * hpage_size;
> + for (i=0; i < (int)iter; i++)
> + do_shmtest(size);
> + tst_res(TPASS, "Successfully tested shared memory segment operations "
> + "backed by hugepages");
This is obviously wrong, you are reporting TPASS regardless if the
do_shmtest() reported failure or not. Ideally you should report TPASS
in the do_shmtest() function in a case that no failures have had
happened.
Also LTP test can run a number of iterations when passed -i parameter,
so instead of duplicating the functionality here the test should be
executed with -i 2 instead.
Also the test is not added into .gitignore and to runtest file
(runtest/hugetlb), which means that it wouldn't be executed at all.\
> +}
> +
> +static void setup(void)
> +{
> + hpage_size = tst_get_hugepage_size();
> + tst_res(TINFO, "hugepage size is %ld", hpage_size);
> +}
> +
> +static void cleanup(void)
> +{
> + if (shmid >= 0)
> + // Remove the shared memory segment
> + 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.39.3
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH] Migrating the libhugetlbfs/testcases/shm-gettest.c test
2023-09-08 12:11 [LTP] [PATCH] Migrating the libhugetlbfs/testcases/shm-gettest.c test Sachin P Bappalige
2023-09-08 12:35 ` Cyril Hrubis
@ 2023-09-09 3:29 ` Geetika M
1 sibling, 0 replies; 4+ messages in thread
From: Geetika M @ 2023-09-09 3:29 UTC (permalink / raw)
To: Sachin P Bappalige, ltp
Hello Sachin!
I think it is more fitting to add this testcase to testcases/kernel/mem/hugetlb/hugeshmget instead of /kernel/mem/hugetlb/hugemmap.
> 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.
>
> Signed-off-by: Sachin P Bappalige <sachinpb@linux.vnet.ibm.com>
> ---
> runtest/hugetlb | 1 +
> testcases/kernel/mem/.gitignore | 1 +
> .../kernel/mem/hugetlb/hugemmap/hugepage35.c | 93 +++++++++++++++++++
> 3 files changed, 95 insertions(+)
> create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
>
> diff --git a/runtest/hugetlb b/runtest/hugetlb
> index 299c07ac9..6bebc706c 100644
> --- a/runtest/hugetlb
> +++ b/runtest/hugetlb
> @@ -35,6 +35,7 @@ hugemmap29 hugemmap29
> hugemmap30 hugemmap30
> hugemmap31 hugemmap31
> hugemmap32 hugemmap32
> +hugemmap35 hugemmap35
> hugemmap05_1 hugemmap05 -m
> hugemmap05_2 hugemmap05 -s
> hugemmap05_3 hugemmap05 -s -m
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index 7258489ed..bbc029716 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -34,6 +34,7 @@
> /hugetlb/hugemmap/hugemmap30
> /hugetlb/hugemmap/hugemmap31
> /hugetlb/hugemmap/hugemmap32
> +/hugetlb/hugemmap/hugemmap35
> /hugetlb/hugeshmat/hugeshmat01
> /hugetlb/hugeshmat/hugeshmat02
> /hugetlb/hugeshmat/hugeshmat03
> diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c b/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
> new file mode 100644
> index 000000000..fb603b4ef
> --- /dev/null
> +++ b/testcases/kernel/mem/hugetlb/hugemmap/hugepage35.c
> @@ -0,0 +1,93 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2005-2006, IBM Corporation.
> + * Author: David Gibson & Adam Litke
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Test Name: shm-gettest.c
> + *
> + * 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 unsigned int iter;
> +static int shmid = -1, key = -1;
> +
> +static void do_shmtest(size_t size) {
> + size_t i, j;
> + char pattern;
> + char *shmaddr;
> +
> + shmid = SAFE_SHMGET(key, size, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W);
> + tst_res(TINFO, "shmid: 0x%x\n", shmid);
> +
> + 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, "Verifying the segment failed."
> + "Got %c, expected %c",
> + *(shmaddr + (i * hpage_size) + j),
> + pattern);
> + }
> + SAFE_SHMDT((const void *)shmaddr);
> +}
> +
> +static void run_test(void)
> +{
> + int i;
> + iter = 2;
> + size_t size;
> + size = NR_HUGEPAGES * hpage_size;
> + for (i=0; i < (int)iter; i++)
> + do_shmtest(size);
> + tst_res(TPASS, "Successfully tested shared memory segment operations "
> + "backed by hugepages");
> +}
> +
> +static void setup(void)
> +{
> + hpage_size = tst_get_hugepage_size();
> + tst_res(TINFO, "hugepage size is %ld", hpage_size);
> +}
> +
> +static void cleanup(void)
> +{
> + if (shmid >= 0)
> + // Remove the shared memory segment
> + 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},
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* [LTP] [PATCH] Migrating the libhugetlbfs/testcases/shm-gettest.c test
@ 2024-05-15 9:21 Sachin P Bappalige
0 siblings, 0 replies; 4+ messages in thread
From: Sachin P Bappalige @ 2024-05-15 9:21 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 for specified number of times.
-Updated 'kernel/mem/.gitignore'
-Updated 'runtest/hugetlb' for number of iterations with -i 10
Signed-off-by: Sachin P Bappalige <sachinpb@linux.ibm.com>
---
runtest/hugetlb | 1 +
testcases/kernel/mem/.gitignore | 1 +
.../mem/hugetlb/hugeshmget/hugeshmget06.c | 78 +++++++++++++++++++
3 files changed, 80 insertions(+)
create mode 100644 testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget06.c
diff --git a/runtest/hugetlb b/runtest/hugetlb
index 299c07ac9..f294e9aaa 100644
--- a/runtest/hugetlb
+++ b/runtest/hugetlb
@@ -55,3 +55,4 @@ hugeshmget01 hugeshmget01 -i 10
hugeshmget02 hugeshmget02 -i 10
hugeshmget03 hugeshmget03 -i 10
hugeshmget05 hugeshmget05 -i 10
+hugeshmget06 hugeshmget06 -i 10
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..85a731113
--- /dev/null
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget06.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2005-2006, IBM Corporation.
+ * Author: David Gibson & Adam Litke
+ */
+
+/*\
+ * [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.
+ * 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 run_test(void)
+{
+ size_t i, j;
+ char pattern;
+ char *shmaddr;
+
+ shmaddr = SAFE_SHMAT(shmid, 0, SHM_RND);
+ tst_res(TINFO, "shmaddr: %p", shmaddr);
+
+ for (i = 0; i < NR_HUGEPAGES; i++) {
+ pattern = 65 + (i % 26);
+ tst_res(TINFO, "Touching %p with %c",
+ 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", (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 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", 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 = 0,
+ .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] 4+ messages in thread
end of thread, other threads:[~2024-05-15 10:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-08 12:11 [LTP] [PATCH] Migrating the libhugetlbfs/testcases/shm-gettest.c test Sachin P Bappalige
2023-09-08 12:35 ` Cyril Hrubis
2023-09-09 3:29 ` Geetika M
-- strict thread matches above, loose matches on Subject: below --
2024-05-15 9:21 Sachin P Bappalige
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.