2 * Copyright (C) 2006-2018 Free Software Foundation, Inc.
3 * Copyright (C) 2018 Christoph Hellwig.
4 * License: LGPLv2.1 or later.
6 * Description: test aio poll and io_pgetevents signal handling.
8 * Very roughly based on glibc tst-pselect.c.
18 static volatile int handler_called;
28 struct timespec to = { .tv_sec = 0, .tv_nsec = 500000000 };
29 pid_t parent = getpid(), p;
30 int pipe1[2], pipe2[2];
31 struct sigaction sa = { .sa_flags = 0 };
33 struct io_context *ctx = NULL;
36 struct iocb *iocbs[] = { &iocb };
39 sigemptyset(&sa.sa_mask);
41 sa.sa_handler = handler;
42 if (sigaction(SIGUSR1, &sa, NULL) != 0) {
43 printf("sigaction(1) failed\n");
47 sa.sa_handler = SIG_IGN;
48 if (sigaction(SIGCHLD, &sa, NULL) != 0) {
49 printf("sigaction(2) failed\n");
53 sigemptyset(&sigmask);
54 sigaddset(&sigmask, SIGUSR1);
55 if (sigprocmask(SIG_BLOCK, &sigmask, NULL) != 0) {
56 printf("sigprocmask failed\n");
60 if (pipe(pipe1) != 0 || pipe(pipe2) != 0) {
61 printf("pipe failed\n");
65 sigprocmask(SIG_SETMASK, NULL, &sigmask);
66 sigdelset(&sigmask, SIGUSR1);
71 printf("fork failed\n");
77 ret = io_setup(1, &ctx);
79 printf("child: io_setup failed: %s\n", strerror(-ret));
83 io_prep_poll(&iocb, pipe1[0], POLLIN);
84 ret = io_submit(ctx, 1, iocbs);
86 /* if poll isn't supported, skip the test */
89 printf("child: io_submit failed: %s\n", strerror(-ret));
94 if (getppid() != parent) {
95 printf("parent died\n");
98 ret = io_pgetevents(ctx, 1, 1, &ev, &to, &sigmask);
101 /* SKIP if the syscall has not been implemented. */
106 printf("child: io_pgetevents did not set errno to "
107 "EINTR: %s\n", strerror(-ret));
113 ret = write(pipe2[1], "foo", 3);
114 } while (ret == -1 && errno == EINTR);
121 io_prep_poll(&iocb, pipe2[0], POLLIN);
123 ret = io_setup(1, &ctx);
125 printf("parent: io_setup failed: %s\n", strerror(-ret));
129 ret = io_submit(ctx, 1, iocbs);
131 /* if poll isn't supported, skip the test */
134 printf("parent: io_submit failed with %d: %s\n",
135 ret, strerror(-ret));
141 ret = io_pgetevents(ctx, 1, 1, &ev, NULL, &sigmask);
142 /* SKIP if the syscall has not been implemented. */
146 printf("parent: io_pgetevents failed: %s\n",
151 printf("parent: io_pgetevents did not report event\n");
154 if (ev.obj != &iocb) {
155 printf("parent: io_pgetevents reports wrong fd\n");
158 if ((ev.res & POLLIN) != POLLIN) {
159 printf("parent: io_pgetevents did not report readable fd\n");