1 #include "test_common.h"
2 #include "libxl_test_fdevent.h"
3 
main(int argc,char ** argv)4 int main(int argc, char **argv) {
5     int rc, i;
6     libxl_asyncop_how how;
7     libxl_event *event;
8 
9     test_common_setup(XTL_DEBUG);
10 
11     how.callback = NULL;
12     how.u.for_event = 1;
13 
14     int fd = open("/dev/null", O_RDONLY);
15     assert(fd > 0);
16 
17     rc = libxl_test_fdevent(ctx, fd, POLLIN, &how);
18     assert(!rc);
19 
20     test_common_beforepoll();
21 
22     rc = libxl_ao_abort(ctx, &how);
23     assert(!rc);
24 
25     rc = libxl_event_check(ctx, &event, LIBXL_EVENTMASK_ALL, 0,0);
26     assert(!rc);
27     assert(event);
28     assert(event->for_user == how.u.for_event);
29     assert(event->type == LIBXL_EVENT_TYPE_OPERATION_COMPLETE);
30     assert(event->u.operation_complete.rc == ERROR_ABORTED);
31 
32     close(fd);
33 
34     test_common_dopoll();
35 
36     for (i=0; i<poll_nfds; i++) {
37         if (poll_fds[i].fd == fd && (poll_fds[i].revents & POLLNVAL)) {
38             fprintf(stderr, "POLLNVAL on fd=%d in slot i=%d as expected\n",
39                     fd, i);
40             goto found;
41         }
42     }
43     abort();
44  found:;
45 
46     int fd2 = open("/dev/null", O_RDONLY);
47     assert(fd2 == fd);
48 
49     how.u.for_event++;
50     rc = libxl_test_fdevent(ctx, fd, POLLIN, &how);
51     assert(!rc);
52 
53     test_common_afterpoll();
54 
55     fprintf(stderr, "complete\n");
56 }
57