syscalls/epoll_*: allow for epoll_wait returning a subset of events
PATCH v2 1/2 syscalls/epoll_*: allow for epoll_wait returning a subset of events
The epoll_wait syscall is not guaranteed to return all pending events - a subset may be returned. Modify the epoll_wait01 and epoll_ctl01 testcases to allow for that.
--- testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c | 52 ++++++++++---------- .../kernel/syscalls/epoll_wait/epoll_wait01.c | 55 ++++++++++++---------- 2 files changed, 57 insertions(+), 50 deletions(-)
testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c +27 -25
@@ -85,41 +85,43 @@ static int has_event(struct epoll_event *epvs, int len,static void check_epoll_ctl (int opt,int exp_num) {int res; - +unsigned int events;char write_buf[] ="test" ;char read_buf[sizeof (write_buf)]; +struct epoll_event res_evs[2 ]; -struct epoll_event res_evs[2 ] = { - {.events =0 , .data.fd =0 }, - {.events =0 , .data.fd =0 } - }; + events =EPOLLIN ; +if (exp_num ==2 ) + events |=EPOLLOUT ;SAFE_WRITE (1 , fd[1 ], write_buf,sizeof (write_buf)); - res =epoll_wait (epfd, res_evs,2 ,-1 ); -if (res ==-1 ) -tst_brk (TBROK |TERRNO ,"epoll_wait() fails" ); - -if (res != exp_num) { -tst_res (TFAIL ,"epoll_wait() returns %i, expected %i" , - res, exp_num); - goto end; - } +while (events) { +int events_matched =0 ; +bzero (res_evs,sizeof (res_evs)); -if (exp_num ==1 ) { -if (!has_event (res_evs,2 , fd[0 ],EPOLLIN ) || - !has_event (res_evs,2 ,0 ,0 )) { -tst_res (TFAIL ,"epoll_wait() fails to " -"get expected fd and event" ); + res =epoll_wait (epfd, res_evs,2 ,-1 ); +if (res <=0 ) { +tst_res (TFAIL |TERRNO ,"epoll_wait() returned %i" , + res); goto end; } - } -if (exp_num ==2 ) { -if (!has_event (res_evs,2 , fd[0 ],EPOLLIN ) || - !has_event (res_evs,2 , fd[1 ],EPOLLOUT )) { -tst_res (TFAIL ,"epoll_wait() fails to " -"get expected fd and event" ); +if ((events &EPOLLIN ) && +has_event (res_evs,2 , fd[0 ],EPOLLIN )) { + events_matched++; + events &= ~EPOLLIN ; + } + +if ((events &EPOLLOUT ) && +has_event (res_evs,2 , fd[1 ],EPOLLOUT )) { + events_matched++; + events &= ~EPOLLOUT ; + } + +if (res != events_matched) { +tst_res (TFAIL , +"epoll_wait() returned unexpected events" ); goto end; } }
testcases/kernel/syscalls/epoll_wait/epoll_wait01.c +30 -25
64 lines not on this page · raw message
Signature · 1 line
2.14.0.rc0.400.g1c36432dff-goog
PATCH v2 2/2 syscalls/epoll_wait01: cleanup data structure usage
The fds2 data structure is not used during the test, remove it. Ensure the event structure that epoll_wait() writes into is cleared prior to invoking the call so that the returned data is confidently known.
--- .../kernel/syscalls/epoll_wait/epoll_wait01.c | 49 ++++++++++------------ 1 file changed, 22 insertions(+), 27 deletions(-)
testcases/kernel/syscalls/epoll_wait/epoll_wait01.c +22 -27
@@ -34,11 +34,10 @@char *TCID ="epoll_wait01" ;int TST_TOTAL =3 ; -static int write_size, epfd, fds[2 ], fds2[2 ]; -static struct epoll_event epevs[3 ] = { +static int write_size, epfd, fds[2 ]; +static struct epoll_event epevs[2 ] = { {.events =EPOLLIN }, {.events =EPOLLOUT }, - {.events =EPOLLIN } };static void setup (void );
@@ -77,7 +76,6 @@ static void setup(void)TEST_PAUSE ;SAFE_PIPE (NULL , fds); -SAFE_PIPE (cleanup, fds2); write_size =get_writesize ();
@@ -89,11 +87,9 @@ static void setup(void) epevs[0 ].data.fd = fds[0 ]; epevs[1 ].data.fd = fds[1 ]; - epevs[2 ].data.fd = fds2[0 ];if (epoll_ctl (epfd,EPOLL_CTL_ADD , fds[0 ], &epevs[0 ]) || -epoll_ctl (epfd,EPOLL_CTL_ADD , fds[1 ], &epevs[1 ]) || -epoll_ctl (epfd,EPOLL_CTL_ADD , fds2[0 ], &epevs[2 ])) { +epoll_ctl (epfd,EPOLL_CTL_ADD , fds[1 ], &epevs[1 ])) {tst_brkm (TBROK |TERRNO , cleanup,"failed to register epoll target" ); }
@@ -128,7 +124,9 @@ static int get_writesize(void)static void verify_epollout (void ) { -TEST (epoll_wait (epfd, epevs,3 ,-1 )); +struct epoll_event ret_evs = {.events =0 , .data.fd =0 }; + +TEST (epoll_wait (epfd, &ret_evs,1 ,-1 ));if (TEST_RETURN ==-1 ) {tst_resm (TFAIL |TTERRNO ,"epoll_wait() epollout failed" );
@@ -141,15 +139,15 @@ static void verify_epollout(void)return ; } -if (epevs[0 ].data.fd != fds[1 ]) { +if (ret_evs.data.fd != fds[1 ]) {tst_resm (TFAIL ,"epoll.data.fd %i, expected %i" , - epevs[0 ].data.fd, fds[1 ]); + ret_evs.data.fd, fds[1 ]);return ; } -if (epevs[0 ].events !=EPOLLOUT ) { +if (ret_evs.events !=EPOLLOUT ) {tst_resm (TFAIL ,"epoll.events %x, expected EPOLLOUT %x" , - epevs[0 ].events,EPOLLOUT ); + ret_evs.events,EPOLLOUT );return ; }
@@ -160,12 +158,13 @@ static void verify_epollin(void) {char write_buf[write_size];char read_buf[sizeof (write_buf)]; +struct epoll_event ret_evs = {.events =0 , .data.fd =0 };memset (write_buf,'a' ,sizeof (write_buf));SAFE_WRITE (cleanup,1 , fds[1 ], write_buf,sizeof (write_buf)); -TEST (epoll_wait (epfd, epevs,3 ,-1 )); +TEST (epoll_wait (epfd, &ret_evs,1 ,-1 ));if (TEST_RETURN ==-1 ) {tst_resm (TFAIL |TTERRNO ,"epoll_wait() epollin failed" );
@@ -178,15 +177,15 @@ static void verify_epollin(void) goto end; } -if (epevs[0 ].data.fd != fds[0 ]) { +if (ret_evs.data.fd != fds[0 ]) {tst_resm (TFAIL ,"epoll.data.fd %i, expected %i" , - epevs[0 ].data.fd, fds[0 ]); + ret_evs.data.fd, fds[0 ]); goto end; } -if (epevs[0 ].events !=EPOLLIN ) { +if (ret_evs.events !=EPOLLIN ) {tst_resm (TFAIL ,"epoll.events %x, expected EPOLLIN %x" , - epevs[0 ].events,EPOLLIN ); + ret_evs.events,EPOLLIN ); goto end; }
@@ -201,13 +200,15 @@ static void verify_epollio(void)char write_buf[] ="Testing" ;char read_buf[sizeof (write_buf)];uint32_t events =EPOLLIN |EPOLLOUT ; +struct epoll_event ret_evs[2 ];SAFE_WRITE (cleanup,1 , fds[1 ], write_buf,sizeof (write_buf));while (events) {int events_matched =0 ; -TEST (epoll_wait (epfd, epevs,3 ,-1 )); +bzero (ret_evs,sizeof (ret_evs)); +TEST (epoll_wait (epfd, ret_evs,2 ,-1 ));if (TEST_RETURN <=0 ) { tst_resm(TFAIL | TTERRNO, "epoll_wait() returned %i",
@@ -216,13 +217,13 @@ static void verify_epollio(void) }if ((events &EPOLLIN ) && -has_event (epevs,2 , fds[0 ],EPOLLIN )) { +has_event (ret_evs,2 , fds[0 ],EPOLLIN )) { events_matched++; events &= ~EPOLLIN ; }if ((events &EPOLLOUT ) && -has_event (epevs,2 , fds[1 ],EPOLLOUT )) { +has_event (ret_evs,2 , fds[1 ],EPOLLOUT )) { events_matched++; events &= ~EPOLLOUT ; }
@@ -230,7 +231,7 @@ static void verify_epollio(void)if (TEST_RETURN != events_matched) {tst_resm (TFAIL ,"epoll_wait() returned unexpected events" ); -dump_epevs (epevs,2 ); +dump_epevs (ret_evs,2 ); goto end; } }
@@ -274,10 +275,4 @@ static void cleanup(void)if (close (fds[1 ]))tst_resm (TWARN |TERRNO ,"failed to close fds[1]" ); - -if (fds2[0 ] >0 &&close (fds2[0 ])) -tst_resm (TWARN |TERRNO ,"failed to close fds2[0]" ); - -if (fds2[1 ] >0 &&close (fds2[1 ])) -tst_resm (TWARN |TERRNO ,"failed to close fds2[1]" ); }
Signature · 1 line
2.14.0.rc0.400.g1c36432dff-goog
PATCH v2 2/2 syscalls/epoll_wait01: cleanup data structure usage
Hi!
testcases/kernel/syscalls/epoll_wait/epoll_wait01.c static void verify_epollio(void) · line 214
Quoted 2 lines
testcases/kernel/syscalls/epoll_wait/epoll_wait01.c +0
-0if (TEST_RETURN <=0 ) { tst_resm(TFAIL | TTERRNO, "epoll_wait() returned %i",
^
The TEST_RETURN is long hence this has to be %li
I've ammended this changed to this patch and pushed both, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]