Wed Aug 5 18:33:20 2009 UTC ()
Pull up following revision(s) (requested by tls in ticket #854):
	regress/lib/libevent/regress.c: revision 1.2
	regress/lib/libevent/regress.gen.c: revision 1.2
	regress/lib/libevent/regress.gen.h: revision 1.2
	regress/lib/libevent/regress_dns.c: revision 1.2
	regress/lib/libevent/regress_http.c: revision 1.2
	regress/lib/libevent/regress_rpc.c: revision 1.2
Update regression tests for libevent-1.4.11-stable.


(snj)
diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/regress.c
diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/regress.gen.c
diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/regress.gen.h
diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/regress_dns.c
diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/regress_http.c
diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/regress_rpc.c

cvs diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/Attic/regress.c (expand / switch to unified diff)

--- src/regress/lib/libevent/Attic/regress.c 2008/05/16 20:24:57 1.1
+++ src/regress/lib/libevent/Attic/regress.c 2009/08/05 18:33:20 1.1.8.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: regress.c,v 1.1 2008/05/16 20:24:57 peter Exp $ */ 1/* $NetBSD: regress.c,v 1.1.8.1 2009/08/05 18:33:20 snj Exp $ */
2/* 2/*
3 * Copyright (c) 2003, 2004 Niels Provos <provos@citi.umich.edu> 3 * Copyright (c) 2003, 2004 Niels Provos <provos@citi.umich.edu>
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products 14 * 3. The name of the author may not be used to endorse or promote products
@@ -73,44 +73,50 @@ static struct event_base *global_base; @@ -73,44 +73,50 @@ static struct event_base *global_base;
73#define TEST1 "this is a test" 73#define TEST1 "this is a test"
74#define SECONDS 1 74#define SECONDS 1
75 75
76#ifndef SHUT_WR 76#ifndef SHUT_WR
77#define SHUT_WR 1 77#define SHUT_WR 1
78#endif 78#endif
79 79
80static void 80static void
81simple_read_cb(int fd, short event, void *arg) 81simple_read_cb(int fd, short event, void *arg)
82{ 82{
83 char buf[256]; 83 char buf[256];
84 int len; 84 int len;
85 85
 86 if (arg == NULL)
 87 return;
 88
86 len = read(fd, buf, sizeof(buf)); 89 len = read(fd, buf, sizeof(buf));
87 90
88 if (len) { 91 if (len) {
89 if (!called) { 92 if (!called) {
90 if (event_add(arg, NULL) == -1) 93 if (event_add(arg, NULL) == -1)
91 exit(1); 94 exit(1);
92 } 95 }
93 } else if (called == 1) 96 } else if (called == 1)
94 test_ok = 1; 97 test_ok = 1;
95 98
96 called++; 99 called++;
97} 100}
98 101
99static void 102static void
100simple_write_cb(int fd, short event, void *arg) 103simple_write_cb(int fd, short event, void *arg)
101{ 104{
102 int len; 105 int len;
103 106
 107 if (arg == NULL)
 108 return;
 109
104 len = write(fd, TEST1, strlen(TEST1) + 1); 110 len = write(fd, TEST1, strlen(TEST1) + 1);
105 if (len == -1) 111 if (len == -1)
106 test_ok = 0; 112 test_ok = 0;
107 else 113 else
108 test_ok = 1; 114 test_ok = 1;
109} 115}
110 116
111static void 117static void
112multiple_write_cb(int fd, short event, void *arg) 118multiple_write_cb(int fd, short event, void *arg)
113{ 119{
114 struct event *ev = arg; 120 struct event *ev = arg;
115 int len; 121 int len;
116 122
@@ -159,27 +165,27 @@ multiple_read_cb(int fd, short event, vo @@ -159,27 +165,27 @@ multiple_read_cb(int fd, short event, vo
159 roff += len; 165 roff += len;
160 if (!usepersist) { 166 if (!usepersist) {
161 if (event_add(ev, NULL) == -1)  167 if (event_add(ev, NULL) == -1)
162 exit(1); 168 exit(1);
163 } 169 }
164} 170}
165 171
166static void 172static void
167timeout_cb(int fd, short event, void *arg) 173timeout_cb(int fd, short event, void *arg)
168{ 174{
169 struct timeval tv; 175 struct timeval tv;
170 int diff; 176 int diff;
171 177
172 gettimeofday(&tcalled, NULL); 178 evutil_gettimeofday(&tcalled, NULL);
173 if (evutil_timercmp(&tcalled, &tset, >)) 179 if (evutil_timercmp(&tcalled, &tset, >))
174 evutil_timersub(&tcalled, &tset, &tv); 180 evutil_timersub(&tcalled, &tset, &tv);
175 else 181 else
176 evutil_timersub(&tset, &tcalled, &tv); 182 evutil_timersub(&tset, &tcalled, &tv);
177 183
178 diff = tv.tv_sec*1000 + tv.tv_usec/1000 - SECONDS * 1000; 184 diff = tv.tv_sec*1000 + tv.tv_usec/1000 - SECONDS * 1000;
179 if (diff < 0) 185 if (diff < 0)
180 diff = -diff; 186 diff = -diff;
181 187
182 if (diff < 100) 188 if (diff < 100)
183 test_ok = 1; 189 test_ok = 1;
184} 190}
185 191
@@ -278,26 +284,72 @@ cleanup_test(void) @@ -278,26 +284,72 @@ cleanup_test(void)
278 close(pair[1]); 284 close(pair[1]);
279 285
280 if (test_ok) 286 if (test_ok)
281 fprintf(stdout, "OK\n"); 287 fprintf(stdout, "OK\n");
282 else { 288 else {
283 fprintf(stdout, "FAILED\n"); 289 fprintf(stdout, "FAILED\n");
284 exit(1); 290 exit(1);
285 } 291 }
286 test_ok = 0; 292 test_ok = 0;
287 return (0); 293 return (0);
288} 294}
289 295
290static void 296static void
 297test_registerfds(void)
 298{
 299 int i, j;
 300 int pair[2];
 301 struct event read_evs[512];
 302 struct event write_evs[512];
 303
 304 struct event_base *base = event_base_new();
 305
 306 fprintf(stdout, "Testing register fds: ");
 307
 308 for (i = 0; i < 512; ++i) {
 309 if (evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
 310 /* run up to the limit of file descriptors */
 311 break;
 312 }
 313 event_set(&read_evs[i], pair[0],
 314 EV_READ|EV_PERSIST, simple_read_cb, NULL);
 315 event_base_set(base, &read_evs[i]);
 316 event_add(&read_evs[i], NULL);
 317 event_set(&write_evs[i], pair[1],
 318 EV_WRITE|EV_PERSIST, simple_write_cb, NULL);
 319 event_base_set(base, &write_evs[i]);
 320 event_add(&write_evs[i], NULL);
 321
 322 /* just loop once */
 323 event_base_loop(base, EVLOOP_ONCE);
 324 }
 325
 326 /* now delete everything */
 327 for (j = 0; j < i; ++j) {
 328 event_del(&read_evs[j]);
 329 event_del(&write_evs[j]);
 330 close(read_evs[j].ev_fd);
 331 close(write_evs[j].ev_fd);
 332
 333 /* just loop once */
 334 event_base_loop(base, EVLOOP_ONCE);
 335 }
 336
 337 event_base_free(base);
 338
 339 fprintf(stdout, "OK\n");
 340}
 341
 342static void
291test_simpleread(void) 343test_simpleread(void)
292{ 344{
293 struct event ev; 345 struct event ev;
294 346
295 /* Very simple read test */ 347 /* Very simple read test */
296 setup_test("Simple read: "); 348 setup_test("Simple read: ");
297  349
298 write(pair[0], TEST1, strlen(TEST1)+1); 350 write(pair[0], TEST1, strlen(TEST1)+1);
299 shutdown(pair[0], SHUT_WR); 351 shutdown(pair[0], SHUT_WR);
300 352
301 event_set(&ev, pair[1], EV_READ, simple_read_cb, &ev); 353 event_set(&ev, pair[1], EV_READ, simple_read_cb, &ev);
302 if (event_add(&ev, NULL) == -1) 354 if (event_add(&ev, NULL) == -1)
303 exit(1); 355 exit(1);
@@ -418,55 +470,74 @@ test_combined(void) @@ -418,55 +470,74 @@ test_combined(void)
418static void 470static void
419test_simpletimeout(void) 471test_simpletimeout(void)
420{ 472{
421 struct timeval tv; 473 struct timeval tv;
422 struct event ev; 474 struct event ev;
423 475
424 setup_test("Simple timeout: "); 476 setup_test("Simple timeout: ");
425 477
426 tv.tv_usec = 0; 478 tv.tv_usec = 0;
427 tv.tv_sec = SECONDS; 479 tv.tv_sec = SECONDS;
428 evtimer_set(&ev, timeout_cb, NULL); 480 evtimer_set(&ev, timeout_cb, NULL);
429 evtimer_add(&ev, &tv); 481 evtimer_add(&ev, &tv);
430 482
431 gettimeofday(&tset, NULL); 483 evutil_gettimeofday(&tset, NULL);
432 event_dispatch(); 484 event_dispatch();
433 485
434 cleanup_test(); 486 cleanup_test();
435} 487}
436 488
437extern struct event_base *current_base; 489extern struct event_base *current_base;
 490
 491static void
 492child_signal_cb(int fd, short event, void *arg)
 493{
 494 struct timeval tv;
 495 int *pint = arg;
 496
 497 *pint = 1;
 498
 499 tv.tv_usec = 500000;
 500 tv.tv_sec = 0;
 501 event_loopexit(&tv);
 502}
 503
438static void 504static void
439test_fork(void) 505test_fork(void)
440{ 506{
441 int status; 507 int status, got_sigchld = 0;
442 struct event ev; 508 struct event ev, sig_ev;
443 pid_t pid; 509 pid_t pid;
444 510
445 setup_test("After fork: "); 511 setup_test("After fork: ");
446 512
447 write(pair[0], TEST1, strlen(TEST1)+1); 513 write(pair[0], TEST1, strlen(TEST1)+1);
448 514
449 event_set(&ev, pair[1], EV_READ, simple_read_cb, &ev); 515 event_set(&ev, pair[1], EV_READ, simple_read_cb, &ev);
450 if (event_add(&ev, NULL) == -1) 516 if (event_add(&ev, NULL) == -1)
451 exit(1); 517 exit(1);
452 518
 519 signal_set(&sig_ev, SIGCHLD, child_signal_cb, &got_sigchld);
 520 signal_add(&sig_ev, NULL);
 521
453 if ((pid = fork()) == 0) { 522 if ((pid = fork()) == 0) {
454 /* in the child */ 523 /* in the child */
455 if (event_reinit(current_base) == -1) { 524 if (event_reinit(current_base) == -1) {
456 fprintf(stderr, "FAILED (reinit)\n"); 525 fprintf(stderr, "FAILED (reinit)\n");
457 exit(1); 526 exit(1);
458 } 527 }
459 528
 529 signal_del(&sig_ev);
 530
460 called = 0; 531 called = 0;
461 532
462 event_dispatch(); 533 event_dispatch();
463 534
464 /* we do not send an EOF; simple_read_cb requires an EOF  535 /* we do not send an EOF; simple_read_cb requires an EOF
465 * to set test_ok. we just verify that the callback was 536 * to set test_ok. we just verify that the callback was
466 * called. */ 537 * called. */
467 exit(test_ok != 0 || called != 2 ? -2 : 76); 538 exit(test_ok != 0 || called != 2 ? -2 : 76);
468 } 539 }
469 540
470 /* wait for the child to read the data */ 541 /* wait for the child to read the data */
471 sleep(1); 542 sleep(1);
472 543
@@ -478,53 +549,93 @@ test_fork(void) @@ -478,53 +549,93 @@ test_fork(void)
478 } 549 }
479  550
480 if (WEXITSTATUS(status) != 76) { 551 if (WEXITSTATUS(status) != 76) {
481 fprintf(stderr, "FAILED (exit): %d\n", WEXITSTATUS(status)); 552 fprintf(stderr, "FAILED (exit): %d\n", WEXITSTATUS(status));
482 exit(1); 553 exit(1);
483 } 554 }
484 555
485 /* test that the current event loop still works */ 556 /* test that the current event loop still works */
486 write(pair[0], TEST1, strlen(TEST1)+1); 557 write(pair[0], TEST1, strlen(TEST1)+1);
487 shutdown(pair[0], SHUT_WR); 558 shutdown(pair[0], SHUT_WR);
488 559
489 event_dispatch(); 560 event_dispatch();
490 561
 562 if (!got_sigchld) {
 563 fprintf(stdout, "FAILED (sigchld)\n");
 564 exit(1);
 565 }
 566
 567 signal_del(&sig_ev);
 568
491 cleanup_test(); 569 cleanup_test();
492} 570}
493 571
494static void 572static void
495test_simplesignal(void) 573test_simplesignal(void)
496{ 574{
497 struct event ev; 575 struct event ev;
498 struct itimerval itv; 576 struct itimerval itv;
499 577
500 setup_test("Simple signal: "); 578 setup_test("Simple signal: ");
501 signal_set(&ev, SIGALRM, signal_cb, &ev); 579 signal_set(&ev, SIGALRM, signal_cb, &ev);
502 signal_add(&ev, NULL); 580 signal_add(&ev, NULL);
 581 /* find bugs in which operations are re-ordered */
 582 signal_del(&ev);
 583 signal_add(&ev, NULL);
503 584
504 memset(&itv, 0, sizeof(itv)); 585 memset(&itv, 0, sizeof(itv));
505 itv.it_value.tv_sec = 1; 586 itv.it_value.tv_sec = 1;
506 if (setitimer(ITIMER_REAL, &itv, NULL) == -1) 587 if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
507 goto skip_simplesignal; 588 goto skip_simplesignal;
508 589
509 event_dispatch(); 590 event_dispatch();
510 skip_simplesignal: 591 skip_simplesignal:
511 if (signal_del(&ev) == -1) 592 if (signal_del(&ev) == -1)
512 test_ok = 0; 593 test_ok = 0;
513 594
514 cleanup_test(); 595 cleanup_test();
515} 596}
516 597
517static void 598static void
 599test_multiplesignal(void)
 600{
 601 struct event ev_one, ev_two;
 602 struct itimerval itv;
 603
 604 setup_test("Multiple signal: ");
 605
 606 signal_set(&ev_one, SIGALRM, signal_cb, &ev_one);
 607 signal_add(&ev_one, NULL);
 608
 609 signal_set(&ev_two, SIGALRM, signal_cb, &ev_two);
 610 signal_add(&ev_two, NULL);
 611
 612 memset(&itv, 0, sizeof(itv));
 613 itv.it_value.tv_sec = 1;
 614 if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
 615 goto skip_simplesignal;
 616
 617 event_dispatch();
 618
 619 skip_simplesignal:
 620 if (signal_del(&ev_one) == -1)
 621 test_ok = 0;
 622 if (signal_del(&ev_two) == -1)
 623 test_ok = 0;
 624
 625 cleanup_test();
 626}
 627
 628static void
