[9/9] test: eventfs00 -- Extend to test duped fd

Submitted by Cyrill Gorcunov on June 20, 2018, 12:01 p.m.

Details

Message ID 20180620120143.8604-10-gorcunov@gmail.com
State New
Series "epoll: Add support for duped targets"
Headers show

Commit Message

Cyrill Gorcunov June 20, 2018, 12:01 p.m.
From: Cyrill Gorcunov <gorcunov@openvz.org>

To make sure criu can handle dup'ed and closed
file descriptors.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
 test/zdtm/static/eventfs00.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/eventfs00.c b/test/zdtm/static/eventfs00.c
index 72fd38a9cfa2..61d26e90ba7f 100644
--- a/test/zdtm/static/eventfs00.c
+++ b/test/zdtm/static/eventfs00.c
@@ -33,8 +33,8 @@  const char *test_author	= "Cyrill Gorcunov <gorcunov@openvz.org>";
 
 int main(int argc, char *argv[])
 {
-	int efd, ret, epollfd;
-	int pipefd[2];
+	int pipefd1[2], pipefd2[2];
+	int efd, ret, epollfd, fd;
 	uint64_t v = EVENTFD_INITIAL;
 	struct epoll_event ev;
 
@@ -55,16 +55,31 @@  int main(int argc, char *argv[])
 	memset(&ev, 0xff, sizeof(ev));
 	ev.events = EPOLLIN | EPOLLOUT;
 
-	if (pipe(pipefd)) {
+	if (pipe(pipefd1) || pipe(pipefd2)) {
 		fail("pipe");
 		exit(1);
 	}
 
-	if (epoll_ctl(epollfd, EPOLL_CTL_ADD, pipefd[0], &ev)) {
+	test_msg("epoll %d add %d native\n", epollfd, pipefd1[0]);
+	if (epoll_ctl(epollfd, EPOLL_CTL_ADD, pipefd1[0], &ev)) {
 		fail("epoll_ctl");
 		exit(1);
 	}
 
+	fd = dup2(pipefd2[0], 64);
+	if (fd < 0) {
+		fail(" dup on pipe");
+		exit(1);
+	}
+
+	test_msg("epoll %d add %d dup'ed from %d\n", epollfd, fd, pipefd2[0]);
+	if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev)) {
+		fail("epoll_ctl on duped pipe");
+		exit(1);
+	}
+	close(fd);
+	test_msg("epoll source %d closed\n", fd);
+
 	test_msg("created eventfd with %"PRIu64"\n", v);
 
 	ret = write(efd, &v, sizeof(v));