37 #include <sys/types.h>
39 #ifdef HAVE_SYS_TIME_H
42 #include <sys/queue.h>
44 #include <sys/socket.h>
60 #include "event-internal.h"
65 #include "regress.gen.h"
71 static char wbuf[4096];
72 static char rbuf[4096];
75 static int usepersist;
80 #define TEST1 "this is a test"
88 #define write(fd,buf,len) send((fd),(buf),(len),0)
89 #define read(fd,buf,len) recv((fd),(buf),(len),0)
93 simple_read_cb(
int fd,
short event,
void *arg)
101 len = read(fd, buf,
sizeof(buf));
105 if (event_add(arg, NULL) == -1)
108 }
else if (called == 1)
115 simple_write_cb(
int fd,
short event,
void *arg)
122 len = write(fd, TEST1, strlen(TEST1) + 1);
130 multiple_write_cb(
int fd,
short event,
void *arg)
132 struct event *ev = arg;
136 if (woff + len >=
sizeof(wbuf))
137 len =
sizeof(wbuf) - woff;
139 len = write(fd, wbuf + woff, len);
141 fprintf(stderr,
"%s: write\n", __func__);
149 if (woff >=
sizeof(wbuf)) {
150 shutdown(fd, SHUT_WR);
157 if (event_add(ev, NULL) == -1)
163 multiple_read_cb(
int fd,
short event,
void *arg)
165 struct event *ev = arg;
168 len = read(fd, rbuf + roff,
sizeof(rbuf) - roff);
170 fprintf(stderr,
"%s: read\n", __func__);
179 if (event_add(ev, NULL) == -1)
185 timeout_cb(
int fd,
short event,
void *arg)
190 evutil_gettimeofday(&tcalled, NULL);
191 if (evutil_timercmp(&tcalled, &tset, >))
192 evutil_timersub(&tcalled, &tset, &tv);
194 evutil_timersub(&tset, &tcalled, &tv);
196 diff = tv.tv_sec*1000 + tv.tv_usec/1000 - SECONDS * 1000;
206 signal_cb_sa(
int sig)
212 signal_cb(
int fd,
short event,
void *arg)
214 struct event *ev = arg;
227 combined_read_cb(
int fd,
short event,
void *arg)
233 len = read(fd, buf,
sizeof(buf));
235 fprintf(stderr,
"%s: read\n", __func__);
240 if (event_add(&both->ev, NULL) == -1)
245 combined_write_cb(
int fd,
short event,
void *arg)
247 struct both *both = arg;
252 if (len > both->nread)
255 len = write(fd, buf, len);
257 fprintf(stderr,
"%s: write\n", __func__);
259 shutdown(fd, SHUT_WR);
264 if (event_add(&both->ev, NULL) == -1)
271 setup_test(
const char *
name)
274 fprintf(stdout,
"%s", name);
276 if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
277 fprintf(stderr,
"%s: socketpair\n", __func__);
282 if (fcntl(pair[0], F_SETFL, O_NONBLOCK) == -1)
283 fprintf(stderr,
"fcntl(O_NONBLOCK)");
285 if (fcntl(pair[1], F_SETFL, O_NONBLOCK) == -1)
286 fprintf(stderr,
"fcntl(O_NONBLOCK)");
301 CloseHandle((HANDLE)pair[0]);
302 CloseHandle((HANDLE)pair[1]);
305 fprintf(stdout,
"OK\n");
307 fprintf(stdout,
"FAILED\n");
315 test_registerfds(
void)
319 struct event read_evs[512];
320 struct event write_evs[512];
324 fprintf(stdout,
"Testing register fds: ");
326 for (i = 0; i < 512; ++
i) {
327 if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
331 event_set(&read_evs[i], pair[0],
332 EV_READ|EV_PERSIST, simple_read_cb, NULL);
333 event_base_set(base, &read_evs[i]);
334 event_add(&read_evs[i], NULL);
335 event_set(&write_evs[i], pair[1],
336 EV_WRITE|EV_PERSIST, simple_write_cb, NULL);
337 event_base_set(base, &write_evs[i]);
338 event_add(&write_evs[i], NULL);
345 for (j = 0; j <
i; ++j) {
346 event_del(&read_evs[j]);
347 event_del(&write_evs[j]);
349 close(read_evs[j].ev_fd);
350 close(write_evs[j].ev_fd);
352 CloseHandle((HANDLE)read_evs[j].ev_fd);
353 CloseHandle((HANDLE)write_evs[j].ev_fd);
360 event_base_free(base);
362 fprintf(stdout,
"OK\n");
366 test_simpleread(
void)
371 setup_test(
"Simple read: ");
373 write(pair[0], TEST1, strlen(TEST1)+1);
374 shutdown(pair[0], SHUT_WR);
376 event_set(&ev, pair[1], EV_READ, simple_read_cb, &ev);
377 if (event_add(&ev, NULL) == -1)
385 test_simplewrite(
void)
390 setup_test(
"Simple write: ");
392 event_set(&ev, pair[0], EV_WRITE, simple_write_cb, &ev);
393 if (event_add(&ev, NULL) == -1)
403 struct event ev, ev2;
407 setup_test(
"Multiple read/write: ");
408 memset(rbuf, 0,
sizeof(rbuf));
409 for (i = 0; i <
sizeof(wbuf); i++)
415 event_set(&ev, pair[0], EV_WRITE, multiple_write_cb, &ev);
416 if (event_add(&ev, NULL) == -1)
418 event_set(&ev2, pair[1], EV_READ, multiple_read_cb, &ev2);
419 if (event_add(&ev2, NULL) == -1)
424 test_ok = memcmp(rbuf, wbuf,
sizeof(wbuf)) == 0;
430 test_persistent(
void)
432 struct event ev, ev2;
436 setup_test(
"Persist read/write: ");
437 memset(rbuf, 0,
sizeof(rbuf));
438 for (i = 0; i <
sizeof(wbuf); i++)
444 event_set(&ev, pair[0], EV_WRITE|EV_PERSIST, multiple_write_cb, &ev);
445 if (event_add(&ev, NULL) == -1)
447 event_set(&ev2, pair[1], EV_READ|EV_PERSIST, multiple_read_cb, &ev2);
448 if (event_add(&ev2, NULL) == -1)
453 test_ok = memcmp(rbuf, wbuf,
sizeof(wbuf)) == 0;
461 struct both r1, r2, w1, w2;
463 setup_test(
"Combined read/write: ");
464 memset(&r1, 0,
sizeof(r1));
465 memset(&r2, 0,
sizeof(r2));
466 memset(&w1, 0,
sizeof(w1));
467 memset(&w2, 0,
sizeof(w2));
472 event_set(&r1.ev, pair[0], EV_READ, combined_read_cb, &r1);
473 event_set(&w1.ev, pair[0], EV_WRITE, combined_write_cb, &w1);
474 event_set(&r2.ev, pair[1], EV_READ, combined_read_cb, &r2);
475 event_set(&w2.ev, pair[1], EV_WRITE, combined_write_cb, &w2);
476 if (event_add(&r1.ev, NULL) == -1)
478 if (event_add(&w1.ev, NULL))
480 if (event_add(&r2.ev, NULL))
482 if (event_add(&w2.ev, NULL))
487 if (r1.nread == 8192 && r2.nread == 4096)
494 test_simpletimeout(
void)
499 setup_test(
"Simple timeout: ");
506 evutil_gettimeofday(&tset, NULL);
516 child_signal_cb(
int fd,
short event,
void *arg)
531 int status, got_sigchld = 0;
532 struct event ev, sig_ev;
535 setup_test(
"After fork: ");
537 write(pair[0], TEST1, strlen(TEST1)+1);
539 event_set(&ev, pair[1], EV_READ, simple_read_cb, &ev);
540 if (event_add(&ev, NULL) == -1)
543 signal_set(&sig_ev, SIGCHLD, child_signal_cb, &got_sigchld);
544 signal_add(&sig_ev, NULL);
546 if ((pid = fork()) == 0) {
548 if (event_reinit(current_base) == -1) {
549 fprintf(stderr,
"FAILED (reinit)\n");
562 exit(test_ok != 0 || called != 2 ? -2 : 76);
568 write(pair[0], TEST1, strlen(TEST1)+1);
570 if (waitpid(pid, &status, 0) == -1) {
571 fprintf(stderr,
"FAILED (fork)\n");
575 if (WEXITSTATUS(status) != 76) {
576 fprintf(stderr,
"FAILED (exit): %d\n", WEXITSTATUS(status));
581 write(pair[0], TEST1, strlen(TEST1)+1);
582 shutdown(pair[0], SHUT_WR);
587 fprintf(stdout,
"FAILED (sigchld)\n");
597 test_simplesignal(
void)
602 setup_test(
"Simple signal: ");
603 signal_set(&ev, SIGALRM, signal_cb, &ev);
604 signal_add(&ev, NULL);
607 signal_add(&ev, NULL);
609 memset(&itv, 0,
sizeof(itv));
610 itv.it_value.tv_sec = 1;
611 if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
612 goto skip_simplesignal;
616 if (signal_del(&ev) == -1)
623 test_multiplesignal(
void)
625 struct event ev_one, ev_two;
628 setup_test(
"Multiple signal: ");
630 signal_set(&ev_one, SIGALRM, signal_cb, &ev_one);
631 signal_add(&ev_one, NULL);
633 signal_set(&ev_two, SIGALRM, signal_cb, &ev_two);
634 signal_add(&ev_two, NULL);
636 memset(&itv, 0,
sizeof(itv));
637 itv.it_value.tv_sec = 1;
638 if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
639 goto skip_simplesignal;
644 if (signal_del(&ev_one) == -1)
646 if (signal_del(&ev_two) == -1)
653 test_immediatesignal(
void)
658 printf(
"Immediate signal: ");
659 signal_set(&ev, SIGUSR1, signal_cb, &ev);
660 signal_add(&ev, NULL);
668 test_signal_dealloc(
void)
673 printf(
"Signal dealloc: ");
674 signal_set(&ev, SIGUSR1, signal_cb, &ev);
675 signal_add(&ev, NULL);
677 event_base_free(base);
684 test_signal_pipeloss(
void)
690 printf(
"Signal pipeloss: ");
691 base1 = event_init();
692 pipe1 = base1->sig.ev_signal_pair[0];
693 base2 = event_init();
694 event_base_free(base2);
695 event_base_free(base1);
696 if (close(pipe1) != -1 || errno!=EBADF) {
698 printf(
"signal pipe not closed. ");
712 test_signal_switchbase(
void)
714 struct event ev1, ev2;
718 printf(
"Signal switchbase: ");
719 base1 = event_init();
720 base2 = event_init();
721 is_kqueue = !strcmp(event_get_method(),
"kqueue");
722 signal_set(&ev1, SIGUSR1, signal_cb, &ev1);
723 signal_set(&ev2, SIGUSR1, signal_cb, &ev2);
724 if (event_base_set(base1, &ev1) ||
725 event_base_set(base2, &ev2) ||
726 event_add(&ev1, NULL) ||
727 event_add(&ev2, NULL)) {
728 fprintf(stderr,
"%s: cannot set base, add\n", __func__);
742 if (test_ok && !is_kqueue) {
752 event_base_free(base1);
753 event_base_free(base2);
762 test_signal_assert(
void)
767 printf(
"Signal handler assert: ");
769 signal_set(&ev, SIGCONT, signal_cb, &ev);
770 signal_add(&ev, NULL);
779 if (base->sig.evsignal_caught)
784 event_base_free(base);
793 test_signal_restore(
void)
797 #ifdef HAVE_SIGACTION
802 printf(
"Signal handler restore: ");
803 #ifdef HAVE_SIGACTION
804 sa.sa_handler = signal_cb_sa;
806 sigemptyset(&sa.sa_mask);
810 if (signal(SIGUSR1, signal_cb_sa) == SIG_ERR)
813 signal_set(&ev, SIGUSR1, signal_cb, &ev);
814 signal_add(&ev, NULL);
822 event_base_free(base);
828 signal_cb_swp(
int sig,
short event,
void *arg)
834 event_loopexit(NULL);
837 timeout_cb_swp(
int fd,
short event,
void *arg)
848 event_loopexit(NULL);
852 test_signal_while_processing(
void)
855 struct event ev, ev_timer;
858 setup_test(
"Receiving a signal while processing other signal: ");
862 signal_set(&ev, SIGUSR1, signal_cb_swp, NULL);
863 signal_add(&ev, NULL);
868 event_base_free(base);
875 test_free_active_base(
void)
879 setup_test(
"Free active base: ");
880 base1 = event_init();
881 event_set(&ev1, pair[1], EV_READ, simple_read_cb, &ev1);
882 event_base_set(base1, &ev1);
883 event_add(&ev1, NULL);
885 event_base_free(base1);
891 test_event_base_new(
void)
895 setup_test(
"Event base new: ");
897 write(pair[0], TEST1, strlen(TEST1)+1);
898 shutdown(pair[0], SHUT_WR);
900 base = event_base_new();
901 event_set(&ev1, pair[1], EV_READ, simple_read_cb, &ev1);
902 event_base_set(base, &ev1);
903 event_add(&ev1, NULL);
905 event_base_dispatch(base);
907 event_base_free(base);
915 struct timeval tv, tv_start, tv_end;
918 setup_test(
"Loop exit: ");
921 tv.tv_sec = 60*60*24;
929 evutil_gettimeofday(&tv_start, NULL);
931 evutil_gettimeofday(&tv_end, NULL);
932 evutil_timersub(&tv_end, &tv_start, &tv_end);
943 test_loopexit_multiple(
void)
948 setup_test(
"Loop Multiple exit: ");
950 base = event_base_new();
954 event_base_loopexit(base, &tv);
958 event_base_loopexit(base, &tv);
960 event_base_dispatch(base);
962 event_base_free(base);
970 break_cb(
int fd,
short events,
void *arg)
977 fail_cb(
int fd,
short events,
void *arg)
985 struct event ev1, ev2;
988 setup_test(
"Loop break: ");
1006 test_evbuffer(
void) {
1008 struct evbuffer *evb = evbuffer_new();
1009 setup_test(
"Testing Evbuffer: ");
1011 evbuffer_add_printf(evb,
"%s/%d",
"hello", 1);
1013 if (EVBUFFER_LENGTH(evb) == 7 &&
1014 strcmp((
char*)EVBUFFER_DATA(evb),
"hello/1") == 0)
1023 test_evbuffer_find(
void)
1026 const char* test1 =
"1234567890\r\n";
1027 const char* test2 =
"1234567890\r";
1028 #define EVBUFFER_INITIAL_LENGTH 256
1029 char test3[EVBUFFER_INITIAL_LENGTH];
1031 struct evbuffer * buf = evbuffer_new();
1034 fprintf(stdout,
"Testing evbuffer_find 1: ");
1035 evbuffer_add(buf, (u_char*)test1, strlen(test1));
1036 evbuffer_drain(buf, strlen(test1));
1037 evbuffer_add(buf, (u_char*)test2, strlen(test2));
1038 p = evbuffer_find(buf, (u_char*)
"\r\n", 2);
1040 fprintf(stdout,
"OK\n");
1042 fprintf(stdout,
"FAILED\n");
1050 fprintf(stdout,
"Testing evbuffer_find 2: ");
1051 evbuffer_drain(buf, strlen(test2));
1052 for (i = 0; i < EVBUFFER_INITIAL_LENGTH; ++
i)
1054 test3[EVBUFFER_INITIAL_LENGTH - 1] =
'x';
1055 evbuffer_add(buf, (u_char *)test3, EVBUFFER_INITIAL_LENGTH);
1056 p = evbuffer_find(buf, (u_char *)
"xy", 2);
1060 fprintf(stdout,
"FAILED\n");
1065 fprintf(stdout,
"Testing evbuffer_find 3: ");
1066 p = evbuffer_find(buf, (u_char *)
"ax", 2);
1067 if (p != NULL && strncmp((
char*)p,
"ax", 2) == 0) {
1070 fprintf(stdout,
"FAILED\n");
1084 if (EVBUFFER_LENGTH(bev->input) == 8333) {
1085 bufferevent_disable(bev, EV_READ);
1093 if (EVBUFFER_LENGTH(bev->output) == 0)
1098 errorcb(
struct bufferevent *bev,
short what,
void *arg)
1104 test_bufferevent(
void)
1110 setup_test(
"Bufferevent: ");
1112 bev1 = bufferevent_new(pair[0], readcb, writecb, errorcb, NULL);
1113 bev2 = bufferevent_new(pair[1], readcb, writecb, errorcb, NULL);
1115 bufferevent_disable(bev1, EV_READ);
1116 bufferevent_enable(bev2, EV_READ);
1118 for (i = 0; i <
sizeof(buffer); i++)
1121 bufferevent_write(bev1, buffer,
sizeof(buffer));
1125 bufferevent_free(bev1);
1126 bufferevent_free(bev2);
1141 int len = EVBUFFER_LENGTH(bev->input);
1144 assert(len >= 10 && len <= 20);
1146 evbuffer_drain(bev->input, len);
1149 if (nread == 65000) {
1150 bufferevent_disable(bev, EV_READ);
1158 if (EVBUFFER_LENGTH(bev->output) == 0)
1163 wm_errorcb(
struct bufferevent *bev,
short what,
void *arg)
1169 test_bufferevent_watermarks(
void)
1175 setup_test(
"Bufferevent Watermarks: ");
1177 bev1 = bufferevent_new(pair[0], NULL, wm_writecb, wm_errorcb, NULL);
1178 bev2 = bufferevent_new(pair[1], wm_readcb, NULL, wm_errorcb, NULL);
1180 bufferevent_disable(bev1, EV_READ);
1181 bufferevent_enable(bev2, EV_READ);
1183 for (i = 0; i <
sizeof(buffer); i++)
1186 bufferevent_write(bev1, buffer,
sizeof(buffer));
1189 bufferevent_setwatermark(bev2, EV_READ, 10, 20);
1193 bufferevent_free(bev1);
1194 bufferevent_free(bev2);
1208 test_priorities_cb(
int fd,
short what,
void *arg)
1213 if (pri->count == 3) {
1214 event_loopexit(NULL);
1220 evutil_timerclear(&tv);
1221 event_add(&pri->ev, &tv);
1225 test_priorities(
int npriorities)
1231 evutil_snprintf(buf,
sizeof(buf),
"Testing Priorities %d: ", npriorities);
1234 event_base_priority_init(global_base, npriorities);
1236 memset(&one, 0,
sizeof(one));
1237 memset(&two, 0,
sizeof(two));
1240 if (event_priority_set(&one.ev, 0) == -1) {
1241 fprintf(stderr,
"%s: failed to set priority", __func__);
1246 if (event_priority_set(&two.ev, npriorities - 1) == -1) {
1247 fprintf(stderr,
"%s: failed to set priority", __func__);
1251 evutil_timerclear(&tv);
1253 if (event_add(&one.ev, &tv) == -1)
1255 if (event_add(&two.ev, &tv) == -1)
1263 if (npriorities == 1) {
1264 if (one.count == 3 && two.count == 3)
1266 }
else if (npriorities == 2) {
1268 if (one.count == 3 && two.count == 1)
1271 if (one.count == 3 && two.count == 0)
1279 test_multiple_cb(
int fd,
short event,
void *arg)
1281 if (event & EV_READ)
1283 else if (event & EV_WRITE)
1288 test_multiple_events_for_same_fd(
void)
1290 struct event e1, e2;
1292 setup_test(
"Multiple events for same fd: ");
1294 event_set(&e1, pair[0], EV_READ, test_multiple_cb, NULL);
1295 event_add(&e1, NULL);
1296 event_set(&e2, pair[0], EV_WRITE, test_multiple_cb, NULL);
1297 event_add(&e2, NULL);
1300 write(pair[1], TEST1, strlen(TEST1)+1);
1310 int evtag_decode_int(uint32_t *pnumber,
struct evbuffer *evbuf);
1311 int evtag_encode_tag(
struct evbuffer *evbuf, uint32_t number);
1312 int evtag_decode_tag(uint32_t *pnumber,
struct evbuffer *evbuf);
1315 read_once_cb(
int fd,
short event,
void *arg)
1320 len = read(fd, buf,
sizeof(buf));
1326 write(pair[0], TEST1, strlen(TEST1)+1);
1334 test_want_only_once(
void)
1340 setup_test(
"Want read only once: ");
1342 write(pair[0], TEST1, strlen(TEST1)+1);
1345 evutil_timerclear(&tv);
1347 event_loopexit(&tv);
1349 event_set(&ev, pair[1], EV_READ, read_once_cb, &ev);
1350 if (event_add(&ev, NULL) == -1)
1357 #define TEST_MAX_INT 6
1360 evtag_int_test(
void)
1362 struct evbuffer *tmp = evbuffer_new();
1363 uint32_t integers[TEST_MAX_INT] = {
1364 0xaf0, 0x1000, 0x1, 0xdeadbeef, 0x00, 0xbef000
1369 for (i = 0; i < TEST_MAX_INT; i++) {
1371 oldlen = EVBUFFER_LENGTH(tmp);
1373 newlen = EVBUFFER_LENGTH(tmp);
1374 fprintf(stdout,
"\t\tencoded 0x%08x with %d bytes\n",
1375 integers[i], newlen - oldlen);
1378 for (i = 0; i < TEST_MAX_INT; i++) {
1379 if (evtag_decode_int(&integer, tmp) == -1) {
1380 fprintf(stderr,
"decode %d failed", i);
1383 if (integer != integers[i]) {
1384 fprintf(stderr,
"got %x, wanted %x",
1385 integer, integers[i]);
1390 if (EVBUFFER_LENGTH(tmp) != 0) {
1391 fprintf(stderr,
"trailing data");
1396 fprintf(stdout,
"\t%s: OK\n", __func__);
1402 u_char buffer[4096];
1403 struct evbuffer *tmp = evbuffer_new();
1408 for (j = 0; j < 100; j++) {
1409 for (i = 0; i <
sizeof(buffer); i++)
1411 evbuffer_drain(tmp, -1);
1412 evbuffer_add(tmp, buffer,
sizeof(buffer));
1414 if (evtag_unmarshal_timeval(tmp, 0, &tv) != -1)
1419 if (not_failed >= 10) {
1420 fprintf(stderr,
"evtag_unmarshal should have failed");
1425 evbuffer_drain(tmp, -1);
1426 evutil_timerclear(&tv);
1428 evtag_marshal_timeval(tmp, 0, &tv);
1429 evbuffer_add(tmp, buffer,
sizeof(buffer));
1431 EVBUFFER_DATA(tmp)[1] = 0xff;
1432 if (evtag_unmarshal_timeval(tmp, 0, &tv) != -1) {
1433 fprintf(stderr,
"evtag_unmarshal_timeval should have failed");
1439 fprintf(stdout,
"\t%s: OK\n", __func__);
1443 evtag_tag_encoding(
void)
1445 struct evbuffer *tmp = evbuffer_new();
1446 uint32_t integers[TEST_MAX_INT] = {
1447 0xaf0, 0x1000, 0x1, 0xdeadbeef, 0x00, 0xbef000
1452 for (i = 0; i < TEST_MAX_INT; i++) {
1454 oldlen = EVBUFFER_LENGTH(tmp);
1455 evtag_encode_tag(tmp, integers[i]);
1456 newlen = EVBUFFER_LENGTH(tmp);
1457 fprintf(stdout,
"\t\tencoded 0x%08x with %d bytes\n",
1458 integers[i], newlen - oldlen);
1461 for (i = 0; i < TEST_MAX_INT; i++) {
1462 if (evtag_decode_tag(&integer, tmp) == -1) {
1463 fprintf(stderr,
"decode %d failed", i);
1466 if (integer != integers[i]) {
1467 fprintf(stderr,
"got %x, wanted %x",
1468 integer, integers[i]);
1473 if (EVBUFFER_LENGTH(tmp) != 0) {
1474 fprintf(stderr,
"trailing data");
1479 fprintf(stdout,
"\t%s: OK\n", __func__);
1485 fprintf(stdout,
"Testing Tagging:\n");
1491 evtag_tag_encoding();
1493 fprintf(stdout,
"OK\n");
1501 struct kill *attack;
1503 struct evbuffer *tmp = evbuffer_new();
1504 struct timeval tv_start, tv_end;
1508 fprintf(stdout,
"Testing RPC: ");
1511 EVTAG_ASSIGN(msg, from_name,
"niels");
1512 EVTAG_ASSIGN(msg, to_name,
"phoenix");
1514 if (EVTAG_GET(msg, attack, &attack) == -1) {
1515 fprintf(stderr,
"Failed to set kill message.\n");
1519 EVTAG_ASSIGN(attack, weapon,
"feather");
1520 EVTAG_ASSIGN(attack, action,
"tickle");
1522 evutil_gettimeofday(&tv_start, NULL);
1523 for (i = 0; i < 1000; ++
i) {
1524 run = EVTAG_ADD(msg, run);
1526 fprintf(stderr,
"Failed to add run message.\n");
1529 EVTAG_ASSIGN(run, how,
"very fast but with some data in it");
1530 EVTAG_ASSIGN(run, fixed_bytes,
1531 (
unsigned char*)
"012345678901234567890123");
1534 if (msg_complete(msg) == -1) {
1535 fprintf(stderr,
"Failed to make complete message.\n");
1539 evtag_marshal_msg(tmp, 0xdeaf, msg);
1541 if (evtag_peek(tmp, &tag) == -1) {
1542 fprintf(stderr,
"Failed to peak tag.\n");
1546 if (tag != 0xdeaf) {
1547 fprintf(stderr,
"Got incorrect tag: %0x.\n", tag);
1552 if (evtag_unmarshal_msg(tmp, 0xdeaf, msg2) == -1) {
1553 fprintf(stderr,
"Failed to unmarshal message.\n");
1557 evutil_gettimeofday(&tv_end, NULL);
1558 evutil_timersub(&tv_end, &tv_start, &tv_end);
1559 fprintf(stderr,
"(%.1f us/add) ",
1560 (
float)tv_end.tv_sec/(
float)i * 1000000.0 +
1561 tv_end.tv_usec / (
float)i);
1563 if (!EVTAG_HAS(msg2, from_name) ||
1564 !EVTAG_HAS(msg2, to_name) ||
1565 !EVTAG_HAS(msg2, attack)) {
1566 fprintf(stderr,
"Missing data structures.\n");
1570 if (EVTAG_LEN(msg2, run) != i) {
1571 fprintf(stderr,
"Wrong number of run messages.\n");
1580 fprintf(stdout,
"OK\n");
1585 test_evutil_strtoll(
void)
1589 setup_test(
"evutil_stroll: ");
1592 if (evutil_strtoll(
"5000000000", NULL, 10) != ((ev_int64_t)5000000)*1000)
1594 if (evutil_strtoll(
"-5000000000", NULL, 10) != ((ev_int64_t)5000000)*-1000)
1597 if (evutil_strtoll(s, &endptr, 10) != (ev_int64_t)99999)
1601 if (evutil_strtoll(
"foo", NULL, 10) != 0)
1611 main (
int argc,
char **argv)
1614 WORD wVersionRequested;
1618 wVersionRequested = MAKEWORD( 2, 2 );
1620 err = WSAStartup( wVersionRequested, &wsaData );
1624 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
1627 setvbuf(stdout, NULL, _IONBF, 0);
1630 global_base = event_init();
1634 test_evutil_strtoll();
1642 test_evbuffer_find();
1645 test_bufferevent_watermarks();
1647 test_free_active_base();
1649 test_event_base_new();
1673 test_simpletimeout();
1675 test_simplesignal();
1676 test_multiplesignal();
1677 test_immediatesignal();
1682 test_loopexit_multiple();
1684 test_multiple_events_for_same_fd();
1686 test_want_only_once();
1693 test_signal_dealloc();
1694 test_signal_pipeloss();
1695 test_signal_switchbase();
1696 test_signal_restore();
1697 test_signal_assert();
1698 test_signal_while_processing();