|
| 1 | + |
| 2 | +import sys; |
| 3 | +import epoll; |
| 4 | + |
| 5 | +class Main |
| 6 | +{ |
| 7 | + static public main(argv) |
| 8 | + {/*{{{*/ |
| 9 | + |
| 10 | + // - constructor with 0 flags - |
| 11 | + ep = new Epoll(0); |
| 12 | + if ($ep != "Epoll") |
| 13 | + { |
| 14 | + new Exception("Epoll(0) to_string: expected Epoll, got %s" % $ep).throw(); |
| 15 | + } |
| 16 | + |
| 17 | + // - constructor with CLOEXEC - |
| 18 | + ep = new Epoll(Epoll.CLOEXEC); |
| 19 | + if ($ep != "Epoll") |
| 20 | + { |
| 21 | + new Exception("Epoll(CLOEXEC) to_string: expected Epoll, got %s" % $ep).throw(); |
| 22 | + } |
| 23 | + |
| 24 | + // - create pipe for testable fds - |
| 25 | + pp = Sys.pipe(); |
| 26 | + rd_fd = pp[0].get_fd(); |
| 27 | + wr_fd = pp[1].get_fd(); |
| 28 | + |
| 29 | + // - has before add returns 0 - |
| 30 | + if (ep.has(rd_fd) != 0) |
| 31 | + { |
| 32 | + new Exception("has before add: expected 0, got %d" % ep.has(rd_fd)).throw(); |
| 33 | + } |
| 34 | + |
| 35 | + // - add returns self - |
| 36 | + ret = ep.add(rd_fd,Epoll.EPOLLIN); |
| 37 | + if ($ret != "Epoll") |
| 38 | + { |
| 39 | + new Exception("add return: expected Epoll, got %s" % $ret).throw(); |
| 40 | + } |
| 41 | + |
| 42 | + // - has after add returns 1 - |
| 43 | + if (ep.has(rd_fd) != 1) |
| 44 | + { |
| 45 | + new Exception("has after add: expected 1, got %d" % ep.has(rd_fd)).throw(); |
| 46 | + } |
| 47 | + |
| 48 | + // - add second fd - |
| 49 | + ep.add(wr_fd,Epoll.EPOLLOUT); |
| 50 | + if (ep.has(wr_fd) != 1) |
| 51 | + { |
| 52 | + new Exception("has wr_fd after add: expected 1, got %d" % ep.has(wr_fd)).throw(); |
| 53 | + } |
| 54 | + |
| 55 | + // - del returns self - |
| 56 | + ret = ep.del(rd_fd); |
| 57 | + if ($ret != "Epoll") |
| 58 | + { |
| 59 | + new Exception("del return: expected Epoll, got %s" % $ret).throw(); |
| 60 | + } |
| 61 | + |
| 62 | + // - has after del returns 0 - |
| 63 | + if (ep.has(rd_fd) != 0) |
| 64 | + { |
| 65 | + new Exception("has after del: expected 0, got %d" % ep.has(rd_fd)).throw(); |
| 66 | + } |
| 67 | + |
| 68 | + // - other fd still tracked - |
| 69 | + if (ep.has(wr_fd) != 1) |
| 70 | + { |
| 71 | + new Exception("has wr_fd after del rd_fd: expected 1, got %d" % ep.has(wr_fd)).throw(); |
| 72 | + } |
| 73 | + |
| 74 | + // - re-add rd_fd for reinit test - |
| 75 | + ep.add(rd_fd,Epoll.EPOLLIN); |
| 76 | + |
| 77 | + // - reinit returns self - |
| 78 | + ret = ep.reinit(); |
| 79 | + if ($ret != "Epoll") |
| 80 | + { |
| 81 | + new Exception("reinit return: expected Epoll, got %s" % $ret).throw(); |
| 82 | + } |
| 83 | + |
| 84 | + // - fds still tracked after reinit - |
| 85 | + if (ep.has(rd_fd) != 1) |
| 86 | + { |
| 87 | + new Exception("has rd_fd after reinit: expected 1, got %d" % ep.has(rd_fd)).throw(); |
| 88 | + } |
| 89 | + if (ep.has(wr_fd) != 1) |
| 90 | + { |
| 91 | + new Exception("has wr_fd after reinit: expected 1, got %d" % ep.has(wr_fd)).throw(); |
| 92 | + } |
| 93 | + |
| 94 | + // - add with modified events (re-add same fd = modify) - |
| 95 | + ep.add(rd_fd,Epoll.EPOLLIN | Epoll.EPOLLPRI); |
| 96 | + |
| 97 | + // - cleanup - |
| 98 | + pp[0].close(); |
| 99 | + pp[1].close(); |
| 100 | + }/*}}}*/ |
| 101 | +} |
0 commit comments