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

Cyrill Gorcunov gorcunov at gmail.com
Wed Jun 20 15:01:43 MSK 2018


From: Cyrill Gorcunov <gorcunov at openvz.org>

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

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

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 at 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));
-- 
2.14.4



More information about the CRIU mailing list