lapi/sem.h: Add SEM_STAT_ANY
PATCH v2 1/3 lapi/sem.h: Add SEM_STAT_ANY
1) Rename semun.h to sem.h and apply it
2) Add SEM_STAT_ANY
--- include/ipcsem.h | 2 +- include/lapi/sem.h | 28 +++++++++++++++++++++++++ include/lapi/semun.h | 22 ------------------- testcases/kernel/containers/sysvipc/sem_comm.c | 3 +-- testcases/kernel/ipc/pipeio/pipeio.c | 3 +-- testcases/kernel/ipc/semaphore/sem01.c | 3 +-- testcases/kernel/ipc/semaphore/sem02.c | 3 +-- testcases/kernel/sched/process_stress/process.c | 3 +-- testcases/kernel/syscalls/ipc/semctl/semctl08.c | 2 +- testcases/kernel/syscalls/ipc/semop/semop01.c | 3 +-- testcases/kernel/syscalls/ipc/semop/semop02.c | 3 +-- testcases/kernel/syscalls/ipc/semop/semop03.c | 3 +-- testcases/kernel/syscalls/sendmsg/sendmsg02.c | 3 +-- 13 files changed, 39 insertions(+), 42 deletions(-) create mode 100644 include/lapi/sem.h delete mode 100644 include/lapi/semun.h
include/ipcsem.h +1 -1
@@ -29,7 +29,7 @@#include <sys/sem.h> #include "test.h" -#include "lapi/semun.h" +#include "lapi/sem.h" void cleanup (void );void setup (void );
include/lapi/sem.h new file +28 -0
@@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2015 Linux Test Project +*/ + +#include <sys/sem.h> + +#ifndef LAPI_SEM_H +#define LAPI_SEM_H + +#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) +/* union semun is defined by including <sys/sem.h> */ +#else +/* according to X/OPEN we have to define it ourselves */ +union semun { +int val;/* value for SETVAL */ +struct semid_ds *buf;/* buffer for IPC_STAT, IPC_SET */ +unsigned short *array;/* array for GETALL, SETALL */ +/* Linux specific part: */ +struct seminfo *__buf;/* buffer for IPC_INFO */ +}; +#endif + +#ifndef SEM_STAT_ANY +# define SEM_STAT_ANY 20 +#endif + +#endif /* LAPI_SEM_H */
include/lapi/semun.h deleted +0 -22
@@ -1,22 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* -* Copyright (c) 2015 Linux Test Project -*/ - -#ifndef SEMUN_H__ -#define SEMUN_H__ - -#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) -/* union semun is defined by including <sys/sem.h> */ -#else -/* according to X/OPEN we have to define it ourselves */ -union semun { -int val;/* value for SETVAL */ -struct semid_ds *buf;/* buffer for IPC_STAT, IPC_SET */ -unsigned short *array;/* array for GETALL, SETALL */ -/* Linux specific part: */ -struct seminfo *__buf;/* buffer for IPC_INFO */ -}; -#endif - -#endif /* SEMUN_H__ */
testcases/kernel/containers/sysvipc/sem_comm.c +1 -2
@@ -27,7 +27,6 @@#define _GNU_SOURCE#include <sys/ipc.h> -#include <sys/sem.h> #include <sys/types.h> #include <sys/wait.h> #include <stdio.h>
@@ -35,7 +34,7 @@#include "ipcns_helper.h" #include "test.h" #include "safe_macros.h" -#include "lapi/semun.h" +#include "lapi/sem.h" #define TESTKEY 124426Lchar *TCID ="sem_comm" ;
testcases/kernel/ipc/pipeio/pipeio.c +1 -2
@@ -47,13 +47,12 @@#include <string.h> #include <signal.h> #include <sys/stat.h> -#include <sys/sem.h> #include "tlibio.h" #include "test.h" #include "safe_macros.h" -#include "lapi/semun.h" +#include "lapi/sem.h" char *TCID ="pipeio" ;int TST_TOTAL =1 ;
testcases/kernel/ipc/semaphore/sem01.c +1 -2
@@ -40,8 +40,7 @@#include <sys/types.h> #include <sys/wait.h> #include <sys/ipc.h> -#include <sys/sem.h> -#include "lapi/semun.h" +#include "lapi/sem.h" int verbose =0 ;int loops =100 ;
testcases/kernel/ipc/semaphore/sem02.c +1 -2
@@ -45,12 +45,11 @@#include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <sys/sem.h> #include <errno.h> #include <pthread.h> #include <sys/types.h> #include <sys/ipc.h> -#include "lapi/semun.h" +#include "lapi/sem.h" #include "test.h" #define KEY IPC_PRIVATE
testcases/kernel/sched/process_stress/process.c +1 -2
@@ -40,11 +40,10 @@#include <sys/msg.h> #include <sys/resource.h> #include <sys/select.h> -#include <sys/sem.h> #include <sys/shm.h> #include <sys/types.h> #include <sys/wait.h> -#include "lapi/semun.h" +#include "lapi/sem.h" /* indexes into environment variable array */ #define ADBG 0
testcases/kernel/syscalls/ipc/semctl/semctl08.c +1 -1
@@ -6,7 +6,7 @@* Cross verify the _high fields being set to 0 by the kernel. */ #include "lapi/sembuf.h" -#include "lapi/semun.h" +#include "lapi/sem.h" #include "tst_test.h" #include "libnewipc.h"
testcases/kernel/syscalls/ipc/semop/semop01.c +1 -2
@@ -8,10 +8,9 @@*/ #include <stdlib.h> -#include <sys/sem.h> #include "tst_test.h" #include "libnewipc.h" -#include "lapi/semun.h" +#include "lapi/sem.h" #include "semop.h" #define NSEMS 4
testcases/kernel/syscalls/ipc/semop/semop02.c +1 -2
@@ -22,10 +22,9 @@#define _GNU_SOURCE#include <pwd.h> #include <sys/ipc.h> -#include <sys/sem.h> #include "tst_test.h" #include "libnewipc.h" -#include "lapi/semun.h" +#include "lapi/sem.h" #include "semop.h" static int valid_sem_id =-1 ;
testcases/kernel/syscalls/ipc/semop/semop03.c +1 -2
@@ -11,10 +11,9 @@#include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> -#include <sys/sem.h> #include "tst_test.h" #include "libnewipc.h" -#include "lapi/semun.h" +#include "lapi/sem.h" #include "semop.h" static key_t semkey;
testcases/kernel/syscalls/sendmsg/sendmsg02.c +1 -2
@@ -34,7 +34,6 @@#define _GNU_SOURCE#include <sys/ipc.h> #include <sys/stat.h> -#include <sys/sem.h> #include <sys/socket.h> #include <sys/types.h> #include <sys/un.h>
@@ -45,7 +44,7 @@#include "config.h" #include "test.h" #include "safe_macros.h" -#include "lapi/semun.h" +#include "lapi/sem.h" char *TCID ="sendmsg02" ;
Signature · 1 line
1.8.3.1
PATCH v2 2/3 Add SAFE_SEMCTL() and SAFE_SEMGET() macro
--- include/tst_safe_sysv_ipc.h | 14 ++++++++++++++ lib/tst_safe_sysv_ipc.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
include/tst_safe_sysv_ipc.h +14 -0
@@ -9,6 +9,7 @@#include <sys/ipc.h> #include <sys/msg.h> #include <sys/shm.h> +#include <sys/sem.h> int safe_msgget (const char *file,const int lineno,key_t key,int msgflg);#define SAFE_MSGGET (key, msgflg) \
@@ -51,4 +52,17 @@ int safe_shmctl(const char *file, const int lineno, int shmid, int cmd, (shmid) = ((cmd) ==IPC_RMID ?-1 : (shmid)); \ tst_ret_;}) +int safe_semget (const char *file,const int lineno,key_t key,int nsems, +int semflg); +#define SAFE_SEMGET (key, nsems, semflg) \ + safe_semget(__FILE__, __LINE__, (key), (nsems), (semflg)) + +int safe_semctl (const char *file,const int lineno,int semid,int semnum, +int cmd, ...); +#define SAFE_SEMCTL (semid, semnum, cmd, ...) ({ \ + int tst_ret_ = safe_semctl(__FILE__, __LINE__, (semid), (semnum), \ + (cmd), ##__VA_ARGS__); \ + (semid) = ((cmd) == IPC_RMID ? -1 : (semid)); \ + tst_ret_; }) +#endif /* TST_SAFE_SYSV_IPC_H__ */
lib/tst_safe_sysv_ipc.c +47 -0
56 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 3/3 syscalls/ipc: semctl09: add a test for SEM_STAT_ANY
In reply to Feiyu ZhuValidate the content of the seminfo structure and the return value.
The return value is highest used index to a kernel table, so we call semctl() with SEM_STAT_ANY which shouldn't fail if the value is correct.
We also test SEM_STAT_ANY by calling semctl() directly by syscall(), because glibc have a bug that caused fails to pass the buffer specified by the caller to the kernel.
We parse /proc/sysvipc/sem and check that the information is consistent with the content of seminfo structure.
--- runtest/syscalls | 1 + runtest/syscalls-ipc | 1 + testcases/kernel/syscalls/ipc/semctl/.gitignore | 1 + testcases/kernel/syscalls/ipc/semctl/Makefile | 2 +- testcases/kernel/syscalls/ipc/semctl/semctl09.c | 197 ++++++++++++++++++++++++ 5 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/ipc/semctl/semctl09.c
runtest/syscalls +1 -0
@@ -1179,6 +1179,7 @@ semctl05 semctl05 semctl06 semctl06 semctl07 semctl07 semctl08 semctl08 +semctl09 semctl09 semget01 semget01 semget02 semget02
runtest/syscalls-ipc +1 -0
@@ -37,6 +37,7 @@ semctl05 semctl05 semctl06 semctl06 semctl07 semctl07 semctl08 semctl08 +semctl09 semctl09 semget01 semget01 semget02 semget02
testcases/kernel/syscalls/ipc/semctl/.gitignore +1 -0
@@ -6,3 +6,4 @@ /semctl06 /semctl07 /semctl08 +/semctl09
testcases/kernel/syscalls/ipc/semctl/Makefile +1 -1
@@ -8,6 +8,6 @@ LTPLIBS = ltpipc ltpnewipc include $(top_srcdir)/include/mk/testcases.mk semctl01 semctl02 semctl03 semctl04 semctl05 semctl06 semctl07: LTPLDLIBS = -lltpipc -semctl08: LTPLDLIBS = -lltpnewipc +semctl08 semctl09: LTPLDLIBS = -lltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/ipc/semctl/semctl09.c new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 3/3 syscalls/ipc: semctl09: add a test for SEM_STAT_ANY
Hi!
Merged this patchset, thanks!
Best Regards
Yang Xu
Quoted 15 lines
Validate the content of the seminfo structure and the return value.
The return value is highest used index to a kernel table, so we call
semctl()withSEM_STAT_ANYwhich shouldn't fail if the value is correct.We also test
SEM_STAT_ANYby callingsemctl()directly bysyscall(), because glibc have a bug that caused fails to pass the buffer specified by the caller to the kernel.We parse
/proc/sysvipc/semand check that the information is consistent with the content of seminfo structure.Signed-off-by Feiyu Zhu<[email protected]>Reviewed-by Yang Xu<[email protected]>---