From: Stephen Bertram via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Stephen Bertram <sbertram@redhat.com>, fdarocha@redhat.com
Subject: [LTP] [PATCH v7] semctl01: look up SEM_STAT index for this test's sem_id
Date: Tue, 28 Jul 2026 16:33:33 -0400 [thread overview]
Message-ID: <20260728203333.3949671-1-sbertram@redhat.com> (raw)
In-Reply-To: <20260728162351.3845090-1-sbertram@redhat.com>
Walk 0..max_idx with SEM_STAT until the returned id equals this test's
sem_id.
Test: ./kirk -w 4 -f syscalls_8 -p semctl01 -i 1000
Results summary before:
Total runs: 8000
Runtime: 4m 8s
Passed: 103994
Failed: 0
Skipped: 0
Broken: 3
Warnings: 0
Results summary after:
Total runs: 8000
Runtime: 4m 9s
Passed: 104000
Failed: 0
Skipped: 0
Broken: 0
Warnings: 0
Assisted-by: Cursor
Signed-off-by: Stephen Bertram <sbertram@redhat.com>
---
testcases/kernel/syscalls/semctl/semctl01.c | 85 +++++++++++++++------
1 file changed, 62 insertions(+), 23 deletions(-)
diff --git a/testcases/kernel/syscalls/semctl/semctl01.c b/testcases/kernel/syscalls/semctl/semctl01.c
index 5bd675ab6..7b60d5739 100644
--- a/testcases/kernel/syscalls/semctl/semctl01.c
+++ b/testcases/kernel/syscalls/semctl/semctl01.c
@@ -19,7 +19,6 @@
#define SEMUN_CAST (union semun)
static int sem_id = -1;
-static int sem_index;
static struct semid_ds buf;
static struct seminfo ipc_buf;
static unsigned short array[PSEMS];
@@ -210,13 +209,10 @@ static void func_rmid(void)
static void func_iinfo(int hidx)
{
- if (hidx >= 0) {
- sem_index = hidx;
+ if (hidx >= 0)
tst_res(TPASS, "the highest index is correct");
- } else {
- sem_index = 0;
+ else
tst_res(TFAIL, "the highest index is incorrect");
- }
}
static void func_sinfo(void)
@@ -229,35 +225,73 @@ static void func_sinfo(void)
static void func_sstat(int semidx)
{
- if (semidx >= 0)
+ if (semidx == sem_id)
tst_res(TPASS, "id of the semaphore set is correct");
else
- tst_res(TFAIL, "id of the semaphore set is incorrect");
+ tst_res(TFAIL, "expected sem_id %d, got %d", sem_id, semidx);
}
static struct tcases {
- int *semid;
int semnum;
int cmd;
void (*func_test) ();
union semun arg;
void (*func_setup) ();
} tests[] = {
- {&sem_id, 0, IPC_STAT, func_stat, SEMUN_CAST & buf, NULL},
- {&sem_id, 0, IPC_SET, func_set, SEMUN_CAST & buf, set_setup},
- {&sem_id, 0, GETALL, func_gall, SEMUN_CAST array, NULL},
- {&sem_id, 4, GETNCNT, func_cnt, SEMUN_CAST & buf, cnt_setup},
- {&sem_id, 2, GETPID, func_pid, SEMUN_CAST & buf, pid_setup},
- {&sem_id, 2, GETVAL, func_gval, SEMUN_CAST & buf, NULL},
- {&sem_id, 4, GETZCNT, func_cnt, SEMUN_CAST & buf, cnt_setup},
- {&sem_id, 0, SETALL, func_sall, SEMUN_CAST array, sall_setup},
- {&sem_id, 4, SETVAL, func_sval, SEMUN_CAST INCVAL, NULL},
- {&sem_id, 0, IPC_INFO, func_iinfo, SEMUN_CAST & ipc_buf, NULL},
- {&sem_id, 0, SEM_INFO, func_sinfo, SEMUN_CAST & ipc_buf, NULL},
- {&sem_index, 0, SEM_STAT, func_sstat, SEMUN_CAST & buf, NULL},
- {&sem_id, 0, IPC_RMID, func_rmid, SEMUN_CAST & buf, NULL},
+ {0, IPC_STAT, func_stat, SEMUN_CAST & buf, NULL},
+ {0, IPC_SET, func_set, SEMUN_CAST & buf, set_setup},
+ {0, GETALL, func_gall, SEMUN_CAST array, NULL},
+ {4, GETNCNT, func_cnt, SEMUN_CAST & buf, cnt_setup},
+ {2, GETPID, func_pid, SEMUN_CAST & buf, pid_setup},
+ {2, GETVAL, func_gval, SEMUN_CAST & buf, NULL},
+ {4, GETZCNT, func_cnt, SEMUN_CAST & buf, cnt_setup},
+ {0, SETALL, func_sall, SEMUN_CAST array, sall_setup},
+ {4, SETVAL, func_sval, SEMUN_CAST INCVAL, NULL},
+ {0, IPC_INFO, func_iinfo, SEMUN_CAST & ipc_buf, NULL},
+ {0, SEM_INFO, func_sinfo, SEMUN_CAST & ipc_buf, NULL},
+ {0, SEM_STAT, func_sstat, SEMUN_CAST & buf, NULL},
+ {0, IPC_RMID, func_rmid, SEMUN_CAST & buf, NULL},
};
+/*
+ * SEM_STAT takes an idr index. Walk 0..max_idx until SEM_STAT
+ * returns this test's sem_id so parallel IPC tests cannot make us exercise
+ * some other process's set (EIDRM/EINVAL/EACCES on a moving max_idx).
+ * Returns that semid.
+ */
+static int sem_stat_for_id(int id, union semun arg)
+{
+ struct seminfo info;
+ union semun info_arg;
+ int max_idx, i, ret;
+
+ info_arg.__buf = &info;
+ max_idx = SAFE_SEMCTL(id, 0, IPC_INFO, info_arg);
+
+ for (i = 0; i <= max_idx; i++) {
+ ret = semctl(i, 0, SEM_STAT, arg);
+ if (ret == id)
+ return ret;
+ if (ret == -1 && errno != EIDRM && errno != EINVAL &&
+ errno != EACCES)
+ tst_brk(TBROK | TERRNO, "semctl(%d, SEM_STAT)", i);
+ }
+
+ return -1;
+}
+
+static int do_sem_stat(union semun arg)
+{
+ int ret;
+
+ ret = sem_stat_for_id(sem_id, arg);
+ if (ret < 0)
+ tst_brk(TBROK, "Failed to find SEM_STAT for sem_id %d",
+ sem_id);
+
+ return ret;
+}
+
static void verify_semctl(unsigned int n)
{
struct tcases *tc = &tests[n];
@@ -265,6 +299,7 @@ static void verify_semctl(unsigned int n)
if (sem_id == -1)
sem_id = SAFE_SEMGET(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
+
if (tc->func_setup) {
switch (tc->cmd) {
case GETNCNT:
@@ -279,7 +314,11 @@ static void verify_semctl(unsigned int n)
}
}
- rval = SAFE_SEMCTL(*(tc->semid), tc->semnum, tc->cmd, tc->arg);
+ if (tc->cmd == SEM_STAT)
+ rval = do_sem_stat(tc->arg);
+ else
+ rval = SAFE_SEMCTL(sem_id, tc->semnum, tc->cmd, tc->arg);
+
switch (tc->cmd) {
case GETNCNT:
case GETZCNT:
--
2.55.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-07-28 20:34 UTC|newest]
Thread overview: 13+ 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 ` Stephen Bertram via ltp [this message]
2026-07-28 21:12 ` [LTP] semctl01: look up SEM_STAT index for this test's sem_id linuxtestproject.agent
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=20260728203333.3949671-1-sbertram@redhat.com \
--to=ltp@lists.linux.it \
--cc=fdarocha@redhat.com \
--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