Skip to contentSkip to conversation

syscalls: select: Add test to verify clearing of fd sets

PATCH New Viresh Kumar 2 participants 2 messages Nov 18, 2020

lore
Share & tools
lore
#0 lore raw

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.

---
 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
index aeacb8bc8312..a5363277f478 100644
@@ -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
index b6bff2d4f961..9d64cb8b8a1b 100644
@@ -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
#1 lore raw

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
index 8106dea8b..dd042562d 100644
@@ -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]