Skip to contentSkip to conversation

Add more epoll tests

PATCH In review Cyril Hrubis 4 participants 36 messages Jul 9 – Jul 14 Library code

lore
Share & tools
lore
#0 lore raw

v3 cover Add more epoll tests

This patchset adds much more epoll tests, with that the coverage is mostly complete so that we can remove the old and ugly epoll-ltp test.

v3:
- fixed failures pointed out by Li
- added :manpage: links to doc comments
- fixed doc comments (as requested by ltp-agent)
- fixed copyrights
- added SAFE_POLL()
- simplified epoll_wait10 (as requested by Andrea)

Cyril Hrubis (9):
syscalls: Add epoll_create03
syscalls: Add epoll_wait08
syscalls: Add epoll_wait09
syscalls: Add epoll_ctl06
syscalls: Add epoll_wait10
syscalls: Add epoll_wait11
SAFE_MACROS: Add SAFE_POLL()
syscalls: Add epoll_wait12
syscalls: Remove old epoll-ltp test

 include/tst_safe_macros.h                     |   6 +
 lib/tst_safe_macros.c                         |  18 +
 runtest/syscalls                              |  12 +-
 testcases/kernel/syscalls/epoll/.gitignore    |   1 -
 testcases/kernel/syscalls/epoll/Makefile      |   8 -
 testcases/kernel/syscalls/epoll/README.1ST    |  38 -
 testcases/kernel/syscalls/epoll/epoll-ltp.c   | 738 ------------------
 .../kernel/syscalls/epoll_create/.gitignore   |   1 +
 .../syscalls/epoll_create/epoll_create03.c    |  72 ++
 .../kernel/syscalls/epoll_ctl/.gitignore      |   1 +
 .../kernel/syscalls/epoll_ctl/epoll_ctl06.c   |  72 ++
 .../kernel/syscalls/epoll_wait/.gitignore     |   5 +
 .../kernel/syscalls/epoll_wait/epoll_wait08.c |  69 ++
 .../kernel/syscalls/epoll_wait/epoll_wait09.c | 132 ++++
 .../kernel/syscalls/epoll_wait/epoll_wait10.c | 103 +++
 .../kernel/syscalls/epoll_wait/epoll_wait11.c |  93 +++
 .../kernel/syscalls/epoll_wait/epoll_wait12.c | 111 +++
 17 files changed, 694 insertions(+), 786 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/epoll/.gitignore
 delete mode 100644 testcases/kernel/syscalls/epoll/Makefile
 delete mode 100644 testcases/kernel/syscalls/epoll/README.1ST
 delete mode 100644 testcases/kernel/syscalls/epoll/epoll-ltp.c
 create mode 100644 testcases/kernel/syscalls/epoll_create/epoll_create03.c
 create mode 100644 testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait08.c
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait09.c
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait10.c
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait11.c
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait12.c
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v3 1/9 syscalls: Add epoll_create03

Test that checks that we get EMFILE when limit on per-process file descriptors is hit.

---
 runtest/syscalls                              |  2 +
 .../kernel/syscalls/epoll_create/.gitignore   |  1 +
 .../syscalls/epoll_create/epoll_create03.c    | 72 +++++++++++++++++++
 3 files changed, 75 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_create/epoll_create03.c
runtest/syscalls +2 -0
index a021c79da..65bac761b 100644
@@ -177,6 +177,8 @@ dup3_02 dup3_02
 
 epoll_create01 epoll_create01
 epoll_create02 epoll_create02
+epoll_create03 epoll_create03
+
 epoll_create1_01 epoll_create1_01
 epoll_create1_02 epoll_create1_02
 epoll01 epoll-ltp
testcases/kernel/syscalls/epoll_create/.gitignore +1 -0
index 5c16cfa8c..855bf255c 100644
@@ -1,2 +1,3 @@
 epoll_create01
 epoll_create02
+epoll_create03
testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +72 -0

72 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] syscalls: Add epoll_create03

Hi Cyril,

Quoted 1 line · Cyril Hrubis

syscalls: Add epoll_create03

--- [PATCH 1/9] ---

Quoted 4 lines

/*\
* Verify that :manpage:epoll_create() fails with EMFILE when the per-process
* limit on the number of open file descriptors has been reached. */

The :manpage: role is missing backticks and the section number. Should be :manpage:epoll_create(2).

--- [PATCH 2/9] ---

Quoted 11 lines

/*\
* Verify that :manpage:epoll_wait() fails with EINTR when a signal arrives
* while waiting for events.
*
* [Algorithm]
*
* - Create an epoll instance
* - Fork a child that waits in the :manpage:epoll_wait(), parents sends
* SIGUSR1 to interrupt it.
* - Verify that :manpage:epoll_wait() returns -1 with errno set to EINTR. */

Three occurrences of :manpage:epoll_wait() are missing backticks and the section number. Each should be :manpage:epoll_wait(2).

"parents sends" should be "parent sends".

Quoted 2 lines
	TST_EXP_FAIL(epoll_wait(efd, &ev, 1, -1), EINTR,
		     "epoll_wait() interrupted by signal");

