syscalls: select: Merge few tests and migrate to new format
PATCH v3 1/3 syscalls: select: Merge few tests and migrate to new format
This merges the first three tests and updates them to new test format.
---
V3:
- Improved print message
- Improved comment at the top
runtest/quickhit | 8 +- runtest/syscalls | 2 - testcases/kernel/syscalls/select/.gitignore | 2 - testcases/kernel/syscalls/select/select01.c | 168 ++++++++------------ testcases/kernel/syscalls/select/select02.c | 114 ------------- testcases/kernel/syscalls/select/select03.c | 134 ---------------- 6 files changed, 66 insertions(+), 362 deletions(-) delete mode 100644 testcases/kernel/syscalls/select/select02.c delete mode 100644 testcases/kernel/syscalls/select/select03.c
runtest/quickhit +1 -7
@@ -179,14 +179,8 @@ rename02 rename02 sbrk01 sbrk01 # Basic test for sbrk(2) select01 select01 -# select to a file -# TEST CASES -# 1.) select(2) to a fd of regular file with no I/O and small timeout -select02 select02 -# select of system pipe fds -select03 select03 +# Basic select tests select04 select04 -# select of fd of a named-pipe (FIFO) setgid01 setgid01 # Basic test for setgid(2) setpgid01 setpgid01
runtest/syscalls +0 -2
@@ -1150,8 +1150,6 @@ sched_getattr01 sched_getattr01 sched_getattr02 sched_getattr02 select01 select01 -select02 select02 -select03 select03 select04 select04 semctl01 semctl01
testcases/kernel/syscalls/select/.gitignore +0 -2
@@ -1,4 +1,2 @@ /select01 -/select02 -/select03 /select04
testcases/kernel/syscalls/select/select01.c +65 -103
191 lines not on this page · raw message
testcases/kernel/syscalls/select/select02.c deleted +0 -114
114 lines not on this page · raw message
testcases/kernel/syscalls/select/select03.c deleted +0 -134
134 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v3 1/3 syscalls: select: Merge few tests and migrate to new format
Quoted 8 lines · Viresh Kumar
This merges the first three tests and updates them to new test format.
Acked-by Li Wang <[email protected]>Signed-off-by Viresh Kumar <[email protected]>---
V3:
- Improved print message
- Improved comment at the top
Ping.
Signature · 1 line
viresh
PATCH v3 2/3 syscalls: select: Verify that data is available to read
In reply to Viresh Kumarselect() returns a positive value on success if timeout hasn't happened, else returns 0. Check that and send some data to the write file descriptor for the same.
--- testcases/kernel/syscalls/select/select01.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/select/select01.c +10 -3
@@ -25,25 +25,32 @@ static struct select_info {int *nfds;fd_set *readfds;fd_set *writefds; +int *writefd;char *desc; } tests[] = { - {&fd_reg, &readfds_reg, NULL, "with regular file"}, - {&fds_pipe[1], &readfds_pipe, &writefds_pipe, "with system pipe"}, - {&fd_npipe, &readfds_npipe, &writefds_npipe, "with named pipe (FIFO)"}, + {&fd_reg, &readfds_reg, NULL, NULL, "with regular file"}, + {&fds_pipe[1], &readfds_pipe, &writefds_pipe, &fds_pipe[1], "with system pipe"}, + {&fd_npipe, &readfds_npipe, &writefds_npipe, &fd_npipe, "with named pipe (FIFO)"}, }; static void run(unsigned int n) { struct select_info *tc = &tests[n]; struct timeval timeout; + char buf; timeout.tv_sec = 0; timeout.tv_usec = 100000; + if (tc->writefd) + SAFE_WRITE(0, *tc->writefd, &buf, sizeof(buf)); + TEST(do_select(*tc->nfds + 1, tc->readfds, tc->writefds, 0, &timeout)); if (TST_RET == -1) tst_res(TFAIL | TTERRNO, "select() failed %s", tc->desc); + else if (!TST_RET) + tst_res(TFAIL, "select() timed out %s", tc->desc); else tst_res(TPASS, "select() passed %s", tc->desc); }
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v3 2/3 syscalls: select: Verify that data is available to read
Hi!
Quoted 30 lines
select()returns a positive value on success if timeout hasn't happened, else returns 0. Check that and send some data to the write file descriptor for the same.Acked-by Li Wang <[email protected]>Signed-off-by Viresh Kumar <[email protected]>--- testcases/kernel/syscalls/select/select01.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)testcases/kernel/syscalls/select/select01.c +4
-3@@ -25,25 +25,32 @@ static struct select_info {int *nfds;fd_set *readfds;fd_set *writefds; +int *writefd;char *desc; } tests[] = { - {&fd_reg, &readfds_reg, NULL, "with regular file"}, - {&fds_pipe[1], &readfds_pipe, &writefds_pipe, "with system pipe"}, - {&fd_npipe, &readfds_npipe, &writefds_npipe, "with named pipe (FIFO)"}, + {&fd_reg, &readfds_reg, NULL, NULL, "with regular file"}, + {&fds_pipe[1], &readfds_pipe, &writefds_pipe, &fds_pipe[1], "with system pipe"}, + {&fd_npipe, &readfds_npipe, &writefds_npipe, &fd_npipe, "with named pipe (FIFO)"}, }; static void run(unsigned int n)
testcases/kernel/syscalls/select/select01.c static struct select_info { · line 46
Quoted 10 lines
testcases/kernel/syscalls/select/select01.c +3
-0{struct select_info *tc = &tests[n];struct timeval timeout; +char buf; timeout.tv_sec =0 ; timeout.tv_usec =100000 ; +if (tc->writefd) +SAFE_WRITE (0 , *tc->writefd, &buf,sizeof (buf));
I'm not sure why we are writing data here. For both the pipe and fifo the select() will return that we can write there, hence the return would be non-zero regardless.
Also I would like to be more specific. E.g. expecting specific return instead of just non-zero and also making sure the right bits are enabled in the fd sets.
Quoted 12 lines
testcases/kernel/syscalls/select/select01.c +2
-0TEST (do_select (*tc->nfds +1 , tc->readfds, tc->writefds,0 , &timeout));if (TST_RET ==-1 )tst_res (TFAIL |TTERRNO ,"select() failed %s" , tc->desc); +else if (!TST_RET ) +tst_res (TFAIL ,"select() timed out %s" , tc->desc);else tst_res (TPASS ,"select() passed %s" , tc->desc); }Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 2/3 syscalls: select: Verify that data is available to read
Quoted 39 lines · Cyril Hrubis
Hi!
Quoted 38 lines
select()returns a positive value on success if timeout hasn't happened, else returns 0. Check that and send some data to the write file descriptor for the same.Acked-by Li Wang <[email protected]>Signed-off-by Viresh Kumar <[email protected]>--- testcases/kernel/syscalls/select/select01.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)testcases/kernel/syscalls/select/select01.c +5
-3@@ -25,25 +25,32 @@ static struct select_info {int *nfds;fd_set *readfds;fd_set *writefds; +int *writefd;char *desc; } tests[] = { - {&fd_reg, &readfds_reg, NULL, "with regular file"}, - {&fds_pipe[1], &readfds_pipe, &writefds_pipe, "with system pipe"}, - {&fd_npipe, &readfds_npipe, &writefds_npipe, "with named pipe (FIFO)"}, + {&fd_reg, &readfds_reg, NULL, NULL, "with regular file"}, + {&fds_pipe[1], &readfds_pipe, &writefds_pipe, &fds_pipe[1], "with system pipe"}, + {&fd_npipe, &readfds_npipe, &writefds_npipe, &fd_npipe, "with named pipe (FIFO)"}, }; static void run(unsigned int n) { struct select_info *tc = &tests[n]; struct timeval timeout; + char buf; timeout.tv_sec = 0; timeout.tv_usec = 100000;
Quoted 6 lines
testcases/kernel/syscalls/select/select01.c static struct select_info { · line 46
Quoted 2 lines
testcases/kernel/syscalls/select/select01.c +2
-0+if (tc->writefd) +SAFE_WRITE (0 , *tc->writefd, &buf,sizeof (buf));I'm not sure why we are writing data here. For both the pipe and fifo the
select()will return that we can write there, hence the return would be non-zero regardless.
Maybe I haven't understood what you meant when you said this earlier:
And the coverate in these tests is a bit lacking, we do not have a single tests that would send a data over a pipe to a fd select is watching and check that select was woken up by that. There is no such test in the pselect/ directory either.
Quoted 3 lines
Also I would like to be more specific. E.g. expecting specific return instead of just non-zero and also making sure the right bits are enabled in the fd sets.
Something like this ?
testcases/kernel/syscalls/select/select01.c +6 -1
@@ -38,12 +38,15 @@ static void run(unsigned int n)struct tcases *tc = &tests[n];struct timeval timeout;char buf; +int exp_ret =1 ; timeout.tv_sec =0 ; timeout.tv_usec =100000 ; -if (tc->writefd) +if (tc->writefd) {SAFE_WRITE (0 , *tc->writefd, &buf,sizeof (buf)); + exp_ret++; + }TEST (do_select (*tc->nfds +1 , tc->readfds, tc->writefds,0 , &timeout));
@@ -51,6 +54,8 @@ static void run(unsigned int n)tst_res (TFAIL |TTERRNO ,"select() failed %s" , tc->desc); else if (!TST_RET) tst_res(TFAIL, "select() timed out %s", tc->desc); + else if (TST_RET != exp_ret) + tst_res(TFAIL, "select() returned incorrect value: %s, expected: %d, got: %lu", tc->desc, exp_ret, TST_RET); else tst_res(TPASS, "select() passed %s", tc->desc); }
Signature · 1 line
viresh
PATCH v3 2/3 syscalls: select: Verify that data is available to read
Hi!
Quoted 7 lines
Maybe I haven't understood what you meant when you said this earlier:
And the coverate in these tests is a bit lacking, we do not have a single tests that would send a data over a pipe to a fd select is watching and check that select was woken up by that. There is no such test in the pselect/ directory either.
Quoted 5 lines
Quoted 3 lines
Also I would like to be more specific. E.g. expecting specific return instead of just non-zero and also making sure the right bits are enabled in the fd sets.
Something like this ?
This is much better, I suppose that we should as well check the individual bits in the fd_sets to make it perfect.
Quoted 33 lines
testcases/kernel/syscalls/select/select01.c +6
-1@@ -38,12 +38,15 @@ static void run(unsigned int n)struct tcases *tc = &tests[n];struct timeval timeout;char buf; +int exp_ret =1 ; timeout.tv_sec =0 ; timeout.tv_usec =100000 ; -if (tc->writefd) +if (tc->writefd) {SAFE_WRITE (0 , *tc->writefd, &buf,sizeof (buf)); + exp_ret++; + }TEST (do_select (*tc->nfds +1 , tc->readfds, tc->writefds,0 , &timeout));@@ -51,6 +54,8 @@ static void run(unsigned int n)tst_res (TFAIL |TTERRNO ,"select() failed %s" , tc->desc); else if (!TST_RET) tst_res(TFAIL, "select() timed out %s", tc->desc); + else if (TST_RET != exp_ret) + tst_res(TFAIL, "select() returned incorrect value: %s, expected: %d, got: %lu", tc->desc, exp_ret, TST_RET); else tst_res(TPASS, "select() passed %s", tc->desc); }Signature · 2 lines
-- viresh
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 2/3 syscalls: select: Verify that data is available to read
In reply to Viresh Kumarselect() returns a positive value on success if timeout hasn't happened, else returns 0. Check that and send some data to the write file descriptor for the same.
---
V4:
- test individual bits in the fd_sets to verify properly.
testcases/kernel/syscalls/select/select01.c | 23 +++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/select/select01.c +19 -4
@@ -25,27 +25,42 @@ static struct tcases {int *nfds;fd_set *readfds;fd_set *writefds; +int *readfd; +int *writefd;char *desc; } tests[] = { - {&fd_reg, &readfds_reg, NULL, "with regular file"}, - {&fds_pipe[1], &readfds_pipe, &writefds_pipe, "with system pipe"}, - {&fd_npipe, &readfds_npipe, &writefds_npipe, "with named pipe (FIFO)"}, + {&fd_reg, &readfds_reg, NULL, &fd_reg, NULL, "with regular file"}, + {&fds_pipe[1], &readfds_pipe, &writefds_pipe, &fds_pipe[0], &fds_pipe[1], "with system pipe"}, + {&fd_npipe, &readfds_npipe, &writefds_npipe, &fd_npipe, &fd_npipe, "with named pipe (FIFO)"}, }; static void run(unsigned int n) { struct tcases *tc = &tests[n]; struct timeval timeout; + char buf; + int exp_ret = 1; timeout.tv_sec = 0; timeout.tv_usec = 100000; + if (tc->writefd) { + SAFE_WRITE(0, *tc->writefd, &buf, sizeof(buf)); + exp_ret++; + } + TEST(do_select(*tc->nfds + 1, tc->readfds, tc->writefds, 0, &timeout)); if (TST_RET == -1) tst_res(TFAIL | TTERRNO, "select() failed %s", tc->desc); - else + else if (!TST_RET) + tst_res(TFAIL, "select() timed out %s", tc->desc); + else if (TST_RET != exp_ret) + tst_res(TFAIL, "select() returned incorrect value %s, expected: %d, got: %lu", tc->desc, exp_ret, TST_RET); + else if (FD_ISSET(*tc->readfd, tc->readfds) && (!tc->writefd || FD_ISSET(*tc->writefd, tc->writefds))) tst_res(TPASS, "select() passed %s", tc->desc); + else + tst_res(TFAIL, "select() returned expected value %s, but all file descriptors aren't ready", tc->desc); } static void setup(void)
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v4 2/3 syscalls: select: Verify that data is available to read
Hi!
testcases/kernel/syscalls/select/select01.c static struct tcases { · line 63
Quoted 8 lines
testcases/kernel/syscalls/select/select01.c +7
-0+else if (!TST_RET ) +tst_res (TFAIL ,"select() timed out %s" , tc->desc); +else if (TST_RET != exp_ret) +tst_res (TFAIL ,"select() returned incorrect value %s, expected: %d, got: %lu" , tc->desc, exp_ret,TST_RET ); +else if (FD_ISSET (*tc->readfd, tc->readfds) && (!tc->writefd ||FD_ISSET (*tc->writefd, tc->writefds)))tst_res (TPASS ,"select() passed %s" , tc->desc); +else +tst_res (TFAIL ,"select() returned expected value %s, but all file descriptors aren't ready" , tc->desc);
In the end I've rewritten this part to use returns in order to avoid this if else maze with overly long lines and pushed, thanks.
I guess that we still need a test where select would clear the bits from fd->set though, I supposes that the easiest solution would be to add select04.c for that...
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v4 2/3 syscalls: select: Verify that data is available to read
Quoted 3 lines · Cyril Hrubis
I guess that we still need a test where select would clear the bits from
fd->setthough, I supposes that the easiest solution would be to addselect04.cfor that...
I am not sure how to do that and why would that matter ? :)
Signature · 1 line
viresh
PATCH v4 2/3 syscalls: select: Verify that data is available to read
Hi!
Quoted 5 lines
Quoted 3 lines
I guess that we still need a test where select would clear the bits from
fd->setthough, I supposes that the easiest solution would be to addselect04.cfor that...I am not sure how to do that and why would that matter ? :)
So the tests we do have now are checking that the bits in the fdset are not cleared when there are data ready to be read/written from/to the filke descriptor, right?
What we need is a test where we ask for a data to be read from an empty pipe, ask for data to be written to a pipe filled with data (write there till we get EAGAIN in setup), etc. We can do this with a very short timeout or even with a timeout set to zero (polling) and check that the bits were cleared once we have returned from the call.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 3/3 syscalls: select: Rename select04.c to select02.c
In reply to Viresh KumarDo the rename.
---
runtest/quickhit | 2 +-
runtest/syscalls | 2 +-
testcases/kernel/syscalls/select/.gitignore | 2 +-
testcases/kernel/syscalls/select/{select04.c => select02.c} | 0
4 files changed, 3 insertions(+), 3 deletions(-)
rename testcases/kernel/syscalls/select/{select04.c => select02.c} (100%)runtest/quickhit +1 -1
@@ -180,7 +180,7 @@ sbrk01 sbrk01 # Basic test for sbrk(2) select01 select01 # Basic select tests -select04 select04 +select02 select02 setgid01 setgid01 # Basic test for setgid(2) setpgid01 setpgid01
runtest/syscalls +1 -1
@@ -1150,7 +1150,7 @@ sched_getattr01 sched_getattr01 sched_getattr02 sched_getattr02 select01 select01 -select04 select04 +select02 select02 semctl01 semctl01 semctl02 semctl02
testcases/kernel/syscalls/select/.gitignore +1 -1
@@ -1,2 +1,2 @@ /select01 -/select04 +/select02
testcases/kernel/syscalls/select/select02.c renamed from testcases/kernel/syscalls/select/select04.c +0 -0
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v3 3/3 syscalls: select: Rename select04.c to select02.c
Hi!
We will have to implement a test for the errors as well, so I wouldn't rename the test like this yet.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 3/3 syscalls: select: Rename select04.c to select02.c
Quoted 3 lines · Cyril Hrubis
Hi!
We will have to implement a test for the errors as well, so I wouldn't rename the test like this yet.
Maybe just pick it up as is (so I don't need to resend it) and then apply below patch:
-------------------------8<-------------------------
From b35b85ecaab98f3e3711a7f6fc2642c96657ee18 Mon Sep 17 00:00:00 2001
Message-Id: <b35b85ecaab98f3e3711a7f6fc2642c96657ee18.1603107392.git.viresh.kumar@linaro.org>
From: Viresh Kumar <[email protected]>
Date: Mon, 19 Oct 2020 17:06:02 +0530
Subject: [PATCH] syscalls: select: Add failure tests
This adds a variety of failure tests to select() syscall.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/select/.gitignore | 1 + testcases/kernel/syscalls/select/select03.c | 95 +++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 testcases/kernel/syscalls/select/select03.c
runtest/syscalls +1 -0
@@ -1157,6 +1157,7 @@ sched_getattr02 sched_getattr02 select01 select01 select02 select02 +select03 select03 semctl01 semctl01 semctl02 semctl02
testcases/kernel/syscalls/select/.gitignore +1 -0
@@ -1,2 +1,3 @@ /select01 /select02 +/select03
testcases/kernel/syscalls/select/select03.c new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v3 3/3 syscalls: select: Rename select04.c to select02.c
Hi!
Quoted 2 lines
Maybe just pick it up as is (so I don't need to resend it) and then apply below patch:
Sure.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 4/4 syscalls: select: Add failure tests
In reply to Viresh KumarThis adds a variety of failure tests to select() syscalls. Another helper is added in select_var.h to make sure we don't access a bad address while reading/writing the timeout value.
---
I am resending the patch formally here and marking it as V2 as I fixed an issue with it.
runtest/syscalls | 1 + testcases/kernel/syscalls/select/.gitignore | 1 + testcases/kernel/syscalls/select/select03.c | 96 +++++++++++++++++++ testcases/kernel/syscalls/select/select_var.h | 55 ++++++++--- 4 files changed, 138 insertions(+), 15 deletions(-) create mode 100644 testcases/kernel/syscalls/select/select03.c
runtest/syscalls +1 -0
@@ -1157,6 +1157,7 @@ sched_getattr02 sched_getattr02 select01 select01 select02 select02 +select03 select03 semctl01 semctl01 semctl02 semctl02
testcases/kernel/syscalls/select/.gitignore +1 -0
@@ -1,2 +1,3 @@ /select01 /select02 +/select03
testcases/kernel/syscalls/select/select03.c new file +96 -0
96 lines not on this page · raw message
testcases/kernel/syscalls/select/select_var.h +40 -15
78 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v2 4/4 syscalls: select: Add failure tests
Hi!
Pushed with cosmetic changes, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/3 syscalls: select: Merge few tests and migrate to new format
In reply to Viresh KumarHi!
Quoted 1 line
+static struct
select_info{
^
I've renamed this to struct tcases because we do have a select_info function as well...
And pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]