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

Cyrill Gorcunov gorcunov at gmail.com
Wed Jun 27 12:12:05 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 | 81 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 63 insertions(+), 18 deletions(-)

diff --git a/test/zdtm/static/eventfs00.c b/test/zdtm/static/eventfs00.c
index 72fd38a9cfa2..abcfd036e395 100644
--- a/test/zdtm/static/eventfs00.c
+++ b/test/zdtm/static/eventfs00.c
@@ -29,67 +29,112 @@ const char *test_doc	= "Check for eventfs";
 const char *test_author	= "Cyrill Gorcunov <gorcunov at openvz.org>";
 
 #define EVENTFD_INITIAL	30
-#define EVENTFD_FINAL	90
+#define EVENTFD_FINAL1	90
+#define EVENTFD_FINAL2	(EVENTFD_FINAL1 * 2)
+#define DUPFDNO		999
 
 int main(int argc, char *argv[])
 {
-	int efd, ret, epollfd;
-	int pipefd[2];
 	uint64_t v = EVENTFD_INITIAL;
+	int efd, ret, epollfd, fd;
 	struct epoll_event ev;
+	int i;
+
+	struct {
+		int	pipefd1[2];
+		int	pipefd2[2];
+	} pipes[10];
 
 	test_init(argc, argv);
 
 	epollfd = epoll_create(1);
 	if (epollfd < 0) {
-		fail("epoll_create");
+		pr_perror("epoll_create failed");
 		exit(1);
 	}
 
 	efd = eventfd((unsigned int)v, EFD_NONBLOCK);
 	if (efd < 0) {
-		fail("eventfd");
+		pr_perror("eventfd failed");
 		exit(1);
 	}
 
+	test_msg("created eventfd with %lld\n", (long long)v);
+
 	memset(&ev, 0xff, sizeof(ev));
 	ev.events = EPOLLIN | EPOLLOUT;
 
-	if (pipe(pipefd)) {
-		fail("pipe");
+	for (i = 0; i < ARRAY_SIZE(pipes); i++) {
+		if (pipe(pipes[i].pipefd1) || pipe(pipes[i].pipefd2)) {
+			pr_err("Can't create pipe %d\n", i);
+			exit(1);
+		}
+
+		test_msg("epoll %d add %d native\n", epollfd, pipes[i].pipefd1[0]);
+		if (epoll_ctl(epollfd, EPOLL_CTL_ADD, pipes[i].pipefd1[0], &ev)) {
+			pr_perror("Can't add pipe %d", pipes[i].pipefd1[0]);
+			exit(1);
+		}
+
+		fd = dup2(pipes[i].pipefd2[0], DUPFDNO);
+		if (fd < 0) {
+			pr_perror("Can't dup %d to %d", pipes[i].pipefd2[0], DUPFDNO);
+			exit(1);
+		}
+		test_msg("epoll %d add %d dup'ed from %d\n", epollfd, fd, pipes[i].pipefd2[0]);
+
+		close(fd);
+		test_msg("epoll source %d closed\n", fd);
+	}
+
+	ret = write(efd, &v, sizeof(v));
+	if (ret != sizeof(v)) {
+		pr_perror("write failed");
 		exit(1);
 	}
 
-	if (epoll_ctl(epollfd, EPOLL_CTL_ADD, pipefd[0], &ev)) {
-		fail("epoll_ctl");
+	ret = write(efd, &v, sizeof(v));
+	if (ret != sizeof(v)) {
+		pr_perror("write failed");
 		exit(1);
 	}
 
-	test_msg("created eventfd with %"PRIu64"\n", v);
+	test_daemon();
+	test_waitsig();
 
-	ret = write(efd, &v, sizeof(v));
+	ret = read(efd, &v, sizeof(v));
 	if (ret != sizeof(v)) {
-		fail("write");
+		pr_perror("read failed");
+		exit(1);
+	}
+
+	if (v != EVENTFD_FINAL1) {
+		fail("EVENTFD_FINAL1 mismatch (got %lld but %lld expected)\n",
+		     (long long)v, (long long)EVENTFD_FINAL1);
 		exit(1);
 	}
 
 	ret = write(efd, &v, sizeof(v));
 	if (ret != sizeof(v)) {
-		fail("write");
+		pr_perror("write failed");
 		exit(1);
 	}
 
-	test_daemon();
-	test_waitsig();
+	ret = write(efd, &v, sizeof(v));
+	if (ret != sizeof(v)) {
+		pr_perror("write failed");
+		exit(1);
+	}
 
 	ret = read(efd, &v, sizeof(v));
 	if (ret != sizeof(v)) {
-		fail("write");
+		pr_perror("read failed");
 		exit(1);
 	}
 
-	if (v != EVENTFD_FINAL) {
-		fail("EVENTFD_FINAL mismatch\n");
+	if (v != EVENTFD_FINAL2) {
+		fail("EVENTFD_FINAL2 mismatch (got %lld but %lld expected)\n",
+		     (long long)v, (long long)EVENTFD_FINAL2);
 		exit(1);
 	}
 
-- 
2.14.4



More information about the CRIU mailing list