[CRIU] [PATCH v4 13/13] zdtm/static: add a test to check epoll file descriptors
Cyrill Gorcunov
gorcunov at gmail.com
Mon Jul 2 23:13:33 MSK 2018
From: Andrei Vagin <avagin at virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
test/zdtm/static/Makefile | 1 +
test/zdtm/static/epoll.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 131 insertions(+)
create mode 100644 test/zdtm/static/epoll.c
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index d61ef33b9fe5..4c32f991fb56 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -121,6 +121,7 @@ TST_NOFILE := \
proc-self \
proc-self01 \
eventfs00 \
+ epoll \
signalfd00 \
inotify_irmap \
fanotify00 \
diff --git a/test/zdtm/static/epoll.c b/test/zdtm/static/epoll.c
new file mode 100644
index 000000000000..b655274e91b2
--- /dev/null
+++ b/test/zdtm/static/epoll.c
@@ -0,0 +1,130 @@
+#include <unistd.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/eventfd.h>
+#include <sys/ioctl.h>
+#include <sys/epoll.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <inttypes.h>
+
+#include "zdtmtst.h"
+
+#ifndef F_SETSIG
+#define F_SETSIG 10 /* for sockets. */
+#define F_GETSIG 11 /* for sockets. */
+#endif
+
+const char *test_doc = "Check for eventfs";
+const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+#define EVENTFD_INITIAL 30
+#define EVENTFD_FINAL1 90
+#define EVENTFD_FINAL2 (EVENTFD_FINAL1 * 2)
+#define DUPFDNO 999
+
+int main(int argc, char *argv[])
+{
+ uint64_t v = EVENTFD_INITIAL;
+ int epollfd, epollfd2, fd;
+ struct epoll_event ev;
+ int i, ret;
+
+ struct {
+ int pipefd[2];
+ } pipes[10];
+
+ test_init(argc, argv);
+
+ epollfd = epoll_create(1);
+ if (epollfd < 0) {
+ pr_perror("epoll_create failed");
+ exit(1);
+ }
+ epollfd2 = epoll_create(1);
+ if (epollfd2 < 0) {
+ pr_perror("epoll_create failed");
+ exit(1);
+ }
+
+
+ test_msg("created eventfd with %lld\n", (long long)v);
+
+ memset(&ev, 0xff, sizeof(ev));
+ ev.events = EPOLLIN | EPOLLOUT;
+
+ for (i = 0; i < ARRAY_SIZE(pipes); i++) {
+ if (pipe(pipes[i].pipefd)) {
+ pr_err("Can't create pipe %d\n", i);
+ exit(1);
+ }
+
+ ev.data.u64 = i;
+ fd = dup2(pipes[i].pipefd[0], DUPFDNO);
+ if (fd < 0) {
+ pr_perror("Can't dup %d to %d", pipes[i].pipefd[0], DUPFDNO);
+ exit(1);
+ }
+ test_msg("epoll %d add %d native\n", epollfd, pipes[i].pipefd[0]);
+ if (epoll_ctl(epollfd, EPOLL_CTL_ADD, DUPFDNO, &ev)) {
+ pr_perror("Can't add pipe %d", pipes[i].pipefd[0]);
+ exit(1);
+ }
+ test_msg("epoll %d add %d dup'ed from %d\n", epollfd, fd, pipes[i].pipefd[0]);
+ if (epoll_ctl(epollfd2, EPOLL_CTL_ADD, fd, &ev)) {
+ pr_perror("Can't add pipe %d", pipes[i].pipefd[0]);
+ exit(1);
+ }
+
+
+ close(fd);
+ test_msg("epoll source %d closed\n", fd);
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ ret = 0;
+ for (i = 0; i < ARRAY_SIZE(pipes); i++) {
+ char c;
+ if (write(pipes[i].pipefd[1], "x", 1) != 1) {
+ pr_perror("Unable to write into a pipe\n");
+ return 1;
+ }
+ if (epoll_wait(epollfd, &ev, 1, -1) != 1) {
+ pr_perror("Unable to wain events");
+ return 1;
+ }
+ if (ev.data.u64 != i) {
+ pr_err("ev.fd=%d ev.data.ptr=0x%p (%d)\n", ev.data.fd, ev.data.ptr, i);
+ ret |= 1;
+ }
+ if (epoll_wait(epollfd2, &ev, 1, -1) != 1) {
+ pr_perror("Unable to wain events");
+ return 1;
+ }
+ if (ev.data.u64 != i) {
+ pr_err("ev.fd=%d ev.data.ptr=0x%p (%d)\n", ev.data.fd, ev.data.ptr, i);
+ ret |= 1;
+ }
+ if (read(pipes[i].pipefd[0], &c, 1) != 1) {
+ pr_perror("read");
+ return 1;
+ }
+ }
+ if (ret)
+ return 1;
+
+ pass();
+ return 0;
+}
--
2.14.4
More information about the CRIU
mailing list