From: Stephen Bertram via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Stephen Bertram <sbertram@redhat.com>
Subject: [LTP] [PATCH v1 1/2] newipc: Factor out generic get_ipc_idx_from_id() helper
Date: Thu, 30 Jul 2026 15:49:50 -0400 [thread overview]
Message-ID: <20260730194953.274721-2-sbertram@redhat.com> (raw)
In-Reply-To: <20260730194953.274721-1-sbertram@redhat.com>
From: Stephen Bertram <sbertram@redhat.com>
get_shm_idx_from_id()'s per-index STAT loop will be needed again for
semctl01's SEM_STAT lookup. Move it into a generic get_ipc_idx_from_id()
helper in libs/newipc, taking a per-family stat() wrapper, so IPC tests
that need to translate an id to its live kernel index can share one
implementation instead of duplicating the loop.
shmctl01 is converted to use the new helper. No functional change.
Signed-off-by: Stephen Bertram <sbertram@redhat.com>
Assisted-by: Cursor:Sonnet-5
---
Test: ./kirk -w 4 -f syscalls_32 -p shmctl01 -i 1000
After changes:
Total runs: 32000
Runtime: 24m 57s
Passed: 384000
Failed: 0
Skipped: 0
Broken: 0
Warnings: 0
include/tse_newipc.h | 20 ++++++++++++++++++++
libs/newipc/tse_newipc.c | 13 +++++++++++++
testcases/kernel/syscalls/shmctl/shmctl01.c | 14 +++++++-------
3 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/include/tse_newipc.h b/include/tse_newipc.h
index 1d3bbd129..175a60234 100644
--- a/include/tse_newipc.h
+++ b/include/tse_newipc.h
@@ -49,4 +49,24 @@ void *probe_free_addr(const char *file, const int lineno);
#define PROBE_FREE_ADDR() \
probe_free_addr(__FILE__, __LINE__)
+/**
+ * get_ipc_idx_from_id() - Find the kernel index of an IPC resource by id.
+ *
+ * @id: The msqid/semid/shmid to look for.
+ * @max_idx: Highest kernel index to search, from IPC_INFO/SEM_INFO/SHM_INFO.
+ * @stat_fn: Per-family *_STAT wrapper called as stat_fn(idx, buf) for
+ * each idx in [0, max_idx]; must return the id at idx, or -1
+ * on error, without aborting the test.
+ * @buf: Buffer passed through to @stat_fn.
+ *
+ * SysV *_STAT commands (MSG_STAT/SEM_STAT/SHM_STAT) take a kernel array
+ * index rather than the id returned by *get(), and that index is not
+ * guaranteed to match the id when other IPC users are active. This walks
+ * the live indices to find the one that currently maps to @id.
+ *
+ * Return: The kernel index mapping to @id, or -1 if none was found.
+ */
+int get_ipc_idx_from_id(int id, int max_idx,
+ int (*stat_fn)(int idx, void *buf), void *buf);
+
#endif /* tse_newipc.h */
diff --git a/libs/newipc/tse_newipc.c b/libs/newipc/tse_newipc.c
index f7edda6b5..aee286a31 100644
--- a/libs/newipc/tse_newipc.c
+++ b/libs/newipc/tse_newipc.c
@@ -86,3 +86,16 @@ void *probe_free_addr(const char *file, const int lineno)
return addr;
}
+
+int get_ipc_idx_from_id(int id, int max_idx,
+ int (*stat_fn)(int idx, void *buf), void *buf)
+{
+ int i;
+
+ for (i = 0; i <= max_idx; i++) {
+ if (stat_fn(i, buf) == id)
+ return i;
+ }
+
+ return -1;
+}
diff --git a/testcases/kernel/syscalls/shmctl/shmctl01.c b/testcases/kernel/syscalls/shmctl/shmctl01.c
index 05aea58cc..bfc11fa39 100644
--- a/testcases/kernel/syscalls/shmctl/shmctl01.c
+++ b/testcases/kernel/syscalls/shmctl/shmctl01.c
@@ -224,20 +224,20 @@ static void dummy_sighandler(int sig)
(void)sig;
}
+static int shm_stat(int idx, void *buf)
+{
+ return shmctl(idx, SHM_STAT, buf);
+}
+
static int get_shm_idx_from_id(int shm_id)
{
struct shm_info dummy;
struct shmid_ds dummy_ds;
- int max_idx, i;
+ int max_idx;
max_idx = SAFE_SHMCTL(shm_id, SHM_INFO, (void *)&dummy);
- for (i = 0; i <= max_idx; i++) {
- if (shmctl(i, SHM_STAT, &dummy_ds) == shm_id)
- return i;
- }
-
- return -1;
+ return get_ipc_idx_from_id(shm_id, max_idx, shm_stat, &dummy_ds);
}
static void setup(void)
--
2.55.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-07-30 19:54 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 16:49 [LTP] [PATCH v2] semctl: updates for multi worker testing Stephen Bertram via ltp
2026-04-14 17:15 ` [LTP] " linuxtestproject.agent
2026-07-20 22:49 ` [LTP] [PATCH v3] semctl01: tolerate SEM_STAT races under parallel LTP runs Stephen Bertram via ltp
2026-07-20 23:13 ` [LTP] " linuxtestproject.agent
2026-07-20 23:56 ` [LTP] [PATCH v4] " Stephen Bertram via ltp
2026-07-21 2:38 ` [LTP] " linuxtestproject.agent
2026-07-21 13:55 ` [LTP] [PATCH v5] " Stephen Bertram via ltp
2026-07-21 14:40 ` [LTP] " linuxtestproject.agent
2026-07-28 13:06 ` [LTP] [PATCH v5] " Andrea Cervesato via ltp
2026-07-28 16:23 ` [LTP] [PATCH v6] " Stephen Bertram via ltp
2026-07-28 17:31 ` [LTP] " linuxtestproject.agent
2026-07-28 20:33 ` [LTP] [PATCH v7] semctl01: look up SEM_STAT index for this test's sem_id Stephen Bertram via ltp
2026-07-28 21:12 ` [LTP] " linuxtestproject.agent
2026-07-29 14:53 ` [LTP] [PATCH v8] semctl01: fix SEM_STAT failures under parallel LTP runs Stephen Bertram via ltp
2026-07-29 16:26 ` [LTP] " linuxtestproject.agent
2026-07-29 17:56 ` [LTP] [PATCH v9] " Stephen Bertram via ltp
2026-07-29 18:14 ` [LTP] " linuxtestproject.agent
2026-07-29 19:33 ` [LTP] [PATCH v10] " Stephen Bertram via ltp
2026-07-29 20:20 ` [LTP] " linuxtestproject.agent
2026-07-29 21:00 ` [LTP] [PATCH v11] " Stephen Bertram via ltp
2026-07-29 22:07 ` [LTP] " linuxtestproject.agent
2026-07-30 2:08 ` [LTP] [PATCH v12] " Stephen Bertram via ltp
2026-07-30 2:19 ` [LTP] " linuxtestproject.agent
2026-07-30 4:47 ` [LTP] [PATCH v13] " Stephen Bertram via ltp
2026-07-30 5:46 ` [LTP] " linuxtestproject.agent
2026-07-30 15:01 ` [LTP] [PATCH v14] " Stephen Bertram via ltp
2026-07-30 16:00 ` [LTP] " linuxtestproject.agent
2026-07-30 17:19 ` [LTP] [PATCH v15] " Stephen Bertram via ltp
2026-07-30 17:30 ` [LTP] " linuxtestproject.agent
2026-07-30 19:49 ` [LTP] [PATCH v1 0/2] " Stephen Bertram via ltp
2026-07-30 19:49 ` Stephen Bertram via ltp [this message]
2026-07-30 21:13 ` [LTP] newipc: Factor out generic get_ipc_idx_from_id() helper linuxtestproject.agent
2026-07-30 19:49 ` [LTP] [PATCH v1 2/2] semctl01: fix SEM_STAT failures under parallel LTP runs Stephen Bertram via ltp
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=20260730194953.274721-2-sbertram@redhat.com \
--to=ltp@lists.linux.it \
--cc=sbertram@redhat.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