1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
#include <sys/epoll.h> #include <sys/mman.h> #include <unistd.h> #include <string.h> #include <errno.h>
#include "tst_test.h"
static int page_size, fds[2], epfd, inv_epfd, bad_epfd = -1;
static struct epoll_event epevs[1] = { {.events = EPOLLOUT} };
static struct epoll_event *ev_rdwr = epevs; static struct epoll_event *ev_rdonly;
static struct tcase { int *epfd; struct epoll_event **ev; int maxevents; int exp_errno; } tcases[] = { {&bad_epfd, &ev_rdwr, 1, EBADF}, {&inv_epfd, &ev_rdwr, 1, EINVAL}, {&epfd, &ev_rdwr, -1, EINVAL}, {&epfd, &ev_rdwr, 0, EINVAL}, {&epfd, &ev_rdonly, 1, EFAULT} };
static void my_test(unsigned int n) { struct tcase *tc = &tcases[n];
TEST(epoll_wait(*(tc->epfd), *(tc->ev), tc->maxevents, -1));
if (TEST_RETURN != -1) tst_res(TFAIL, "epoll_wait() succeed unexpectedly"); else if (tc->exp_errno == TEST_ERRNO) tst_res(TPASS | TTERRNO, "epoll_wait() fails as expected"); else tst_res(TFAIL | TTERRNO, "epoll_wait() fails unexpectedly, expected %d: %s", tc->exp_errno, strerror(tc->exp_errno)); }
static void setup(void) { page_size = getpagesize();
ev_rdonly = SAFE_MMAP(NULL, page_size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
SAFE_PIPE(fds);
epfd = epoll_create(1); if (epfd == -1) tst_brk(TBROK | TERRNO, "failed to create epoll instance");
epevs[0].data.fd = fds[1];
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[1], &epevs[0])) tst_brk(TBROK | TERRNO, "failed to register epoll target"); }
static void cleanup(void) { if (epfd > 0 && close(epfd)) tst_res(TWARN | TERRNO, "failed to close epfd");
if (close(fds[0])) tst_res(TWARN | TERRNO, "close(fds[0]) failed");
if (close(fds[1])) tst_res(TWARN | TERRNO, "close(fds[1]) failed"); }
static struct tst_test test = { .tcnt = ARRAY_SIZE(tcases), .test = my_test, .needs_checkpoints = 1, .setup = setup, .cleanup = cleanup };
|