[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / third_party / libevent / test / test-time.c
blob703bc32b5722a966a1d84e38ed78029464465d39
1 /*
2 * Compile with:
3 * cc -I/usr/local/include -o time-test time-test.c -L/usr/local/lib -levent
4 */
5 #ifdef HAVE_CONFIG_H
6 #include "config.h"
7 #endif
9 #ifdef WIN32
10 #include <winsock2.h>
11 #endif
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #ifdef HAVE_SYS_TIME_H
16 #include <sys/time.h>
17 #endif
18 #include <fcntl.h>
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #ifdef HAVE_UNISTD_H
23 #include <unistd.h>
24 #endif
25 #include <errno.h>
27 #include <event.h>
29 int called = 0;
31 #define NEVENT 20000
33 struct event *ev[NEVENT];
35 static int
36 rand_int(int n)
38 #ifdef WIN32
39 return (int)(rand() * n);
40 #else
41 return (int)(random() % n);
42 #endif
45 static void
46 time_cb(int fd, short event, void *arg)
48 struct timeval tv;
49 int i, j;
51 called++;
53 if (called < 10*NEVENT) {
54 for (i = 0; i < 10; i++) {
55 j = rand_int(NEVENT);
56 tv.tv_sec = 0;
57 tv.tv_usec = rand_int(50000);
58 if (tv.tv_usec % 2)
59 evtimer_add(ev[j], &tv);
60 else
61 evtimer_del(ev[j]);
66 int
67 main (int argc, char **argv)
69 struct timeval tv;
70 int i;
72 /* Initalize the event library */
73 event_init();
75 for (i = 0; i < NEVENT; i++) {
76 ev[i] = malloc(sizeof(struct event));
78 /* Initalize one event */
79 evtimer_set(ev[i], time_cb, ev[i]);
80 tv.tv_sec = 0;
81 tv.tv_usec = rand_int(50000);
82 evtimer_add(ev[i], &tv);
85 event_dispatch();
87 return (called < NEVENT);