TST_EXP_FAIL is for syscalls that return 0 on success. epoll_wait() returns a non-negative event count on success, so TST_EXP_FAIL2 is the appropriate macro here.

In this particular setup it makes no practical difference (no fds registered, infinite timeout), but using the wrong variant produces a misleading error message if the expectation is ever violated.

--- [PATCH 3/9] ---

Quoted 8 lines

/*\
* Verify that :manpage:epoll_wait() works with nested epoll instances up to
* the maximum nesting depth of 5 allowed by the kernel (EP_MAX_NESTS). *
* [Algorithm]
*
* ...
* - Call :manpage:epoll_wait() on the outermost epoll instance and verify it

Two occurrences of :manpage:epoll_wait() are missing backticks and the section number. Should be :manpage:epoll_wait(2).

--- [PATCH 4/9] ---

Quoted 3 lines

/*\
* Verify :manpage:epoll_ctl() EPOLL_CTL_ADD behavior across all file
* descriptor types.

The :manpage: role is missing backticks and the section number. Should be :manpage:epoll_ctl(2).

--- [PATCH 5/9] ---

Quoted 3 lines

/*\
* Verify that :manpage:epoll_wait() with EPOLLPRI detects changes to
* /proc/mounts.

The :manpage: role is missing backticks and the section number. Should be :manpage:epoll_wait(2).

--- [PATCH 6/9] ---

Quoted 8 lines

/*\
* Verify that :manpage:epoll_wait() reports EPOLLHUP when the write end of a
* pipe is closed while a child process is blocked in epoll_wait. *
* [Algorithm]
*
* ...
* - The child's :manpage:epoll_wait() should return with EPOLLHUP.

Two occurrences of :manpage:epoll_wait() are missing backticks and the section number. Should be :manpage:epoll_wait(2).

--- [PATCH 7/9] ---

Quoted 9 lines
	rval = poll(fds, nfds, timeout);
	if (rval == -1) {
		tst_brk_(file, lineno, TBROK | TERRNO,
			"poll(%p, %li, %i) failed", fds, (long)nfds, timeout);
	} else if (rval < -1) {
		tst_brk_(file, lineno, TBROK | TERRNO,
			"Invalid poll(%p, %li, %i) return value %i",
			fds, (long)nfds, timeout, rval);
	}

poll() returns -1 on error or >= 0 on success; it cannot return a value less than -1. The else-if branch is dead code.

The nearby safe_statvfs() uses "else if (rval)" to catch unexpected non-zero returns for a function that is 0 on success. poll() returns 0 (timeout) and positive values (events ready) as normal outcomes, so no such secondary check applies here. The body should just have the rval == -1 guard and return rval.

Quoted 4 lines

int safe_poll(const char *const file, const int lineno, struct pollfd *fds,

		nfds_t nfds, int timeout);
#define SAFE_POLL(fds, nfds, timeout) \
	safe_poll(__FILE__, __LINE__, (fds), (nfds), (timeout))

New public functions in include/ must be documented with kernel-doc syntax. A /** ... */ block covering the parameters and return value is required.

--- [PATCH 8/9] ---

Quoted 9 lines