518test_immediatesignal(void) 629test_immediatesignal(void)
519{ 630{
520 struct event ev; 631 struct event ev;
521 632
522 test_ok = 0; 633 test_ok = 0;
523 printf("Immediate signal: "); 634 printf("Immediate signal: ");
524 signal_set(&ev, SIGUSR1, signal_cb, &ev); 635 signal_set(&ev, SIGUSR1, signal_cb, &ev);
525 signal_add(&ev, NULL); 636 signal_add(&ev, NULL);
526 raise(SIGUSR1); 637 raise(SIGUSR1);
527 event_loop(EVLOOP_NONBLOCK); 638 event_loop(EVLOOP_NONBLOCK);
528 signal_del(&ev); 639 signal_del(&ev);
529 cleanup_test(); 640 cleanup_test();
530} 641}
@@ -680,26 +791,72 @@ test_signal_restore(void) @@ -680,26 +791,72 @@ test_signal_restore(void)
680 signal_del(&ev); 791 signal_del(&ev);
681 792
682 raise(SIGUSR1); 793 raise(SIGUSR1);
683 /* 1 == signal_cb, 2 == signal_cb_sa, we want our previous handler */ 794 /* 1 == signal_cb, 2 == signal_cb_sa, we want our previous handler */
684 if (test_ok != 2) 795 if (test_ok != 2)
685 test_ok = 0; 796 test_ok = 0;
686out: 797out:
687 event_base_free(base); 798 event_base_free(base);
688 cleanup_test(); 799 cleanup_test();
689 return; 800 return;
690} 801}
691 802
692static void 803static void
 804signal_cb_swp(int sig, short event, void *arg)
 805{
 806 called++;
 807 if (called < 5)
 808 raise(sig);
 809 else
 810 event_loopexit(NULL);
 811}
 812static void
 813timeout_cb_swp(int fd, short event, void *arg)
 814{
 815 if (called == -1) {
 816 struct timeval tv = {5, 0};
 817
 818 called = 0;
 819 evtimer_add((struct event *)arg, &tv);
 820 raise(SIGUSR1);
 821 return;
 822 }
 823 test_ok = 0;
 824 event_loopexit(NULL);
 825}
 826
 827static void
 828test_signal_while_processing(void)
 829{
 830 struct event_base *base = event_init();
 831 struct event ev, ev_timer;
 832 struct timeval tv = {0, 0};
 833
 834 setup_test("Receiving a signal while processing other signal: ");
 835
 836 called = -1;
 837 test_ok = 1;
 838 signal_set(&ev, SIGUSR1, signal_cb_swp, NULL);
 839 signal_add(&ev, NULL);
 840 evtimer_set(&ev_timer, timeout_cb_swp, &ev_timer);
 841 evtimer_add(&ev_timer, &tv);
 842 event_dispatch();
 843
 844 event_base_free(base);
 845 cleanup_test();
 846 return;
 847}
 848
 849static void
693test_free_active_base(void) 850test_free_active_base(void)
694{ 851{
695 struct event_base *base1; 852 struct event_base *base1;
696 struct event ev1; 853 struct event ev1;
697 setup_test("Free active base: "); 854 setup_test("Free active base: ");
698 base1 = event_init(); 855 base1 = event_init();
699 event_set(&ev1, pair[1], EV_READ, simple_read_cb, &ev1); 856 event_set(&ev1, pair[1], EV_READ, simple_read_cb, &ev1);
700 event_base_set(base1, &ev1); 857 event_base_set(base1, &ev1);
701 event_add(&ev1, NULL); 858 event_add(&ev1, NULL);
702 /* event_del(&ev1); */ 859 /* event_del(&ev1); */
703 event_base_free(base1); 860 event_base_free(base1);
704 test_ok = 1; 861 test_ok = 1;
705 cleanup_test(); 862 cleanup_test();
@@ -734,29 +891,29 @@ test_loopexit(void) @@ -734,29 +891,29 @@ test_loopexit(void)
734 struct event ev; 891 struct event ev;
735 892
736 setup_test("Loop exit: "); 893 setup_test("Loop exit: ");
737 894
738 tv.tv_usec = 0; 895 tv.tv_usec = 0;
739 tv.tv_sec = 60*60*24; 896 tv.tv_sec = 60*60*24;
740 evtimer_set(&ev, timeout_cb, NULL); 897 evtimer_set(&ev, timeout_cb, NULL);
741 evtimer_add(&ev, &tv); 898 evtimer_add(&ev, &tv);
742 899
743 tv.tv_usec = 0; 900 tv.tv_usec = 0;
744 tv.tv_sec = 1; 901 tv.tv_sec = 1;
745 event_loopexit(&tv); 902 event_loopexit(&tv);
746 903
747 gettimeofday(&tv_start, NULL); 904 evutil_gettimeofday(&tv_start, NULL);
748 event_dispatch(); 905 event_dispatch();
749 gettimeofday(&tv_end, NULL); 906 evutil_gettimeofday(&tv_end, NULL);
750 evutil_timersub(&tv_end, &tv_start, &tv_end); 907 evutil_timersub(&tv_end, &tv_start, &tv_end);
751 908
752 evtimer_del(&ev); 909 evtimer_del(&ev);
753 910
754 if (tv.tv_sec < 2) 911 if (tv.tv_sec < 2)
755 test_ok = 1; 912 test_ok = 1;
756 913
757 cleanup_test(); 914 cleanup_test();
758} 915}
759 916
760static void 917static void
761test_loopexit_multiple(void) 918test_loopexit_multiple(void)
762{ 919{
@@ -1036,27 +1193,27 @@ test_priorities_cb(int fd, short what, v @@ -1036,27 +1193,27 @@ test_priorities_cb(int fd, short what, v
1036 pri->count++; 1193 pri->count++;
1037 1194
1038 evutil_timerclear(&tv); 1195 evutil_timerclear(&tv);
1039 event_add(&pri->ev, &tv); 1196 event_add(&pri->ev, &tv);
1040} 1197}
1041 1198
1042static void 1199static void
1043test_priorities(int npriorities) 1200test_priorities(int npriorities)
1044{ 1201{
1045 char buf[32]; 1202 char buf[32];
1046 struct test_pri_event one, two; 1203 struct test_pri_event one, two;
1047 struct timeval tv; 1204 struct timeval tv;
1048 1205
1049 snprintf(buf, sizeof(buf), "Testing Priorities %d: ", npriorities); 1206 evutil_snprintf(buf, sizeof(buf), "Testing Priorities %d: ", npriorities);
1050 setup_test(buf); 1207 setup_test(buf);
1051 1208
1052 event_base_priority_init(global_base, npriorities); 1209 event_base_priority_init(global_base, npriorities);
1053 1210
1054 memset(&one, 0, sizeof(one)); 1211 memset(&one, 0, sizeof(one));
1055 memset(&two, 0, sizeof(two)); 1212 memset(&two, 0, sizeof(two));
1056 1213
1057 timeout_set(&one.ev, test_priorities_cb, &one); 1214 timeout_set(&one.ev, test_priorities_cb, &one);
1058 if (event_priority_set(&one.ev, 0) == -1) { 1215 if (event_priority_set(&one.ev, 0) == -1) {
1059 fprintf(stderr, "%s: failed to set priority", __func__); 1216 fprintf(stderr, "%s: failed to set priority", __func__);
1060 exit(1); 1217 exit(1);
1061 } 1218 }
1062 1219
@@ -1326,60 +1483,62 @@ rpc_test(void) @@ -1326,60 +1483,62 @@ rpc_test(void)
1326 1483
1327 msg = msg_new(); 1484 msg = msg_new();
1328 EVTAG_ASSIGN(msg, from_name, "niels"); 1485 EVTAG_ASSIGN(msg, from_name, "niels");
1329 EVTAG_ASSIGN(msg, to_name, "phoenix"); 1486 EVTAG_ASSIGN(msg, to_name, "phoenix");
1330 1487
1331 if (EVTAG_GET(msg, attack, &attack) == -1) { 1488 if (EVTAG_GET(msg, attack, &attack) == -1) {
1332 fprintf(stderr, "Failed to set kill message.\n"); 1489 fprintf(stderr, "Failed to set kill message.\n");
1333 exit(1); 1490 exit(1);
1334 } 1491 }
1335 1492
1336 EVTAG_ASSIGN(attack, weapon, "feather"); 1493 EVTAG_ASSIGN(attack, weapon, "feather");
1337 EVTAG_ASSIGN(attack, action, "tickle"); 1494 EVTAG_ASSIGN(attack, action, "tickle");
1338 1495
1339 gettimeofday(&tv_start, NULL); 1496 evutil_gettimeofday(&tv_start, NULL);
1340 for (i = 0; i < 1000; ++i) { 1497 for (i = 0; i < 1000; ++i) {
1341 run = EVTAG_ADD(msg, run); 1498 run = EVTAG_ADD(msg, run);
1342 if (run == NULL) { 1499 if (run == NULL) {
1343 fprintf(stderr, "Failed to add run message.\n"); 1500 fprintf(stderr, "Failed to add run message.\n");
1344 exit(1); 1501 exit(1);
1345 } 1502 }
1346 EVTAG_ASSIGN(run, how, "very fast but with some data in it"); 1503 EVTAG_ASSIGN(run, how, "very fast but with some data in it");
 1504 EVTAG_ASSIGN(run, fixed_bytes,
 1505 (unsigned char*)"012345678901234567890123");
1347 } 1506 }
1348 1507
1349 if (msg_complete(msg) == -1) { 1508 if (msg_complete(msg) == -1) {
1350 fprintf(stderr, "Failed to make complete message.\n"); 1509 fprintf(stderr, "Failed to make complete message.\n");
1351 exit(1); 1510 exit(1);
1352 } 1511 }
1353 1512
1354 evtag_marshal_msg(tmp, 0xdeaf, msg); 1513 evtag_marshal_msg(tmp, 0xdeaf, msg);
1355 1514
1356 if (evtag_peek(tmp, &tag) == -1) { 1515 if (evtag_peek(tmp, &tag) == -1) {
1357 fprintf(stderr, "Failed to peak tag.\n"); 1516 fprintf(stderr, "Failed to peak tag.\n");
1358 exit (1); 1517 exit (1);
1359 } 1518 }
1360 1519
1361 if (tag != 0xdeaf) { 1520 if (tag != 0xdeaf) {
1362 fprintf(stderr, "Got incorrect tag: %0x.\n", tag); 1521 fprintf(stderr, "Got incorrect tag: %0x.\n", tag);
1363 exit (1); 1522 exit (1);
1364 } 1523 }
1365 1524
1366 msg2 = msg_new(); 1525 msg2 = msg_new();
1367 if (evtag_unmarshal_msg(tmp, 0xdeaf, msg2) == -1) { 1526 if (evtag_unmarshal_msg(tmp, 0xdeaf, msg2) == -1) {
1368 fprintf(stderr, "Failed to unmarshal message.\n"); 1527 fprintf(stderr, "Failed to unmarshal message.\n");
1369 exit(1); 1528 exit(1);
1370 } 1529 }
1371 1530
1372 gettimeofday(&tv_end, NULL); 1531 evutil_gettimeofday(&tv_end, NULL);
1373 evutil_timersub(&tv_end, &tv_start, &tv_end); 1532 evutil_timersub(&tv_end, &tv_start, &tv_end);
1374 fprintf(stderr, "(%.1f us/add) ", 1533 fprintf(stderr, "(%.1f us/add) ",
1375 (float)tv_end.tv_sec/(float)i * 1000000.0 + 1534 (float)tv_end.tv_sec/(float)i * 1000000.0 +
1376 tv_end.tv_usec / (float)i); 1535 tv_end.tv_usec / (float)i);
1377 1536
1378 if (!EVTAG_HAS(msg2, from_name) || 1537 if (!EVTAG_HAS(msg2, from_name) ||
1379 !EVTAG_HAS(msg2, to_name) || 1538 !EVTAG_HAS(msg2, to_name) ||
1380 !EVTAG_HAS(msg2, attack)) { 1539 !EVTAG_HAS(msg2, attack)) {
1381 fprintf(stderr, "Missing data structures.\n"); 1540 fprintf(stderr, "Missing data structures.\n");
1382 exit(1); 1541 exit(1);
1383 } 1542 }
1384 1543
1385 if (EVTAG_LEN(msg2, run) != i) { 1544 if (EVTAG_LEN(msg2, run) != i) {
@@ -1415,31 +1574,35 @@ test_evutil_strtoll(void) @@ -1415,31 +1574,35 @@ test_evutil_strtoll(void)
1415 if (evutil_strtoll("foo", NULL, 10) != 0) 1574 if (evutil_strtoll("foo", NULL, 10) != 0)
1416 goto err; 1575 goto err;
1417 1576
1418 test_ok = 1; 1577 test_ok = 1;
1419 err: 1578 err:
1420 cleanup_test(); 1579 cleanup_test();
1421} 1580}
1422 1581
1423 1582
1424int 1583int
1425main (int argc, char **argv) 1584main (int argc, char **argv)
1426{ 1585{
1427 1586
 1587 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
 1588 return (1);
1428 setvbuf(stdout, NULL, _IONBF, 0); 1589 setvbuf(stdout, NULL, _IONBF, 0);
1429 1590
1430 /* Initalize the event library */ 1591 /* Initalize the event library */
1431 global_base = event_init(); 1592 global_base = event_init();
1432 1593
 1594 test_registerfds();
 1595
1433 test_evutil_strtoll(); 1596 test_evutil_strtoll();
1434 1597
1435 /* use the global event base and need to be called first */ 1598 /* use the global event base and need to be called first */
1436 test_priorities(1); 1599 test_priorities(1);
1437 test_priorities(2); 1600 test_priorities(2);
1438 test_priorities(3); 1601 test_priorities(3);
1439 1602
1440 test_evbuffer(); 1603 test_evbuffer();
1441 test_evbuffer_find(); 1604 test_evbuffer_find();
1442  1605
1443 test_bufferevent(); 1606 test_bufferevent();
1444 test_bufferevent_watermarks(); 1607 test_bufferevent_watermarks();
1445 1608
@@ -1457,37 +1620,39 @@ main (int argc, char **argv) @@ -1457,37 +1620,39 @@ main (int argc, char **argv)
1457 1620
1458 test_simpleread(); 1621 test_simpleread();
1459 1622
1460 test_simplewrite(); 1623 test_simplewrite();
1461 1624
1462 test_multiple(); 1625 test_multiple();
1463 1626
1464 test_persistent(); 1627 test_persistent();
1465 1628
1466 test_combined(); 1629 test_combined();
1467 1630
1468 test_simpletimeout(); 1631 test_simpletimeout();
1469 test_simplesignal(); 1632 test_simplesignal();
 1633 test_multiplesignal();
1470 test_immediatesignal(); 1634 test_immediatesignal();
1471 1635
1472 test_loopexit(); 1636 test_loopexit();
1473 test_loopbreak(); 1637 test_loopbreak();
1474 1638
1475 test_loopexit_multiple(); 1639 test_loopexit_multiple();
1476  1640
1477 test_multiple_events_for_same_fd(); 1641 test_multiple_events_for_same_fd();
1478 1642
1479 test_want_only_once(); 1643 test_want_only_once();
1480 1644
1481 evtag_test(); 1645 evtag_test();
1482 1646
1483 rpc_test(); 1647 rpc_test();
1484 1648
1485 test_signal_dealloc(); 1649 test_signal_dealloc();
1486 test_signal_pipeloss(); 1650 test_signal_pipeloss();
1487 test_signal_switchbase(); 1651 test_signal_switchbase();
1488 test_signal_restore(); 1652 test_signal_restore();
1489 test_signal_assert(); 1653 test_signal_assert();
 1654 test_signal_while_processing();
1490  1655
1491 return (0); 1656 return (0);
1492} 1657}
1493 1658

cvs diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/Attic/regress.gen.c (expand / switch to unified diff)

--- src/regress/lib/libevent/Attic/regress.gen.c 2008/05/16 20:24:57 1.1
+++ src/regress/lib/libevent/Attic/regress.gen.c 2009/08/05 18:33:20 1.1.8.1
@@ -1,28 +1,27 @@ @@ -1,28 +1,27 @@
1/* $NetBSD: regress.gen.c,v 1.1 2008/05/16 20:24:57 peter Exp $ */ 
2/* 1/*
3 * Automatically generated from ./regress.rpc 2 * Automatically generated from regress.rpc
4 * by event_rpcgen.py/0.1. DO NOT EDIT THIS FILE. 3 * by event_rpcgen.py/0.1. DO NOT EDIT THIS FILE.
5 */ 4 */
6 5
7#include <sys/types.h> 6#include <sys/types.h>
8#include <sys/time.h> 7#include <sys/time.h>
9#include <stdlib.h> 8#include <stdlib.h>
10#include <string.h> 9#include <string.h>
11#include <assert.h> 10#include <assert.h>
12#include <event.h> 11#include <event.h>
13 12
14 13
15#include "./regress.gen.h" 14#include "regress.gen.h"
16 15
17void event_err(int eval, const char *fmt, ...); 16void event_err(int eval, const char *fmt, ...);
18void event_warn(const char *fmt, ...); 17void event_warn(const char *fmt, ...);
19void event_errx(int eval, const char *fmt, ...); 18void event_errx(int eval, const char *fmt, ...);
20void event_warnx(const char *fmt, ...); 19void event_warnx(const char *fmt, ...);
21 20
22 21
23/* 22/*
24 * Implementation of msg 23 * Implementation of msg
25 */ 24 */
26 25
27static struct msg_access_ __msg_base = { 26static struct msg_access_ __msg_base = {
28 msg_from_name_assign, 27 msg_from_name_assign,
@@ -630,124 +629,222 @@ evtag_marshal_kill(struct evbuffer *evbu @@ -630,124 +629,222 @@ evtag_marshal_kill(struct evbuffer *evbu
630 evbuffer_drain(_buf, -1); 629 evbuffer_drain(_buf, -1);
631 kill_marshal(_buf, msg); 630 kill_marshal(_buf, msg);
632 evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), EVBUFFER_LENGTH(_buf)); 631 evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), EVBUFFER_LENGTH(_buf));
633 evbuffer_free(_buf); 632 evbuffer_free(_buf);
634} 633}
635 634
636/* 635/*
637 * Implementation of run 636 * Implementation of run
638 */ 637 */
639 638
640static struct run_access_ __run_base = { 639static struct run_access_ __run_base = {
641 run_how_assign, 640 run_how_assign,
642 run_how_get, 641 run_how_get,
 642 run_some_bytes_assign,
 643 run_some_bytes_get,
 644 run_fixed_bytes_assign,
 645 run_fixed_bytes_get,
643}; 646};
644 647
645struct run * 648struct run *
646run_new(void) 649run_new(void)
647{ 650{
648 struct run *tmp; 651 struct run *tmp;
649 if ((tmp = malloc(sizeof(struct run))) == NULL) { 652 if ((tmp = malloc(sizeof(struct run))) == NULL) {
650 event_warn("%s: malloc", __func__); 653 event_warn("%s: malloc", __func__);
651 return (NULL); 654 return (NULL);
652 } 655 }
653 tmp->base = &__run_base; 656 tmp->base = &__run_base;
654 657
655 tmp->how_data = NULL; 658 tmp->how_data = NULL;
656 tmp->how_set = 0; 659 tmp->how_set = 0;
657 660
 661 tmp->some_bytes_data = NULL;
 662 tmp->some_bytes_length = 0;
 663 tmp->some_bytes_set = 0;
 664
 665 memset(tmp->fixed_bytes_data, 0, sizeof(tmp->fixed_bytes_data));
 666 tmp->fixed_bytes_set = 0;
 667
658 return (tmp); 668 return (tmp);
659} 669}
660 670
661 671
 672
 673
662int 674int
663run_how_assign(struct run *msg, 675run_how_assign(struct run *msg,
664 const char * value) 676 const char * value)
665{ 677{
666 if (msg->how_data != NULL) 678 if (msg->how_data != NULL)
667 free(msg->how_data); 679 free(msg->how_data);
668 if ((msg->how_data = strdup(value)) == NULL) 680 if ((msg->how_data = strdup(value)) == NULL)
669 return (-1); 681 return (-1);
670 msg->how_set = 1; 682 msg->how_set = 1;
671 return (0); 683 return (0);
672} 684}
673 685
674int 686int
 687run_some_bytes_assign(struct run *msg, const uint8_t * value, uint32_t len)
 688{
 689 if (msg->some_bytes_data != NULL)
 690 free (msg->some_bytes_data);
 691 msg->some_bytes_data = malloc(len);
 692 if (msg->some_bytes_data == NULL)
 693 return (-1);
 694 msg->some_bytes_set = 1;
 695 msg->some_bytes_length = len;
 696 memcpy(msg->some_bytes_data, value, len);
 697 return (0);
 698}
 699
 700int
 701run_fixed_bytes_assign(struct run *msg, const uint8_t *value)
 702{
 703 msg->fixed_bytes_set = 1;
 704 memcpy(msg->fixed_bytes_data, value, 24);
 705 return (0);
 706}
 707
 708int
675run_how_get(struct run *msg, char * *value) 709run_how_get(struct run *msg, char * *value)
676{ 710{
677 if (msg->how_set != 1) 711 if (msg->how_set != 1)
678 return (-1); 712 return (-1);
679 *value = msg->how_data; 713 *value = msg->how_data;
680 return (0); 714 return (0);
681} 715}
682 716
 717int
 718run_some_bytes_get(struct run *msg, uint8_t * *value, uint32_t *plen)
 719{
 720 if (msg->some_bytes_set != 1)
 721 return (-1);
 722 *value = msg->some_bytes_data;
 723 *plen = msg->some_bytes_length;
 724 return (0);
 725}
 726
 727int
 728run_fixed_bytes_get(struct run *msg, uint8_t **value)
 729{
 730 if (msg->fixed_bytes_set != 1)
 731 return (-1);
 732 *value = msg->fixed_bytes_data;
 733 return (0);
 734}
 735
683void 736void
684run_clear(struct run *tmp) 737run_clear(struct run *tmp)
685{ 738{
686 if (tmp->how_set == 1) { 739 if (tmp->how_set == 1) {
687 free (tmp->how_data); 740 free (tmp->how_data);
688 tmp->how_data = NULL; 741 tmp->how_data = NULL;
689 tmp->how_set = 0; 742 tmp->how_set = 0;
690 } 743 }
 744 if (tmp->some_bytes_set == 1) {
 745 free (tmp->some_bytes_data);
 746 tmp->some_bytes_data = NULL;
 747 tmp->some_bytes_length = 0;
 748 tmp->some_bytes_set = 0;
 749 }
 750 tmp->fixed_bytes_set = 0;
 751 memset(tmp->fixed_bytes_data, 0, sizeof(tmp->fixed_bytes_data));
691} 752}
692 753
693void 754void
694run_free(struct run *tmp) 755run_free(struct run *tmp)
695{ 756{
696 if (tmp->how_data != NULL) 757 if (tmp->how_data != NULL)
697 free (tmp->how_data);  758 free (tmp->how_data);
 759 if (tmp->some_bytes_data != NULL)
 760 free (tmp->some_bytes_data);
698 free(tmp); 761 free(tmp);
699} 762}
700 763
701void 764void
702run_marshal(struct evbuffer *evbuf, const struct run *tmp){ 765run_marshal(struct evbuffer *evbuf, const struct run *tmp){
703 evtag_marshal_string(evbuf, RUN_HOW, tmp->how_data); 766 evtag_marshal_string(evbuf, RUN_HOW, tmp->how_data);
 767 if (tmp->some_bytes_set) {
 768 evtag_marshal(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length);
 769 }
 770 evtag_marshal(evbuf, RUN_FIXED_BYTES, tmp->fixed_bytes_data, sizeof(tmp->fixed_bytes_data));
704} 771}
705 772
706int 773int
707run_unmarshal(struct run *tmp, struct evbuffer *evbuf) 774run_unmarshal(struct run *tmp, struct evbuffer *evbuf)
708{ 775{
709 uint32_t tag; 776 uint32_t tag;
710 while (EVBUFFER_LENGTH(evbuf) > 0) { 777 while (EVBUFFER_LENGTH(evbuf) > 0) {
711 if (evtag_peek(evbuf, &tag) == -1) 778 if (evtag_peek(evbuf, &tag) == -1)
712 return (-1); 779 return (-1);
713 switch (tag) { 780 switch (tag) {
714 781
715 case RUN_HOW: 782 case RUN_HOW:
716 783
717 if (tmp->how_set) 784 if (tmp->how_set)
718 return (-1); 785 return (-1);
719 if (evtag_unmarshal_string(evbuf, RUN_HOW, &tmp->how_data) == -1) { 786 if (evtag_unmarshal_string(evbuf, RUN_HOW, &tmp->how_data) == -1) {
720 event_warnx("%s: failed to unmarshal how", __func__); 787 event_warnx("%s: failed to unmarshal how", __func__);
721 return (-1); 788 return (-1);
722 } 789 }
723 tmp->how_set = 1; 790 tmp->how_set = 1;
724 break; 791 break;
725 792
 793 case RUN_SOME_BYTES:
 794
 795 if (tmp->some_bytes_set)
 796 return (-1);
 797 if (evtag_payload_length(evbuf, &tmp->some_bytes_length) == -1)
 798 return (-1);
 799 if (tmp->some_bytes_length > EVBUFFER_LENGTH(evbuf))
 800 return (-1);
 801 if ((tmp->some_bytes_data = malloc(tmp->some_bytes_length)) == NULL)
 802 return (-1);
 803 if (evtag_unmarshal_fixed(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length) == -1) {
 804 event_warnx("%s: failed to unmarshal some_bytes", __func__);
 805 return (-1);
 806 }
 807 tmp->some_bytes_set = 1;
 808 break;
 809
 810 case RUN_FIXED_BYTES:
 811
 812 if (tmp->fixed_bytes_set)
 813 return (-1);
 814 if (evtag_unmarshal_fixed(evbuf, RUN_FIXED_BYTES, tmp->fixed_bytes_data, sizeof(tmp->fixed_bytes_data)) == -1) {
 815 event_warnx("%s: failed to unmarshal fixed_bytes", __func__);
 816 return (-1);
 817 }
 818 tmp->fixed_bytes_set = 1;
 819 break;
 820
726 default: 821 default:
727 return -1; 822 return -1;
728 } 823 }
729 } 824 }
730 825
731 if (run_complete(tmp) == -1) 826 if (run_complete(tmp) == -1)
732 return (-1); 827 return (-1);
733 return (0); 828 return (0);
734} 829}
735 830
736int 831int
737run_complete(struct run *msg) 832run_complete(struct run *msg)
738{ 833{
739 if (!msg->how_set) 834 if (!msg->how_set)
740 return (-1); 835 return (-1);
 836 if (!msg->fixed_bytes_set)
 837 return (-1);
741 return (0); 838 return (0);
742} 839}
743 840
744int 841int
745evtag_unmarshal_run(struct evbuffer *evbuf, uint32_t need_tag, struct run *msg) 842evtag_unmarshal_run(struct evbuffer *evbuf, uint32_t need_tag, struct run *msg)
746{ 843{
747 uint32_t tag; 844 uint32_t tag;
748 int res = -1; 845 int res = -1;
749 846
750 struct evbuffer *tmp = evbuffer_new(); 847 struct evbuffer *tmp = evbuffer_new();
751 848
752 if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag) 849 if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
753 goto error; 850 goto error;

cvs diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/Attic/regress.gen.h (expand / switch to unified diff)

--- src/regress/lib/libevent/Attic/regress.gen.h 2008/05/16 20:24:57 1.1
+++ src/regress/lib/libevent/Attic/regress.gen.h 2009/08/05 18:33:20 1.1.8.1
@@ -1,22 +1,24 @@ @@ -1,22 +1,24 @@
1/* $NetBSD: regress.gen.h,v 1.1 2008/05/16 20:24:57 peter Exp $ */ 
2/* 1/*
3 * Automatically generated from ./regress.rpc 2 * Automatically generated from regress.rpc
4 */ 3 */
5 4
6#ifndef ___REGRESS_RPC_ 5#ifndef _REGRESS_RPC_
7#define ___REGRESS_RPC_ 6#define _REGRESS_RPC_
8 7
 8#include <event-config.h>
 9#ifdef _EVENT_HAVE_STDINT_H
9#include <stdint.h> 10#include <stdint.h>
 11#endif
10#define EVTAG_HAS(msg, member) ((msg)->member##_set == 1) 12#define EVTAG_HAS(msg, member) ((msg)->member##_set == 1)
11#define EVTAG_ASSIGN(msg, member, args...) (*(msg)->base->member##_assign)(msg, ## args) 13#define EVTAG_ASSIGN(msg, member, args...) (*(msg)->base->member##_assign)(msg, ## args)
12#define EVTAG_GET(msg, member, args...) (*(msg)->base->member##_get)(msg, ## args) 14#define EVTAG_GET(msg, member, args...) (*(msg)->base->member##_get)(msg, ## args)
13#define EVTAG_ADD(msg, member) (*(msg)->base->member##_add)(msg) 15#define EVTAG_ADD(msg, member) (*(msg)->base->member##_add)(msg)
14#define EVTAG_LEN(msg, member) ((msg)->member##_length) 16#define EVTAG_LEN(msg, member) ((msg)->member##_length)
15 17
16struct msg; 18struct msg;
17struct kill; 19struct kill;
18struct run; 20struct run;
19 21
20/* Tag definition for msg */ 22/* Tag definition for msg */
21enum msg_ { 23enum msg_ {
22 MSG_FROM_NAME=1, 24 MSG_FROM_NAME=1,
@@ -117,45 +119,60 @@ void evtag_marshal_kill(struct evbuffer  @@ -117,45 +119,60 @@ void evtag_marshal_kill(struct evbuffer
117int evtag_unmarshal_kill(struct evbuffer *, uint32_t, 119int evtag_unmarshal_kill(struct evbuffer *, uint32_t,
118 struct kill *); 120 struct kill *);
119int kill_weapon_assign(struct kill *, const char *); 121int kill_weapon_assign(struct kill *, const char *);
120int kill_weapon_get(struct kill *, char * *); 122int kill_weapon_get(struct kill *, char * *);
121int kill_action_assign(struct kill *, const char *); 123int kill_action_assign(struct kill *, const char *);
122int kill_action_get(struct kill *, char * *); 124int kill_action_get(struct kill *, char * *);
123int kill_how_often_assign(struct kill *, const uint32_t); 125int kill_how_often_assign(struct kill *, const uint32_t);
124int kill_how_often_get(struct kill *, uint32_t *); 126int kill_how_often_get(struct kill *, uint32_t *);
125/* --- kill done --- */ 127/* --- kill done --- */
126 128
127/* Tag definition for run */ 129/* Tag definition for run */
128enum run_ { 130enum run_ {
129 RUN_HOW=1, 131 RUN_HOW=1,
 132 RUN_SOME_BYTES=2,
 133 RUN_FIXED_BYTES=3,
130 RUN_MAX_TAGS 134 RUN_MAX_TAGS
131}; 135};
132 136
133/* Structure declaration for run */ 137/* Structure declaration for run */
134struct run_access_ { 138struct run_access_ {
135 int (*how_assign)(struct run *, const char *); 139 int (*how_assign)(struct run *, const char *);
136 int (*how_get)(struct run *, char * *); 140 int (*how_get)(struct run *, char * *);
 141 int (*some_bytes_assign)(struct run *, const uint8_t *, uint32_t);
 142 int (*some_bytes_get)(struct run *, uint8_t * *, uint32_t *);
 143 int (*fixed_bytes_assign)(struct run *, const uint8_t *);
 144 int (*fixed_bytes_get)(struct run *, uint8_t **);
137}; 145};
138 146
139struct run { 147struct run {
140 struct run_access_ *base; 148 struct run_access_ *base;
141 149
142 char *how_data; 150 char *how_data;
 151 uint8_t *some_bytes_data;
 152 uint32_t some_bytes_length;
 153 uint8_t fixed_bytes_data[24];
143 154
144 uint8_t how_set; 155 uint8_t how_set;
 156 uint8_t some_bytes_set;
 157 uint8_t fixed_bytes_set;
145}; 158};
146 159
147struct run *run_new(void); 160struct run *run_new(void);
148void run_free(struct run *); 161void run_free(struct run *);
149void run_clear(struct run *); 162void run_clear(struct run *);
150void run_marshal(struct evbuffer *, const struct run *); 163void run_marshal(struct evbuffer *, const struct run *);
151int run_unmarshal(struct run *, struct evbuffer *); 164int run_unmarshal(struct run *, struct evbuffer *);
152int run_complete(struct run *); 165int run_complete(struct run *);
153void evtag_marshal_run(struct evbuffer *, uint32_t,  166void evtag_marshal_run(struct evbuffer *, uint32_t,
154 const struct run *); 167 const struct run *);
155int evtag_unmarshal_run(struct evbuffer *, uint32_t, 168int evtag_unmarshal_run(struct evbuffer *, uint32_t,
156 struct run *); 169 struct run *);
157int run_how_assign(struct run *, const char *); 170int run_how_assign(struct run *, const char *);
158int run_how_get(struct run *, char * *); 171int run_how_get(struct run *, char * *);
 172int run_some_bytes_assign(struct run *, const uint8_t *, uint32_t);
 173int run_some_bytes_get(struct run *, uint8_t * *, uint32_t *);
 174int run_fixed_bytes_assign(struct run *, const uint8_t *);
 175int run_fixed_bytes_get(struct run *, uint8_t **);
159/* --- run done --- */ 176/* --- run done --- */
160 177
161#endif /* ___REGRESS_RPC_ */ 178#endif /* _REGRESS_RPC_ */

cvs diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/Attic/regress_dns.c (expand / switch to unified diff)

--- src/regress/lib/libevent/Attic/regress_dns.c 2008/05/16 20:24:57 1.1
+++ src/regress/lib/libevent/Attic/regress_dns.c 2009/08/05 18:33:20 1.1.8.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: regress_dns.c,v 1.1 2008/05/16 20:24:57 peter Exp $ */ 1/* $NetBSD: regress_dns.c,v 1.1.8.1 2009/08/05 18:33:20 snj Exp $ */
2/* 2/*
3 * Copyright (c) 2003-2006 Niels Provos <provos@citi.umich.edu> 3 * Copyright (c) 2003-2006 Niels Provos <provos@citi.umich.edu>
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products 14 * 3. The name of the author may not be used to endorse or promote products
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 */ 27 */
28 28
29#ifdef HAVE_CONFIG_H 29#ifdef HAVE_CONFIG_H
30#include "config.h" 30#include "config.h"
31#endif 31#endif
32 32
33#include <sys/types.h> 33#include <sys/types.h>
34#include <sys/stat.h> 34#include <sys/stat.h>
35#ifdef HAVE_SYS_TIME_H 35#ifdef HAVE_SYS_TIME_H
36#include <sys/time.h> 36#include <sys/time.h>
37#endif 37#endif
38#include <sys/queue.h> 38#include <sys/queue.h>
39#include <sys/socket.h> 39#include <sys/socket.h>
40#include <sys/signal.h> 40#include <signal.h>
41#include <netinet/in.h> 41#include <netinet/in.h>
42#include <arpa/inet.h> 42#include <arpa/inet.h>
43#include <unistd.h> 43#include <unistd.h>
44#ifdef HAVE_NETINET_IN6_H 44#ifdef HAVE_NETINET_IN6_H
45#include <netinet/in6.h> 45#include <netinet/in6.h>
46#endif 46#endif
47#ifdef HAVE_NETDB_H 47#ifdef HAVE_NETDB_H
48#include <netdb.h> 48#include <netdb.h>
49#endif 49#endif
50#include <fcntl.h> 50#include <fcntl.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <stdio.h> 52#include <stdio.h>
53#include <string.h> 53#include <string.h>
@@ -73,27 +73,27 @@ dns_gethostbyname_cb(int result, char ty @@ -73,27 +73,27 @@ dns_gethostbyname_cb(int result, char ty
73 dns_err = result; 73 dns_err = result;
74 goto out; 74 goto out;
75 } 75 }
76 76
77 if (result != DNS_ERR_NONE) { 77 if (result != DNS_ERR_NONE) {
78 fprintf(stdout, "[Error code %d] ", result); 78 fprintf(stdout, "[Error code %d] ", result);
79 goto out; 79 goto out;
80 } 80 }
81 81
82 fprintf(stderr, "type: %d, count: %d, ttl: %d: ", type, count, ttl); 82 fprintf(stderr, "type: %d, count: %d, ttl: %d: ", type, count, ttl);
83 83
84 switch (type) { 84 switch (type) {
85 case DNS_IPv6_AAAA: { 85 case DNS_IPv6_AAAA: {
86#if defined(HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) 86#if defined(HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN)
87 struct in6_addr *in6_addrs = addresses; 87 struct in6_addr *in6_addrs = addresses;
88 char buf[INET6_ADDRSTRLEN+1]; 88 char buf[INET6_ADDRSTRLEN+1];
89 int i; 89 int i;
90 /* a resolution that's not valid does not help */ 90 /* a resolution that's not valid does not help */
91 if (ttl < 0) 91 if (ttl < 0)
92 goto out; 92 goto out;
93 for (i = 0; i < count; ++i) { 93 for (i = 0; i < count; ++i) {
94 const char *b = inet_ntop(AF_INET6, &in6_addrs[i], buf,sizeof(buf)); 94 const char *b = inet_ntop(AF_INET6, &in6_addrs[i], buf,sizeof(buf));
95 if (b) 95 if (b)
96 fprintf(stderr, "%s ", b); 96 fprintf(stderr, "%s ", b);
97 else 97 else
98 fprintf(stderr, "%s ", strerror(errno)); 98 fprintf(stderr, "%s ", strerror(errno));
99 } 99 }
@@ -242,27 +242,27 @@ dns_server_gethostbyname_cb(int result,  @@ -242,27 +242,27 @@ dns_server_gethostbyname_cb(int result,
242 } 242 }
243 switch (type) { 243 switch (type) {
244 case DNS_IPv4_A: { 244 case DNS_IPv4_A: {
245 struct in_addr *in_addrs = addresses; 245 struct in_addr *in_addrs = addresses;
246 if (in_addrs[0].s_addr != htonl(0xc0a80b0bUL) || ttl != 12345) { 246 if (in_addrs[0].s_addr != htonl(0xc0a80b0bUL) || ttl != 12345) {
247 fprintf(stdout, "Bad IPv4 response \"%s\" %d. ", 247 fprintf(stdout, "Bad IPv4 response \"%s\" %d. ",
248 inet_ntoa(in_addrs[0]), ttl); 248 inet_ntoa(in_addrs[0]), ttl);
249 dns_ok = 0; 249 dns_ok = 0;
250 goto out; 250 goto out;
251 } 251 }
252 break; 252 break;
253 } 253 }
254 case DNS_IPv6_AAAA: { 254 case DNS_IPv6_AAAA: {
255#if defined (HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) 255#if defined (HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP) && defined(INET6_ADDRSTRLEN)
256 struct in6_addr *in6_addrs = addresses; 256 struct in6_addr *in6_addrs = addresses;
257 char buf[INET6_ADDRSTRLEN+1]; 257 char buf[INET6_ADDRSTRLEN+1];
258 if (memcmp(&in6_addrs[0].s6_addr, "abcdefghijklmnop", 16) 258 if (memcmp(&in6_addrs[0].s6_addr, "abcdefghijklmnop", 16)
259 || ttl != 123) { 259 || ttl != 123) {
260 const char *b = inet_ntop(AF_INET6, &in6_addrs[0],buf,sizeof(buf)); 260 const char *b = inet_ntop(AF_INET6, &in6_addrs[0],buf,sizeof(buf));
261 fprintf(stdout, "Bad IPv6 response \"%s\" %d. ", b, ttl); 261 fprintf(stdout, "Bad IPv6 response \"%s\" %d. ", b, ttl);
262 dns_ok = 0; 262 dns_ok = 0;
263 goto out; 263 goto out;
264 } 264 }
265#endif 265#endif
266 break; 266 break;
267 } 267 }
268 case DNS_PTR: { 268 case DNS_PTR: {

cvs diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/Attic/regress_http.c (expand / switch to unified diff)

--- src/regress/lib/libevent/Attic/regress_http.c 2008/05/16 20:24:57 1.1
+++ src/regress/lib/libevent/Attic/regress_http.c 2009/08/05 18:33:20 1.1.8.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: regress_http.c,v 1.1 2008/05/16 20:24:57 peter Exp $ */ 1/* $NetBSD: regress_http.c,v 1.1.8.1 2009/08/05 18:33:20 snj Exp $ */
2/* 2/*
3 * Copyright (c) 2003-2006 Niels Provos <provos@citi.umich.edu> 3 * Copyright (c) 2003-2006 Niels Provos <provos@citi.umich.edu>
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products 14 * 3. The name of the author may not be used to endorse or promote products
@@ -27,75 +27,79 @@ @@ -27,75 +27,79 @@
27 */ 27 */
28 28
29#ifdef HAVE_CONFIG_H 29#ifdef HAVE_CONFIG_H
30#include "config.h" 30#include "config.h"
31#endif 31#endif
32 32
33#include <sys/types.h> 33#include <sys/types.h>
34#include <sys/stat.h> 34#include <sys/stat.h>
35#ifdef HAVE_SYS_TIME_H 35#ifdef HAVE_SYS_TIME_H
36#include <sys/time.h> 36#include <sys/time.h>
37#endif 37#endif
38#include <sys/queue.h> 38#include <sys/queue.h>
39#include <sys/socket.h> 39#include <sys/socket.h>
40#include <sys/signal.h> 40#include <signal.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <netdb.h> 42#include <netdb.h>
43#include <fcntl.h> 43#include <fcntl.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <string.h> 46#include <string.h>
47#include <errno.h> 47#include <errno.h>
48 48
49#include "event.h" 49#include "event.h"
50#include "evhttp.h" 50#include "evhttp.h"
51#include "log.h" 51#include "log.h"
52#include "http-internal.h" 52#include "http-internal.h"
53 53
54extern int pair[]; 54extern int pair[];
55extern int test_ok; 55extern int test_ok;
56 56
57static struct evhttp *http; 57static struct evhttp *http;
58/* set if a test needs to call loopexit on a base */ 58/* set if a test needs to call loopexit on a base */
59static struct event_base *base; 59static struct event_base *base;
60 60
61void http_suite(void); 61void http_suite(void);
62 62
63void http_basic_cb(struct evhttp_request *req, void *arg); 63void http_basic_cb(struct evhttp_request *req, void *arg);
 64static void http_chunked_cb(struct evhttp_request *req, void *arg);
64void http_post_cb(struct evhttp_request *req, void *arg); 65void http_post_cb(struct evhttp_request *req, void *arg);
65void http_dispatcher_cb(struct evhttp_request *req, void *arg); 66void http_dispatcher_cb(struct evhttp_request *req, void *arg);
 67static void http_large_delay_cb(struct evhttp_request *req, void *arg);
66 68
67static struct evhttp * 69static struct evhttp *
68http_setup(short *pport, struct event_base *base) 70http_setup(short *pport, struct event_base *base)
69{ 71{
70 int i; 72 int i;
71 struct evhttp *myhttp; 73 struct evhttp *myhttp;
72 short port = -1; 74 short port = -1;
73 75
74 /* Try a few different ports */ 76 /* Try a few different ports */
75 myhttp = evhttp_new(base); 77 myhttp = evhttp_new(base);
76 for (i = 0; i < 50; ++i) { 78 for (i = 0; i < 50; ++i) {
77 if (evhttp_bind_socket(myhttp, "127.0.0.1", 8080 + i) != -1) { 79 if (evhttp_bind_socket(myhttp, "127.0.0.1", 8080 + i) != -1) {
78 port = 8080 + i; 80 port = 8080 + i;
79 break; 81 break;
80 } 82 }
81 } 83 }
82 84
83 if (port == -1) 85 if (port == -1)
84 event_errx(1, "Could not start web server"); 86 event_errx(1, "Could not start web server");
85 87
86 /* Register a callback for certain types of requests */ 88 /* Register a callback for certain types of requests */
87 evhttp_set_cb(myhttp, "/test", http_basic_cb, NULL); 89 evhttp_set_cb(myhttp, "/test", http_basic_cb, NULL);
 90 evhttp_set_cb(myhttp, "/chunked", http_chunked_cb, NULL);
88 evhttp_set_cb(myhttp, "/postit", http_post_cb, NULL); 91 evhttp_set_cb(myhttp, "/postit", http_post_cb, NULL);
 92 evhttp_set_cb(myhttp, "/largedelay", http_large_delay_cb, NULL);
89 evhttp_set_cb(myhttp, "/", http_dispatcher_cb, NULL); 93 evhttp_set_cb(myhttp, "/", http_dispatcher_cb, NULL);
90 94
91 *pport = port; 95 *pport = port;
92 return (myhttp); 96 return (myhttp);
93} 97}
94 98
95#ifndef NI_MAXSERV 99#ifndef NI_MAXSERV
96#define NI_MAXSERV 1024 100#define NI_MAXSERV 1024
97#endif 101#endif
98 102
99static int 103static int
100http_connect(const char *address, u_short port) 104http_connect(const char *address, u_short port)
101{ 105{
@@ -129,35 +133,43 @@ http_connect(const char *address, u_shor @@ -129,35 +133,43 @@ http_connect(const char *address, u_shor
129 return (fd); 133 return (fd);
130} 134}
131 135
132static void 136static void
133http_readcb(struct bufferevent *bev, void *arg) 137http_readcb(struct bufferevent *bev, void *arg)
134{ 138{
135 const char *what = "This is funny"; 139 const char *what = "This is funny";
136 140
137 event_debug(("%s: %s\n", __func__, EVBUFFER_DATA(bev->input))); 141 event_debug(("%s: %s\n", __func__, EVBUFFER_DATA(bev->input)));
138  142
139 if (evbuffer_find(bev->input, 143 if (evbuffer_find(bev->input,
140 (const unsigned char*) what, strlen(what)) != NULL) { 144 (const unsigned char*) what, strlen(what)) != NULL) {
141 struct evhttp_request *req = evhttp_request_new(NULL, NULL); 145 struct evhttp_request *req = evhttp_request_new(NULL, NULL);
142 int done; 146 enum message_read_status done;
143 147
144 req->kind = EVHTTP_RESPONSE; 148 req->kind = EVHTTP_RESPONSE;
145 done = evhttp_parse_lines(req, bev->input); 149 done = evhttp_parse_firstline(req, bev->input);
 150 if (done != ALL_DATA_READ)
 151 goto out;
 152
 153 done = evhttp_parse_headers(req, bev->input);
 154 if (done != ALL_DATA_READ)
 155 goto out;
146 156
147 if (done == 1 && 157 if (done == 1 &&
148 evhttp_find_header(req->input_headers, 158 evhttp_find_header(req->input_headers,
149 "Content-Type") != NULL) 159 "Content-Type") != NULL)
150 test_ok++; 160 test_ok++;
 161
 162 out:
151 evhttp_request_free(req); 163 evhttp_request_free(req);
152 bufferevent_disable(bev, EV_READ); 164 bufferevent_disable(bev, EV_READ);
153 if (base) 165 if (base)
154 event_base_loopexit(base, NULL); 166 event_base_loopexit(base, NULL);
155 else 167 else
156 event_loopexit(NULL); 168 event_loopexit(NULL);
157 } 169 }
158} 170}
159 171
160static void 172static void
161http_writecb(struct bufferevent *bev, void *arg) 173http_writecb(struct bufferevent *bev, void *arg)
162{ 174{
163 if (EVBUFFER_LENGTH(bev->output) == 0) { 175 if (EVBUFFER_LENGTH(bev->output) == 0) {
@@ -171,107 +183,211 @@ static void @@ -171,107 +183,211 @@ static void
171http_errorcb(struct bufferevent *bev, short what, void *arg) 183http_errorcb(struct bufferevent *bev, short what, void *arg)
172{ 184{
173 test_ok = -2; 185 test_ok = -2;
174 event_loopexit(NULL); 186 event_loopexit(NULL);
175} 187}
176 188
177void 189void
178http_basic_cb(struct evhttp_request *req, void *arg) 190http_basic_cb(struct evhttp_request *req, void *arg)
179{ 191{
180 struct evbuffer *evb = evbuffer_new(); 192 struct evbuffer *evb = evbuffer_new();
181 int empty = evhttp_find_header(req->input_headers, "Empty") != NULL; 193 int empty = evhttp_find_header(req->input_headers, "Empty") != NULL;
182 event_debug(("%s: called\n", __func__)); 194 event_debug(("%s: called\n", __func__));
183 evbuffer_add_printf(evb, "This is funny"); 195 evbuffer_add_printf(evb, "This is funny");
 196
 197 /* For multi-line headers test */
 198 {
 199 const char *multi =
 200 evhttp_find_header(req->input_headers,"X-multi");
 201 if (multi) {
 202 if (strcmp("END", multi + strlen(multi) - 3) == 0)
 203 test_ok++;
 204 if (evhttp_find_header(req->input_headers, "X-Last"))
 205 test_ok++;
 206 }
 207 }
 208
 209 /* injecting a bad content-length */
 210 if (evhttp_find_header(req->input_headers, "X-Negative"))
 211 evhttp_add_header(req->output_headers,
 212 "Content-Length", "-100");
184 213
185 /* allow sending of an empty reply */ 214 /* allow sending of an empty reply */
186 evhttp_send_reply(req, HTTP_OK, "Everything is fine", 215 evhttp_send_reply(req, HTTP_OK, "Everything is fine",
187 !empty ? evb : NULL); 216 !empty ? evb : NULL);
188 217
189 evbuffer_free(evb); 218 evbuffer_free(evb);
190} 219}
191 220
 221static char const* const CHUNKS[] = {
 222 "This is funny",
 223 "but not hilarious.",
 224 "bwv 1052"
 225};
 226
 227struct chunk_req_state {
 228 struct evhttp_request *req;
 229 int i;
 230};
 231
 232static void
 233http_chunked_trickle_cb(int fd, short events, void *arg)
 234{
 235 struct evbuffer *evb = evbuffer_new();
 236 struct chunk_req_state *state = arg;
 237 struct timeval when = { 0, 0 };
 238
 239 evbuffer_add_printf(evb, "%s", CHUNKS[state->i]);
 240 evhttp_send_reply_chunk(state->req, evb);
 241 evbuffer_free(evb);
 242
 243 if (++state->i < sizeof(CHUNKS)/sizeof(CHUNKS[0])) {
 244 event_once(-1, EV_TIMEOUT,
 245 http_chunked_trickle_cb, state, &when);
 246 } else {
 247 evhttp_send_reply_end(state->req);
 248 free(state);
 249 }
 250}
 251
 252static void
 253http_chunked_cb(struct evhttp_request *req, void *arg)
 254{
 255 struct timeval when = { 0, 0 };
 256 struct chunk_req_state *state = malloc(sizeof(struct chunk_req_state));
 257 event_debug(("%s: called\n", __func__));
 258
 259 memset(state, 0, sizeof(struct chunk_req_state));
 260 state->req = req;
 261
 262 /* generate a chunked reply */
 263 evhttp_send_reply_start(req, HTTP_OK, "Everything is fine");
 264
 265 /* but trickle it across several iterations to ensure we're not
 266 * assuming it comes all at once */
 267 event_once(-1, EV_TIMEOUT, http_chunked_trickle_cb, state, &when);
 268}
 269
 270static void
 271http_complete_write(int fd, short what, void *arg)
 272{
 273 struct bufferevent *bev = arg;
 274 const char *http_request = "host\r\n"
 275 "Connection: close\r\n"
 276 "\r\n";
 277 bufferevent_write(bev, http_request, strlen(http_request));
 278}
 279
192static void 280static void
193http_basic_test(void) 281http_basic_test(void)
194{ 282{
 283 struct timeval tv;
195 struct bufferevent *bev; 284 struct bufferevent *bev;
196 int fd; 285 int fd;
197 const char *http_request; 286 const char *http_request;
198 short port = -1; 287 short port = -1;
199 288
200 test_ok = 0; 289 test_ok = 0;
201 fprintf(stdout, "Testing Basic HTTP Server: "); 290 fprintf(stdout, "Testing Basic HTTP Server: ");
202 291
203 http = http_setup(&port, NULL); 292 http = http_setup(&port, NULL);
204 293
205 /* bind to a second socket */ 294 /* bind to a second socket */
206 if (evhttp_bind_socket(http, "127.0.0.1", port + 1) == -1) { 295 if (evhttp_bind_socket(http, "127.0.0.1", port + 1) == -1) {
207 fprintf(stdout, "FAILED (bind)\n"); 296 fprintf(stdout, "FAILED (bind)\n");
208 exit(1); 297 exit(1);
209 } 298 }
210  299
211 fd = http_connect("127.0.0.1", port); 300 fd = http_connect("127.0.0.1", port);
212 301
213 /* Stupid thing to send a request */ 302 /* Stupid thing to send a request */
214 bev = bufferevent_new(fd, http_readcb, http_writecb, 303 bev = bufferevent_new(fd, http_readcb, http_writecb,
215 http_errorcb, NULL); 304 http_errorcb, NULL);
216 305
 306 /* first half of the http request */
217 http_request = 307 http_request =
218 "GET /test HTTP/1.1\r\n" 308 "GET /test HTTP/1.1\r\n"
219 "Host: somehost\r\n" 309 "Host: some";
220 "Connection: close\r\n" 
221 "\r\n"; 
222 310
223 bufferevent_write(bev, http_request, strlen(http_request)); 311 bufferevent_write(bev, http_request, strlen(http_request));
 312 timerclear(&tv);
 313 tv.tv_usec = 10000;
 314 event_once(-1, EV_TIMEOUT, http_complete_write, bev, &tv);
224  315
225 event_dispatch(); 316 event_dispatch();
226 317
227 if (test_ok != 2) { 318 if (test_ok != 3) {
228 fprintf(stdout, "FAILED\n"); 319 fprintf(stdout, "FAILED\n");
229 exit(1); 320 exit(1);
230 } 321 }
231 322
232 /* connect to the second port */ 323 /* connect to the second port */
233 bufferevent_free(bev); 324 bufferevent_free(bev);
234 close(fd); 325 EVUTIL_CLOSESOCKET(fd);
235 326
236 fd = http_connect("127.0.0.1", port + 1); 327 fd = http_connect("127.0.0.1", port + 1);
237 328
238 /* Stupid thing to send a request */ 329 /* Stupid thing to send a request */
239 bev = bufferevent_new(fd, http_readcb, http_writecb, 330 bev = bufferevent_new(fd, http_readcb, http_writecb,
240 http_errorcb, NULL); 331 http_errorcb, NULL);
241 332
242 http_request = 333 http_request =
243 "GET /test HTTP/1.1\r\n" 334 "GET /test HTTP/1.1\r\n"
244 "Host: somehost\r\n" 335 "Host: somehost\r\n"
245 "Connection: close\r\n" 336 "Connection: close\r\n"
246 "\r\n"; 337 "\r\n";
247 338
248 bufferevent_write(bev, http_request, strlen(http_request)); 339 bufferevent_write(bev, http_request, strlen(http_request));
249  340
250 event_dispatch(); 341 event_dispatch();
251 342
252 bufferevent_free(bev); 343 bufferevent_free(bev);
253 close(fd); 344 EVUTIL_CLOSESOCKET(fd);
254 345
255 evhttp_free(http); 346 evhttp_free(http);
256  347
257 if (test_ok != 4) { 348 if (test_ok != 5) {
258 fprintf(stdout, "FAILED\n"); 349 fprintf(stdout, "FAILED\n");
259 exit(1); 350 exit(1);
260 } 351 }
261 352
262 fprintf(stdout, "OK\n"); 353 fprintf(stdout, "OK\n");
263} 354}
264 355
 356static struct evhttp_connection *delayed_client;
 357
 358static void
 359http_delay_reply(int fd, short what, void *arg)
 360{
 361 struct evhttp_request *req = arg;
 362
 363 evhttp_send_reply(req, HTTP_OK, "Everything is fine", NULL);
 364
 365 ++test_ok;
 366}
 367
 368static void
 369http_large_delay_cb(struct evhttp_request *req, void *arg)
 370{
 371 struct timeval tv;
 372 timerclear(&tv);
 373 tv.tv_sec = 3;
 374
 375 event_once(-1, EV_TIMEOUT, http_delay_reply, req, &tv);
 376
 377 /* here we close the client connection which will cause an EOF */
 378 evhttp_connection_fail(delayed_client, EVCON_HTTP_EOF);
 379}
 380
265void http_request_done(struct evhttp_request *, void *); 381void http_request_done(struct evhttp_request *, void *);
266void http_request_empty_done(struct evhttp_request *, void *); 382void http_request_empty_done(struct evhttp_request *, void *);
267 383
268static void 384static void
269http_connection_test(int persistent) 385http_connection_test(int persistent)
270{ 386{
271 short port = -1; 387 short port = -1;
272 struct evhttp_connection *evcon = NULL; 388 struct evhttp_connection *evcon = NULL;
273 struct evhttp_request *req = NULL; 389 struct evhttp_request *req = NULL;
274  390
275 test_ok = 0; 391 test_ok = 0;
276 fprintf(stdout, "Testing Request Connection Pipeline %s: ", 392 fprintf(stdout, "Testing Request Connection Pipeline %s: ",
277 persistent ? "(persistent)" : ""); 393 persistent ? "(persistent)" : "");
@@ -681,133 +797,148 @@ http_failure_test(void) @@ -681,133 +797,148 @@ http_failure_test(void)
681 fd = http_connect("127.0.0.1", port); 797 fd = http_connect("127.0.0.1", port);
682 798
683 /* Stupid thing to send a request */ 799 /* Stupid thing to send a request */
684 bev = bufferevent_new(fd, http_failure_readcb, http_writecb, 800 bev = bufferevent_new(fd, http_failure_readcb, http_writecb,
685 http_errorcb, NULL); 801 http_errorcb, NULL);
686 802
687 http_request = "illegal request\r\n"; 803 http_request = "illegal request\r\n";
688 804
689 bufferevent_write(bev, http_request, strlen(http_request)); 805 bufferevent_write(bev, http_request, strlen(http_request));
690  806
691 event_dispatch(); 807 event_dispatch();
692 808
693 bufferevent_free(bev); 809 bufferevent_free(bev);
694 close(fd); 810 EVUTIL_CLOSESOCKET(fd);
695 811
696 evhttp_free(http); 812 evhttp_free(http);
697  813
698 if (test_ok != 2) { 814 if (test_ok != 2) {
699 fprintf(stdout, "FAILED\n"); 815 fprintf(stdout, "FAILED\n");
700 exit(1); 816 exit(1);
701 } 817 }
702  818
703 fprintf(stdout, "OK\n"); 819 fprintf(stdout, "OK\n");
704} 820}
705 821
706static void 822static void
707close_detect_done(struct evhttp_request *req, void *arg) 823close_detect_done(struct evhttp_request *req, void *arg)
708{ 824{
 825 struct timeval tv;
709 if (req == NULL || req->response_code != HTTP_OK) { 826 if (req == NULL || req->response_code != HTTP_OK) {
710  827
711 fprintf(stderr, "FAILED\n"); 828 fprintf(stderr, "FAILED\n");
712 exit(1); 829 exit(1);
713 } 830 }
714 831
715 test_ok = 1; 832 test_ok = 1;
716 event_loopexit(NULL); 833
 834 timerclear(&tv);
 835 tv.tv_sec = 3; /* longer than the http time out */
 836
 837 event_loopexit(&tv);
717} 838}
718 839
719static void 840static void
720close_detect_launch(int fd, short what, void *arg) 841close_detect_launch(int fd, short what, void *arg)
721{ 842{
722 struct evhttp_connection *evcon = arg; 843 struct evhttp_connection *evcon = arg;
723 struct evhttp_request *req; 844 struct evhttp_request *req;
724 845
725 req = evhttp_request_new(close_detect_done, NULL); 846 req = evhttp_request_new(close_detect_done, NULL);
726 847
727 /* Add the information that we care about */ 848 /* Add the information that we care about */
728 evhttp_add_header(req->output_headers, "Host", "somehost"); 849 evhttp_add_header(req->output_headers, "Host", "somehost");
729 850
730 /* We give ownership of the request to the connection */ 851 /* We give ownership of the request to the connection */
731 if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) { 852 if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
732 fprintf(stdout, "FAILED\n"); 853 fprintf(stdout, "FAILED\n");
733 exit(1); 854 exit(1);
734 } 855 }
735} 856}
736 857
737static void 858static void
738close_detect_cb(struct evhttp_request *req, void *arg) 859close_detect_cb(struct evhttp_request *req, void *arg)
739{ 860{
740 struct evhttp_connection *evcon = arg; 861 struct evhttp_connection *evcon = arg;
741 struct timeval tv; 862 struct timeval tv;
742 863
743 if (req->response_code != HTTP_OK) { 864 if (req != NULL && req->response_code != HTTP_OK) {
744  865
745 fprintf(stderr, "FAILED\n"); 866 fprintf(stderr, "FAILED\n");
746 exit(1); 867 exit(1);
747 } 868 }
748 869
749 timerclear(&tv); 870 timerclear(&tv);
750 tv.tv_sec = 3; /* longer than the http time out */ 871 tv.tv_sec = 3; /* longer than the http time out */
751 872
752 /* launch a new request on the persistent connection in 6 seconds */ 873 /* launch a new request on the persistent connection in 6 seconds */
753 event_once(-1, EV_TIMEOUT, close_detect_launch, evcon, &tv); 874 event_once(-1, EV_TIMEOUT, close_detect_launch, evcon, &tv);
754} 875}
755 876
756 877
757static void 878static void
758http_close_detection(void) 879http_close_detection(int with_delay)
759{ 880{
760 short port = -1; 881 short port = -1;
761 struct evhttp_connection *evcon = NULL; 882 struct evhttp_connection *evcon = NULL;
762 struct evhttp_request *req = NULL; 883 struct evhttp_request *req = NULL;
763  884
764 test_ok = 0; 885 test_ok = 0;
765 fprintf(stdout, "Testing Connection Close Detection: "); 886 fprintf(stdout, "Testing Connection Close Detection%s: ",
 887 with_delay ? " (with delay)" : "");
766 888
767 http = http_setup(&port, NULL); 889 http = http_setup(&port, NULL);
768 890
769 /* 2 second timeout */ 891 /* 2 second timeout */
770 evhttp_set_timeout(http, 2); 892 evhttp_set_timeout(http, 2);
771 893
772 evcon = evhttp_connection_new("127.0.0.1", port); 894 evcon = evhttp_connection_new("127.0.0.1", port);
773 if (evcon == NULL) { 895 if (evcon == NULL) {
774 fprintf(stdout, "FAILED\n"); 896 fprintf(stdout, "FAILED\n");
775 exit(1); 897 exit(1);
776 } 898 }
777 899
 900 delayed_client = evcon;
 901
778 /* 902 /*
779 * At this point, we want to schedule a request to the HTTP 903 * At this point, we want to schedule a request to the HTTP
780 * server using our make request method. 904 * server using our make request method.
781 */ 905 */
782 906
783 req = evhttp_request_new(close_detect_cb, evcon); 907 req = evhttp_request_new(close_detect_cb, evcon);
784 908
785 /* Add the information that we care about */ 909 /* Add the information that we care about */
786 evhttp_add_header(req->output_headers, "Host", "somehost"); 910 evhttp_add_header(req->output_headers, "Host", "somehost");
787 911
788 /* We give ownership of the request to the connection */ 912 /* We give ownership of the request to the connection */
789 if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) { 913 if (evhttp_make_request(evcon,
 914 req, EVHTTP_REQ_GET, with_delay ? "/largedelay" : "/test") == -1) {
790 fprintf(stdout, "FAILED\n"); 915 fprintf(stdout, "FAILED\n");
791 exit(1); 916 exit(1);
792 } 917 }
793 918
794 event_dispatch(); 919 event_dispatch();
795 920
796 if (test_ok != 1) { 921 if (test_ok != 1) {
797 fprintf(stdout, "FAILED\n"); 922 fprintf(stdout, "FAILED\n");
798 exit(1); 923 exit(1);
799 } 924 }
800 925
 926 /* at this point, the http server should have no connection */
 927 if (TAILQ_FIRST(&http->connections) != NULL) {
 928 fprintf(stdout, "FAILED (left connections)\n");
 929 exit(1);
 930 }
 931
801 evhttp_connection_free(evcon); 932 evhttp_connection_free(evcon);
802 evhttp_free(http); 933 evhttp_free(http);
803  934
804 fprintf(stdout, "OK\n"); 935 fprintf(stdout, "OK\n");
805} 936}
806 937
807static void 938static void
808http_highport_test(void) 939http_highport_test(void)
809{ 940{
810 int i = -1; 941 int i = -1;
811 struct evhttp *myhttp = NULL; 942 struct evhttp *myhttp = NULL;
812  943
813 fprintf(stdout, "Testing HTTP Server with high port: "); 944 fprintf(stdout, "Testing HTTP Server with high port: ");
@@ -830,45 +961,103 @@ static void @@ -830,45 +961,103 @@ static void
830http_bad_header_test(void) 961http_bad_header_test(void)
831{ 962{
832 struct evkeyvalq headers; 963 struct evkeyvalq headers;
833 964
834 fprintf(stdout, "Testing HTTP Header filtering: "); 965 fprintf(stdout, "Testing HTTP Header filtering: ");
835 966
836 TAILQ_INIT(&headers); 967 TAILQ_INIT(&headers);
837 968
838 if (evhttp_add_header(&headers, "One", "Two") != 0) 969 if (evhttp_add_header(&headers, "One", "Two") != 0)
839 goto fail; 970 goto fail;
840  971
841 if (evhttp_add_header(&headers, "One\r", "Two") != -1) 972 if (evhttp_add_header(&headers, "One\r", "Two") != -1)
842 goto fail; 973 goto fail;
843 974 if (evhttp_add_header(&headers, "One", "Two") != 0)
 975 goto fail;
 976 if (evhttp_add_header(&headers, "One", "Two\r\n Three") != 0)
 977 goto fail;
 978 if (evhttp_add_header(&headers, "One\r", "Two") != -1)
 979 goto fail;
844 if (evhttp_add_header(&headers, "One\n", "Two") != -1) 980 if (evhttp_add_header(&headers, "One\n", "Two") != -1)
845 goto fail; 981 goto fail;
846 
847 if (evhttp_add_header(&headers, "One", "Two\r") != -1) 982 if (evhttp_add_header(&headers, "One", "Two\r") != -1)
848 goto fail; 983 goto fail;
849 
850 if (evhttp_add_header(&headers, "One", "Two\n") != -1) 984 if (evhttp_add_header(&headers, "One", "Two\n") != -1)
851 goto fail; 985 goto fail;
852 986
853 evhttp_clear_headers(&headers); 987 evhttp_clear_headers(&headers);
854 988
855 fprintf(stdout, "OK\n"); 989 fprintf(stdout, "OK\n");
856 return; 990 return;
857fail: 991fail:
858 fprintf(stdout, "FAILED\n"); 992 fprintf(stdout, "FAILED\n");
859 exit(1); 993 exit(1);
860} 994}
861 995
 996static int validate_header(
 997 const struct evkeyvalq* headers,
 998 const char *key, const char *value)
 999{
 1000 const char *real_val = evhttp_find_header(headers, key);
 1001 if (real_val == NULL)
 1002 return (-1);
 1003 if (strcmp(real_val, value) != 0)
 1004 return (-1);
 1005 return (0);
 1006}
 1007
 1008static void
 1009http_parse_query_test(void)
 1010{
 1011 struct evkeyvalq headers;
 1012
 1013 fprintf(stdout, "Testing HTTP query parsing: ");
 1014
 1015 TAILQ_INIT(&headers);
 1016
 1017 evhttp_parse_query("http://www.test.com/?q=test", &headers);
 1018 if (validate_header(&headers, "q", "test") != 0)
 1019 goto fail;
 1020 evhttp_clear_headers(&headers);
 1021
 1022 evhttp_parse_query("http://www.test.com/?q=test&foo=bar", &headers);
 1023 if (validate_header(&headers, "q", "test") != 0)
 1024 goto fail;
 1025 if (validate_header(&headers, "foo", "bar") != 0)
 1026 goto fail;
 1027 evhttp_clear_headers(&headers);
 1028
 1029 evhttp_parse_query("http://www.test.com/?q=test+foo", &headers);
 1030 if (validate_header(&headers, "q", "test foo") != 0)
 1031 goto fail;
 1032 evhttp_clear_headers(&headers);
 1033
 1034 evhttp_parse_query("http://www.test.com/?q=test%0Afoo", &headers);
 1035 if (validate_header(&headers, "q", "test\nfoo") != 0)
 1036 goto fail;
 1037 evhttp_clear_headers(&headers);
 1038
 1039 evhttp_parse_query("http://www.test.com/?q=test%0Dfoo", &headers);
 1040 if (validate_header(&headers, "q", "test\rfoo") != 0)
 1041 goto fail;
 1042 evhttp_clear_headers(&headers);
 1043
 1044 fprintf(stdout, "OK\n");
 1045 return;
 1046fail:
 1047 fprintf(stdout, "FAILED\n");
 1048 exit(1);
 1049}
 1050
862static void 1051static void
863http_base_test(void) 1052http_base_test(void)
864{ 1053{
865 struct bufferevent *bev; 1054 struct bufferevent *bev;
866 int fd; 1055 int fd;
867 const char *http_request; 1056 const char *http_request;
868 short port = -1; 1057 short port = -1;
869 1058
870 test_ok = 0; 1059 test_ok = 0;
871 fprintf(stdout, "Testing HTTP Server Event Base: "); 1060 fprintf(stdout, "Testing HTTP Server Event Base: ");
872 1061
873 base = event_init(); 1062 base = event_init();
874 1063
@@ -888,42 +1077,376 @@ http_base_test(void) @@ -888,42 +1077,376 @@ http_base_test(void)
888 bufferevent_base_set(base, bev); 1077 bufferevent_base_set(base, bev);
889 1078
890 http_request = 1079 http_request =
891 "GET /test HTTP/1.1\r\n" 1080 "GET /test HTTP/1.1\r\n"
892 "Host: somehost\r\n" 1081 "Host: somehost\r\n"
893 "Connection: close\r\n" 1082 "Connection: close\r\n"
894 "\r\n"; 1083 "\r\n";
895 1084
896 bufferevent_write(bev, http_request, strlen(http_request)); 1085 bufferevent_write(bev, http_request, strlen(http_request));
897  1086
898 event_base_dispatch(base); 1087 event_base_dispatch(base);
899 1088
900 bufferevent_free(bev); 1089 bufferevent_free(bev);
901 close(fd); 1090 EVUTIL_CLOSESOCKET(fd);
902 1091
903 evhttp_free(http); 1092 evhttp_free(http);
904 1093
905 event_base_free(base); 1094 event_base_free(base);
906 base = NULL; 1095 base = NULL;
907  1096
908 if (test_ok != 2) { 1097 if (test_ok != 2) {
909 fprintf(stdout, "FAILED\n"); 1098 fprintf(stdout, "FAILED\n");
910 exit(1); 1099 exit(1);
911 } 1100 }
912  1101
913 fprintf(stdout, "OK\n"); 1102 fprintf(stdout, "OK\n");
914} 1103}
915 1104
 1105/*
 1106 * the server is going to reply with chunked data.
 1107 */
 1108
 1109static void
 1110http_chunked_readcb(struct bufferevent *bev, void *arg)
 1111{
 1112 /* nothing here */
 1113}
 1114
 1115static void
 1116http_chunked_errorcb(struct bufferevent *bev, short what, void *arg)
 1117{
 1118 if (!test_ok)
 1119 goto out;
 1120
 1121 test_ok = -1;
 1122
 1123 if ((what & EVBUFFER_EOF) != 0) {
 1124 struct evhttp_request *req = evhttp_request_new(NULL, NULL);
 1125 const char *header;
 1126 enum message_read_status done;
 1127
 1128 req->kind = EVHTTP_RESPONSE;
 1129 done = evhttp_parse_firstline(req, EVBUFFER_INPUT(bev));
 1130 if (done != ALL_DATA_READ)
 1131 goto out;
 1132
 1133 done = evhttp_parse_headers(req, EVBUFFER_INPUT(bev));
 1134 if (done != ALL_DATA_READ)
 1135 goto out;
 1136
 1137 header = evhttp_find_header(req->input_headers, "Transfer-Encoding");
 1138 if (header == NULL || strcmp(header, "chunked"))
 1139 goto out;
 1140
 1141 header = evhttp_find_header(req->input_headers, "Connection");
 1142 if (header == NULL || strcmp(header, "close"))
 1143 goto out;
 1144
 1145 header = evbuffer_readline(EVBUFFER_INPUT(bev));
 1146 if (header == NULL)
 1147 goto out;
 1148 /* 13 chars */
 1149 if (strcmp(header, "d"))
 1150 goto out;
 1151 free((char*)header);
 1152
 1153 if (strncmp((char *)EVBUFFER_DATA(EVBUFFER_INPUT(bev)),
 1154 "This is funny", 13))
 1155 goto out;
 1156
 1157 evbuffer_drain(EVBUFFER_INPUT(bev), 13 + 2);
 1158
 1159 header = evbuffer_readline(EVBUFFER_INPUT(bev));
 1160 if (header == NULL)
 1161 goto out;
 1162 /* 18 chars */
 1163 if (strcmp(header, "12"))
 1164 goto out;
 1165 free((char *)header);
 1166
 1167 if (strncmp((char *)EVBUFFER_DATA(EVBUFFER_INPUT(bev)),
 1168 "but not hilarious.", 18))
 1169 goto out;
 1170
 1171 evbuffer_drain(EVBUFFER_INPUT(bev), 18 + 2);
 1172
 1173 header = evbuffer_readline(EVBUFFER_INPUT(bev));
 1174 if (header == NULL)
 1175 goto out;
 1176 /* 8 chars */
 1177 if (strcmp(header, "8"))
 1178 goto out;
 1179 free((char *)header);
 1180
 1181 if (strncmp((char *)EVBUFFER_DATA(EVBUFFER_INPUT(bev)),
 1182 "bwv 1052.", 8))
 1183 goto out;
 1184
 1185 evbuffer_drain(EVBUFFER_INPUT(bev), 8 + 2);
 1186
 1187 header = evbuffer_readline(EVBUFFER_INPUT(bev));
 1188 if (header == NULL)
 1189 goto out;
 1190 /* 0 chars */
 1191 if (strcmp(header, "0"))
 1192 goto out;
 1193 free((char *)header);
 1194
 1195 test_ok = 2;
 1196 }
 1197
 1198out:
 1199 event_loopexit(NULL);
 1200}
 1201
 1202static void
 1203http_chunked_writecb(struct bufferevent *bev, void *arg)
 1204{
 1205 if (EVBUFFER_LENGTH(EVBUFFER_OUTPUT(bev)) == 0) {
 1206 /* enable reading of the reply */
 1207 bufferevent_enable(bev, EV_READ);
 1208 test_ok++;
 1209 }
 1210}
 1211
 1212static void
 1213http_chunked_request_done(struct evhttp_request *req, void *arg)
 1214{
 1215 if (req->response_code != HTTP_OK) {
 1216 fprintf(stderr, "FAILED\n");
 1217 exit(1);
 1218 }
 1219
 1220 if (evhttp_find_header(req->input_headers,
 1221 "Transfer-Encoding") == NULL) {
 1222 fprintf(stderr, "FAILED\n");
 1223 exit(1);
 1224 }
 1225
 1226 if (EVBUFFER_LENGTH(req->input_buffer) != 13 + 18 + 8) {
 1227 fprintf(stderr, "FAILED\n");
 1228 exit(1);
 1229 }
 1230
 1231 if (strncmp((char *)EVBUFFER_DATA(req->input_buffer),
 1232 "This is funnybut not hilarious.bwv 1052",
 1233 13 + 18 + 8)) {
 1234 fprintf(stderr, "FAILED\n");
 1235 exit(1);
 1236 }
 1237
 1238 test_ok = 1;
 1239 event_loopexit(NULL);
 1240}
 1241
 1242static void
 1243http_chunked_test(void)
 1244{
 1245 struct bufferevent *bev;
 1246 int fd;
 1247 const char *http_request;
 1248 short port = -1;
 1249 struct timeval tv_start, tv_end;
 1250 struct evhttp_connection *evcon = NULL;
 1251 struct evhttp_request *req = NULL;
 1252 int i;
 1253
 1254 test_ok = 0;
 1255 fprintf(stdout, "Testing Chunked HTTP Reply: ");
 1256
 1257 http = http_setup(&port, NULL);
 1258
 1259 fd = http_connect("127.0.0.1", port);
 1260
 1261 /* Stupid thing to send a request */
 1262 bev = bufferevent_new(fd,
 1263 http_chunked_readcb, http_chunked_writecb,
 1264 http_chunked_errorcb, NULL);
 1265
 1266 http_request =
 1267 "GET /chunked HTTP/1.1\r\n"
 1268 "Host: somehost\r\n"
 1269 "Connection: close\r\n"
 1270 "\r\n";
 1271
 1272 bufferevent_write(bev, http_request, strlen(http_request));
 1273
 1274 evutil_gettimeofday(&tv_start, NULL);
 1275
 1276 event_dispatch();
 1277
 1278 evutil_gettimeofday(&tv_end, NULL);
 1279 evutil_timersub(&tv_end, &tv_start, &tv_end);
 1280
 1281 if (tv_end.tv_sec >= 1) {
 1282 fprintf(stdout, "FAILED (time)\n");
 1283 exit (1);
 1284 }
 1285
 1286
 1287 if (test_ok != 2) {
 1288 fprintf(stdout, "FAILED\n");
 1289 exit(1);
 1290 }
 1291
 1292 /* now try again with the regular connection object */
 1293 evcon = evhttp_connection_new("127.0.0.1", port);
 1294 if (evcon == NULL) {
 1295 fprintf(stdout, "FAILED\n");
 1296 exit(1);
 1297 }
 1298
 1299 /* make two requests to check the keepalive behavior */
 1300 for (i = 0; i < 2; i++) {
 1301 test_ok = 0;
 1302 req = evhttp_request_new(http_chunked_request_done, NULL);
 1303
 1304 /* Add the information that we care about */
 1305 evhttp_add_header(req->output_headers, "Host", "somehost");
 1306
 1307 /* We give ownership of the request to the connection */
 1308 if (evhttp_make_request(evcon, req,
 1309 EVHTTP_REQ_GET, "/chunked") == -1) {
 1310 fprintf(stdout, "FAILED\n");
 1311 exit(1);
 1312 }
 1313
 1314 event_dispatch();
 1315
 1316 if (test_ok != 1) {
 1317 fprintf(stdout, "FAILED\n");
 1318 exit(1);
 1319 }
 1320 }
 1321
 1322 evhttp_connection_free(evcon);
 1323 evhttp_free(http);
 1324
 1325 fprintf(stdout, "OK\n");
 1326}
 1327
 1328static void
 1329http_multi_line_header_test(void)
 1330{
 1331 struct bufferevent *bev;
 1332 int fd;
 1333 const char *http_start_request;
 1334 short port = -1;
 1335
 1336 test_ok = 0;
 1337 fprintf(stdout, "Testing HTTP Server with multi line: ");
 1338
 1339 http = http_setup(&port, NULL);
 1340
 1341 fd = http_connect("127.0.0.1", port);
 1342
 1343 /* Stupid thing to send a request */
 1344 bev = bufferevent_new(fd, http_readcb, http_writecb,
 1345 http_errorcb, NULL);
 1346
 1347 http_start_request =
 1348 "GET /test HTTP/1.1\r\n"
 1349 "Host: somehost\r\n"
 1350 "Connection: close\r\n"
 1351 "X-Multi: aaaaaaaa\r\n"
 1352 " a\r\n"
 1353 "\tEND\r\n"
 1354 "X-Last: last\r\n"
 1355 "\r\n";
 1356
 1357 bufferevent_write(bev, http_start_request, strlen(http_start_request));
 1358
 1359 event_dispatch();
 1360
 1361 bufferevent_free(bev);
 1362 EVUTIL_CLOSESOCKET(fd);
 1363
 1364 evhttp_free(http);
 1365
 1366 if (test_ok != 4) {
 1367 fprintf(stdout, "FAILED\n");
 1368 exit(1);
 1369 }
 1370
 1371 fprintf(stdout, "OK\n");
 1372}
 1373
 1374static void
 1375http_request_bad(struct evhttp_request *req, void *arg)
 1376{
 1377 if (req != NULL) {
 1378 fprintf(stderr, "FAILED\n");
 1379 exit(1);
 1380 }
 1381
 1382 test_ok = 1;
 1383 event_loopexit(NULL);
 1384}
 1385
 1386static void
 1387http_negative_content_length_test(void)
 1388{
 1389 short port = -1;
 1390 struct evhttp_connection *evcon = NULL;
 1391 struct evhttp_request *req = NULL;
 1392
 1393 test_ok = 0;
 1394 fprintf(stdout, "Testing HTTP Negative Content Length: ");
 1395
 1396 http = http_setup(&port, NULL);
 1397
 1398 evcon = evhttp_connection_new("127.0.0.1", port);
 1399 if (evcon == NULL) {
 1400 fprintf(stdout, "FAILED\n");
 1401 exit(1);
 1402 }
 1403
 1404 /*
 1405 * At this point, we want to schedule a request to the HTTP
 1406 * server using our make request method.
 1407 */
 1408
 1409 req = evhttp_request_new(http_request_bad, NULL);
 1410
 1411 /* Cause the response to have a negative content-length */
 1412 evhttp_add_header(req->output_headers, "X-Negative", "makeitso");
 1413
 1414 /* We give ownership of the request to the connection */
 1415 if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") == -1) {
 1416 fprintf(stdout, "FAILED\n");
 1417 exit(1);
 1418 }
 1419
 1420 event_dispatch();
 1421
 1422 evhttp_free(http);
 1423
 1424 if (test_ok != 1) {
 1425 fprintf(stdout, "FAILED\n");
 1426 exit(1);
 1427 }
 1428
 1429 fprintf(stdout, "OK\n");
 1430}
 1431
916void 1432void
917http_suite(void) 1433http_suite(void)
918{ 1434{
919 http_base_test(); 1435 http_base_test();
920 http_bad_header_test(); 1436 http_bad_header_test();
 1437 http_parse_query_test();
921 http_basic_test(); 1438 http_basic_test();
922 http_connection_test(0 /* not-persistent */); 1439 http_connection_test(0 /* not-persistent */);
923 http_connection_test(1 /* persistent */); 1440 http_connection_test(1 /* persistent */);
924 http_close_detection(); 1441 http_close_detection(0 /* with delay */);
 1442 http_close_detection(1 /* with delay */);
925 http_post_test(); 1443 http_post_test();
926 http_failure_test(); 1444 http_failure_test();
927 http_highport_test(); 1445 http_highport_test();
928 http_dispatcher_test(); 1446 http_dispatcher_test();
 1447
 1448 http_multi_line_header_test();
 1449 http_negative_content_length_test();
 1450
 1451 http_chunked_test();
929} 1452}

cvs diff -r1.1 -r1.1.8.1 src/regress/lib/libevent/Attic/regress_rpc.c (expand / switch to unified diff)

--- src/regress/lib/libevent/Attic/regress_rpc.c 2008/05/16 20:24:57 1.1
+++ src/regress/lib/libevent/Attic/regress_rpc.c 2009/08/05 18:33:20 1.1.8.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: regress_rpc.c,v 1.1 2008/05/16 20:24:57 peter Exp $ */ 1/* $NetBSD: regress_rpc.c,v 1.1.8.1 2009/08/05 18:33:20 snj Exp $ */
2/* 2/*
3 * Copyright (c) 2003-2006 Niels Provos <provos@citi.umich.edu> 3 * Copyright (c) 2003-2006 Niels Provos <provos@citi.umich.edu>
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products 14 * 3. The name of the author may not be used to endorse or promote products
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 */ 27 */
28 28
29#ifdef HAVE_CONFIG_H 29#ifdef HAVE_CONFIG_H
30#include "config.h" 30#include "config.h"
31#endif 31#endif
32 32
33#include <sys/types.h> 33#include <sys/types.h>
34#include <sys/stat.h> 34#include <sys/stat.h>
35#ifdef HAVE_SYS_TIME_H 35#ifdef HAVE_SYS_TIME_H
36#include <sys/time.h> 36#include <sys/time.h>
37#endif 37#endif
38#include <sys/queue.h> 38#include <sys/queue.h>
39#include <sys/socket.h> 39#include <sys/socket.h>
40#include <sys/signal.h> 40#include <signal.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <netdb.h> 42#include <netdb.h>
43#include <fcntl.h> 43#include <fcntl.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <stdio.h> 45#include <stdio.h>
46#include <string.h> 46#include <string.h>
47#include <errno.h> 47#include <errno.h>
48#include <assert.h> 48#include <assert.h>
49 49
50#include "event.h" 50#include "event.h"
51#include "evhttp.h" 51#include "evhttp.h"
52#include "log.h" 52#include "log.h"
53#include "evrpc.h" 53#include "evrpc.h"
@@ -434,34 +434,34 @@ rpc_basic_client(void) @@ -434,34 +434,34 @@ rpc_basic_client(void)
434 struct evhttp *http = NULL; 434 struct evhttp *http = NULL;
435 struct evrpc_base *base = NULL; 435 struct evrpc_base *base = NULL;
436 struct evrpc_pool *pool = NULL; 436 struct evrpc_pool *pool = NULL;
437 struct msg *msg; 437 struct msg *msg;
438 struct kill *kill; 438 struct kill *kill;
439 439
440 fprintf(stdout, "Testing RPC Client: "); 440 fprintf(stdout, "Testing RPC Client: ");
441 441
442 rpc_setup(&http, &port, &base); 442 rpc_setup(&http, &port, &base);
443 443
444 need_input_hook = 1; 444 need_input_hook = 1;
445 need_output_hook = 1; 445 need_output_hook = 1;
446 446
447 assert(evrpc_add_hook(base, INPUT, rpc_hook_add_header, (void*)"input") 447 assert(evrpc_add_hook(base, EVRPC_INPUT, rpc_hook_add_header, (void*)"input")
448 != NULL); 448 != NULL);
449 assert(evrpc_add_hook(base, OUTPUT, rpc_hook_add_header, (void*)"output") 449 assert(evrpc_add_hook(base, EVRPC_OUTPUT, rpc_hook_add_header, (void*)"output")
450 != NULL); 450 != NULL);
451 451
452 pool = rpc_pool_with_connection(port); 452 pool = rpc_pool_with_connection(port);
453 453
454 assert(evrpc_add_hook(pool, INPUT, rpc_hook_remove_header, (void*)"output")); 454 assert(evrpc_add_hook(pool, EVRPC_INPUT, rpc_hook_remove_header, (void*)"output"));
455 455
456 /* set up the basic message */ 456 /* set up the basic message */
457 msg = msg_new(); 457 msg = msg_new();
458 EVTAG_ASSIGN(msg, from_name, "niels"); 458 EVTAG_ASSIGN(msg, from_name, "niels");
459 EVTAG_ASSIGN(msg, to_name, "tester"); 459 EVTAG_ASSIGN(msg, to_name, "tester");
460 460
461 kill = kill_new(); 461 kill = kill_new();
462 462
463 EVRPC_MAKE_REQUEST(Message, pool, msg, kill, GotKillCb, NULL); 463 EVRPC_MAKE_REQUEST(Message, pool, msg, kill, GotKillCb, NULL);
464 464
465 test_ok = 0; 465 test_ok = 0;
466 466
467 event_dispatch(); 467 event_dispatch();