epoll: Add more basic test for epoll_{create, create1, ctl}
cover epoll: Add more basic test for epoll_{create, create1, ctl}
Xie Ziyao (7):
epoll_ctl: Add docparse formatting and cleanup for epoll_ctl01
epoll_ctl: Add docparse formatting and cleanup for epoll_ctl02
epoll_ctl: Add test for epoll_ctl03
epoll_create1: Add docparse formatting and cleanup for
epoll_create1_01
epoll_create1: Add test for epoll_create1_02
epoll_create: Add test for epoll_create01
epoll_create: Add test for epoll_create02
runtest/syscalls | 4 + .../kernel/syscalls/epoll_create/.gitignore | 2 + .../kernel/syscalls/epoll_create/Makefile | 9 ++ .../syscalls/epoll_create/epoll_create01.c | 40 +++++++++ .../syscalls/epoll_create/epoll_create02.c | 37 ++++++++ .../kernel/syscalls/epoll_create1/.gitignore | 3 +- .../syscalls/epoll_create1/epoll_create1_01.c | 53 ++++++----- .../syscalls/epoll_create1/epoll_create1_02.c | 38 ++++++++ .../kernel/syscalls/epoll_ctl/.gitignore | 5 +- .../kernel/syscalls/epoll_ctl/epoll_ctl01.c | 28 +++--- .../kernel/syscalls/epoll_ctl/epoll_ctl02.c | 87 +++++++------------ .../kernel/syscalls/epoll_ctl/epoll_ctl03.c | 75 ++++++++++++++++ 12 files changed, 280 insertions(+), 101 deletions(-) create mode 100644 testcases/kernel/syscalls/epoll_create/.gitignore create mode 100644 testcases/kernel/syscalls/epoll_create/Makefile create mode 100644 testcases/kernel/syscalls/epoll_create/epoll_create01.c create mode 100644 testcases/kernel/syscalls/epoll_create/epoll_create02.c create mode 100644 testcases/kernel/syscalls/epoll_create1/epoll_create1_02.c create mode 100644 testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c
--
2.17.1
PATCH 1/7 epoll_ctl: Add docparse formatting and cleanup for epoll_ctl01
Add docparse formatting and fix warnings from checkpatch.pl for epoll_ctl01.
--- .../kernel/syscalls/epoll_ctl/epoll_ctl01.c | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-)
testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c +13 -15
@@ -4,25 +4,22 @@* Author: Xiao Yang <[email protected]> */ -/* -* Test Name: epoll_ctl01.c +/*\ +* [Description] * -* Description: -* Testcase to check the basic functionality of the epoll_ctl(2). -* 1) when epoll_ctl(2) succeeds to register fd on the epoll instance and -* associates event with fd, epoll_wait(2) will get registered fd and -* event correctly. -* 2) when epoll_ctl(2) succeeds to chage event which is related to fd, -* epoll_wait(2) will get chaged event correctly. -* 3) when epoll_ctl(2) succeeds to deregister fd from the epoll instance -* epoll_wait(2) won't get deregistered fd and event. +* Check the basic functionality of the epoll_ctl: * +* - When epoll_ctl succeeds to register fd on the epoll instance and associates +* event with fd, epoll_wait will get registered fd and event correctly. +* - When epoll_ctl succeeds to change event which is related to fd, epoll_wait +* will get changed event correctly. +* - When epoll_ctl succeeds to deregister fd from the epoll instance epoll_wait +* won't get deregistered fd and event. */ -#include <sys/epoll.h> #include <poll.h> -#include <string.h> -#include <errno.h> +#include <sys/epoll.h> +#include "tst_test.h" static int epfd;
@@ -88,9 +85,10 @@ static void check_epoll_ctl(int opt, int exp_num)while (events) {int events_matched =0 ; -memset (res_evs,0 ,sizeof (res_evs)); +memset (res_evs,0 ,sizeof (res_evs)); res =epoll_wait (epfd, res_evs,2 ,-1 ); +if (res <=0 ) {tst_res (TFAIL |TERRNO ,"epoll_wait() returned %i" , res);
--
2.17.1
PATCH 1/7 epoll_ctl: Add docparse formatting and cleanup for epoll_ctl01
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/7 epoll_ctl: Add docparse formatting and cleanup for epoll_ctl02
In reply to Xie Ziyao1. Add docparse formatting.
2. Make use of TST_EXP_FAIL(...).
3. Add test for events=NULL.
--- .../kernel/syscalls/epoll_ctl/epoll_ctl02.c | 87 +++++++------------ 1 file changed, 32 insertions(+), 55 deletions(-)
testcases/kernel/syscalls/epoll_ctl/epoll_ctl02.c +32 -55
@@ -4,34 +4,23 @@* Author: Xiao Yang <[email protected]> */ -/* -* Test Name: epoll_ctl02.c -* -* Description: -* 1) epoll_ctl(2) fails if epfd is a invalid file descriptor. -* 2) epoll_ctl(2) fails if fd is a invalid file descriptor. -* 3) epoll_ctl(2) fails if op is not supported by this interface. -* 4) epoll_ctl(2) fails if fd is the same as epfd. -* 5) epoll_ctl(2) fails with EPOLL_CTL_DEL if fd is not registered -* with this epoll instance. -* 6) epoll_ctl(2) fails with EPOLL_CTL_MOD if fd is not registered -* with this epoll instance. -* 7) epoll_ctl(2) fails with EPOLL_CTL_ADD if fd is already registered -* with this epoll instance. -* -* Expected Result: -* 1) epoll_ctl(2) should return -1 and set errno to EBADF. -* 2) epoll_ctl(2) should return -1 and set errno to EBADF. -* 3) epoll_ctl(2) should return -1 and set errno to EINVAL. -* 4) epoll_ctl(2) should return -1 and set errno to EINVAL. -* 5) epoll_ctl(2) should return -1 and set errno to ENOENT. -* 6) epoll_ctl(2) should return -1 and set errno to ENOENT. -* 7) epoll_ctl(2) should return -1 and set errno to EEXIST. +/*\ +* [Description] * +* Verify that, +* - epoll_ctl fails with EBADF if epfd is an invalid fd. +* - epoll_ctl fails with EBADF if fd is an invalid fd. +* - epoll_ctl fails with EINVAL if op is not supported. +* - epoll_ctl fails with EINVAL if fd is the same as epfd. +* - epoll_ctl fails with EINVAL if events is NULL. +* - epoll_ctl fails with ENOENT if fd is not registered with EPOLL_CTL_DEL. +* - epoll_ctl fails with ENOENT if fd is not registered with EPOLL_CTL_MOD. +* - epoll_ctl fails with EEXIST if fd is already registered with EPOLL_CTL_ADD. */ -#include <sys/epoll.h> +#include <poll.h> -#include <errno.h> +#include <sys/epoll.h> +#include "tst_test.h" static int epfd;
@@ -44,19 +33,21 @@ static struct epoll_event events[2] = { };static struct testcase { -int *epfds; +int *epfd;int opt; -int *fds; -struct epoll_event *ts_event; +int *fd; +struct epoll_event *event;int exp_err; -} tcases[] = { - {&inv,EPOLL_CTL_ADD , &fd[1 ], &events[1 ],EBADF }, - {&epfd,EPOLL_CTL_ADD , &inv, &events[1 ],EBADF }, - {&epfd,-1 , &fd[1 ], &events[1 ],EINVAL }, - {&epfd,EPOLL_CTL_ADD , &epfd, &events[1 ],EINVAL }, - {&epfd,EPOLL_CTL_DEL , &fd[1 ], &events[1 ],ENOENT }, - {&epfd,EPOLL_CTL_MOD , &fd[1 ], &events[1 ],ENOENT }, - {&epfd,EPOLL_CTL_ADD , &fd[0 ], &events[0 ],EEXIST } +const char *desc; +} tc[] = { + {&inv,EPOLL_CTL_ADD , &fd[1 ], &events[1 ],EBADF ,"epfd is an invalid fd" }, + {&epfd,EPOLL_CTL_ADD , &inv, &events[1 ],EBADF ,"fd is an invalid fd" }, + {&epfd,-1 , &fd[1 ], &events[1 ],EINVAL ,"op is not supported" }, + {&epfd,EPOLL_CTL_ADD , &epfd, &events[1 ],EINVAL ,"fd is the same as epfd" }, + {&epfd,EPOLL_CTL_ADD , &fd[1 ],NULL ,EFAULT ,"events is NULL" }, + {&epfd,EPOLL_CTL_DEL , &fd[1 ], &events[1 ],ENOENT ,"fd is not registered with EPOLL_CTL_DEL" }, + {&epfd,EPOLL_CTL_MOD , &fd[1 ], &events[1 ],ENOENT ,"fd is not registered with EPOLL_CTL_MOD" }, + {&epfd,EPOLL_CTL_ADD , &fd[0 ], &events[0 ],EEXIST ,"fd is already registered with EPOLL_CTL_ADD" } };static void setup (void )
@@ -70,9 +61,8 @@ static void setup(void) events[0 ].data.fd = fd[0 ]; events[1 ].data.fd = fd[1 ]; -TEST (epoll_ctl (epfd,EPOLL_CTL_ADD , fd[0 ], &events[0 ])); -if (TST_RET ==-1 ) -tst_brk (TFAIL |TTERRNO ,"epoll_ctl() fails to init" ); +if (epoll_ctl (epfd,EPOLL_CTL_ADD , fd[0 ], &events[0 ])) +tst_brk (TBROK |TERRNO ,"epoll_clt(..., EPOLL_CTL_ADD, ...)" ); }static void cleanup (void )
@@ -89,25 +79,12 @@ static void cleanup(void)static void verify_epoll_ctl (unsigned int n) { -struct testcase *tc = &tcases[n]; - -TEST (epoll_ctl (*tc->epfds, tc->opt, *tc->fds, tc->ts_event)); -if (TST_RET !=-1 ) { -tst_res (TFAIL ,"epoll_ctl() succeeds unexpectedly" ); -return ; - } - -if (tc->exp_err ==TST_ERR ) { -tst_res (TPASS |TTERRNO ,"epoll_ctl() fails as expected" ); - }else { -tst_res (TFAIL |TTERRNO , -"epoll_ctl() fails unexpectedly, expected %i: %s" , - tc->exp_err,tst_strerrno (tc->exp_err)); - } +TST_EXP_FAIL (epoll_ctl (*tc[n].epfd, tc[n].opt, *tc[n].fd, tc[n].event), + tc[n].exp_err,"epoll_clt(...) if %s" , tc[n].desc); }static struct tst_test test = { - .tcnt =ARRAY_SIZE (tcases), + .tcnt =ARRAY_SIZE (tc), .setup = setup, .cleanup = cleanup, .test = verify_epoll_ctl,
--
2.17.1
PATCH 2/7 epoll_ctl: Add docparse formatting and cleanup for epoll_ctl02
Hi!
Pushed with a minor change to the documentation comment, thanks.
Quoted 4 lines
+/*\
+ * [Description]
*
+ * Verify that,
Quoted 8 lines
+ * -
epoll_ctlfails with EBADF if epfd is an invalid fd.
+ * -epoll_ctlfails with EBADF if fd is an invalid fd.
+ * -epoll_ctlfails with EINVAL if op is not supported.
+ * -epoll_ctlfails with EINVAL if fd is the same as epfd.
+ * -epoll_ctlfails with EINVAL if events is NULL.
+ * -epoll_ctlfails with ENOENT if fd is not registered withEPOLL_CTL_DEL.
+ * -epoll_ctlfails with ENOENT if fd is not registered withEPOLL_CTL_MOD.
+ * -epoll_ctlfails with EEXIST if fd is already registered withEPOLL_CTL_ADD.
There is no reason to repeat the 'epoll_ctl fails with' so I've moved it to the "Verify that," part and also there has to be empty line after the "Verify that..." so that the list renders as a list in asciidoc.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/7 epoll_ctl: Add test for epoll_ctl03
In reply to Xie ZiyaoCheck that epoll_ctl returns zero with different combinations of events on success.
--- runtest/syscalls | 1 + .../kernel/syscalls/epoll_ctl/.gitignore | 5 +- .../kernel/syscalls/epoll_ctl/epoll_ctl03.c | 75 +++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c
runtest/syscalls +1 -0
@@ -160,6 +160,7 @@ epoll_create1_01 epoll_create1_01 epoll01 epoll-ltp epoll_ctl01 epoll_ctl01 epoll_ctl02 epoll_ctl02 +epoll_ctl03 epoll_ctl03 epoll_wait01 epoll_wait01 epoll_wait02 epoll_wait02 epoll_wait03 epoll_wait03
testcases/kernel/syscalls/epoll_ctl/.gitignore +3 -2
@@ -1,2 +1,3 @@ -/epoll_ctl01 -/epoll_ctl02 +epoll_ctl01 +epoll_ctl02 +epoll_ctl03
testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c new file +75 -0
75 lines not on this page · raw message
--
2.17.1
PATCH 3/7 epoll_ctl: Add test for epoll_ctl03
testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c line 36
Quoted 13 lines
testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c new file +13
-0+static void run_all (void ) +{ +unsigned int index, events_bitmap; + +for (index =0 ; index <WIDTH_EPOLL_EVENTS ; index++) { + events_bitmap = ((EPOLLIN * ((index &0x01 ) >>0 )) | + (EPOLLOUT * ((index &0x02 ) >>1 )) | + (EPOLLPRI * ((index &0x04 ) >>2 )) | + (EPOLLERR * ((index &0x08 ) >>3 )) | + (EPOLLHUP * ((index &0x10 ) >>4 )) | + (EPOLLET * ((index &0x20 ) >>5 )) | + (EPOLLONESHOT * ((index &0x40 ) >>6 )) | + (EPOLLRDHUP * ((index &0x80 ) >>7 )));
I guess that we can as well add a IS_BIT_SET() macro that would do:
#define IS_BIT_SET(val, bit) (((val) & (1<<(bit))) >> (bit))
And use that here instead.
Otherwise it looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/7 epoll_ctl: Add test for epoll_ctl03
Hi, Cyril,
Quoted 16 lines
testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c line 36
Quoted 13 lines
testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c new file +13
-0+static void run_all (void ) +{ +unsigned int index, events_bitmap; + +for (index =0 ; index <WIDTH_EPOLL_EVENTS ; index++) { + events_bitmap = ((EPOLLIN * ((index &0x01 ) >>0 )) | + (EPOLLOUT * ((index &0x02 ) >>1 )) | + (EPOLLPRI * ((index &0x04 ) >>2 )) | + (EPOLLERR * ((index &0x08 ) >>3 )) | + (EPOLLHUP * ((index &0x10 ) >>4 )) | + (EPOLLET * ((index &0x20 ) >>5 )) | + (EPOLLONESHOT * ((index &0x40 ) >>6 )) | + (EPOLLRDHUP * ((index &0x80 ) >>7 )));I guess that we can as well add a
IS_BIT_SET()macro that would do:
Quoted 1 line
#define
IS_BIT_SET(val, bit)(((val) & (1<<(bit))) >> (bit))
Looks good, thanks. I've added this macro to include/tst_bitmap.h in the v2 patchset, other changes have also been applied.
Besides, I've used a different outlook email to submit and hope it doesn't cause misunderstandings.
Quoted 5 lines
And use that here instead.
Otherwise it looks good.
Please see: https://patchwork.ozlabs.org/project/ltp/list/?series=259628
Thanks for your review.
Signature · 3 lines
Best Regards, Xie Ziyao E-mail:[email protected]
PATCH 4/7 epoll_create1: Add docparse formatting and cleanup for epoll_create1_01
In reply to Xie Ziyao1. Add docparse formatting.
2. Make use of ARRAY_SIZE().
--- .../syscalls/epoll_create1/epoll_create1_01.c | 53 +++++++++---------- .../syscalls/epoll_create1/epoll_create1_02.c | 0 2 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 testcases/kernel/syscalls/epoll_create1/epoll_create1_02.c
testcases/kernel/syscalls/epoll_create1/epoll_create1_01.c +25 -28
@@ -2,51 +2,48 @@/* * Copyright (c) Ulrich Drepper <[email protected]> * Copyright (c) International Business Machines Corp., 2009 +*/ + +/*\ +* [Description] * -* Test system call introduced in 2.6.27. -* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=a0998b50c3f0b8fdd265c63e0032f86ebe377dbf -* -* This patch adds the new epoll_create1 syscall. It extends the old -* epoll_create syscall by one parameter which is meant to hold a flag value. -* In this patch the only flag support is EPOLL_CLOEXEC which causes the -* close-on-exec flag for the returned file descriptor to be set. A new name -* EPOLL_CLOEXEC is introduced which in this implementation must have the same -* value as O_CLOEXEC. +* Verify that epoll_create1 sets the close-on-exec flag for the returned +* file descriptor with the only flag support, EPOLL_CLOEXEC. */ -#include <errno.h> +#include <sys/epoll.h> +#include "tst_test.h" #include "lapi/epoll.h" #include "lapi/syscalls.h" -static void verify_epoll_create1 (void ) +static struct test_case_t { +int flags; +int exp_flag; +const char *desc; +} tc[] = { + {0 ,0 ,"flags=0 didn't set close-on-exec flag" }, + {EPOLL_CLOEXEC ,1 ,"flags=EPOLL_CLOEXEC set close-on-exec" } +}; + +static void run (unsigned int n) {int fd, coe; - fd =tst_syscall (__NR_epoll_create1,0 ); + fd =tst_syscall (__NR_epoll_create1, tc[n].flags);if (fd ==-1 ) -tst_brk (TFAIL |TERRNO ,"epoll_create1(0) failed" ); +tst_brk (TFAIL |TERRNO ,"epoll_create1(...) failed" ); coe =SAFE_FCNTL (fd,F_GETFD ); -if (coe &FD_CLOEXEC ) -tst_brk (TFAIL ,"flags=0 set close-on-exec flag" ); +if ((coe &FD_CLOEXEC ) != tc[n].exp_flag) +tst_brk (TFAIL ,"epoll_create1(...) with %s" , tc[n].desc); +tst_res (TPASS ,"epoll_create1(...) with %s" , tc[n].desc);SAFE_CLOSE (fd); - - fd =tst_syscall (__NR_epoll_create1,EPOLL_CLOEXEC ); -if (fd ==-1 ) -tst_brk (TFAIL |TERRNO ,"epoll_create1(EPOLL_CLOEXEC) failed" ); - - coe =SAFE_FCNTL (fd,F_GETFD ); -if ((coe &FD_CLOEXEC ) ==0 ) -tst_brk (TFAIL ,"flags=EPOLL_CLOEXEC didn't set close-on-exec" ); - -SAFE_CLOSE (fd); - -tst_res (TPASS ,"epoll_create1(EPOLL_CLOEXEC) PASSED" ); }static struct tst_test test = { .min_kver ="2.6.27" , - .test_all = verify_epoll_create1, + .tcnt =ARRAY_SIZE (tc), + .test = run, };
testcases/kernel/syscalls/epoll_create1/epoll_create1_02.c new file +0 -0
--
2.17.1
PATCH 4/7 epoll_create1: Add docparse formatting and cleanup for epoll_create1_01
Hi!
Pushed with a few changes, thanks.
The main problem was that the commit added empty epoll_create1_02.c which did break the compilation and had to be removed.
Apart from that I've changed the tst_brk(TFAIL, ...) to tst_res(TFAIL, ...) since there is no real need for tst_brk() and adjusted the messages a bit.
diff:
testcases/kernel/syscalls/epoll_create1/epoll_create1_01.c +6 -5
@@ -8,7 +8,7 @@* [Description] * * Verify that epoll_create1 sets the close-on-exec flag for the returned -* file descriptor with the only flag support, EPOLL_CLOEXEC. +* file descriptor with EPOLL_CLOEXEC. */ #include <sys/epoll.h>
@@ -22,8 +22,8 @@ static struct test_case_t {int exp_flag;const char *desc; } tc[] = { - {0, 0, "flags=0 didn't set close-on-exec flag"}, - {EPOLL_CLOEXEC, 1, "flags=EPOLL_CLOEXEC set close-on-exec"} + {0, 0, "without EPOLL_CLOEXEC"}, + {EPOLL_CLOEXEC, 1, "with EPOLL_CLOEXEC"} };static void run (unsigned int n)
@@ -36,8 +36,9 @@ static void run(unsigned int n) coe =SAFE_FCNTL (fd,F_GETFD );if ((coe &FD_CLOEXEC ) != tc[n].exp_flag) -tst_brk (TFAIL ,"epoll_create1(...) with %s" , tc[n].desc); -tst_res (TPASS ,"epoll_create1(...) with %s" , tc[n].desc); +tst_res (TFAIL ,"epoll_create1(...) %s" , tc[n].desc); +else +tst_res (TPASS ,"epoll_create1(...) %s" , tc[n].desc);SAFE_CLOSE (fd); }
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 5/7 epoll_create1: Add test for epoll_create1_02
In reply to Xie ZiyaoVerify that epoll_create1 returns -1 and set errno to EINVAL with an invalid value specified in flags.
--- runtest/syscalls | 1 + .../kernel/syscalls/epoll_create1/.gitignore | 3 +- .../syscalls/epoll_create1/epoll_create1_02.c | 38 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-)
runtest/syscalls +1 -0
@@ -157,6 +157,7 @@ dup3_01 dup3_01 dup3_02 dup3_02 epoll_create1_01 epoll_create1_01 +epoll_create1_02 epoll_create1_02 epoll01 epoll-ltp epoll_ctl01 epoll_ctl01 epoll_ctl02 epoll_ctl02
testcases/kernel/syscalls/epoll_create1/.gitignore +2 -1
@@ -1 +1,2 @@ -/epoll_create1_01 +epoll_create1_01 +epoll_create1_02
testcases/kernel/syscalls/epoll_create1/epoll_create1_02.c +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. +* Author: Xie Ziyao <[email protected]> +*/ + +/*\ +* [Description] +* +* Verify that epoll_create1 returns -1 and set errno to EINVAL with an invalid +* value specified in flags. +*/ + +#include <sys/epoll.h> + +#include "tst_test.h" +#include "lapi/epoll.h" +#include "lapi/syscalls.h" + +static struct test_case_t { +int flags; +int exp_err; +const char *desc; +} tc[] = { + {-1 ,EINVAL ,"-1" }, + {EPOLL_CLOEXEC +1 ,EINVAL ,"EPOLL_CLOEXEC+1" } +}; + +static void run (unsigned int n) +{ +TST_EXP_FAIL (tst_syscall (__NR_epoll_create1, tc[n].flags), + tc[n].exp_err,"create(%s)" , tc[n].desc); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tc), + .test = run, +};
--
2.17.1
PATCH 5/7 epoll_create1: Add test for epoll_create1_02
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 6/7 epoll_create: Add test for epoll_create01
In reply to Xie ZiyaoVerify that epoll_create return a nonnegative file descriptor on success.
--- runtest/syscalls | 1 + .../kernel/syscalls/epoll_create/.gitignore | 1 + .../kernel/syscalls/epoll_create/Makefile | 9 +++++ .../syscalls/epoll_create/epoll_create01.c | 40 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 testcases/kernel/syscalls/epoll_create/.gitignore create mode 100644 testcases/kernel/syscalls/epoll_create/Makefile create mode 100644 testcases/kernel/syscalls/epoll_create/epoll_create01.c
runtest/syscalls +1 -0
@@ -156,6 +156,7 @@ dup205 dup205 dup3_01 dup3_01 dup3_02 dup3_02 +epoll_create01 epoll_create01 epoll_create1_01 epoll_create1_01 epoll_create1_02 epoll_create1_02 epoll01 epoll-ltp
testcases/kernel/syscalls/epoll_create/.gitignore new file +1 -0
@@ -0,0 +1 @@ +epoll_create01
testcases/kernel/syscalls/epoll_create/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. +# Author: Xie Ziyao <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/epoll_create/epoll_create01.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. +* Author: Xie Ziyao <[email protected]> +*/ + +/*\ +* [Description] +* +* Verify that epoll_create return a nonnegative file descriptor on success. +* +* The size argument informed the kernel of the number of file descriptors +* that the caller expected to add to the epoll instance, but it is no longer +* required. +*/ + +#include <sys/epoll.h> + +#include "tst_test.h" +#include "lapi/epoll.h" +#include "lapi/syscalls.h" + +static int tc[] = {1 ,INT_MAX }; + +static void run (unsigned int n) +{ +int fd; + + fd =tst_syscall (__NR_epoll_create, tc[n]); +if (fd <0 ) +tst_brk (TFAIL |TERRNO ,"epoll_create(%d) failed" , tc[n]); +tst_res (TPASS ,"epoll_create(%d)" , tc[n]); + +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tc), + .test = run, +};
--
2.17.1
PATCH 6/7 epoll_create: Add test for epoll_create01
Hi!
testcases/kernel/syscalls/epoll_create/epoll_create01.c line 32
Quoted 4 lines
testcases/kernel/syscalls/epoll_create/epoll_create01.c new file +4
-0+ fd =tst_syscall (__NR_epoll_create, tc[n]); +if (fd <0 ) +tst_brk (TFAIL |TERRNO ,"epoll_create(%d) failed" , tc[n]); +tst_res (TPASS ,"epoll_create(%d)" , tc[n]);
We even have TST_EXP_FD() exactly for this case.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 7/7 epoll_create: Add test for epoll_create02
In reply to Xie ZiyaoVerify that epoll_create returns -1 and set errno to EINVAL if size is not positive.
--- runtest/syscalls | 1 + .../kernel/syscalls/epoll_create/.gitignore | 1 + .../syscalls/epoll_create/epoll_create02.c | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 testcases/kernel/syscalls/epoll_create/epoll_create02.c
runtest/syscalls +1 -0
@@ -157,6 +157,7 @@ dup3_01 dup3_01 dup3_02 dup3_02 epoll_create01 epoll_create01 +epoll_create02 epoll_create02 epoll_create1_01 epoll_create1_01 epoll_create1_02 epoll_create1_02 epoll01 epoll-ltp
testcases/kernel/syscalls/epoll_create/.gitignore +1 -0
@@ -1 +1,2 @@ epoll_create01 +epoll_create02
testcases/kernel/syscalls/epoll_create/epoll_create02.c new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. +* Author: Xie Ziyao <[email protected]> +*/ + +/*\ +* [Description] +* +* Verify that epoll_create returns -1 and set errno to EINVAL if size is not +* positive. +*/ + +#include <sys/epoll.h> + +#include "tst_test.h" +#include "lapi/epoll.h" +#include "lapi/syscalls.h" + +static struct test_case_t { +int size; +int exp_err; +} tc[] = { + {0 ,EINVAL }, + {-1 ,EINVAL } +}; + +static void run (unsigned int n) +{ +TST_EXP_FAIL (tst_syscall (__NR_epoll_create, tc[n].size), + tc[n].exp_err,"create(%d)" , tc[n].size); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tc), + .test = run, +};
--
2.17.1
PATCH 7/7 epoll_create: Add test for epoll_create02
Hi!
This one looks fine, but needs the previous patch applied first.
Signature · 2 lines
Cyril Hrubis [email protected]