/*\
* Verify that :manpage:epoll_wait() reports EPOLLERR when the read end of a
* pipe is closed while a child process is blocked in epoll_wait on the write
* end.
*
* [Algorithm]
*
* ...
* - The child's :manpage:epoll_wait() should return with EPOLLERR set.

Two occurrences of :manpage:epoll_wait() are missing backticks and the section number. Should be :manpage:epoll_wait(2).

--- [PATCH 9/9] ---

Quoted 1 line

Now that the epoll coverate is greater than it ever was we can remove

"coverate" should be "coverage".

Quoted 1 line

The Fixes: tag must reference a commit hash in the local git history, not a URL. For a GitHub issue reference use Closes: instead.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] syscalls: Add epoll_create03

Hi!

Quoted 12 lines

--- [PATCH 7/9] ---

Quoted 9 lines
	rval = poll(fds, nfds, timeout);
	if (rval == -1) {
		tst_brk_(file, lineno, TBROK | TERRNO,
			"poll(%p, %li, %i) failed", fds, (long)nfds, timeout);
	} else if (rval < -1) {
		tst_brk_(file, lineno, TBROK | TERRNO,
			"Invalid poll(%p, %li, %i) return value %i",
			fds, (long)nfds, timeout, rval);
	}
Quoted 8 lines

poll() returns -1 on error or >= 0 on success; it cannot return a value less than -1. The else-if branch is dead code.

The nearby safe_statvfs() uses "else if (rval)" to catch unexpected non-zero returns for a function that is 0 on success. poll() returns 0 (timeout) and positive values (events ready) as normal outcomes, so no such secondary check applies here. The body should just have the rval == -1 guard and return rval.

I will ignore this one since we are guarding againts kernel bugs with this code. I.e. if kernel returns impossible value we want the test to report it.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 1/9
#4 lore raw

Re: [LTP] [PATCH v3 1/9] syscalls: Add epoll_create03

In reply to Cyril Hrubis

Hi Cyril,

Quoted 2 lines

Test that checks that we get EMFILE when limit on per-process file descriptors is hit.

+1.

...

testcases/kernel/syscalls/epoll_create/epoll_create03.c line 7

Quoted 9 lines

+++ b/testcases/kernel/syscalls/epoll_create/epoll_create03.c

testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +7 -0
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <[email protected]>
+ */
+
+/*\
+ * Verify that :manpage:epoll_create() fails with EMFILE when the per-process

Please add 2 to the manpage link.

:manpage:epoll_create(2)

Without it it's not working (plain text instead of link). Can be changed before merge.

Quoted 25 lines
testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +25 -0
+ * limit on the number of open file descriptors has been reached.
+ */
+
+#include <stdlib.h>
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "lapi/epoll.h"
+#include "lapi/syscalls.h"
+
+#include "epoll_create.h"
+
+static int *fds;
+static int nfds;
+static long maxfds;
+
+static void setup(void)
+{
+	int fd;
+
+	variant_info();
+
+	maxfds = SAFE_SYSCONF(_SC_OPEN_MAX);
+	fds = SAFE_MALLOC(maxfds * sizeof(int));
+	memset(fds, -1, maxfds * sizeof(int));

testcases/kernel/syscalls/epoll_create/epoll_create03.c line 42

Quoted 10 lines
testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +10 -0
+
+	fds[0] = SAFE_OPEN("dummy", O_RDWR | O_CREAT, 0700);
+	nfds = 1;
+
+	for (int i = 1; i < maxfds; i++) {
+		fd = dup(fds[0]);
+		if (fd == -1)
+			break;
+		fds[nfds++] = fd;
+	}

How many files are created is done via ulimit -n, right? (not sure if there is file for it in /proc/sys).
Would it be worth we check that? Or at least check that at least 2 files were opened? Maybe this check should be rather put into dup03.c.

Or maybe to print how many descriptors was created? tst_res(TINFO, "Created %d file descriptors", nfds);

testcases/kernel/syscalls/epoll_create/epoll_create03.c line 48

Quoted 6 lines
testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +6 -0
+}
+
+static void run(void)
+{
+	TST_EXP_FAIL2(do_epoll_create(1), EMFILE,
+		      "epoll_create(1) with exhausted fds");

Otherwise LGTM.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v3 1/9] syscalls: Add epoll_create03

Hi Cyril,

Quoted 5 lines
Quoted 2 lines

+/*\
+ * Verify that :manpage:epoll_create() fails with EMFILE when the per-process

Please add 2 to the manpage link.

:manpage:epoll_create(2)

I'm sorry, also `` are needed:

:manpage:epoll_create(2)

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v3 1/9] syscalls: Add epoll_create03

Hi!

Quoted 1 line

:manpage:epoll_create(2)

I will fix all of these before applying.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Re: [LTP] [PATCH v3 1/9] syscalls: Add epoll_create03

In reply to Petr Vorel

Hi!

Quoted 14 lines
Quoted 14 lines
testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +14 -0
+static void setup(void)
+{
+	int fd;
+
+	variant_info();
+
+	maxfds = SAFE_SYSCONF(_SC_OPEN_MAX);
+	fds = SAFE_MALLOC(maxfds * sizeof(int));
+	memset(fds, -1, maxfds * sizeof(int));
+
+	fds[0] = SAFE_OPEN("dummy", O_RDWR | O_CREAT, 0700);
+	nfds = 1;
+
+	for (int i = 1; i < maxfds; i++) {
Quoted 8 lines

testcases/kernel/syscalls/epoll_create/epoll_create03.c line 42

Quoted 5 lines
testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +5 -0
+		fd = dup(fds[0]);
+		if (fd == -1)
+			break;
+		fds[nfds++] = fd;
+	}

How many files are created is done via ulimit -n, right? (not sure if there is file for it in /proc/sys).

It's not about created files. There is a per-process limit on the number of file descriptors. That can be accessed either via sysconf() or via rlimit() and the values are also exported into /proc/$PID/limits.

Quoted 2 lines

Would it be worth we check that? Or at least check that at least 2 files were opened? Maybe this check should be rather put into dup03.c.

I guess that it would make more sense to put such check into dup03.c. However we would have to scan the whole file descriptor table first to check on how many fds are already open.

Something as;

	int used_fds = 0;

	for (i = 0; i < maxfds; i++) {
		if (fcntl(i, F_GETFD) != -1)
			used_fds++;
	}

Then we can expect that the limit for the test is maxfds - used_fd

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Re: [LTP] [PATCH v3 1/9] syscalls: Add epoll_create03

Quoted 24 lines

Hi!

Quoted 14 lines
Quoted 14 lines
testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +14 -0
+static void setup(void)
+{
+	int fd;
+
+	variant_info();
+
+	maxfds = SAFE_SYSCONF(_SC_OPEN_MAX);
+	fds = SAFE_MALLOC(maxfds * sizeof(int));
+	memset(fds, -1, maxfds * sizeof(int));
+
+	fds[0] = SAFE_OPEN("dummy", O_RDWR | O_CREAT, 0700);
+	nfds = 1;
+
+	for (int i = 1; i < maxfds; i++) {
Quoted 8 lines

testcases/kernel/syscalls/epoll_create/epoll_create03.c line 42

Quoted 5 lines
testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +5 -0
+		fd = dup(fds[0]);
+		if (fd == -1)
+			break;
+		fds[nfds++] = fd;
+	}

How many files are created is done via ulimit -n, right? (not sure if there is file for it in /proc/sys).

Quoted 8 lines

It's not about created files. There is a per-process limit on the number of file descriptors. That can be accessed either via sysconf() or via rlimit() and the values are also exported into /proc/$PID/limits.

Quoted 2 lines

Would it be worth we check that? Or at least check that at least 2 files were opened? Maybe this check should be rather put into dup03.c.

I guess that it would make more sense to put such check into dup03.c.

OK, let's ignore it.

Quoted 5 lines

However we would have to scan the whole file descriptor table first to check on how many fds are already open.

Something as;

Quoted 8 lines
	int used_fds = 0;

	for (i = 0; i < maxfds; i++) {
		if (fcntl(i, F_GETFD) != -1)
			used_fds++;
	}

Then we can expect that the limit for the test is maxfds - used_fd

+1

I'll try to add it either into my TODO list or to the issues.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH v3 1/9] syscalls: Add epoll_create03

In reply to Petr Vorel

Hi!

Quoted 11 lines

testcases/kernel/syscalls/epoll_create/epoll_create03.c line 7

Quoted 9 lines

+++ b/testcases/kernel/syscalls/epoll_create/epoll_create03.c

testcases/kernel/syscalls/epoll_create/epoll_create03.c new file +7 -0
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <[email protected]>
+ */
+
+/*\
+ * Verify that :manpage:epoll_create() fails with EMFILE when the per-process

Please add 2 to the manpage link.

Quoted 4 lines

:manpage:epoll_create(2)

Without it it's not working (plain text instead of link). Can be changed before merge.

Fixed the link and pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

PATCH v3 2/9 syscalls: Add epoll_wait08

In reply to Cyril Hrubis

Tests that epoll_wait() can be interrupted by a signal and returns EINTR.

---
 runtest/syscalls                              |  3 +
 .../kernel/syscalls/epoll_wait/.gitignore     |  1 +
 .../kernel/syscalls/epoll_wait/epoll_wait08.c | 69 +++++++++++++++++++
 3 files changed, 73 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait08.c
runtest/syscalls +3 -0
index 65bac761b..debe64ff9 100644
@@ -187,6 +187,7 @@ epoll_ctl02 epoll_ctl02
 epoll_ctl03 epoll_ctl03
 epoll_ctl04 epoll_ctl04
 epoll_ctl05 epoll_ctl05
+
 epoll_wait01 epoll_wait01
 epoll_wait02 epoll_wait02
 epoll_wait03 epoll_wait03
@@ -194,6 +195,8 @@ epoll_wait04 epoll_wait04
 epoll_wait05 epoll_wait05
 epoll_wait06 epoll_wait06
 epoll_wait07 epoll_wait07
+epoll_wait08 epoll_wait08
+
 epoll_pwait01 epoll_pwait01
 epoll_pwait02 epoll_pwait02
 epoll_pwait03 epoll_pwait03
testcases/kernel/syscalls/epoll_wait/.gitignore +1 -0
index 66ac18ae2..f3b208950 100644
@@ -5,3 +5,4 @@ epoll_wait04
 epoll_wait05
 epoll_wait06
 epoll_wait07
+epoll_wait08
testcases/kernel/syscalls/epoll_wait/epoll_wait08.c new file +69 -0

69 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 2/9
#11 lore raw

Re: [LTP] [PATCH v3 2/9] syscalls: Add epoll_wait08

Hi Cyril,

Quoted 2 lines

+/*\
+ * Verify that :manpage:epoll_wait() fails with EINTR when a signal arrives

Besides using correct form (apply to all tests and of course can be fixed before merge) LGTM.

:manpage:epoll_create(2)

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

Re: [LTP] [PATCH v3 2/9] syscalls: Add epoll_wait08

Hi!

Quoted 6 lines
Quoted 2 lines

+/*\
+ * Verify that :manpage:epoll_wait() fails with EINTR when a signal arrives

Besides using correct form (apply to all tests and of course can be fixed before merge) LGTM.

:manpage:epoll_create(2)

I've fixed that and also TST_EXP_FAIL2() as pointed out by the ltp-agent and pushed. Thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v3 3/9 syscalls: Add epoll_wait09

In reply to Cyril Hrubis

Test checks that events from recursive epoll are propagated correctly.

---
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/epoll_wait/.gitignore     |   1 +
 .../kernel/syscalls/epoll_wait/epoll_wait09.c | 132 ++++++++++++++++++
 3 files changed, 134 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait09.c
runtest/syscalls +1 -0
index debe64ff9..727156950 100644
@@ -196,6 +196,7 @@ epoll_wait05 epoll_wait05
 epoll_wait06 epoll_wait06
 epoll_wait07 epoll_wait07
 epoll_wait08 epoll_wait08
+epoll_wait09 epoll_wait09
 
 epoll_pwait01 epoll_pwait01
 epoll_pwait02 epoll_pwait02
testcases/kernel/syscalls/epoll_wait/.gitignore +1 -0
index f3b208950..f32ec535b 100644
@@ -6,3 +6,4 @@ epoll_wait05
 epoll_wait06
 epoll_wait07
 epoll_wait08
+epoll_wait09
testcases/kernel/syscalls/epoll_wait/epoll_wait09.c new file +132 -0

132 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 3/9
#14 lore raw

Re: [LTP] [PATCH v3 3/9] syscalls: Add epoll_wait09

Hi Cyril,

Quoted 1 line

Test checks that events from recursive epoll are propagated correctly.

+1

Quoted 8 lines

+/*\
+ * Verify that :manpage:epoll_wait() works with nested epoll instances up to
+ * the maximum nesting depth of 5 allowed by the kernel (EP_MAX_NESTS).
+ *
+ * [Algorithm]
+ *
+ * - Create a pipe.
+ * - Build a chain of epoll instances of the given depth where the innermost

Quoted 8 lines

+ * monitors the pipe read end and each subsequent one monitors the previous.
+ * - Write data to the pipe.
+ * - Call :manpage:epoll_wait() on the outermost epoll instance and verify it
+ * reports EPOLLIN.
+ * - Walk the chain inward calling epoll_wait on each level and verify that
+ * every level reports EPOLLIN on the expected fd.
+ * - Read the data from the pipe to drain it.
+ */

Thanks for the description.

Quoted 8 lines
testcases/kernel/syscalls/epoll_wait/epoll_wait09.c new file +8 -0
+
+#include <sys/epoll.h>
+
+#include "tst_epoll.h"
+#include "tst_test.h"
+
+#define MAX_DEPTH 5
+

testcases/kernel/syscalls/epoll_wait/epoll_wait09.c line 39

Quoted 10 lines
testcases/kernel/syscalls/epoll_wait/epoll_wait09.c new file +10 -0
+static int epfds[MAX_DEPTH];
+static int fds[2] = {-1, -1};
+
+static struct tcase {
+	int depth;
+} tcases[] = {
+	{2},
+	{3},
+	{4},
+	{5},

nit: why not just define depth in the test?
int depth = n + 2;

And
- .tcnt = ARRAY_SIZE(tcases),
+ .tcnt = MAX_DEPTH,

That would help having to sync these 3 (tcases[], MAX_DEPTH and .tcnt).

Also, could you run make check to fix formatting complains?

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

Re: [LTP] [PATCH v3 3/9] syscalls: Add epoll_wait09

Hi!

Quoted 23 lines
Quoted 8 lines
testcases/kernel/syscalls/epoll_wait/epoll_wait09.c new file +8 -0
+
+#include <sys/epoll.h>
+
+#include "tst_epoll.h"
+#include "tst_test.h"
+
+#define MAX_DEPTH 5
+

testcases/kernel/syscalls/epoll_wait/epoll_wait09.c line 39

Quoted 10 lines
testcases/kernel/syscalls/epoll_wait/epoll_wait09.c new file +10 -0
+static int epfds[MAX_DEPTH];
+static int fds[2] = {-1, -1};
+
+static struct tcase {
+	int depth;
+} tcases[] = {
+	{2},
+	{3},
+	{4},
+	{5},

nit: why not just define depth in the test?
int depth = n + 2;

And

Review

Quoted 2 lines
(quoted diff) +1 -1
-	.tcnt = ARRAY_SIZE(tcases),
+	.tcnt = MAX_DEPTH,

Done, however this has to be MAX_DEPTH-1,
since we are starting at depth 2.

Quoted 1 line

Also, could you run make check to fix formatting complains?

Also done.

And pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#16 lore raw

PATCH v3 4/9 syscalls: Add epoll_ctl06

In reply to Cyril Hrubis

Test that iterates over different types of file descriptors, attempts to add them to epoll and expects either success or a failure based on the type of the file descriptor.

---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/epoll_ctl/.gitignore      |  1 +
 .../kernel/syscalls/epoll_ctl/epoll_ctl06.c   | 72 +++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c
runtest/syscalls +1 -0
index 727156950..b78d565fb 100644
@@ -187,6 +187,7 @@ epoll_ctl02 epoll_ctl02
 epoll_ctl03 epoll_ctl03
 epoll_ctl04 epoll_ctl04
 epoll_ctl05 epoll_ctl05
+epoll_ctl06 epoll_ctl06
 
 epoll_wait01 epoll_wait01
 epoll_wait02 epoll_wait02
testcases/kernel/syscalls/epoll_ctl/.gitignore +1 -0
index 3e05f2e1f..9c555f41b 100644
@@ -3,3 +3,4 @@ epoll_ctl02
 epoll_ctl03
 epoll_ctl04
 epoll_ctl05
+epoll_ctl06
testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c new file +72 -0

72 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 4/9
#17 lore raw

Re: [LTP] [PATCH v3 4/9] syscalls: Add epoll_ctl06

Hi Cyril,

LGTM.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#18 lore raw

Re: [LTP] [PATCH v3 4/9] syscalls: Add epoll_ctl06

Hi!
Pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#19 lore raw

PATCH v3 5/9 syscalls: Add epoll_wait10

In reply to Cyril Hrubis

Functional test for EPOLLPRI using /proc/mounts that produces POLLPRI when a filesystem is mounted/umounted.

---
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/epoll_wait/.gitignore     |   1 +
 .../kernel/syscalls/epoll_wait/epoll_wait10.c | 103 ++++++++++++++++++
 3 files changed, 105 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait10.c
runtest/syscalls +1 -0
index b78d565fb..08b31c9f5 100644
@@ -198,6 +198,7 @@ epoll_wait06 epoll_wait06
 epoll_wait07 epoll_wait07
 epoll_wait08 epoll_wait08
 epoll_wait09 epoll_wait09
+epoll_wait10 epoll_wait10
 
 epoll_pwait01 epoll_pwait01
 epoll_pwait02 epoll_pwait02
testcases/kernel/syscalls/epoll_wait/.gitignore +1 -0
index f32ec535b..30139375d 100644
@@ -7,3 +7,4 @@ epoll_wait06
 epoll_wait07
 epoll_wait08
 epoll_wait09
+epoll_wait10
testcases/kernel/syscalls/epoll_wait/epoll_wait10.c new file +103 -0

103 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 5/9
#20 lore raw

Re: [LTP] [PATCH v3 5/9] syscalls: Add epoll_wait10

Hi Cyril,

Quoted 10 lines

+/*\
+ * Verify that :manpage:epoll_wait() with EPOLLPRI detects changes to
+ * /proc/mounts.
+ *
+ * The kernel generates a poll notification (POLLPRI/EPOLLERR) on
+ * /proc/mounts whenever the mount namespace changes. This test verifies
+ * that epoll can observe these notifications.
+ *
+ * [Algorithm]
+ *

Quoted 8 lines

+ * - Open /proc/mounts and register it with an epoll instance for EPOLLPRI.
+ * - Fork a child that mounts and then unmounts a tmpfs filesystem, using
+ * checkpoints to synchronize with the parent.
+ * - After each mount namespace change the parent calls epoll_wait and verifies
+ * it returns an event.
+ *
+ * Needs root to call mount/umount.
+ */

Nice test, thanks for the description.

...

testcases/kernel/syscalls/epoll_wait/epoll_wait10.c line 102

Quoted 8 lines
testcases/kernel/syscalls/epoll_wait/epoll_wait10.c new file +8 -0
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.needs_tmpdir = 1,

Shouldn't we have .needs_kconfigs CONFIG_TMPFS=y I know it's really a corner case when somebody disable it.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#21 lore raw

Re: [LTP] [PATCH v3 5/9] syscalls: Add epoll_wait10

Hi!

Quoted 2 lines

Shouldn't we have .needs_kconfigs CONFIG_TMPFS=y I know it's really a corner case when somebody disable it.

It certainly shouldn't harm anything so I've added CONFIG_TMPFS to the needs_kconfigs.

And pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#22 lore raw

PATCH v3 6/9 syscalls: Add epoll_wait11

In reply to Cyril Hrubis

A test that checks that EPOLLHUP is generated properly when a pipe is closed while epoll_wait() waits on the read end of a pipe.

---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/epoll_wait/.gitignore     |  1 +
 .../kernel/syscalls/epoll_wait/epoll_wait11.c | 93 +++++++++++++++++++
 3 files changed, 95 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait11.c
runtest/syscalls +1 -0
index 08b31c9f5..269fc162a 100644
@@ -199,6 +199,7 @@ epoll_wait07 epoll_wait07
 epoll_wait08 epoll_wait08
 epoll_wait09 epoll_wait09
 epoll_wait10 epoll_wait10
+epoll_wait11 epoll_wait11
 
 epoll_pwait01 epoll_pwait01
 epoll_pwait02 epoll_pwait02
testcases/kernel/syscalls/epoll_wait/.gitignore +1 -0
index 30139375d..57bdf0806 100644
@@ -8,3 +8,4 @@ epoll_wait07
 epoll_wait08
 epoll_wait09
 epoll_wait10
+epoll_wait11
testcases/kernel/syscalls/epoll_wait/epoll_wait11.c new file +93 -0

93 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 6/9
#23 lore raw

Re: [LTP] [PATCH v3 6/9] syscalls: Add epoll_wait11

Hi Cyril,

LGTM.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#24 lore raw

Re: [LTP] [PATCH v3 6/9] syscalls: Add epoll_wait11

Hi!
Pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#25 lore raw

PATCH v3 7/9 SAFE_MACROS: Add SAFE_POLL()

In reply to Cyril Hrubis
---
 include/tst_safe_macros.h |  6 ++++++
 lib/tst_safe_macros.c     | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)
include/tst_safe_macros.h +6 -0
index c73c1acb1..91a130a48 100644
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <grp.h>
+#include <poll.h>
 
 #include "safe_stdio_fn.h"
 #include "safe_macros_fn.h"
@@ -517,4 +518,9 @@ int safe_statvfs(const char *file, const int lineno,
 #define SAFE_STATVFS(path, buf) \
 	safe_statvfs(__FILE__, __LINE__, (path), (buf))
 
+int safe_poll(const char *const file, const int lineno, struct pollfd *fds,
+		nfds_t nfds, int timeout);
+#define SAFE_POLL(fds, nfds, timeout) \
+	safe_poll(__FILE__, __LINE__, (fds), (nfds), (timeout))
+
 #endif /* TST_SAFE_MACROS_H__ */
lib/tst_safe_macros.c +18 -0
index cdc8c7dd3..f17f911ef 100644
@@ -829,3 +829,21 @@ int safe_statvfs(const char *file, const int lineno,
 
 	return rval;
 }
+
+int safe_poll(const char *const file, const int lineno, struct pollfd *fds,
+		nfds_t nfds, int timeout)
+{
+	int rval;
+
+	rval = poll(fds, nfds, timeout);
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"poll(%p, %li, %i) failed", fds, (long)nfds, timeout);
+	} else if (rval < -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid poll(%p, %li, %i) return value %i",
+			fds, (long)nfds, timeout, rval);
+	}
+
+	return rval;
+}
Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 7/9
#26 lore raw

Re: [LTP] [PATCH v3 7/9] SAFE_MACROS: Add SAFE_POLL()

Hi Cyril,

nit: it introduced 3 more formatting issues:
tst_safe_macros.c:834: CHECK: Alignment should match open parenthesis tst_safe_macros.c:841: CHECK: Alignment should match open parenthesis tst_safe_macros.c:844: CHECK: Alignment should match open parenthesis

We can disable PARENTHESIS_ALIGNMENT if we don't care about this formatting.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#27 lore raw

Re: [LTP] [PATCH v3 7/9] SAFE_MACROS: Add SAFE_POLL()

Hi Petr,

Quoted 10 lines

Hi Cyril,

nit: it introduced 3 more formatting issues:
tst_safe_macros.c:834: CHECK: Alignment should match open parenthesis tst_safe_macros.c:841: CHECK: Alignment should match open parenthesis tst_safe_macros.c:844: CHECK: Alignment should match open parenthesis

We can disable PARENTHESIS_ALIGNMENT if we don't care about this formatting.

Yes please, this rule is really annoying and producing lots of non sense issues. As well as the "( should not be at end of line" rule.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#30 lore raw

PATCH v3 8/9 syscalls: Add epoll_wait12

In reply to Cyril Hrubis

A test for EPOLLERR when we are waiting to write into a pipe and the read end is closed.

---
 runtest/syscalls                              |   1 +
 .../kernel/syscalls/epoll_wait/.gitignore     |   1 +
 .../kernel/syscalls/epoll_wait/epoll_wait12.c | 111 ++++++++++++++++++
 3 files changed, 113 insertions(+)
 create mode 100644 testcases/kernel/syscalls/epoll_wait/epoll_wait12.c
runtest/syscalls +1 -0
index 269fc162a..ec4907212 100644
@@ -200,6 +200,7 @@ epoll_wait08 epoll_wait08
 epoll_wait09 epoll_wait09
 epoll_wait10 epoll_wait10
 epoll_wait11 epoll_wait11
+epoll_wait12 epoll_wait12
 
 epoll_pwait01 epoll_pwait01
 epoll_pwait02 epoll_pwait02
testcases/kernel/syscalls/epoll_wait/.gitignore +1 -0
index 57bdf0806..ad890d077 100644
@@ -9,3 +9,4 @@ epoll_wait08
 epoll_wait09
 epoll_wait10
 epoll_wait11
+epoll_wait12
testcases/kernel/syscalls/epoll_wait/epoll_wait12.c new file +111 -0

111 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 8/9
#31 lore raw

Re: [LTP] [PATCH v3 8/9] syscalls: Add epoll_wait12

Hi Cyril,

LGTM.

...

Quoted 17 lines
testcases/kernel/syscalls/epoll_wait/epoll_wait12.c new file +17 -0
+static void run(void)
+{
+	pid_t pid;
+
+	SAFE_PIPE(fds);
+	fill_pipe(fds[1]);
+
+	efd = SAFE_EPOLL_CREATE1(0);
+
+	struct epoll_event ev = {
+		.events = EPOLLOUT,
+		.data.fd = fds[1],
+	};
+
+	SAFE_EPOLL_CTL(efd, EPOLL_CTL_ADD, fds[1], &ev);
+
+	pid = SAFE_FORK();

testcases/kernel/syscalls/epoll_wait/epoll_wait12.c line 70

Quoted 10 lines
testcases/kernel/syscalls/epoll_wait/epoll_wait12.c new file +10 -0
+	if (!pid) {
+		SAFE_CLOSE(fds[0]);
+
+		TEST(epoll_wait(efd, &ev, 1, 5000));
+		if (TST_RET != 1) {
+			tst_res(TFAIL | TTERRNO,
+				"epoll_wait() returned %li, expected 1",
+				TST_RET);
+			exit(0);
+		}

nit: Using TST_EXP_VAL_SILENT(..., 1) would be shorter:

		TST_EXP_VAL_SILENT(epoll_wait(efd, &ev, 1, 5000), 1);
		if (!TST_PASS)
			exit(0);

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#32 lore raw

Re: [LTP] [PATCH v3 8/9] syscalls: Add epoll_wait12

Hi!

Quoted 4 lines

nit: Using TST_EXP_VAL_SILENT(..., 1) would be shorter:

		TST_EXP_VAL_SILENT(epoll_wait(efd, &ev, 1, 5000), 1);
		if (!TST_PASS)
			exit(0);

That is indeed better, changed and pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#33 lore raw

PATCH v3 9/9 syscalls: Remove old epoll-ltp test

In reply to Cyril Hrubis

Now that the epoll coverate is greater than it ever was we can remove the old and ugly epoll-ltp test.

---
 runtest/syscalls                            |   2 +-
 testcases/kernel/syscalls/epoll/.gitignore  |   1 -
 testcases/kernel/syscalls/epoll/Makefile    |   8 -
 testcases/kernel/syscalls/epoll/README.1ST  |  38 -
 testcases/kernel/syscalls/epoll/epoll-ltp.c | 738 --------------------
 5 files changed, 1 insertion(+), 786 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/epoll/.gitignore
 delete mode 100644 testcases/kernel/syscalls/epoll/Makefile
 delete mode 100644 testcases/kernel/syscalls/epoll/README.1ST
 delete mode 100644 testcases/kernel/syscalls/epoll/epoll-ltp.c
runtest/syscalls +1 -1
index ec4907212..789d1550d 100644
@@ -181,7 +181,7 @@ epoll_create03 epoll_create03
 
 epoll_create1_01 epoll_create1_01
 epoll_create1_02 epoll_create1_02
-epoll01 epoll-ltp
+
 epoll_ctl01 epoll_ctl01
 epoll_ctl02 epoll_ctl02
 epoll_ctl03 epoll_ctl03
testcases/kernel/syscalls/epoll/.gitignore deleted +0 -1
deleted file mode 100644
index dfb4445db..000000000
@@ -1 +0,0 @@
-/epoll-ltp
testcases/kernel/syscalls/epoll/Makefile deleted +0 -8
deleted file mode 100644
index 044619fb8..000000000
@@ -1,8 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) International Business Machines  Corp., 2001
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/epoll/README.1ST deleted +0 -38
deleted file mode 100644
index e5c5fcc5c..000000000
@@ -1,38 +0,0 @@
-Epoll Setup
-
-
-	** Directions for glibc version of 2.3.2 or higher **
-
-Epoll support is currently implemented in glibc 2.3.2, therefore if you have a$
-glibc version of 2.3.2 or higher then do the following steps:
-
-1. Download and untar the epoll library from:
-  http://www.xmailserver.org/linux-patches/epoll-lib-0.11.tar.gz
-2. Copy <epoll-lib_directory>/include/epoll.h    /usr/include
-3. Compile epoll-ltp.c in the  <ltp_dir>testcases/kernel/syscall/epoll
-
-
-
-	** Older version of glibc **
-To compile the epoll-ltp successfully the following libraries are needed:
-
-Epoll library http://www.xmailserver.org/linux-patches/epoll-lib-0.11.tar.gz
-Portable Coroutine Library (PCL)  http://www.xmailserver.org/libpcl.html
-
-
-1.	Download and untar the PCL library
-2.	Run ./configure
-3.	Run make
-4.	Run make install
-5.	Copy <libpcl_directory>/pcl/.libs/libpcl.* /lib
-6.	Download and untar the epoll library
-7.	*You may have to modify the makefile in <epoll-lib_directory>/Makefile and <epoll-lib_directory>/examples/Makefile with the following
--	KERNELDIR = kernel_directory
--	#all: .depend $(TARGET) epoll-example  change this line to$
--	all: .$(TARGET) epoll-example
--	#include .depend  comment out this line
-8.	Copy <epoll-lib_directory>/include/epoll.h    /usr/include
-9.	<epoll-lib_directory>  make
-10. Copy <epoll-lib_directory>/lib/libepoll*    /lib
-11. Compile epoll-ltp.c in the  <ltp_dir>testcases/kernel/syscall/epoll
-
testcases/kernel/syscalls/epoll/epoll-ltp.c deleted +0 -738

738 lines not on this page · raw message

Signature · 5 lines
2.53.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v3 9/9
#34 lore raw

Re: [LTP] [PATCH v3 9/9] syscalls: Remove old epoll-ltp test

Hi Cyril,

Quoted 2 lines

Now that the epoll coverate is greater than it ever was we can remove the old and ugly epoll-ltp test.

Thanks for doing nice rewrite!

Obviously correct.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#35 lore raw

Re: [LTP] [PATCH v3 9/9] syscalls: Remove old epoll-ltp test

Hi!

Quoted 1 line

Thanks for doing nice rewrite!

Pushed, thanks for the reviews.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp