[LTP] [PATCH v1 2/2] semctl01: fix SEM_STAT failures under parallel LTP runs
Stephen Bertram
sbertram@redhat.com
Thu Jul 30 21:49:51 CEST 2026
From: Stephen Bertram <sbertram@redhat.com>
SEM_STAT relied on the global high index from IPC_INFO to find this
test's semaphore set. That index is not stable when other IPC tests run
concurrently, and could trigger TBROK aborts under parallel LTP runs.
Look up the index for this test's own semaphore set instead, using the
get_ipc_idx_from_id() helper shmctl01 already shares.
This also updates func_iinfo(), which no longer derives sem_index, and
func_sstat() now also verifies the semaphore data SEM_STAT returns
(sem_nsems, sem_perm.mode), not just the id used to locate it.
Signed-off-by: Stephen Bertram <sbertram@redhat.com>
Assisted-by: Cursor:Sonnet-5
---
Test: ./kirk -w 4 -f syscalls_32 -p semctl01 -i 1000
Before changes:
Total runs: 32000
Runtime: 16m 32s
Passed: 415968
Failed: 0
Skipped: 0
Broken: 16
Warnings: 0
After changes:
Total runs: 32000
Runtime: 16m 37s
Passed: 416000
Failed: 0
Skipped: 0
Broken: 0
Warnings: 0
testcases/kernel/syscalls/semctl/Makefile | 2 +-
testcases/kernel/syscalls/semctl/semctl01.c | 76 +++++++++++++++++----
2 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/testcases/kernel/syscalls/semctl/Makefile b/testcases/kernel/syscalls/semctl/Makefile
index 0e7223998..1f1ec9c81 100644
--- a/testcases/kernel/syscalls/semctl/Makefile
+++ b/testcases/kernel/syscalls/semctl/Makefile
@@ -8,6 +8,6 @@ LTPLIBS = ipc newipc
include $(top_srcdir)/include/mk/testcases.mk
semctl06: LTPLDLIBS = -lltpipc
-semctl02 semctl03 semctl04 semctl05 semctl07 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
+semctl01 semctl02 semctl03 semctl04 semctl05 semctl07 semctl08 semctl09: LTPLDLIBS = -lltpnewipc
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/semctl/semctl01.c b/testcases/kernel/syscalls/semctl/semctl01.c
index 5bd675ab6..398cb3028 100644
--- a/testcases/kernel/syscalls/semctl/semctl01.c
+++ b/testcases/kernel/syscalls/semctl/semctl01.c
@@ -210,13 +210,16 @@ static void func_rmid(void)
static void func_iinfo(int hidx)
{
- if (hidx >= 0) {
- sem_index = hidx;
- tst_res(TPASS, "the highest index is correct");
- } else {
- sem_index = 0;
- tst_res(TFAIL, "the highest index is incorrect");
- }
+ /*
+ * Return value is the highest used index. Our set is alive, so the
+ * highest used index must be at least our index.
+ */
+ if (hidx >= sem_index)
+ tst_res(TPASS, "IPC_INFO highest index %d >= our index %d",
+ hidx, sem_index);
+ else
+ tst_res(TFAIL, "IPC_INFO highest index %d < our index %d",
+ hidx, sem_index);
}
static void func_sinfo(void)
@@ -227,12 +230,54 @@ static void func_sinfo(void)
tst_res(TPASS, "number of semaphore sets is correct");
}
-static void func_sstat(int semidx)
+/*
+ * SEM_STAT fills buf the same way IPC_STAT does. sem_nsems and
+ * sem_perm.mode (set via IPC_SET earlier) verify SEM_STAT's own data,
+ * not just the id already used to find sem_index.
+ */
+static void func_sstat(int semid)
{
- if (semidx >= 0)
- tst_res(TPASS, "id of the semaphore set is correct");
+ if (semid != sem_id) {
+ tst_res(TFAIL, "expected sem_id %d, got %d", sem_id, semid);
+ return;
+ }
+
+ if (buf.sem_nsems == PSEMS && buf.sem_perm.mode == (SEM_RA | NEWMODE))
+ tst_res(TPASS, "id and semaphore STAT info are correct (id=%d)",
+ sem_id);
else
- tst_res(TFAIL, "id of the semaphore set is incorrect");
+ tst_res(TFAIL, "nsems=%d (expected %d), mode=%o (expected %o)",
+ (int)buf.sem_nsems, PSEMS,
+ buf.sem_perm.mode, (SEM_RA | NEWMODE));
+}
+
+/*
+ * SAFE_SEMCTL() would abort the test on per-index failures.
+ */
+static int sem_stat(int idx, void *buf)
+{
+ union semun arg;
+
+ arg.buf = buf;
+ return semctl(idx, 0, SEM_STAT, arg);
+}
+
+/*
+ * SEM_STAT takes an index into the kernel's internal array, not a semid.
+ * Return the index that maps to this test's set.
+ */
+static int get_sem_idx_from_id(int id)
+{
+ struct seminfo info;
+ struct semid_ds dummy_ds;
+ union semun arg;
+ int max_idx;
+
+ arg.__buf = &info;
+ /* SEM_INFO ignores semid; but SAFE_SEMCTL requires an lvalue */
+ max_idx = SAFE_SEMCTL(id, 0, SEM_INFO, arg);
+
+ return get_ipc_idx_from_id(id, max_idx, sem_stat, &dummy_ds);
}
static struct tcases {
@@ -263,8 +308,15 @@ static void verify_semctl(unsigned int n)
struct tcases *tc = &tests[n];
int rval;
- if (sem_id == -1)
+ if (sem_id == -1) {
sem_id = SAFE_SEMGET(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA);
+ sem_index = get_sem_idx_from_id(sem_id);
+ if (sem_index < 0)
+ tst_brk(TBROK,
+ "Failed to get sem_id %d to idx mapping", sem_id);
+ tst_res(TINFO, "sem_id=%d maps to kernel index=%d",
+ sem_id, sem_index);
+ }
if (tc->func_setup) {
switch (tc->cmd) {
case GETNCNT:
--
2.55.0
More information about the ltp
mailing list