Linux Test Project
 help / color / mirror / Atom feed
From: Stephen Bertram via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Stephen Bertram <sbertram@redhat.com>
Subject: [LTP] [PATCH v10] semctl01: fix SEM_STAT failures under parallel LTP runs
Date: Wed, 29 Jul 2026 15:33:05 -0400	[thread overview]
Message-ID: <20260729193307.4187107-1-sbertram@redhat.com> (raw)
In-Reply-To: <20260729145321.4115712-1-sbertram@redhat.com>

SEM_STAT was using the global high index from IPC_INFO, which is not
stable when other IPC tests run in parallel and can abort the test with
TBROK.

Signed-off-by: Stephen Bertram <sbertram@redhat.com>
---
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 36s
Passed:     416000
Failed:     0
Skipped:    0
Broken:     0
Warnings:   0

Assisted-by: Cursor

 testcases/kernel/syscalls/semctl/semctl01.c | 67 ++++++++++++++++++---
 1 file changed, 58 insertions(+), 9 deletions(-)

diff --git a/testcases/kernel/syscalls/semctl/semctl01.c b/testcases/kernel/syscalls/semctl/semctl01.c
index 5bd675ab6..c2aee0eb0 100644
--- a/testcases/kernel/syscalls/semctl/semctl01.c
+++ b/testcases/kernel/syscalls/semctl/semctl01.c
@@ -210,12 +210,27 @@ 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");
+	int semmsl, semmns, semopm, semmni;
+
+	/*
+	 * Return value is the highest used index; SAFE_SEMCTL already
+	 * rejects negatives. Limits are what IPC_INFO actually fills.
+	 */
+	tst_res(TINFO, "IPC_INFO highest index %d (our index %d)",
+		hidx, sem_index);
+
+	SAFE_FILE_SCANF(PATH_KERN_SEM, "%d %d %d %d",
+			&semmsl, &semmns, &semopm, &semmni);
+
+	if (ipc_buf.semmsl == semmsl && ipc_buf.semmns == semmns &&
+		ipc_buf.semopm == semopm && ipc_buf.semmni == semmni) {
+		tst_res(TPASS, "IPC_INFO seminfo matches %s", PATH_KERN_SEM);
 	} else {
-		sem_index = 0;
-		tst_res(TFAIL, "the highest index is incorrect");
+		tst_res(TFAIL,
+			"IPC_INFO seminfo %d %d %d %d, expected %d %d %d %d from %s",
+			ipc_buf.semmsl, ipc_buf.semmns, ipc_buf.semopm,
+			ipc_buf.semmni, semmsl, semmns, semopm, semmni,
+			PATH_KERN_SEM);
 	}
 }
 
@@ -227,12 +242,40 @@ static void func_sinfo(void)
 		tst_res(TPASS, "number of semaphore sets is correct");
 }
 
-static void func_sstat(int semidx)
+static void func_sstat(int semid)
 {
-	if (semidx >= 0)
+	if (semid == 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, semid);
+}
+
+/*
+ * 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 sem_id)
+{
+	struct seminfo info;
+	struct semid_ds dummy_ds;
+	union semun arg;
+	int max_idx, i;
+
+	arg.__buf = &info;
+	/* SEM_INFO ignores semid; but SAFE_SEMCTL requires an lvalue */
+	max_idx = SAFE_SEMCTL(sem_id, 0, SEM_INFO, arg);
+
+	arg.buf = &dummy_ds;
+	for (i = 0; i <= max_idx; i++) {
+		/*
+		 * Bare semctl: unused/unreadable indices fail with
+		 * EINVAL/EACCES; SAFE_SEMCTL would abort the test.
+		 */
+		if (semctl(i, 0, SEM_STAT, arg) == sem_id)
+			return i;
+	}
+
+	return -1;
 }
 
 static struct tcases {
@@ -263,8 +306,14 @@ 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=%i maps to kernel index=%i", sem_id, sem_index);
+	}
 	if (tc->func_setup) {
 		switch (tc->cmd) {
 		case GETNCNT:
-- 
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-07-29 19:33 UTC|newest]

Thread overview: 20+ 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             ` Stephen Bertram via ltp [this message]
2026-07-29 20:20               ` linuxtestproject.agent
2026-07-29 21:00               ` [LTP] [PATCH v11] " 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=20260729193307.4187107-1-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