From: Cyril Hrubis <chrubis@suse.cz>
To: Pavithra <pavrampu@linux.ibm.com>
Cc: ltp@lists.linux.it, Pavithra <pavrampu@linux.vnet.ibm.com>
Subject: Re: [LTP] [PATCH v6] Origin: https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/shm-getraw.c
Date: Tue, 3 Mar 2026 16:47:28 +0100 [thread overview]
Message-ID: <aacCkAN6a1Imktjt@yuki.lan> (raw)
In-Reply-To: <20250925060046.1006111-1-pavrampu@linux.ibm.com>
Hi!
First of all the subject of the patch should be more meaningful such as:
"syscalls: ipc: Add shmget hugepage test"
instead of the
"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
>
> Signed-off-by: Pavithra <pavrampu@linux.vnet.ibm.com>
> ---
> runtest/syscalls-ipc | 1 +
> testcases/kernel/mem/.gitignore | 1 +
> .../kernel/syscalls/ipc/shmget/shmget07.c | 73 +++++++++++++++++++
> 3 files changed, 75 insertions(+)
> create mode 100644 testcases/kernel/syscalls/ipc/shmget/shmget07.c
>
> diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
> index 8960c487c..4159f2331 100644
> --- a/runtest/syscalls-ipc
> +++ b/runtest/syscalls-ipc
> @@ -66,3 +66,4 @@ shmget03 shmget03
> shmget04 shmget04
> shmget05 shmget05
> shmget06 shmget06
> +shmget07 shmget07
> diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
> index b4455de51..f9438606e 100644
> --- a/testcases/kernel/mem/.gitignore
> +++ b/testcases/kernel/mem/.gitignore
> @@ -50,6 +50,7 @@
> /hugetlb/hugeshmget/hugeshmget03
> /hugetlb/hugeshmget/hugeshmget05
> /hugetlb/hugeshmget/hugeshmget06
> +/hugetlb/hugeshmget/hugeshmget07
> /ksm/ksm01
> /ksm/ksm02
> /ksm/ksm03
> diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget07.c b/testcases/kernel/syscalls/ipc/shmget/shmget07.c
> new file mode 100644
> index 000000000..b1bee06f9
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ipc/shmget/shmget07.c
> @@ -0,0 +1,73 @@
> +// 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 "../../../mem/hugetlb/lib/hugetlb.h"
You need to include "tst_test.h" and "tst_hugepage.h" instead of the
local headers.
> +#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) {
> + TST_RET = read(raw_fd, shmaddr, hpage_size);
You need to use whole TEST() macro otherwise you cannot use TERRNO in
the tst_res below.
> + TST_EXP_VAL(TST_RET, hpage_size, "read returned %ld", TST_RET);
> + if (TST_RET != hpage_size)
> + tst_res(TFAIL | TERRNO, "Can't 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.43.5
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2026-03-03 15:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-25 6:00 [LTP] [PATCH v6] Origin: https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/shm-getraw.c Pavithra
2026-03-03 15:47 ` Cyril Hrubis [this message]
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=aacCkAN6a1Imktjt@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=pavrampu@linux.ibm.com \
--cc=pavrampu@linux.vnet.ibm.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox