testcases/kernel/syscalls: Adding new testcases for existing tests
v2 cover testcases/kernel/syscalls: Adding new testcases for existing tests
This series introduces new test cases for existing tests for syscalls
* mq_timedsend() * sendmmsg()
* mq_timedreceive() * recvmmsg()
* clock_nanosleep()
* First patch in the series introduces bad address test cases for 'mq_timedsend()' and 'mq_timedreceive()'
* Second patch in the series introduces bad timespec address cases for 'clock_nanosleep()'
* Third patch in the series introduces a timeout case and an errno test for 'sendmmsg()' and 'recvmmsg()'
More detailed descriptions of these newly added test cases and the implementation details can be found in this series patch commit messages.
These new test cases are part of my work of implementation for 2038 safe variants of the above mentioned syscalls in QEMU:
* mq_timedsend_time64()
* mq_timedreceive_time64()
* clock_nanosleep_time64()
* recvmmsg_time64()
These test cases are needed to make sure that QEMU implementations of the above mentioned time64 syscalls work properly.
These test cases are also used to fix some minor issues with already existing implementations of regular variants of these syscalls.
v2:
* Changed bad address values from (void *)1 to using function 'tst_get_bad_addr()'
* Removed unnecessary implementation descriptions that can be seen from the patches
Filip Bozuta (3):
syscalls/mq_timed{send|receive}: Add test cases for bad address syscalls/clock_nanosleep: add a test case for bad timespec address syscalls/{send|recv}mmsg: add a test case for timeout and errno test
runtest/syscalls | 1 + .../clock_nanosleep/clock_nanosleep01.c | 35 ++- .../mq_timedreceive/mq_timedreceive01.c | 15 +- .../syscalls/mq_timedsend/mq_timedsend01.c | 29 ++- testcases/kernel/syscalls/sendmmsg/.gitignore | 1 + .../kernel/syscalls/sendmmsg/sendmmsg01.c | 68 ++++-- .../kernel/syscalls/sendmmsg/sendmmsg02.c | 231 ++++++++++++++++++ testcases/kernel/syscalls/utils/mq_timed.h | 2 + 8 files changed, 362 insertions(+), 20 deletions(-) create mode 100644 testcases/kernel/syscalls/sendmmsg/sendmmsg02.c
Signature · 1 line
2.25.1
PATCH v2 1/3 syscalls/mq_timed{send|receive}: Add test cases for bad address
This patch introduces test cases for already existing tests for syscalls 'mq_timedsend()' and 'mq_timedreceive()' (mq_timedsend01, mq_timedreceive01). These test cases are for situations when bad addresses are passed for arguments 'msg_ptr' and 'abs_timeout' in which case errno 'EFAULT' is expected to be set.
--- .../mq_timedreceive/mq_timedreceive01.c | 15 +++++++++- .../syscalls/mq_timedsend/mq_timedsend01.c | 29 +++++++++++++++++-- testcases/kernel/syscalls/utils/mq_timed.h | 2 ++ 3 files changed, 43 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +14 -1
@@ -123,6 +123,13 @@ static struct test_case tcase[] = { .ret = -1, .err = EINTR, }, + { + .fd = &fd, + .len = 16, + .bad_ts_addr = 1, + .ret = -1, + .err = EFAULT, + } };static void setup (void )
@@ -144,6 +151,7 @@ static void do_test(unsigned int i)size_t len =MAX_MSGSIZE ;char rmsg[len];pid_t pid =-1 ; +void *abs_timeout;tst_ts_set_sec (&ts, tc->tv_sec);tst_ts_set_nsec (&ts, tc->tv_nsec);
@@ -164,7 +172,12 @@ static void do_test(unsigned int i)if (tc->invalid_msg) len -=1 ; -TEST (tv->receive (*tc->fd, rmsg, len, &prio,tst_ts_get (tc->rq))); +if (tc->bad_ts_addr) + abs_timeout =tst_get_bad_addr (cleanup_common); +else + abs_timeout =tst_ts_get (tc->rq); + +TEST (tv->receive (*tc->fd, rmsg, len, &prio, abs_timeout));if (pid >0 )kill_pid (pid);
testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c +27 -2
@@ -129,6 +129,20 @@ static struct test_case tcase[] = { .ret = -1, .err = EINTR, }, + { + .fd = &fd, + .len = 16, + .bad_msg_addr = 1, + .ret = -1, + .err = EFAULT, + }, + { + .fd = &fd, + .len = 16, + .bad_ts_addr = 1, + .ret = -1, + .err = EFAULT, + } };static void setup (void )
@@ -150,6 +164,7 @@ static void do_test(unsigned int i)size_t len =MAX_MSGSIZE ;char rmsg[len];pid_t pid =-1 ; +void *msg_ptr, *abs_timeout;tst_ts_set_sec (&ts, tc->tv_sec);tst_ts_set_nsec (&ts, tc->tv_nsec);
@@ -168,7 +183,17 @@ static void do_test(unsigned int i) } } -TEST (tv->send (*tc->fd, smsg, tc->len, tc->prio,tst_ts_get (tc->rq))); +if (tc->bad_msg_addr) + msg_ptr =tst_get_bad_addr (cleanup_common); +else + msg_ptr = smsg; + +if (tc->bad_ts_addr) + abs_timeout =tst_get_bad_addr (cleanup_common); +else + abs_timeout =tst_ts_get (tc->rq); + +TEST (tv->send (*tc->fd, msg_ptr, tc->len, tc->prio, abs_timeout));if (pid >0 )kill_pid (pid);
@@ -179,7 +204,7 @@ static void do_test(unsigned int i)"mq_timedsend() failed unexpectedly, expected %s" , tst_strerrno(tc->err)); else - tst_res(TPASS | TTERRNO, "mq_timedreceive() failed expectedly"); + tst_res(TPASS | TTERRNO, "mq_timedsend() failed expectedly");if (*tc->fd == fd)cleanup_queue (fd);
testcases/kernel/syscalls/utils/mq_timed.h +2 -0
@@ -41,6 +41,8 @@ struct test_case {int send;int signal;int timeout; +int bad_msg_addr; +int bad_ts_addr;int ret;int err; };
Signature · 1 line
2.25.1
PATCH v2 1/3 syscalls/mq_timed{send|receive}: Add test cases for bad address
Hi!
Pushed with a minor change, thanks.
I've moved the tst_get_bad_addr() to the setup since that funciton allocates memory, which would cause failures with large enough -i test parameter. The diff is:
testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c +4 -1
@@ -17,6 +17,7 @@ static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1;#include "mq_timed.h" static struct tst_ts ts; +static void *bad_addr;static struct test_case tcase[] = { {
@@ -139,6 +140,8 @@ static void setup(void)tst_res (TINFO ,"Testing variant: %s" , tv->desc); ts.type = tv->type; + bad_addr =tst_get_bad_addr (NULL ); +setup_common (); }
@@ -173,7 +176,7 @@ static void do_test(unsigned int i) len -=1 ;if (tc->bad_ts_addr) - abs_timeout =tst_get_bad_addr (cleanup_common); + abs_timeout = bad_addr;else abs_timeout =tst_ts_get (tc->rq);
testcases/kernel/syscalls/mq_timedsend/mq_timedsend01.c +5 -2
@@ -17,6 +17,7 @@ static int fd, fd_root, fd_nonblock, fd_maxint = INT_MAX - 1, fd_invalid = -1;#include "mq_timed.h" static struct tst_ts ts; +static void *bad_addr;static struct test_case tcase[] = { {
@@ -152,6 +153,8 @@ static void setup(void)tst_res (TINFO ,"Testing variant: %s" , tv->desc); ts.type = tv->type; + bad_addr =tst_get_bad_addr (cleanup_common); +setup_common (); }
@@ -184,12 +187,12 @@ static void do_test(unsigned int i) }if (tc->bad_msg_addr) - msg_ptr =tst_get_bad_addr (cleanup_common); + msg_ptr = bad_addr;else msg_ptr = smsg;if (tc->bad_ts_addr) - abs_timeout =tst_get_bad_addr (cleanup_common); + abs_timeout = bad_addr;else abs_timeout =tst_ts_get (tc->rq);
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/3 syscalls/clock_nanosleep: add a test case for bad timespec address
In reply to Filip BozutaThis patch introduces test cases for already existing test for syscall 'clock_nanosleep()' (clock_nanosleep01). These test cases are for situations when bad timespec addresses are passed for arguments 'request' and 'remain' in which case errno EFAULT ('Bad address') is expected to be set.
--- .../clock_nanosleep/clock_nanosleep01.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +33 -2
@@ -20,6 +20,8 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)enum test_type {NORMAL ,SEND_SIGINT , +BAD_TS_ADDR_REQ , +BAD_TS_ADDR_REM , };#define TYPE_NAME (x) .ttype = x, .desc = #x
@@ -78,6 +80,22 @@ static struct test_case tcase[] = { .exp_ret = -1, .exp_err = EINTR, }, + { + TYPE_NAME(BAD_TS_ADDR_REQ), + .clk_id = CLOCK_REALTIME, + .flags = 0, + .exp_ret = -1, + .exp_err =EFAULT , + }, + { +TYPE_NAME (BAD_TS_ADDR_REM ), + .clk_id = CLOCK_REALTIME, + .flags = 0, + .tv_sec = 10, + .tv_nsec = 0, + .exp_ret = -1, + .exp_err = EFAULT, + }, };static struct tst_ts *rq;
@@ -106,24 +124,37 @@ void setup(void)SAFE_SIGNAL (SIGINT , sighandler); } +void cleanup (void ) {} +static void do_test (unsigned int i) {struct test_variants *tv = &variants[tst_variant];struct test_case *tc = &tcase[i];pid_t pid =0 ; +void *request, *remain;memset (rm,0 ,sizeof (*rm)); rm->type = rq->type;tst_res (TINFO ,"case %s" , tc->desc); -if (tc->ttype ==SEND_SIGINT ) +if (tc->ttype ==SEND_SIGINT || tc->ttype ==BAD_TS_ADDR_REM ) pid =create_sig_proc (SIGINT ,40 ,500000 );tst_ts_set_sec (rq, tc->tv_sec);tst_ts_set_nsec (rq, tc->tv_nsec); -TEST (tv->func (tc->clk_id, tc->flags,tst_ts_get (rq),tst_ts_get (rm))); +if (tc->ttype ==BAD_TS_ADDR_REQ ) + request =tst_get_bad_addr (cleanup); +else + request =tst_ts_get (rq); + +if (tc->ttype ==BAD_TS_ADDR_REM ) + remain =tst_get_bad_addr (cleanup); +else + remain =tst_ts_get (rm); + +TEST (tv->func (tc->clk_id, tc->flags, request, remain));if (tv->func == libc_clock_nanosleep) {/*
Signature · 1 line
2.25.1
PATCH v2 2/3 syscalls/clock_nanosleep: add a test case for bad timespec address
Hi!
Quoted 48 lines
This patch introduces test cases for already existing test for syscall '
clock_nanosleep()' (clock_nanosleep01). These test cases are for situations when bad timespec addresses are passed for arguments 'request' and 'remain' in which case errno EFAULT ('Bad address') is expected to be set.Signed-off-by Filip Bozuta <[email protected]>--- .../clock_nanosleep/clock_nanosleep01.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +18
-0@@ -20,6 +20,8 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)enum test_type {NORMAL ,SEND_SIGINT , +BAD_TS_ADDR_REQ , +BAD_TS_ADDR_REM , };#define TYPE_NAME (x) .ttype = x, .desc = #x@@ -78,6 +80,22 @@ static struct test_case tcase[] = { .exp_ret = -1, .exp_err = EINTR, }, + { + TYPE_NAME(BAD_TS_ADDR_REQ), + .clk_id = CLOCK_REALTIME, + .flags = 0, + .exp_ret = -1, + .exp_err =EFAULT , + }, + { +TYPE_NAME (BAD_TS_ADDR_REM ), + .clk_id = CLOCK_REALTIME, + .flags = 0, + .tv_sec = 10, + .tv_nsec = 0, + .exp_ret = -1, + .exp_err = EFAULT, + }, };static struct tst_ts *rq;
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c void setup(void) · line 127
Quoted 4 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +1
-0@@ -106,24 +124,37 @@ void setup(void)SAFE_SIGNAL (SIGINT , sighandler); } +void cleanup (void ) {}
Please just pass NULL to the tst_get_bad_addr() instead.
Also it should be called only once in the test setup, as I explained for the previous patch.
Quoted 5 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +0
-0static void do_test (unsigned int i) {struct test_variants *tv = &variants[tst_variant];struct test_case *tc = &tcase[i];pid_t pid =0 ;
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c void setup(void) · line 142
Quoted 10 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +2
-1+void *request, *remain;memset (rm,0 ,sizeof (*rm)); rm->type = rq->type;tst_res (TINFO ,"case %s" , tc->desc); -if (tc->ttype ==SEND_SIGINT ) +if (tc->ttype ==SEND_SIGINT || tc->ttype ==BAD_TS_ADDR_REM ) pid =create_sig_proc (SIGINT ,40 ,500000 );
Does the kernel access the remaining time only if the call gets interrupted by a signal?
I guess that this would be better written down in comment.
Generally LTP testcases usually have short documentation in a comment just after the license and copyright. In this case it should be something as:
/*
* EINVAL - negative tv_nsec
* EINVAL - tv_nsec > 1s
* ...
* EFAULT - invalid request pointer
* EFAULT - invalid remain pointer while interrupted by a signal */
Quoted 24 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +11
-1tst_ts_set_sec (rq, tc->tv_sec);tst_ts_set_nsec (rq, tc->tv_nsec); -TEST (tv->func (tc->clk_id, tc->flags,tst_ts_get (rq),tst_ts_get (rm))); +if (tc->ttype ==BAD_TS_ADDR_REQ ) + request =tst_get_bad_addr (cleanup); +else + request =tst_ts_get (rq); + +if (tc->ttype ==BAD_TS_ADDR_REM ) + remain =tst_get_bad_addr (cleanup); +else + remain =tst_ts_get (rm); + +TEST (tv->func (tc->clk_id, tc->flags, request, remain));if (tv->func == libc_clock_nanosleep) {/* Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/3 syscalls/clock_nanosleep: add a test case for bad timespec address
Hello,
thanks for the review!
Quoted 52 lines · Cyril Hrubis
Hi!
Quoted 51 lines
This patch introduces test cases for already existing test for syscall '
clock_nanosleep()' (clock_nanosleep01). These test cases are for situations when bad timespec addresses are passed for arguments 'request' and 'remain' in which case errno EFAULT ('Bad address') is expected to be set.Signed-off-by Filip Bozuta <[email protected]>--- .../clock_nanosleep/clock_nanosleep01.c | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +18
-0@@ -20,6 +20,8 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)enum test_type {NORMAL ,SEND_SIGINT , +BAD_TS_ADDR_REQ , +BAD_TS_ADDR_REM , };#define TYPE_NAME (x) .ttype = x, .desc = #x@@ -78,6 +80,22 @@ static struct test_case tcase[] = { .exp_ret = -1, .exp_err = EINTR, }, + { + TYPE_NAME(BAD_TS_ADDR_REQ), + .clk_id = CLOCK_REALTIME, + .flags = 0, + .exp_ret = -1, + .exp_err =EFAULT , + }, + { +TYPE_NAME (BAD_TS_ADDR_REM ), + .clk_id = CLOCK_REALTIME, + .flags = 0, + .tv_sec = 10, + .tv_nsec = 0, + .exp_ret = -1, + .exp_err = EFAULT, + }, };static struct tst_ts *rq;@@ -106,24 +124,37 @@ void setup(void)SAFE_SIGNAL (SIGINT , sighandler); }
Quoted 5 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c void setup(void) · line 127
Quoted 1 line
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +1
-0+void cleanup (void ) {}Please just pass NULL to the
tst_get_bad_addr()instead.Also it should be called only once in the test setup, as I explained for the previous patch.
Yes I will change this and send v3 for this patch soon. I will pass NULL and move the tst_get_bad_addr() in test setup() same as in the first patch. Thanks for the explanation!
Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +1
-0static void do_test (unsigned int i) {struct test_variants *tv = &variants[tst_variant];struct test_case *tc = &tcase[i];pid_t pid =0 ; +void *request, *remain;memset (rm,0 ,sizeof (*rm)); rm->type = rq->type;
Quoted 7 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c void setup(void) · line 142
Quoted 5 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +1
-1tst_res (TINFO ,"case %s" , tc->desc); -if (tc->ttype ==SEND_SIGINT ) +if (tc->ttype ==SEND_SIGINT || tc->ttype ==BAD_TS_ADDR_REM ) pid =create_sig_proc (SIGINT ,40 ,500000 );Does the kernel access the remaining time only if the call gets interrupted by a signal?
Yes, the the 'remain' argument is accessed only in a case when call gets interrupted by a signal and in case it is not NULL and if flag TIMER_ABSTIME is not set, the argument gets updated with the remaining time from the timeout. For that reason a signal should be set in this test case so that the test fails with expected errno (EFAULT) when kernel tries to access the argument.
Quoted 7 lines
I guess that this would be better written down in comment.
Generally LTP testcases usually have short documentation in a comment just after the license and copyright. In this case it should be something as:
Quoted 7 lines
/*
* EINVAL - negativetv_nsec
* EINVAL -tv_nsec> 1s
* ...
* EFAULT - invalid request pointer
* EFAULT - invalid remain pointer while interrupted by a signal */
Thanks for pointing this out. I will put these short comment explanations in my v3 version of this patch.
Best regards,
Filip
Quoted 24 lines
Quoted 24 lines
testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c +11
-1tst_ts_set_sec (rq, tc->tv_sec);tst_ts_set_nsec (rq, tc->tv_nsec); -TEST (tv->func (tc->clk_id, tc->flags,tst_ts_get (rq),tst_ts_get (rm))); +if (tc->ttype ==BAD_TS_ADDR_REQ ) + request =tst_get_bad_addr (cleanup); +else + request =tst_ts_get (rq); + +if (tc->ttype ==BAD_TS_ADDR_REM ) + remain =tst_get_bad_addr (cleanup); +else + remain =tst_ts_get (rm); + +TEST (tv->func (tc->clk_id, tc->flags, request, remain));if (tv->func == libc_clock_nanosleep) {/* Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/3 syscalls/{send|recv}mmsg: add a test case for timeout and errno test
In reply to Filip BozutaThis patch introduces a test case for the already existing test for syscalls 'sendmmsg()' and 'recvmmsg()' (sendmmsg01). This test case is meant to check whether the timeout is reached aproppriately after the first message is received. The timeout is set to 1 nsec as to make sure that it has to be reached. In this case the expected return value is 1 as the second message is not supposed be received after the timeout is reached.
* Note: No matter how small the timeout is, one message is always gonna have to be received because the timeout is checked only after a received message. This is an existing bug for syscall 'recvmmsg()':
https://man7.org/linux/man-pages/man2/recvmmsg.2.html#BUGS
This patch introduces a new test file for these syscalls (sendmmsg02.c). This test file is meant to check whether the aproppriate errno is set in some sitautions when these syscalls fail. These situations include:
bad socket file descriptor (EBADF), bad message vector address (EFAULT), bad timeout value (EINVAL), bad timeout address (EFAULT).
--- runtest/syscalls | 1 + testcases/kernel/syscalls/sendmmsg/.gitignore | 1 + .../kernel/syscalls/sendmmsg/sendmmsg01.c | 68 ++++-- .../kernel/syscalls/sendmmsg/sendmmsg02.c | 231 ++++++++++++++++++ 4 files changed, 286 insertions(+), 15 deletions(-) create mode 100644 testcases/kernel/syscalls/sendmmsg/sendmmsg02.c
runtest/syscalls +1 -0
@@ -1200,6 +1200,7 @@ sendmsg02 sendmsg02 sendmsg03 sendmsg03 sendmmsg01 sendmmsg01 +sendmmsg02 sendmmsg02 sendto01 sendto01 sendto02 sendto02
testcases/kernel/syscalls/sendmmsg/.gitignore +1 -0
@@ -1 +1,2 @@ sendmmsg01 +sendmmsg02
testcases/kernel/syscalls/sendmmsg/sendmmsg01.c +53 -15
108 lines not on this page · raw message
testcases/kernel/syscalls/sendmmsg/sendmmsg02.c new file +231 -0
231 lines not on this page · raw message
Signature · 1 line
2.25.1