epoll_pwait/epoll_pwait01.c: add new testcase
PATCH 1/2 epoll_pwait/epoll_pwait01.c: add new testcase
Check that epoll_pwait(2) with sigmask argument allows the caller to safely wait until either a file descriptor becomes ready or the timeout expires.
--- configure.ac | 1 + m4/ltp-epoll_pwait.m4 | 25 +++ runtest/ltplite | 2 + runtest/stress.part3 | 2 + runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/epoll_pwait/Makefile | 23 +++ .../kernel/syscalls/epoll_pwait/epoll_pwait.h | 35 +++++ .../kernel/syscalls/epoll_pwait/epoll_pwait01.c | 174 +++++++++++++++++++++ 9 files changed, 264 insertions(+) create mode 100644 m4/ltp-epoll_pwait.m4 create mode 100644 testcases/kernel/syscalls/epoll_pwait/Makefile create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
configure.ac +1 -0
@@ -183,5 +183,6 @@ LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV LTP_CHECK_PWRITEV +LTP_CHECK_EPOLL_PWAIT AC_OUTPUT
m4/ltp-epoll_pwait.m4 new file +25 -0
@@ -0,0 +1,25 @@ +dnl +dnl Copyright (c) 2016 Fujitsu Ltd. +dnl Author: Guangwen Feng <[email protected]> +dnl +dnl This program is free software; you can redistribute it and/or modify +dnl it under the terms of the GNU General Public License as published by +dnl the Free Software Foundation; either version 2 of the License, or +dnl (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +dnl the GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with this program. +dnl + +dnl +dnl LTP_CHECK_EPOLL_PWAIT +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_EPOLL_PWAIT],[ +AC_CHECK_FUNCS(epoll_pwait,,) +])
runtest/ltplite +2 -0
@@ -160,6 +160,8 @@ dup203 dup203 dup204 dup204 dup205 dup205 +epoll_pwait01 epoll_pwait01 + execl01 execl01 execle01 execle01 execlp01 execlp01
runtest/stress.part3 +2 -0
@@ -101,6 +101,8 @@ dup203 dup203 dup204 dup204 dup205 dup205 +epoll_pwait01 epoll_pwait01 + execl01 execl01 execle01 execle01 execlp01 execlp01
runtest/syscalls +1 -0
@@ -123,6 +123,7 @@ dup3_02 dup3_02 epoll_create1_01 epoll_create1_01 epoll01 epoll-ltp +epoll_pwait01 epoll_pwait01 eventfd01 eventfd01
testcases/kernel/syscalls/.gitignore +1 -0
@@ -98,6 +98,7 @@ /dup3/dup3_02 /epoll/epoll-ltp /epoll_create1/epoll_create1_01 +/epoll_pwait/epoll_pwait01 /eventfd/eventfd01 /eventfd2/eventfd2_01 /eventfd2/eventfd2_02
testcases/kernel/syscalls/epoll_pwait/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +# +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Guangwen Feng <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: Guangwen Feng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. +*/ + +#ifndef EPOLL_PWAIT_H +#define EPOLL_PWAIT_H + +#include <sys/types.h> +#include "config.h" +#include "linux_syscall_numbers.h" + +#if !defined(HAVE_EPOLL_PWAIT ) +int epoll_pwait (int epfd,struct epoll_event *events,int maxevents, +int timeout,const sigset_t *sigmask) +{ +return ltp_syscall (__NR_epoll_pwait, epfd, events, maxevents, + timeout, sigmask); +} +#endif + +#endif /* EPOLL_PWAIT_H */
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH 2/2 epoll_pwait/epoll_pwait02.c: add new testcase
Verify that:
epoll_pwait(2) with NULL sigmask argument fails
if interrupted by a signal handler.
Expected result:
epoll_pwait(2) should return -1 and set errno to EINTR.
--- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + .../kernel/syscalls/epoll_pwait/epoll_pwait02.c | 161 +++++++++++++++++++++ 5 files changed, 165 insertions(+) create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait02.c
runtest/ltplite +1 -0
@@ -161,6 +161,7 @@ dup204 dup204 dup205 dup205 epoll_pwait01 epoll_pwait01 +epoll_pwait02 epoll_pwait02 execl01 execl01 execle01 execle01
runtest/stress.part3 +1 -0
@@ -102,6 +102,7 @@ dup204 dup204 dup205 dup205 epoll_pwait01 epoll_pwait01 +epoll_pwait02 epoll_pwait02 execl01 execl01 execle01 execle01
runtest/syscalls +1 -0
@@ -124,6 +124,7 @@ dup3_02 dup3_02 epoll_create1_01 epoll_create1_01 epoll01 epoll-ltp epoll_pwait01 epoll_pwait01 +epoll_pwait02 epoll_pwait02 eventfd01 eventfd01
testcases/kernel/syscalls/.gitignore +1 -0
@@ -99,6 +99,7 @@ /epoll/epoll-ltp /epoll_create1/epoll_create1_01 /epoll_pwait/epoll_pwait01 +/epoll_pwait/epoll_pwait02 /eventfd/eventfd01 /eventfd2/eventfd2_01 /eventfd2/eventfd2_02
testcases/kernel/syscalls/epoll_pwait/epoll_pwait02.c new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH 2/2 epoll_pwait/epoll_pwait02.c: add new testcase
Hi!
Quoted 3 lines
Verify that:
epoll_pwait(2)with NULL sigmask argument fails
if interrupted by a signal handler.
These two testcases are nearly identical, the difference is sinal mask for epoll_pwait() and function that child executes, right?. Why can't we implement both of them in one test?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 epoll_pwait/epoll_pwait01.c: add new testcase
Check that:
1) epoll_pwait(2) with sigmask argument allows the caller to safely wait until either a file descriptor becomes ready or the timeout expires.
2) epoll_pwait(2) with NULL sigmask argument fails if interrupted by a signal handler, epoll_pwait(2) should return -1 and set errno to EINTR.
--- configure.ac | 1 + m4/ltp-epoll_pwait.m4 | 25 +++ runtest/ltplite | 2 + runtest/stress.part3 | 2 + runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/epoll_pwait/Makefile | 23 +++ .../kernel/syscalls/epoll_pwait/epoll_pwait.h | 35 ++++ .../kernel/syscalls/epoll_pwait/epoll_pwait01.c | 191 +++++++++++++++++++++ 9 files changed, 281 insertions(+) create mode 100644 m4/ltp-epoll_pwait.m4 create mode 100644 testcases/kernel/syscalls/epoll_pwait/Makefile create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
configure.ac +1 -0
@@ -183,5 +183,6 @@ LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV LTP_CHECK_PWRITEV +LTP_CHECK_EPOLL_PWAIT AC_OUTPUT
m4/ltp-epoll_pwait.m4 new file +25 -0
@@ -0,0 +1,25 @@ +dnl +dnl Copyright (c) 2016 Fujitsu Ltd. +dnl Author: Guangwen Feng <[email protected]> +dnl +dnl This program is free software; you can redistribute it and/or modify +dnl it under the terms of the GNU General Public License as published by +dnl the Free Software Foundation; either version 2 of the License, or +dnl (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +dnl the GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with this program. +dnl + +dnl +dnl LTP_CHECK_EPOLL_PWAIT +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_EPOLL_PWAIT],[ +AC_CHECK_FUNCS(epoll_pwait,,) +])
runtest/ltplite +2 -0
@@ -159,6 +159,8 @@ dup203 dup203 dup204 dup204 dup205 dup205 +epoll_pwait01 epoll_pwait01 + execl01 execl01 execle01 execle01 execlp01 execlp01
runtest/stress.part3 +2 -0
@@ -100,6 +100,8 @@ dup203 dup203 dup204 dup204 dup205 dup205 +epoll_pwait01 epoll_pwait01 + execl01 execl01 execle01 execle01 execlp01 execlp01
runtest/syscalls +1 -0
@@ -122,6 +122,7 @@ dup3_02 dup3_02 epoll_create1_01 epoll_create1_01 epoll01 epoll-ltp +epoll_pwait01 epoll_pwait01 eventfd01 eventfd01
testcases/kernel/syscalls/.gitignore +1 -0
@@ -97,6 +97,7 @@ /dup3/dup3_02 /epoll/epoll-ltp /epoll_create1/epoll_create1_01 +/epoll_pwait/epoll_pwait01 /eventfd/eventfd01 /eventfd2/eventfd2_01 /eventfd2/eventfd2_02
testcases/kernel/syscalls/epoll_pwait/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +# +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Guangwen Feng <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: Guangwen Feng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. +*/ + +#ifndef EPOLL_PWAIT_H +#define EPOLL_PWAIT_H + +#include <sys/types.h> +#include "config.h" +#include "linux_syscall_numbers.h" + +#if !defined(HAVE_EPOLL_PWAIT ) +int epoll_pwait (int epfd,struct epoll_event *events,int maxevents, +int timeout,const sigset_t *sigmask) +{ +return ltp_syscall (__NR_epoll_pwait, epfd, events, maxevents, + timeout, sigmask); +} +#endif + +#endif /* EPOLL_PWAIT_H */
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +191 -0
191 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH v2 1/1 epoll_pwait/epoll_pwait01.c: add new testcase
Hi!
Quoted 129 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +129
-0+/* +* Description: +* Basic test for epoll_pwait(2). +* 1) epoll_pwait(2) with sigmask argument allows the caller to +* safely wait until either a file descriptor becomes ready +* or the timeout expires. +* 2) epoll_pwait(2) with NULL sigmask argument fails if +* interrupted by a signal handler, epoll_pwait(2) should +* return -1 and set errno to EINTR. +*/ + +#include <sys/epoll.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> + +#include "test.h" +#include "epoll_pwait.h" +#include "safe_macros.h" + +char *TCID ="epoll_pwait01" ; +int TST_TOTAL =2 ; + +static int epfd, fds[2 ]; +static const char buf[] ="Testing" ; +static sigset_t sigset; +static struct epoll_event epevs; +static struct sigaction sa; + +static void setup (void ); +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED); +static void do_test (sigset_t *); +static void do_child (void ); +static void cleanup (void ); + +int main (int ac,char **av) +{ +int lc; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + tst_count =0 ; + +do_test (&sigset); +do_test (NULL ); + } + +cleanup (); +tst_exit (); +} + +static void setup (void ) +{ +if ((tst_kvercmp (2 ,6 ,19 )) <0 ) { +tst_brkm (TCONF ,NULL ,"This test can only run on kernels " +"that are 2.6.19 or higher" ); + } + +tst_sig (FORK ,DEF_HANDLER , cleanup); + +TEST_PAUSE ; + +if (sigemptyset (&sigset) ==-1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"sigemptyset() failed" ); + +if (sigaddset (&sigset,SIGUSR1 ) ==-1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"sigaddset() failed" ); + + sa.sa_flags =0 ; + sa.sa_handler = sighandler; +if (sigemptyset (&sa.sa_mask) ==-1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"sigemptyset() failed" ); + +if (sigaction (SIGUSR1 , &sa,NULL ) ==-1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"sigaction() failed" ); + +SAFE_PIPE (NULL , fds); + + epfd =epoll_create (1 ); +if (epfd ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"failed to create epoll instance" ); + } + + epevs.events =EPOLLIN ; + epevs.data.fd = fds[0 ]; + +if (epoll_ctl (epfd,EPOLL_CTL_ADD , fds[0 ], &epevs) ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"failed to register epoll target" ); + } +} + +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) +{ + +} + +static void do_test (sigset_t *sigmask) +{ +char read_buf[sizeof (buf)]; +pid_t cpid; + + cpid =tst_fork (); +if (cpid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"fork() failed" ); + +if (cpid ==0 ) +do_child (); + +TEST (epoll_pwait (epfd, &epevs,1 ,-1 , sigmask)); + +if (sigmask !=NULL ) { +if (TEST_RETURN ==-1 ) { +tst_resm (TFAIL |TTERRNO ,"epoll_pwait() failed" ); + }else if (TEST_RETURN !=1 ) { +tst_resm (TFAIL ,"epoll_pwait() returned %li, " +"expected 1" ,TEST_RETURN ); + }else { +tst_resm (TPASS ,"epoll_pwait(sigmask) blocked signal" ); + } + }else { +if (TEST_RETURN !=-1 ) { +tst_resm (TFAIL ,"epoll_wait() succeeded unexpectedly" ); + }else {
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 157
Quoted 10 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +10
-0+if (TEST_ERRNO ==EINTR ) { +tst_resm (TPASS |TTERRNO , +"epoll_wait() failed as expected" ); + }else { +tst_resm (TFAIL |TTERRNO , +"epoll_wait() failed unexpectedly, " +"expected errno is EINTR" ); + } + } + }
Can we put the checks in a separate functions and call them from here?
Quoted 5 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +5
-0+tst_record_childstatus (cleanup, cpid); + +SAFE_READ (cleanup,1 , fds[0 ], read_buf,sizeof (buf)); +} +
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 173
Quoted 10 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +10
-0+static void do_child (void ) +{ +if (tst_process_state_wait2 (getppid (),'S' ) !=0 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"failed to wait for parent process's state" ); + } + +SAFE_KILL (cleanup,getppid (),SIGUSR1 ); + +sleep (1 );
One second is too much, 0.1 second should be more than enough for the test.
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 175
Quoted 1 line
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +1
-0+SAFE_WRITE (cleanup,1 , fds[1 ], buf,sizeof (buf));
Technically we don't have to write anything here (and we could exit the child without sleeping as well) if we passed a timeout to the epoll_pwait() instead in the parent (we would have to check for timeout instead of success but that shouldn't matter in this test).
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 72
Quoted 3 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +3
-0+cleanup (); +tst_exit (); +}
Otherwise it looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 epoll_pwait/epoll_pwait01.c: add new testcase
Hi!
Thanks for your review!
OK, I will modify the test case according to your suggestion.
Best Regards,
Guangwen Feng
Quoted 176 lines · Cyril Hrubis
Hi!
Quoted 129 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +129
-0+/* +* Description: +* Basic test for epoll_pwait(2). +* 1) epoll_pwait(2) with sigmask argument allows the caller to +* safely wait until either a file descriptor becomes ready +* or the timeout expires. +* 2) epoll_pwait(2) with NULL sigmask argument fails if +* interrupted by a signal handler, epoll_pwait(2) should +* return -1 and set errno to EINTR. +*/ + +#include <sys/epoll.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> +#include <errno.h> + +#include "test.h" +#include "epoll_pwait.h" +#include "safe_macros.h" + +char *TCID ="epoll_pwait01" ; +int TST_TOTAL =2 ; + +static int epfd, fds[2 ]; +static const char buf[] ="Testing" ; +static sigset_t sigset; +static struct epoll_event epevs; +static struct sigaction sa; + +static void setup (void ); +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED); +static void do_test (sigset_t *); +static void do_child (void ); +static void cleanup (void ); + +int main (int ac,char **av) +{ +int lc; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + tst_count =0 ; + +do_test (&sigset); +do_test (NULL ); + } + +cleanup (); +tst_exit (); +} + +static void setup (void ) +{ +if ((tst_kvercmp (2 ,6 ,19 )) <0 ) { +tst_brkm (TCONF ,NULL ,"This test can only run on kernels " +"that are 2.6.19 or higher" ); + } + +tst_sig (FORK ,DEF_HANDLER , cleanup); + +TEST_PAUSE ; + +if (sigemptyset (&sigset) ==-1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"sigemptyset() failed" ); + +if (sigaddset (&sigset,SIGUSR1 ) ==-1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"sigaddset() failed" ); + + sa.sa_flags =0 ; + sa.sa_handler = sighandler; +if (sigemptyset (&sa.sa_mask) ==-1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"sigemptyset() failed" ); + +if (sigaction (SIGUSR1 , &sa,NULL ) ==-1 ) +tst_brkm (TFAIL |TERRNO ,NULL ,"sigaction() failed" ); + +SAFE_PIPE (NULL , fds); + + epfd =epoll_create (1 ); +if (epfd ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"failed to create epoll instance" ); + } + + epevs.events =EPOLLIN ; + epevs.data.fd = fds[0 ]; + +if (epoll_ctl (epfd,EPOLL_CTL_ADD , fds[0 ], &epevs) ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"failed to register epoll target" ); + } +} + +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) +{ + +} + +static void do_test (sigset_t *sigmask) +{ +char read_buf[sizeof (buf)]; +pid_t cpid; + + cpid =tst_fork (); +if (cpid <0 ) +tst_brkm (TBROK |TERRNO , cleanup,"fork() failed" ); + +if (cpid ==0 ) +do_child (); + +TEST (epoll_pwait (epfd, &epevs,1 ,-1 , sigmask)); + +if (sigmask !=NULL ) { +if (TEST_RETURN ==-1 ) { +tst_resm (TFAIL |TTERRNO ,"epoll_pwait() failed" ); + }else if (TEST_RETURN !=1 ) { +tst_resm (TFAIL ,"epoll_pwait() returned %li, " +"expected 1" ,TEST_RETURN ); + }else { +tst_resm (TPASS ,"epoll_pwait(sigmask) blocked signal" ); + } + }else { +if (TEST_RETURN !=-1 ) { +tst_resm (TFAIL ,"epoll_wait() succeeded unexpectedly" ); + }else {testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 157
Quoted 10 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +10
-0+if (TEST_ERRNO ==EINTR ) { +tst_resm (TPASS |TTERRNO , +"epoll_wait() failed as expected" ); + }else { +tst_resm (TFAIL |TTERRNO , +"epoll_wait() failed unexpectedly, " +"expected errno is EINTR" ); + } + } + }Can we put the checks in a separate functions and call them from here?
Quoted 5 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +5
-0+tst_record_childstatus (cleanup, cpid); + +SAFE_READ (cleanup,1 , fds[0 ], read_buf,sizeof (buf)); +} +testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 173
Quoted 10 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +10
-0+static void do_child (void ) +{ +if (tst_process_state_wait2 (getppid (),'S' ) !=0 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"failed to wait for parent process's state" ); + } + +SAFE_KILL (cleanup,getppid (),SIGUSR1 ); + +sleep (1 );One second is too much, 0.1 second should be more than enough for the test.
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 175
Quoted 1 line
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +1
-0+SAFE_WRITE (cleanup,1 , fds[1 ], buf,sizeof (buf));Technically we don't have to write anything here (and we could exit the child without sleeping as well) if we passed a timeout to the
epoll_pwait()instead in the parent (we would have to check for timeout instead of success but that shouldn't matter in this test).testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 72
Quoted 3 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +3
-0+cleanup (); +tst_exit (); +}Otherwise it looks good.
PATCH v3 1/1 epoll_pwait/epoll_pwait01.c: add new testcase
Check that:
1) epoll_pwait(2) with sigmask argument allows the caller to safely wait until either a file descriptor becomes ready or the timeout expires.
2) epoll_pwait(2) with NULL sigmask argument fails if interrupted by a signal handler, epoll_pwait(2) should return -1 and set errno to EINTR.
--- configure.ac | 1 + m4/ltp-epoll_pwait.m4 | 25 +++ runtest/ltplite | 2 + runtest/stress.part3 | 2 + runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/epoll_pwait/Makefile | 23 +++ .../kernel/syscalls/epoll_pwait/epoll_pwait.h | 35 ++++ .../kernel/syscalls/epoll_pwait/epoll_pwait01.c | 194 +++++++++++++++++++++ 9 files changed, 284 insertions(+) create mode 100644 m4/ltp-epoll_pwait.m4 create mode 100644 testcases/kernel/syscalls/epoll_pwait/Makefile create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h create mode 100644 testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
configure.ac +1 -0
@@ -183,5 +183,6 @@ LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV LTP_CHECK_PWRITEV +LTP_CHECK_EPOLL_PWAIT AC_OUTPUT
m4/ltp-epoll_pwait.m4 new file +25 -0
@@ -0,0 +1,25 @@ +dnl +dnl Copyright (c) 2016 Fujitsu Ltd. +dnl Author: Guangwen Feng <[email protected]> +dnl +dnl This program is free software; you can redistribute it and/or modify +dnl it under the terms of the GNU General Public License as published by +dnl the Free Software Foundation; either version 2 of the License, or +dnl (at your option) any later version. +dnl +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +dnl the GNU General Public License for more details. +dnl +dnl You should have received a copy of the GNU General Public License +dnl along with this program. +dnl + +dnl +dnl LTP_CHECK_EPOLL_PWAIT +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_EPOLL_PWAIT],[ +AC_CHECK_FUNCS(epoll_pwait,,) +])
runtest/ltplite +2 -0
@@ -163,6 +163,8 @@ epoll_wait01 epoll_wait01 epoll_wait02 epoll_wait02 epoll_wait03 epoll_wait03 +epoll_pwait01 epoll_pwait01 + execl01 execl01 execle01 execle01 execlp01 execlp01
runtest/stress.part3 +2 -0
@@ -104,6 +104,8 @@ epoll_wait01 epoll_wait01 epoll_wait02 epoll_wait02 epoll_wait03 epoll_wait03 +epoll_pwait01 epoll_pwait01 + execl01 execl01 execle01 execle01 execlp01 execlp01
runtest/syscalls +1 -0
@@ -125,6 +125,7 @@ epoll01 epoll-ltp epoll_wait01 epoll_wait01 epoll_wait02 epoll_wait02 epoll_wait03 epoll_wait03 +epoll_pwait01 epoll_pwait01 eventfd01 eventfd01
testcases/kernel/syscalls/.gitignore +1 -0
@@ -100,6 +100,7 @@ /epoll_wait/epoll_wait01 /epoll_wait/epoll_wait02 /epoll_wait/epoll_wait03 +/epoll_pwait/epoll_pwait01 /eventfd/eventfd01 /eventfd2/eventfd2_01 /eventfd2/eventfd2_02
testcases/kernel/syscalls/epoll_pwait/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +# +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Guangwen Feng <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: Guangwen Feng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. +*/ + +#ifndef EPOLL_PWAIT_H +#define EPOLL_PWAIT_H + +#include <sys/types.h> +#include "config.h" +#include "linux_syscall_numbers.h" + +#if !defined(HAVE_EPOLL_PWAIT ) +int epoll_pwait (int epfd,struct epoll_event *events,int maxevents, +int timeout,const sigset_t *sigmask) +{ +return ltp_syscall (__NR_epoll_pwait, epfd, events, maxevents, + timeout, sigmask); +} +#endif + +#endif /* EPOLL_PWAIT_H */
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +194 -0
194 lines not on this page · raw message
Signature · 1 line
1.8.4.2
PATCH v3 1/1 epoll_pwait/epoll_pwait01.c: add new testcase
Hi!
Pushed with two changes, thanks.
testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h line 31
Quoted 13 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h new file +13
-0+#ifndef EPOLL_PWAIT_H +#define EPOLL_PWAIT_H + +#include <sys/types.h> +#include "config.h" +#include "linux_syscall_numbers.h" + +#if !defined(HAVE_EPOLL_PWAIT) +int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, + int timeout, const sigset_t *sigmask) +{ + return ltp_syscall(__NR_epoll_pwait, epfd, events, maxevents, + timeout, sigmask);
The syscall takes one more parameter than the glibc wrapper. I had to add the size of the sigmask i.e. _NSIG/8 here otherwise we will get EINVAL from kernel.
Quoted 2 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h new file +2
-0+} +#endif
...
Quoted 5 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +5
-0+static void verify_nonsigmask (void ) +{ +if (TEST_RETURN !=-1 ) { +tst_resm (TFAIL ,"epoll_wait() succeeded unexpectedly" ); + }else {
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c line 143
Quoted 10 lines
testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c new file +10
-0+if (TEST_ERRNO ==EINTR ) { +tst_resm (TPASS |TTERRNO , +"epoll_wait() failed as expected" ); + }else { +tst_resm (TFAIL |TTERRNO , +"epoll_wait() failed unexpectedly, " +"expected errno is EINTR" ); + } + } +}
And changed these two verify function to use return after tst_resm() so that we don't have to do the else-if spagetti code.
Signature · 2 lines
Cyril Hrubis [email protected]