[LTP] semctl01: fix SEM_STAT failures under parallel LTP runs

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Thu Jul 30 07:46:53 CEST 2026


Hi Stephen,

On Thu, 30 Jul 2026, Stephen Bertram wrote:
> semctl01: fix SEM_STAT failures under parallel LTP runs

>  static void func_iinfo(int hidx)
>  {
> +	/*
> +	 * 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);
>  }

The comment states the reason why this condition can never be false:
ipc_get_maxidx() returns the highest index over all live sets, and this
test's set is live for the whole iteration, so hidx >= sem_index always
holds.

That makes the IPC_INFO test case unconditionally pass. The previous
"hidx >= 0" check was equally weak, since semctl_info() returns 0 when
max_idx < 0, so this is not a regression, but since the function is being
touched anyway, would it make sense to check what IPC_INFO actually
returns in the buffer?

IPC_INFO fills struct seminfo with the namespace limits, so semmni,
semmsl and semopm could be compared against /proc/sys/kernel/sem.

> +static int get_sem_idx_from_id(int 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(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) == id)
> +			return i;
> +	}
> +
> +	return -1;
>  }

This is a near-copy of get_shm_idx_from_id() in
testcases/kernel/syscalls/shmctl/shmctl01.c, and msgctl will need the
same thing for MSG_STAT.

Would it be worth putting a generic helper into libs/newipc with a
declaration in include/tse_newipc.h instead, so the three IPC families
share one implementation?

> +	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);

> +		tst_res(TINFO, "sem_id=%d maps to kernel index=%d", sem_id, sem_index);

Nit: these two lines are 89 and 87 columns with tabs expanded. checkpatch
as vendored allows 100 so make check stays silent, but LTP code is
normally kept at 80.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer


More information about the ltp mailing list