semctl: updates for multi worker testing.
PATCH 1/1 semctl: updates for multi worker testing.
Changed semctl03, semctl05 and semctl07 by replacing the key with IPC_PRIVATE.
Changed semctl01, which required updates to reduce interference and provide an allowance for EINVAL and EIDRM.
--- .../kernel/syscalls/ipc/semctl/semctl01.c | 91 +++++++++++++------ .../kernel/syscalls/ipc/semctl/semctl03.c | 5 +- .../kernel/syscalls/ipc/semctl/semctl05.c | 6 +- .../kernel/syscalls/ipc/semctl/semctl07.c | 3 +- 4 files changed, 64 insertions(+), 41 deletions(-)
testcases/kernel/syscalls/ipc/semctl/semctl01.c +61 -30
@@ -8,6 +8,7 @@#define _GNU_SOURCE#include <stdlib.h> +#include <pthread.h> #include "tst_safe_sysv_ipc.h" #include "tst_test.h" #include "lapi/sem.h"
@@ -18,14 +19,16 @@#define NCHILD 5#define SEMUN_CAST (union semun) -static int sem_id =-1 ; -static int sem_index; +static __threadint sem_id =-1 ; +static __threadint sem_index;static struct semid_ds buf;static struct seminfo ipc_buf;static unsigned short array[PSEMS ];static struct sembuf sops;static int pid_arr[NCHILD ]; +static pthread_mutex_t sem_stat_lock =PTHREAD_MUTEX_INITIALIZER ; +static void kill_all_children (void ) {int j;
@@ -243,28 +246,36 @@ static struct tcases {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}, + {NULL, 0, IPC_STAT, func_stat, SEMUN_CAST & buf, NULL}, + {NULL, 0, IPC_SET, func_set, SEMUN_CAST & buf, set_setup}, + {NULL, 0, GETALL, func_gall, SEMUN_CAST array, NULL}, + {NULL, 4, GETNCNT, func_cnt, SEMUN_CAST & buf, cnt_setup}, + {NULL, 2, GETPID, func_pid, SEMUN_CAST & buf, pid_setup}, + {NULL, 2, GETVAL, func_gval, SEMUN_CAST & buf, NULL}, + {NULL, 4, GETZCNT, func_cnt, SEMUN_CAST & buf, cnt_setup}, + {NULL, 0, SETALL, func_sall, SEMUN_CAST array, sall_setup}, + {NULL, 4, SETVAL, func_sval, SEMUN_CAST INCVAL, NULL}, + {NULL, 0, IPC_INFO, func_iinfo, SEMUN_CAST & ipc_buf, NULL}, + {NULL, 0, SEM_INFO, func_sinfo, SEMUN_CAST & ipc_buf, NULL}, + {NULL, 0, SEM_STAT, func_sstat, SEMUN_CAST & buf, NULL}, + {NULL, 0, IPC_RMID, func_rmid, SEMUN_CAST & buf, NULL}, }; static void verify_semctl(unsigned int n) { struct tcases *tc = &tests[n]; - int rval; + int rval, sid; + int retries = 5; + + /* Resolve sem id: SEM_STAT uses sem_index, others use sem_id */ + if (tc->cmd == SEM_STAT) + sid = sem_index; + else { + sid = sem_id; + if (sid == -1) + sem_id = sid = SAFE_SEMGET(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); + } - 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,21 +290,41 @@ static void verify_semctl(unsigned int n) } } - rval =SAFE_SEMCTL (*(tc->semid), tc->semnum, tc->cmd, tc->arg); -switch (tc->cmd) { -case GETNCNT : -case GETZCNT : -case GETPID : -case GETVAL : -case IPC_INFO : -case SEM_STAT : +/* SEM_STAT: get index under lock, call SEM_STAT without lock, retry on EIDRM and EINVAL */ +if (tc->cmd ==SEM_STAT ) { +do { +pthread_mutex_lock (&sem_stat_lock); + sem_index =semctl (0 ,0 ,IPC_INFO , (union semun )&ipc_buf); +pthread_mutex_unlock (&sem_stat_lock); +if (sem_index <0 ) +tst_brk (TBROK |TERRNO ,"semctl(0, 0, IPC_INFO)" ); + rval =semctl (sem_index,0 , tc->cmd, tc->arg); +if (rval >=0 ) +break ; +if ((errno !=EIDRM && errno !=EINVAL ) || --retries <=0 ) +tst_brk (TBROK |TERRNO ,"semctl(SEM_STAT)" ); + }while (1 ); tc->func_test (rval); -break ; -default : + }else if (tc->cmd ==IPC_RMID ) { +pthread_mutex_lock (&sem_stat_lock); +SAFE_SEMCTL (sid, tc->semnum, tc->cmd, tc->arg); +pthread_mutex_unlock (&sem_stat_lock); tc->func_test (); -break ; + }else { + rval =SAFE_SEMCTL (sid, tc->semnum, tc->cmd, tc->arg); +switch (tc->cmd) { +case GETNCNT : +case GETZCNT : +case GETPID : +case GETVAL : +case IPC_INFO : + tc->func_test (rval); +break ; +default : + tc->func_test (); +break ; + } } -if (tc->cmd ==GETNCNT || tc->cmd ==GETZCNT )kill_all_children (); }
testcases/kernel/syscalls/ipc/semctl/semctl03.c +1 -4
@@ -84,14 +84,11 @@ static void verify_semctl(unsigned int n)static void setup (void ) { -static key_t semkey;struct test_variants *tv = &variants[tst_variant];tst_res (TINFO ,"Testing variant: %s" , tv->desc); - semkey =GETIPCKEY (); - - sem_id =SAFE_SEMGET (semkey,PSEMS ,IPC_CREAT |IPC_EXCL |SEM_RA ); + sem_id =SAFE_SEMGET (IPC_PRIVATE ,PSEMS ,IPC_CREAT |IPC_EXCL |SEM_RA ); bad_ptr =tst_get_bad_addr (NULL ); }
testcases/kernel/syscalls/ipc/semctl/semctl05.c +1 -5
@@ -45,11 +45,7 @@ static void verify_semctl(unsigned int n)static void setup (void ) { -static key_t semkey; - - semkey =GETIPCKEY (); - - sem_id =SAFE_SEMGET (semkey,PSEMS ,IPC_CREAT |IPC_EXCL |SEM_RA ); + sem_id =SAFE_SEMGET (IPC_PRIVATE ,PSEMS ,IPC_CREAT |IPC_EXCL |SEM_RA ); }static void cleanup (void )
testcases/kernel/syscalls/ipc/semctl/semctl07.c +1 -2
@@ -130,10 +130,9 @@ static void verify_semctl(void)static void setup (void ) { -key_t key =GETIPCKEY (); nsems =1 ; - semid =SAFE_SEMGET (key, nsems,SEM_RA |IPC_CREAT ); + semid =SAFE_SEMGET (IPC_PRIVATE , nsems,SEM_RA |IPC_CREAT ); }static void cleanup (void )
Signature · 5 lines
2.52.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 2 lines
Changed semctl03, semctl05 and semctl07 by replacing the key with
IPC_PRIVATE.
Can you send changes to these three tests as a separate patch?
Quoted 3 lines
Changed semctl01, which required updates to reduce interference and provide an allowance for EINVAL and EIDRM.
This is a very different change that at least should have been put into a different patch and would require a careful review.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
Done.
- [LTP] [PATCH v2] semctl: updates for multi worker testing.
<https://lists.linux.it/pipermail/ltp/2026-April/047617.html> [1]
- [LTP] [PATCH v1] semctl: use IPC_PRIVATE to minimize interference.
<https://lists.linux.it/pipermail/ltp/2026-April/047618.html>[2]
Thanks,
stephen
He/His/Him
[1] https://lists.linux.it/pipermail/ltp/2026-April/047617.html
[2] https://lists.linux.it/pipermail/ltp/2026-April/047618.html
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp