syscalls/ipc: Make use of TST_EXP_FAIL macro
RFC 1/1 syscalls/ipc: Make use of TST_EXP_FAIL macro
---
Since TST_EXP_FAIL macro only recognizes sycalls succeeded when syscalls return 0, Can we use this macro directly for the these syscalls's error test? It may result in invalid retval value and print errno when syscall succeeded. I think it is a nit and it can improve this api usage range. Is it right?
testcases/kernel/syscalls/ipc/msgget/msgget02.c | 15 ++------------- testcases/kernel/syscalls/ipc/msgget/msgget03.c | 12 ++---------- testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c | 14 ++------------ testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c | 17 ++--------------- testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c | 12 ++---------- testcases/kernel/syscalls/ipc/msgrcv/msgrcv06.c | 11 ++--------- testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c | 14 ++------------ testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c | 14 ++------------ testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c | 14 ++------------ 9 files changed, 18 insertions(+), 105 deletions(-)
testcases/kernel/syscalls/ipc/msgget/msgget02.c +2 -13
@@ -46,19 +46,8 @@ static struct tcase {static void verify_msgget (struct tcase *tc) { -TEST (msgget (*tc->key, tc->flags)); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," -" expected %s" ,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL (msgget (*tc->key, tc->flags), tc->exp_err,"msgget(%i, %i)" , + *tc->key, tc->flags); }static void do_test (unsigned int n)
testcases/kernel/syscalls/ipc/msgget/msgget03.c +2 -10
@@ -26,16 +26,8 @@ static key_t msgkey;static void verify_msgget (void ) { -TEST (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL )); -if (TST_RET !=-1 ) -tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); - -if (TST_ERR ==ENOSPC ) { -tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," -" expected ENOSPC" ); - } +TST_EXP_FAIL (msgget (msgkey + maxmsgs,IPC_CREAT |IPC_EXCL ),ENOSPC , +"msgget(%i, %i)" , msgkey + maxmsgs,IPC_CREAT |IPC_EXCL ); }static void setup (void )
testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c +2 -12
@@ -59,18 +59,8 @@ static struct tcase {static void verify_msgrcv (struct tcase *tc) { -TEST (msgrcv (*tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag)); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"smgrcv() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgrcv() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgrcv() failed unexpectedly," -" expected %s but got" ,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL (msgrcv (*tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag), tc->exp_err, +"msgrcv(%i, %p, %i, %ld, %i)" , *tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag); }static void do_test (unsigned int n)
testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c +2 -15
@@ -59,21 +59,8 @@ static void verify_msgrcv(unsigned int n)tst_res (TINFO ,"%s" , tc->message); -TEST (msgrcv (queue_id, &rcv_buf,MSGSIZE , tc->msg_type,MSG_COPY | tc->msg_flag)); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgrcv() succeeded unexpectedly" ); -SAFE_MSGSND (queue_id, &snd_buf,MSGSIZE ,0 ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgrcv() failed as expected" ); -return ; - } - -tst_res (TFAIL |TTERRNO , -"msgrcv() failed unexpectedly, expected %s got" , -tst_strerrno (tc->exp_err)); +TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE , tc->msg_type,MSG_COPY | tc->msg_flag), tc->exp_err, +"msgrcv(%i, %p, %i, %i, %i)" , queue_id, &rcv_buf,MSGSIZE , tc->msg_type,MSG_COPY | tc->msg_flag); }static void setup (void )
testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c +2 -10
@@ -30,16 +30,8 @@ static void sighandler(int sig)static void verify_msgrcv (void ) { -TEST (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 )); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgrcv() succeeded unexpectedly" ); -return ; - } -if (TST_ERR ==EINTR ) -tst_res (TPASS |TTERRNO ,"msgrcv() failed as expected" ); -else -tst_res (TFAIL |TTERRNO ,"msgrcv() failed expected EINTR but got" ); +TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 ),EINTR , +"msgrcv(%i, %p, %d, 1, 0)" , queue_id, &rcv_buf,MSGSIZE ); }static void do_test (void )
testcases/kernel/syscalls/ipc/msgrcv/msgrcv06.c +2 -9
@@ -24,15 +24,8 @@ static struct buf {static void verify_msgrcv (void ) { -TEST (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 )); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgrcv() succeeded unexpectedly" ); -return ; - } -if (TST_ERR ==EIDRM ) -tst_res (TPASS |TTERRNO ,"msgrcv() failed as expected" ); -else -tst_res (TFAIL |TTERRNO ,"msgrcv() failed expected EIDRM but got" ); +TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 ),EIDRM , +"msgrcv(%i, %p, %d, 1, 0)" , queue_id, &rcv_buf,MSGSIZE ); }static void do_test (void )
testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c +2 -12
@@ -61,18 +61,8 @@ static struct tcase {static void verify_msgsnd (struct tcase *tc) { -TEST (msgsnd (*tc->id, tc->buffer, tc->msgsz,0 )); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"smgsnd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgsnd() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgsnd() failed unexpectedly," -" expected %s" ,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL (msgsnd (*tc->id, tc->buffer, tc->msgsz,0 ), tc->exp_err, +"msgsnd(%i, %p, %i, 0)" , *tc->id, tc->buffer, tc->msgsz); }static void do_test (unsigned int n)
testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c +2 -12
@@ -41,18 +41,8 @@ static struct tcase {static void verify_msgsnd (struct tcase *tc) { -TEST (msgsnd (queue_id, &snd_buf,MSGSIZE , tc->flag)); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgsnd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgsnd() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgsnd() failed unexpectedly," -" expected %s" ,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL (msgsnd (queue_id, &snd_buf,MSGSIZE , tc->flag), tc->exp_err, +"msgsnd(%i, %p, %i, %i)" , queue_id, &snd_buf,MSGSIZE , tc->flag); }static void sighandler (int sig)
testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c +2 -12
@@ -28,18 +28,8 @@ static struct buf {static void verify_msgsnd (void ) { -TEST (msgsnd (queue_id, &snd_buf,MSGSIZE ,0 )); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgsnd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR ==EIDRM ) { -tst_res (TPASS |TTERRNO ,"msgsnd() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO , -"msgsnd() failed unexpectedly, expected EIDRM" ); - } +TST_EXP_FAIL (msgsnd (queue_id, &snd_buf,MSGSIZE ,0 ),EIDRM , +"msgsnd(%i, %p, %i, 0)" , queue_id, &snd_buf,MSGSIZE ); }static void do_test (void )
Signature · 1 line
2.23.0
RFC 1/1 syscalls/ipc: Make use of TST_EXP_FAIL macro
Hi!
Quoted 4 lines
Since
TST_EXP_FAILmacro only recognizes sycalls succeeded when syscalls return 0, Can we use this macro directly for the these syscalls's error test? It may result in invalid retval value and print errno when syscall succeeded. I think it is a nit and it can improve this api usage range. Is it right?
I guess that it would be slightly cleaner to add more generic macro that allows us to pass the condition for succeess and build TST_EXP_FAIL() on the top of that. Maybe something as:
include/tst_test_macros.h +6 -2
@@ -120,13 +120,13 @@ extern void *TST_RET_PTR; TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \ } while (0) \ -#define TST_EXP_FAIL (SCALL ,ERRNO , ...) \ +#define TST_EXP_FAIL_ (PASS_COND ,SCALL ,ERRNO , ...) \ do { \ TEST(SCALL); \ \ TST_PASS = 0; \ \ - if (TST_RET == 0) { \ + if (PASS_COND) { \ TST_MSG_(TFAIL, " succeeded", #SCALL, ##__VA_ARGS__); \ break; \ } \
@@ -150,4 +150,8 @@ extern void *TST_RET_PTR; } \ } while (0) +#define TST_EXP_FAIL (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, ERRNO) + +#define TST_EXP_FAIL2 (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET >= 0, SCALL, ERRNO) +#endif /* TST_TEST_MACROS_H__ */
The only hard thing is to find a good name for TST_EXP_FAIL2(), I'm out of ideas here...
Signature · 2 lines
Cyril Hrubis [email protected]
Hi Cyril
Quoted 40 lines
Hi!
Quoted 4 lines
Since
TST_EXP_FAILmacro only recognizes sycalls succeeded when syscalls return 0, Can we use this macro directly for the these syscalls's error test? It may result in invalid retval value and print errno when syscall succeeded. I think it is a nit and it can improve this api usage range. Is it right?I guess that it would be slightly cleaner to add more generic macro that allows us to pass the condition for succeess and build
TST_EXP_FAIL()on the top of that. Maybe something as:include/tst_test_macros.h +6
-2@@ -120,13 +120,13 @@ extern void *TST_RET_PTR; TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__); \ } while (0) \ -#define TST_EXP_FAIL (SCALL ,ERRNO , ...) \ +#define TST_EXP_FAIL_ (PASS_COND ,SCALL ,ERRNO , ...) \ do { \ TEST(SCALL); \ \ TST_PASS = 0; \ \ - if (TST_RET == 0) { \ + if (PASS_COND) { \ TST_MSG_(TFAIL, " succeeded", #SCALL, ##__VA_ARGS__); \ break; \ } \@@ -150,4 +150,8 @@ extern void *TST_RET_PTR; } \ } while (0) +#define TST_EXP_FAIL (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET == 0, SCALL, ERRNO) + +#define TST_EXP_FAIL2 (SCALL ,ERRNO , ...) TST_EXP_FAIL_(TST_RET>= 0, SCALL, ERRNO) +#endif /* TST_TEST_MACROS_H__ */
Quoted 2 lines
The only hard thing is to find a good name for
TST_EXP_FAIL2(), I'm out of ideas here...
I think using TST_EXP_FAIL2 directly is simple and clear.
Best Regards
Yang Xu
Quoted 1 line
PATCH v2 1/2 syscalls: Use more accurate TST_EXP_FAIL2 macro
In reply to Cyril HrubisFor these modified files, the return value is expected to be non-negative integer if call passes. So they should use TST_EXP_FAIL2 macro.
--- testcases/kernel/syscalls/accept/accept01.c | 2 +- testcases/kernel/syscalls/adjtimex/adjtimex02.c | 2 +- testcases/kernel/syscalls/io_getevents/io_getevents01.c | 3 ++- testcases/kernel/syscalls/io_submit/io_submit03.c | 2 +- testcases/kernel/syscalls/open/open02.c | 2 +- testcases/kernel/syscalls/open/open11.c | 2 +- testcases/kernel/syscalls/recvmmsg/recvmmsg01.c | 2 +- testcases/kernel/syscalls/sendfile/sendfile03.c | 2 +- testcases/kernel/syscalls/sendfile/sendfile04.c | 2 +- 9 files changed, 10 insertions(+), 9 deletions(-)
testcases/kernel/syscalls/accept/accept01.c +1 -1
@@ -97,7 +97,7 @@ void verify_accept(unsigned int nr) {struct test_case *tcase = &tcases[nr]; -TST_EXP_FAIL (accept (*tcase->fd, tcase->sockaddr, &tcase->salen), +TST_EXP_FAIL2 (accept (*tcase->fd, tcase->sockaddr, &tcase->salen), tcase->experrno,"%s" , tcase->desc); }
testcases/kernel/syscalls/adjtimex/adjtimex02.c +1 -1
@@ -110,7 +110,7 @@ static void verify_adjtimex(unsigned int i) } } -TST_EXP_FAIL (tv->adjtimex (bufp), tc[i].exp_err,"adjtimex() error" ); +TST_EXP_FAIL2 (tv->adjtimex (bufp), tc[i].exp_err,"adjtimex() error" );if (tc[i].exp_err ==EPERM )SAFE_SETEUID (0 );
testcases/kernel/syscalls/io_getevents/io_getevents01.c +2 -1
@@ -23,7 +23,8 @@ static void run(void)aio_context_t ctx;memset (&ctx,0 ,sizeof (ctx)); -TST_EXP_FAIL (tst_syscall (__NR_io_getevents, ctx,0 ,0 ,NULL ,NULL ),EINVAL ); +TST_EXP_FAIL2 (tst_syscall (__NR_io_getevents, ctx,0 ,0 ,NULL ,NULL ),EINVAL , +"io_getevents syscall with invalid ctx" ); }static struct tst_test test = {
testcases/kernel/syscalls/io_submit/io_submit03.c +1 -1
@@ -103,7 +103,7 @@ static void cleanup(void)static void run (unsigned int i) { -TST_EXP_FAIL (tst_syscall (__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs), +TST_EXP_FAIL2 (tst_syscall (__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs), tc[i].exp_errno,"io_submit() with %s" , tc[i].desc); }
testcases/kernel/syscalls/open/open02.c +1 -1
@@ -49,7 +49,7 @@ static void verify_open(unsigned int n) {struct tcase *tc = &tcases[n]; -TST_EXP_FAIL (open (tc->filename, tc->flag,0444 ), +TST_EXP_FAIL2 (open (tc->filename, tc->flag,0444 ), tc->exp_errno,"open() %s" , tc->desc); }
testcases/kernel/syscalls/open/open11.c +1 -1
@@ -278,7 +278,7 @@ static struct test_case {static void verify_open (unsigned int n) {if (tc[n].err >0 ) { -TST_EXP_FAIL (open (tc[n].path, tc[n].flags, tc[n].mode), +TST_EXP_FAIL2 (open (tc[n].path, tc[n].flags, tc[n].mode), tc[n].err,"%s" , tc[n].desc); }else if (tc[n].err ==0 ) { TST_EXP_FD(open(tc[n].path, tc[n].flags, tc[n].mode),
testcases/kernel/syscalls/recvmmsg/recvmmsg01.c +1 -1
@@ -89,7 +89,7 @@ static void do_test(unsigned int i)else timeout =tst_ts_get (&ts); -TST_EXP_FAIL (tv->recvmmsg (*tc->fd, *tc->msg_vec,VLEN ,0 , timeout), +TST_EXP_FAIL2 (tv->recvmmsg (*tc->fd, *tc->msg_vec,VLEN ,0 , timeout), tc->exp_errno,"recvmmsg() %s" , tc->desc); }
testcases/kernel/syscalls/sendfile/sendfile03.c +1 -1
@@ -50,7 +50,7 @@ static void cleanup(void)static void run (unsigned int i) { -TST_EXP_FAIL (sendfile (*(tc[i].out_fd), *(tc[i].in_fd),NULL ,1 ), +TST_EXP_FAIL2 (sendfile (*(tc[i].out_fd), *(tc[i].in_fd),NULL ,1 ),EBADF ,"sendfile(..) with %s" , tc[i].desc); }
testcases/kernel/syscalls/sendfile/sendfile04.c +1 -1
@@ -58,7 +58,7 @@ static void run(unsigned int i)if (tc[i].pass_unmapped_buffer)SAFE_MUNMAP (protected_buffer,sizeof (*protected_buffer)); -TST_EXP_FAIL (sendfile (out_fd, in_fd, protected_buffer,1 ), +TST_EXP_FAIL2 (sendfile (out_fd, in_fd, protected_buffer,1 ),EFAULT ,"sendfile(..) with %s, protection=%d" , tc[i].desc, tc[i].protection);
Signature · 1 line
2.23.0
PATCH v2 1/2 syscalls: Use more accurate TST_EXP_FAIL2 macro
Hi Cyril
When I do this patch, I found a tst_res usage problem in sendfile06.c.
see https://github.com/linux-test-project/ltp/runs/2933366481#step:10:3797
Best Regards
Yang Xu
Quoted 134 lines
For these modified files, the return value is expected to be non-negative integer if call passes. So they should use
TST_EXP_FAIL2macro.Signed-off-by Yang Xu<[email protected]>--- testcases/kernel/syscalls/accept/accept01.c | 2 +- testcases/kernel/syscalls/adjtimex/adjtimex02.c | 2 +- testcases/kernel/syscalls/io_getevents/io_getevents01.c | 3 ++- testcases/kernel/syscalls/io_submit/io_submit03.c | 2 +- testcases/kernel/syscalls/open/open02.c | 2 +- testcases/kernel/syscalls/open/open11.c | 2 +- testcases/kernel/syscalls/recvmmsg/recvmmsg01.c | 2 +- testcases/kernel/syscalls/sendfile/sendfile03.c | 2 +- testcases/kernel/syscalls/sendfile/sendfile04.c | 2 +- 9 files changed, 10 insertions(+), 9 deletions(-)testcases/kernel/syscalls/accept/accept01.c +1
-1@@ -97,7 +97,7 @@ void verify_accept(unsigned int nr) {struct test_case *tcase =&tcases[nr]; -TST_EXP_FAIL (accept (*tcase->fd, tcase->sockaddr,&tcase->salen), +TST_EXP_FAIL2 (accept (*tcase->fd, tcase->sockaddr,&tcase->salen), tcase->experrno,"%s" , tcase->desc); }testcases/kernel/syscalls/adjtimex/adjtimex02.c +1
-1@@ -110,7 +110,7 @@ static void verify_adjtimex(unsigned int i) } } -TST_EXP_FAIL (tv->adjtimex (bufp), tc[i].exp_err,"adjtimex() error" ); +TST_EXP_FAIL2 (tv->adjtimex (bufp), tc[i].exp_err,"adjtimex() error" );if (tc[i].exp_err ==EPERM )SAFE_SETEUID (0 );testcases/kernel/syscalls/io_getevents/io_getevents01.c +2
-1@@ -23,7 +23,8 @@ static void run(void)aio_context_t ctx;memset (&ctx,0 ,sizeof (ctx)); -TST_EXP_FAIL (tst_syscall (__NR_io_getevents, ctx,0 ,0 ,NULL ,NULL ),EINVAL ); +TST_EXP_FAIL2 (tst_syscall (__NR_io_getevents, ctx,0 ,0 ,NULL ,NULL ),EINVAL , +"io_getevents syscall with invalid ctx" ); }static struct tst_test test = {testcases/kernel/syscalls/io_submit/io_submit03.c +1
-1@@ -103,7 +103,7 @@ static void cleanup(void)static void run (unsigned int i) { -TST_EXP_FAIL (tst_syscall (__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs), +TST_EXP_FAIL2 (tst_syscall (__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs), tc[i].exp_errno,"io_submit() with %s" , tc[i].desc); }testcases/kernel/syscalls/open/open02.c +1
-1@@ -49,7 +49,7 @@ static void verify_open(unsigned int n) {struct tcase *tc =&tcases[n]; -TST_EXP_FAIL (open (tc->filename, tc->flag,0444 ), +TST_EXP_FAIL2 (open (tc->filename, tc->flag,0444 ), tc->exp_errno,"open() %s" , tc->desc); }testcases/kernel/syscalls/open/open11.c +1
-1@@ -278,7 +278,7 @@ static struct test_case {static void verify_open (unsigned int n) {if (tc[n].err>0 ) { -TST_EXP_FAIL (open (tc[n].path, tc[n].flags, tc[n].mode), +TST_EXP_FAIL2 (open (tc[n].path, tc[n].flags, tc[n].mode), tc[n].err,"%s" , tc[n].desc); }else if (tc[n].err ==0 ) { TST_EXP_FD(open(tc[n].path, tc[n].flags, tc[n].mode),testcases/kernel/syscalls/recvmmsg/recvmmsg01.c +1
-1@@ -89,7 +89,7 @@ static void do_test(unsigned int i)else timeout =tst_ts_get (&ts); -TST_EXP_FAIL (tv->recvmmsg (*tc->fd, *tc->msg_vec,VLEN ,0 , timeout), +TST_EXP_FAIL2 (tv->recvmmsg (*tc->fd, *tc->msg_vec,VLEN ,0 , timeout), tc->exp_errno,"recvmmsg() %s" , tc->desc); }testcases/kernel/syscalls/sendfile/sendfile03.c +1
-1@@ -50,7 +50,7 @@ static void cleanup(void)static void run (unsigned int i) { -TST_EXP_FAIL (sendfile (*(tc[i].out_fd), *(tc[i].in_fd),NULL ,1 ), +TST_EXP_FAIL2 (sendfile (*(tc[i].out_fd), *(tc[i].in_fd),NULL ,1 ),EBADF ,"sendfile(..) with %s" , tc[i].desc); }testcases/kernel/syscalls/sendfile/sendfile04.c +1
-1@@ -58,7 +58,7 @@ static void run(unsigned int i)if (tc[i].pass_unmapped_buffer)SAFE_MUNMAP (protected_buffer,sizeof (*protected_buffer)); -TST_EXP_FAIL (sendfile (out_fd, in_fd, protected_buffer,1 ), +TST_EXP_FAIL2 (sendfile (out_fd, in_fd, protected_buffer,1 ),EFAULT ,"sendfile(..) with %s, protection=%d" , tc[i].desc, tc[i].protection);
PATCH v2 1/2 syscalls: Use more accurate TST_EXP_FAIL2 macro
Hi!
Quoted 3 lines
When I do this patch, I found a
tst_resusage problem insendfile06.c.see https://github.com/linux-test-project/ltp/runs/2933366481#step:10:3797
Someone has put comma between % and the PRId64 which is obviously wrong.
Fixed in: 0880bf5aa757 (syscalls/sendfile06: Fix format string)
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 syscalls/ipc: Make use of TST_EXP_FAIL or TST_EXP_FAIL2 macro
In reply to Yang Xu--- testcases/kernel/syscalls/ipc/msgget/msgget02.c | 15 ++------------- testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c | 14 ++------------ testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c | 17 ++--------------- testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c | 12 ++---------- testcases/kernel/syscalls/ipc/msgrcv/msgrcv06.c | 11 ++--------- testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c | 14 ++------------ testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c | 14 ++------------ testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c | 14 ++------------ 8 files changed, 16 insertions(+), 95 deletions(-)
testcases/kernel/syscalls/ipc/msgget/msgget02.c +2 -13
@@ -46,19 +46,8 @@ static struct tcase {static void verify_msgget (struct tcase *tc) { -TEST (msgget (*tc->key, tc->flags)); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgget() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgget() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgget() failed unexpectedly," -" expected %s" ,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL (msgget (*tc->key, tc->flags), tc->exp_err,"msgget(%i, %i)" , + *tc->key, tc->flags); }static void do_test (unsigned int n)
testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c +2 -12
@@ -59,18 +59,8 @@ static struct tcase {static void verify_msgrcv (struct tcase *tc) { -TEST (msgrcv (*tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag)); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"smgrcv() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgrcv() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgrcv() failed unexpectedly," -" expected %s but got" ,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL2 (msgrcv (*tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag), tc->exp_err, +"msgrcv(%i, %p, %i, %ld, %i)" , *tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag); }static void do_test (unsigned int n)
testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c +2 -15
@@ -59,21 +59,8 @@ static void verify_msgrcv(unsigned int n)tst_res (TINFO ,"%s" , tc->message); -TEST (msgrcv (queue_id, &rcv_buf,MSGSIZE , tc->msg_type,MSG_COPY | tc->msg_flag)); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgrcv() succeeded unexpectedly" ); -SAFE_MSGSND (queue_id, &snd_buf,MSGSIZE ,0 ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgrcv() failed as expected" ); -return ; - } - -tst_res (TFAIL |TTERRNO , -"msgrcv() failed unexpectedly, expected %s got" , -tst_strerrno (tc->exp_err)); +TST_EXP_FAIL2 (msgrcv (queue_id, &rcv_buf,MSGSIZE , tc->msg_type,MSG_COPY | tc->msg_flag), tc->exp_err, +"msgrcv(%i, %p, %i, %i, %i)" , queue_id, &rcv_buf,MSGSIZE , tc->msg_type,MSG_COPY | tc->msg_flag); }static void setup (void )
testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c +2 -10
@@ -30,16 +30,8 @@ static void sighandler(int sig)static void verify_msgrcv (void ) { -TEST (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 )); - -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgrcv() succeeded unexpectedly" ); -return ; - } -if (TST_ERR ==EINTR ) -tst_res (TPASS |TTERRNO ,"msgrcv() failed as expected" ); -else -tst_res (TFAIL |TTERRNO ,"msgrcv() failed expected EINTR but got" ); +TST_EXP_FAIL2 (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 ),EINTR , +"msgrcv(%i, %p, %d, 1, 0)" , queue_id, &rcv_buf,MSGSIZE ); }static void do_test (void )
testcases/kernel/syscalls/ipc/msgrcv/msgrcv06.c +2 -9
@@ -24,15 +24,8 @@ static struct buf {static void verify_msgrcv (void ) { -TEST (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 )); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgrcv() succeeded unexpectedly" ); -return ; - } -if (TST_ERR ==EIDRM ) -tst_res (TPASS |TTERRNO ,"msgrcv() failed as expected" ); -else -tst_res (TFAIL |TTERRNO ,"msgrcv() failed expected EIDRM but got" ); +TST_EXP_FAIL2 (msgrcv (queue_id, &rcv_buf,MSGSIZE ,1 ,0 ),EIDRM , +"msgrcv(%i, %p, %d, 1, 0)" , queue_id, &rcv_buf,MSGSIZE ); }static void do_test (void )
testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c +2 -12
@@ -61,18 +61,8 @@ static struct tcase {static void verify_msgsnd (struct tcase *tc) { -TEST (msgsnd (*tc->id, tc->buffer, tc->msgsz,0 )); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"smgsnd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgsnd() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgsnd() failed unexpectedly," -" expected %s" ,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL (msgsnd (*tc->id, tc->buffer, tc->msgsz,0 ), tc->exp_err, +"msgsnd(%i, %p, %i, 0)" , *tc->id, tc->buffer, tc->msgsz); }static void do_test (unsigned int n)
testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c +2 -12
@@ -41,18 +41,8 @@ static struct tcase {static void verify_msgsnd (struct tcase *tc) { -TEST (msgsnd (queue_id, &snd_buf,MSGSIZE , tc->flag)); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgsnd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR == tc->exp_err) { -tst_res (TPASS |TTERRNO ,"msgsnd() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO ,"msgsnd() failed unexpectedly," -" expected %s" ,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL (msgsnd (queue_id, &snd_buf,MSGSIZE , tc->flag), tc->exp_err, +"msgsnd(%i, %p, %i, %i)" , queue_id, &snd_buf,MSGSIZE , tc->flag); }static void sighandler (int sig)
testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c +2 -12
@@ -28,18 +28,8 @@ static struct buf {static void verify_msgsnd (void ) { -TEST (msgsnd (queue_id, &snd_buf,MSGSIZE ,0 )); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"msgsnd() succeeded unexpectedly" ); -return ; - } - -if (TST_ERR ==EIDRM ) { -tst_res (TPASS |TTERRNO ,"msgsnd() failed as expected" ); - }else { -tst_res (TFAIL |TTERRNO , -"msgsnd() failed unexpectedly, expected EIDRM" ); - } +TST_EXP_FAIL (msgsnd (queue_id, &snd_buf,MSGSIZE ,0 ),EIDRM , +"msgsnd(%i, %p, %i, 0)" , queue_id, &snd_buf,MSGSIZE ); }static void do_test (void )
Signature · 1 line
2.23.0
PATCH v2 2/2 syscalls/ipc: Make use of TST_EXP_FAIL or TST_EXP_FAIL2 macro
Hi!
testcases/kernel/syscalls/ipc/msgget/msgget02.c static struct tcase { · line 51
Quoted 3 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +2
-0+TST_EXP_FAIL (msgget (*tc->key, tc->flags), tc->exp_err,"msgget(%i, %i)" , + *tc->key, tc->flags); }
I've changed this one to TST_EXP_FAIL2() since msgget() returns non-negative integer on success and pushed the patchset, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 syscalls/ipc: Make use of TST_EXP_FAIL or TST_EXP_FAIL2 macro
Hi Cyril
Quoted 7 lines
Hi!
testcases/kernel/syscalls/ipc/msgget/msgget02.c static struct tcase { · line 51
Quoted 3 lines
testcases/kernel/syscalls/ipc/msgget/msgget02.c +2
-0+TST_EXP_FAIL (msgget (*tc->key, tc->flags), tc->exp_err,"msgget(%i, %i)" , + *tc->key, tc->flags); }I've changed this one to
TST_EXP_FAIL2()sincemsgget()returns non-negative integer on success and pushed the patchset, thanks.
Oh, yes! I pasted from v1. Sorry for not changing this.
Best Regards
Yang Xu