1 #include "test_common.h"
2 
3 libxl_ctx *ctx;
4 
test_common_setup(int level)5 void test_common_setup(int level)
6 {
7     xentoollog_logger_stdiostream *logger_s
8         = xtl_createlogger_stdiostream(stderr, level,  0);
9     assert(logger_s);
10 
11     xentoollog_logger *logger = (xentoollog_logger*)logger_s;
12 
13     int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, logger);
14     assert(!rc);
15 }
16 
17 struct timeval now;
18 
test_common_get_now(void)19 void test_common_get_now(void)
20 {
21     int r = gettimeofday(&now, 0);  assert(!r);
22 }
23 
24 int poll_nfds, poll_nfds_allocd;
25 struct pollfd *poll_fds;
26 int poll_timeout;
27 
test_common_beforepoll(void)28 void test_common_beforepoll(void)
29 {
30     for (;;) {
31         test_common_get_now();
32 
33         poll_timeout = -1;
34         poll_nfds = poll_nfds_allocd;
35         int rc = libxl_osevent_beforepoll(ctx, &poll_nfds, poll_fds,
36                                           &poll_timeout, now);
37         if (!rc) return;
38         assert(rc == ERROR_BUFFERFULL);
39 
40         assert(poll_nfds > poll_nfds_allocd);
41         poll_fds = realloc(poll_fds, poll_nfds * sizeof(poll_fds[0]));
42         assert(poll_fds);
43         poll_nfds_allocd = poll_nfds;
44     }
45 }
46 
test_common_dopoll(void)47 void test_common_dopoll(void) {
48     errno = 0;
49     int r = poll(poll_fds, poll_nfds, poll_timeout);
50     fprintf(stderr, "poll: r=%d errno=%s\n", r, strerror(errno));
51 }
52 
test_common_afterpoll(void)53 void test_common_afterpoll(void)
54 {
55     test_common_get_now();
56     libxl_osevent_afterpoll(ctx, poll_nfds, poll_fds, now);
57 }
58