syscalls/semtimedop: Add support for semtimedop and its time64 version
PATCH v11 1/2 syscalls/semtimedop: Add support for semtimedop and its time64 version
This adds support for semtimedop() and its time64 variant to the existing semop() syscall tests.
---
V11:
- s/all_variants/semtimedop_only/
- Change timeout to 10 us for all the tests except semop03, that fails randomly if the timeout is less than 10 ms.
testcases/kernel/syscalls/ipc/semop/semop.h | 55 +++++++++++++++++++ testcases/kernel/syscalls/ipc/semop/semop01.c | 26 ++++++++- testcases/kernel/syscalls/ipc/semop/semop02.c | 44 +++++++++++---- testcases/kernel/syscalls/ipc/semop/semop03.c | 15 ++++- 4 files changed, 125 insertions(+), 15 deletions(-) create mode 100644 testcases/kernel/syscalls/ipc/semop/semop.h
testcases/kernel/syscalls/ipc/semop/semop.h new file +55 -0
@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef SEMOP_VAR__ +#define SEMOP_VAR__ + +#include <sys/sem.h> +#include "tst_timer.h" + +static inline int sys_semtimedop (int semid,struct sembuf *sops,size_t nsops, +void *timeout) +{ +return tst_syscall (__NR_semtimedop, semid, sops, nsops, timeout); +} + +static inline int sys_semtimedop_time64 (int semid,struct sembuf *sops, +size_t nsops,void *timeout) +{ +return tst_syscall (__NR_semtimedop_time64, semid, sops, nsops, timeout); +} + +struct test_variants { +int (*semop)(int semid,struct sembuf *sops,size_t nsops); +int (*semtimedop)(int semid,struct sembuf *sops,size_t nsops,void *timeout); +enum tst_ts_type type; +char *desc; +} variants[] = { + { .semop = semop, .type =TST_LIBC_TIMESPEC , .desc ="semop: syscall" }, + +#if (__NR_semtimedop != __LTP__NR_INVALID_SYSCALL) + { .semtimedop = sys_semtimedop, .type =TST_KERN_OLD_TIMESPEC , .desc ="semtimedop: syscall with old kernel spec" }, +#endif + +#if (__NR_semtimedop_time64 != __LTP__NR_INVALID_SYSCALL) + { .semtimedop = sys_semtimedop_time64, .type =TST_KERN_TIMESPEC , .desc ="semtimedop: syscall time64 with kernel spec" }, +#endif +}; + +static inline int call_semop (struct test_variants *tv,int semid, +struct sembuf *sops,size_t nsops,void *timeout) +{ +if (tv->semop) +return tv->semop (semid, sops, nsops); + +return tv->semtimedop (semid, sops, nsops, timeout); +} + +static inline void semop_supported_by_kernel (struct test_variants *tv) +{ +/* Check if the syscall is implemented on the platform */ +TEST (call_semop (tv,0 ,NULL ,0 ,NULL )); +if (TST_RET ==-1 &&TST_ERR ==ENOSYS ) +tst_brk (TCONF ,"Test not supported on kernel/platform" ); +} + +#endif /* SEMOP_VAR__ */
testcases/kernel/syscalls/ipc/semop/semop01.c +23 -3
@@ -12,6 +12,7 @@#include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" #define NSEMS 4
@@ -21,14 +22,23 @@ static key_t semkey;static unsigned short int sarr[PSEMS ];static union semun get_arr = {.array = sarr};static struct sembuf sops[PSEMS ]; +static struct tst_ts timeout; -static void run (void ) +static struct test_case_t { +struct tst_ts *to; +} tc[] = { + {NULL }, + {&timeout} +}; + +static void run (unsigned int n) { +struct test_variants *tv = &variants[tst_variant];union semun arr = { .val =0 };int fail =0 ;int i; -TEST (semop (sem_id, sops,NSEMS )); +TEST (call_semop (tv, sem_id, sops,NSEMS ,tst_ts_get (tc[n].to)));if (TST_RET ==-1 ) {tst_res (TFAIL |TTERRNO ,"semop() failed" );return ;
@@ -56,8 +66,16 @@ static void run(void)static void setup (void ) { +struct test_variants *tv = &variants[tst_variant];int i; +tst_res (TINFO ,"Testing variant: %s" , tv->desc); +semop_supported_by_kernel (tv); + + timeout.type = tv->type; +tst_ts_set_sec (&timeout,0 ); +tst_ts_set_nsec (&timeout,10000 ); + semkey =GETIPCKEY (); sem_id =semget (semkey,PSEMS ,IPC_CREAT |IPC_EXCL |SEM_RA );
@@ -80,7 +98,9 @@ static void cleanup(void) }static struct tst_test test = { - .test_all = run, + .test = run, + .tcnt =ARRAY_SIZE (tc), + .test_variants =ARRAY_SIZE (variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir =1 ,
testcases/kernel/syscalls/ipc/semop/semop02.c +33 -11
106 lines not on this page · raw message
testcases/kernel/syscalls/ipc/semop/semop03.c +14 -1
@@ -15,9 +15,11 @@#include "tst_test.h" #include "libnewipc.h" #include "lapi/semun.h" +#include "semop.h" static key_t semkey;static int sem_id =-1 ; +static struct tst_ts timeout;struct test_case_t {union semun semunptr;
@@ -34,13 +36,14 @@ struct test_case_t {static void do_child (int i) { +struct test_variants *tv = &variants[tst_variant];struct sembuf s_buf = { .sem_op = tc[i].op, .sem_flg = tc[i].flg, .sem_num = tc[i].num, }; -TEST (semop (sem_id, &s_buf,1 )); +TEST (call_semop (tv, sem_id, &s_buf,1 ,tst_ts_get (&timeout)));if (TST_RET !=-1 ) {tst_res (TFAIL ,"call succeeded when error expected" );exit (0 );
@@ -62,6 +65,15 @@ static void sighandler(int sig)static void setup (void ) { +struct test_variants *tv = &variants[tst_variant]; + +tst_res (TINFO ,"Testing variant: %s" , tv->desc); +semop_supported_by_kernel (tv); + + timeout.type = tv->type; +tst_ts_set_sec (&timeout,0 ); +tst_ts_set_nsec (&timeout,10000000 ); +SAFE_SIGNAL (SIGHUP , sighandler); semkey =GETIPCKEY ();
@@ -119,6 +131,7 @@ static void run(unsigned int i)static struct tst_test test = { .test = run, .tcnt =ARRAY_SIZE (tc), + .test_variants =ARRAY_SIZE (variants), .setup = setup, .cleanup = cleanup, .needs_tmpdir =1 ,
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v11 2/2 syscalls/semtimedop: Add failure test for invalid timeout pointer
This adds test for invalid timeout pointer.
---
V11:
- Fixed rebase conflicts.
testcases/kernel/syscalls/ipc/semop/semop02.c | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-)
testcases/kernel/syscalls/ipc/semop/semop02.c +27 -14
@@ -12,6 +12,7 @@* EAGAIN - semop = -1 for zero semaphore and IPC_NOWAIT passed in flags * EAGAIN - semop = 0 and timeout happens * EAGAIN - semop = -1 and timeout happens +* EFAULT - invalid timeout pointer * * Copyright (c) International Business Machines Corp., 2001 * 03/2001 - Written by Wayne Boyer
@@ -33,6 +34,7 @@ static int bad_sem_id = -1;static short sem_op_max, sem_op_1 =1 , sem_op_negative =-1 , sem_op_zero =0 ;static struct sembuf *faulty_buf;static struct tst_ts timeout; +static struct tst_ts *valid_to = &timeout, *invalid_to;#define NSOPS 1#define BIGOPS 1024
@@ -47,20 +49,22 @@ static struct test_case_t {short sem_flg;unsigned t_ops;int arr_val; +struct tst_ts **to;int error; } tc[] = { - {0, &valid_sem_id, NULL, &sem_op_1, 0, 0, 0, BIGOPS, 1, E2BIG}, - {0, &noperm_sem_id, NULL, &sem_op_1, 0, 0, 0, NSOPS, 1, EACCES}, - {0, &valid_sem_id, &faulty_buf, &sem_op_1, 0, 0, 0, NSOPS, 1, EFAULT}, - {0, &valid_sem_id, NULL, &sem_op_1, 0, 0, 0, 0, 1, EINVAL}, - {0, &bad_sem_id, NULL, &sem_op_1, 0, 0, 0, NSOPS, 1, EINVAL}, - {0, &valid_sem_id, NULL, &sem_op_max, 0, 0, 0, 1, 1, ERANGE}, - {0, &valid_sem_id, NULL, &sem_op_1, 0, -1, SEM_UNDO, 1, 1, EFBIG}, - {0, &valid_sem_id, NULL, &sem_op_1, 0, PSEMS + 1, SEM_UNDO, 1, 1, EFBIG}, - {0, &valid_sem_id, NULL, &sem_op_zero, 2, 2, IPC_NOWAIT, 1, 1, EAGAIN}, - {0, &valid_sem_id, NULL, &sem_op_negative, 2, 2, IPC_NOWAIT, 1, 0, EAGAIN}, - {1, &valid_sem_id, NULL, &sem_op_zero, 0, 0, SEM_UNDO, 1, 1, EAGAIN}, - {1, &valid_sem_id, NULL, &sem_op_negative, 0, 0, SEM_UNDO, 1, 0, EAGAIN}, + {0, &valid_sem_id, NULL, &sem_op_1, 0, 0, 0, BIGOPS, 1, &valid_to, E2BIG}, + {0, &noperm_sem_id, NULL, &sem_op_1, 0, 0, 0, NSOPS, 1, &valid_to, EACCES}, + {0, &valid_sem_id, &faulty_buf, &sem_op_1, 0, 0, 0, NSOPS, 1, &valid_to, EFAULT}, + {0, &valid_sem_id, NULL, &sem_op_1, 0, 0, 0, 0, 1, &valid_to, EINVAL}, + {0, &bad_sem_id, NULL, &sem_op_1, 0, 0, 0, NSOPS, 1, &valid_to, EINVAL}, + {0, &valid_sem_id, NULL, &sem_op_max, 0, 0, 0, 1, 1, &valid_to, ERANGE}, + {0, &valid_sem_id, NULL, &sem_op_1, 0, -1, SEM_UNDO, 1, 1, &valid_to, EFBIG}, + {0, &valid_sem_id, NULL, &sem_op_1, 0, PSEMS + 1, SEM_UNDO, 1, 1, &valid_to, EFBIG}, + {0, &valid_sem_id, NULL, &sem_op_zero, 2, 2, IPC_NOWAIT, 1, 1, &valid_to, EAGAIN}, + {0, &valid_sem_id, NULL, &sem_op_negative, 2, 2, IPC_NOWAIT, 1, 0, &valid_to, EAGAIN}, + {1, &valid_sem_id, NULL, &sem_op_zero, 0, 0, SEM_UNDO, 1, 1, &valid_to, EAGAIN}, + {1, &valid_sem_id, NULL, &sem_op_negative, 0, 0, SEM_UNDO, 1, 0, &valid_to, EAGAIN}, + {1, &valid_sem_id, NULL, &sem_op_zero, 0, 0, SEM_UNDO, 1, 1, &invalid_to, EFAULT}, }; static void setup(void)
@@ -70,6 +74,7 @@ static void setup(void)key_t semkey;union semun arr;struct seminfo ipc_buf; +void *faulty_address;tst_res (TINFO ,"Testing variant: %s" , tv->desc);semop_supported_by_kernel (tv);
@@ -98,7 +103,9 @@ static void setup(void)tst_brk (TBROK |TERRNO ,"semctl() IPC_INFO failed" ); sem_op_max = ipc_buf.semvmx; - faulty_buf =tst_get_bad_addr (NULL ); + faulty_address =tst_get_bad_addr (NULL ); + invalid_to = faulty_address; + faulty_buf = faulty_address; }static void run (unsigned int i)
@@ -111,6 +118,7 @@ static void run(unsigned int i) .sem_num = tc[i].sem_num, };struct sembuf *ptr = &buf; +void *to;if (tc[i].semtimedop_only && tv->semop) {tst_res (TCONF ,"Test not supported for variant" );
@@ -125,7 +133,12 @@ static void run(unsigned int i)if (tc[i].buf) ptr = *tc[i].buf; -TEST (call_semop (tv, *(tc[i].semid), ptr, tc[i].t_ops,tst_ts_get (&timeout))); +if (*tc[i].to == invalid_to) + to = invalid_to; +else + to =tst_ts_get (*tc[i].to); + +TEST (call_semop (tv, *(tc[i].semid), ptr, tc[i].t_ops, to));if (TST_RET !=-1 ) {tst_res (TFAIL |TTERRNO ,"call succeeded unexpectedly" );
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v11 2/2 syscalls/semtimedop: Add failure test for invalid timeout pointer
Viresh Kumar <[email protected]> wrote:
This adds test for invalid timeout pointer.
Quoted 3 lines
Signed-off-by Viresh Kumar <[email protected]>
For the series:
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200903/60bf39a4/attachment.htm>
PATCH v11 1/2 syscalls/semtimedop: Add support for semtimedop and its time64 version
In reply to Viresh KumarHi!
Both pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v11 1/2 syscalls/semtimedop: Add support for semtimedop and its time64 version
In reply to Viresh KumarHi!
Quoted 2 lines
- Change timeout to 10 us for all the tests except semop03, that fails randomly if the timeout is less than 10 ms.
The short timeout is important only to semop02, where we actually wait for the timeout. We can raise the timeout for semop03 to minutes if needed, since we actually do not wait for it to expire.
Signature · 2 lines
Cyril Hrubis [email protected]