syscalls: select: Add test to verify clearing of fd sets
PATCH 1/1 syscalls: select: Add test to verify clearing of fd sets
This adds a test to check if fd sets are cleared by select() or not in the event of a timeout when the read descriptor is empty or the write descriptor is full.
Suggested-by Cyril Hrubis <[email protected]>
Signed-off-by Viresh Kumar <[email protected]>
--- runtest/syscalls | 1 + testcases/kernel/syscalls/select/.gitignore | 1 + testcases/kernel/syscalls/select/select04.c | 82 +++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 testcases/kernel/syscalls/select/select04.c
runtest/syscalls +1 -0
@@ -1159,6 +1159,7 @@ sched_getattr02 sched_getattr02 select01 select01 select02 select02 select03 select03 +select04 select04 semctl01 semctl01 semctl02 semctl02
testcases/kernel/syscalls/select/.gitignore +1 -0
@@ -1,3 +1,4 @@ /select01 /select02 /select03 +/select04
testcases/kernel/syscalls/select/select04.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH 1/1 syscalls: select: Add test to verify clearing of fd sets
Hi!
Pushed with minor changes, thanks.
- moved the code that enables the bits to the run() function so that the test actually checks the condition on -i 2
- shortened the timeout so that the test runs fast enough
- formatted the top level comment properly, since we merged the docparse patchset special comments are exported into the generated documentation
Full diff:
testcases/kernel/syscalls/select/select04.c +14 -8
@@ -2,10 +2,18 @@/* * Copyright (c) 2020 Linaro Limited. All rights reserved. * Author: Viresh Kumar <[email protected]> -* -* Test to check if fd sets are cleared by select() or not. */ +/*\ +* [DESCRIPTION] +* +* Test to check if fd set bits are cleared by select(). +* +* [ALGORITHM] +* - Check that writefds flag is cleared on full pipe +* - Check that readfds flag is cleared on empty pipe +\*/ +#include <unistd.h> #include <errno.h> #include <sys/time.h>
@@ -29,12 +37,12 @@ static struct tcases {static void run (unsigned int n) {struct tcases *tc = &tests[n]; -struct timeval timeout; +struct timeval timeout = {.tv_sec =0 , .tv_usec =1000 }; - timeout.tv_sec =0 ; - timeout.tv_usec =100000 ; +FD_SET (fd_empty[0 ], &readfds_pipe); +FD_SET (fd_full[1 ], &writefds_pipe); -TEST (do_select (*tc->fd +1 , tc->readfds, tc->writefds,0 , &timeout)); +TEST (do_select (*tc->fd +1 , tc->readfds, tc->writefds,NULL , &timeout));if (TST_RET ) {tst_res (TFAIL ,"%s: select() should have timed out" , tc->desc);
@@ -58,11 +66,9 @@ static void setup(void)SAFE_PIPE (fd_empty);FD_ZERO (&readfds_pipe); -FD_SET (fd_empty[0 ], &readfds_pipe);SAFE_PIPE2 (fd_full,O_NONBLOCK );FD_ZERO (&writefds_pipe); -FD_SET (fd_full[1 ], &writefds_pipe);/* Make the write buffer full for fd_full */ do {
Signature · 2 lines
Cyril Hrubis [email protected]