test-time: do not use deprecated API

- event_init() -> event_base_new()
- event_set() -> event_new()
- check return value of event_base_dispatch()
- use EXIT_SUCCESS/EXIT_FAILURE

(cherry picked from commit 4e5a41ca0f668da1a18832e5cb02b4afeae074ff)
This commit is contained in:
Azat Khuzhin 2020-03-01 15:47:40 +03:00
parent 29e2c7f2b7
commit e41a1969b0

View File

@ -81,8 +81,10 @@ time_cb(evutil_socket_t fd, short event, void *arg)
int
main(int argc, char **argv)
{
struct event_base *base;
struct timeval tv;
int i;
#ifdef _WIN32
WORD wVersionRequested;
WSADATA wsaData;
@ -98,23 +100,24 @@ main(int argc, char **argv)
event_enable_debug_logging(EVENT_DBG_ALL);
}
/* Initialize the event library */
event_init();
base = event_base_new();
for (i = 0; i < NEVENT; i++) {
ev[i] = malloc(sizeof(struct event));
/* Initialize one event */
evtimer_set(ev[i], time_cb, ev[i]);
ev[i] = evtimer_new(base, time_cb, event_self_cbarg());
tv.tv_sec = 0;
tv.tv_usec = rand_int(50000);
evtimer_add(ev[i], &tv);
}
event_dispatch();
i = event_base_dispatch(base);
printf("event_base_dispatch=%d, called=%d, EVENT=%d\n",
i, called, NEVENT);
printf("%d, %d\n", called, NEVENT);
return (called < NEVENT);
if (i == 1 && called >= NEVENT) {
return EXIT_SUCCESS;
} else {
return EXIT_FAILURE;
}
}