A clone of btpd with my configuration changes.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

924 lignes
17 KiB

  1. /*
  2. * Copyright (c) 2003, 2004 Niels Provos <provos@citi.umich.edu>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifdef WIN32
  28. #include <winsock2.h>
  29. #include <windows.h>
  30. #endif
  31. #ifdef HAVE_CONFIG_H
  32. #include "config.h"
  33. #endif
  34. #include <sys/types.h>
  35. #include <sys/stat.h>
  36. #ifdef HAVE_SYS_TIME_H
  37. #include <sys/time.h>
  38. #endif
  39. #include <sys/queue.h>
  40. #ifndef WIN32
  41. #include <sys/socket.h>
  42. #include <sys/signal.h>
  43. #include <unistd.h>
  44. #endif
  45. #include <netdb.h>
  46. #include <fcntl.h>
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #include <string.h>
  50. #include <errno.h>
  51. #include "event.h"
  52. #include "log.h"
  53. #include "regress.h"
  54. #include "regress.gen.h"
  55. int pair[2];
  56. int test_ok;
  57. static int called;
  58. static char wbuf[4096];
  59. static char rbuf[4096];
  60. static int woff;
  61. static int roff;
  62. static int usepersist;
  63. static struct timeval tset;
  64. static struct timeval tcalled;
  65. static struct event_base *event_base;
  66. #define TEST1 "this is a test"
  67. #define SECONDS 1
  68. void
  69. simple_read_cb(int fd, short event, void *arg)
  70. {
  71. char buf[256];
  72. int len;
  73. len = read(fd, buf, sizeof(buf));
  74. if (len) {
  75. if (!called) {
  76. if (event_add(arg, NULL) == -1)
  77. exit(1);
  78. }
  79. } else if (called == 1)
  80. test_ok = 1;
  81. called++;
  82. }
  83. void
  84. simple_write_cb(int fd, short event, void *arg)
  85. {
  86. int len;
  87. len = write(fd, TEST1, strlen(TEST1) + 1);
  88. if (len == -1)
  89. test_ok = 0;
  90. else
  91. test_ok = 1;
  92. }
  93. void
  94. multiple_write_cb(int fd, short event, void *arg)
  95. {
  96. struct event *ev = arg;
  97. int len;
  98. len = 128;
  99. if (woff + len >= sizeof(wbuf))
  100. len = sizeof(wbuf) - woff;
  101. len = write(fd, wbuf + woff, len);
  102. if (len == -1) {
  103. fprintf(stderr, "%s: write\n", __func__);
  104. if (usepersist)
  105. event_del(ev);
  106. return;
  107. }
  108. woff += len;
  109. if (woff >= sizeof(wbuf)) {
  110. shutdown(fd, SHUT_WR);
  111. if (usepersist)
  112. event_del(ev);
  113. return;
  114. }
  115. if (!usepersist) {
  116. if (event_add(ev, NULL) == -1)
  117. exit(1);
  118. }
  119. }
  120. void
  121. multiple_read_cb(int fd, short event, void *arg)
  122. {
  123. struct event *ev = arg;
  124. int len;
  125. len = read(fd, rbuf + roff, sizeof(rbuf) - roff);
  126. if (len == -1)
  127. fprintf(stderr, "%s: read\n", __func__);
  128. if (len <= 0) {
  129. if (usepersist)
  130. event_del(ev);
  131. return;
  132. }
  133. roff += len;
  134. if (!usepersist) {
  135. if (event_add(ev, NULL) == -1)
  136. exit(1);
  137. }
  138. }
  139. void
  140. timeout_cb(int fd, short event, void *arg)
  141. {
  142. struct timeval tv;
  143. int diff;
  144. gettimeofday(&tcalled, NULL);
  145. if (timercmp(&tcalled, &tset, >))
  146. timersub(&tcalled, &tset, &tv);
  147. else
  148. timersub(&tset, &tcalled, &tv);
  149. diff = tv.tv_sec*1000 + tv.tv_usec/1000 - SECONDS * 1000;
  150. if (diff < 0)
  151. diff = -diff;
  152. if (diff < 100)
  153. test_ok = 1;
  154. }
  155. void
  156. signal_cb(int fd, short event, void *arg)
  157. {
  158. struct event *ev = arg;
  159. signal_del(ev);
  160. test_ok = 1;
  161. }
  162. struct both {
  163. struct event ev;
  164. int nread;
  165. };
  166. void
  167. combined_read_cb(int fd, short event, void *arg)
  168. {
  169. struct both *both = arg;
  170. char buf[128];
  171. int len;
  172. len = read(fd, buf, sizeof(buf));
  173. if (len == -1)
  174. fprintf(stderr, "%s: read\n", __func__);
  175. if (len <= 0)
  176. return;
  177. both->nread += len;
  178. if (event_add(&both->ev, NULL) == -1)
  179. exit(1);
  180. }
  181. void
  182. combined_write_cb(int fd, short event, void *arg)
  183. {
  184. struct both *both = arg;
  185. char buf[128];
  186. int len;
  187. len = sizeof(buf);
  188. if (len > both->nread)
  189. len = both->nread;
  190. len = write(fd, buf, len);
  191. if (len == -1)
  192. fprintf(stderr, "%s: write\n", __func__);
  193. if (len <= 0) {
  194. shutdown(fd, SHUT_WR);
  195. return;
  196. }
  197. both->nread -= len;
  198. if (event_add(&both->ev, NULL) == -1)
  199. exit(1);
  200. }
  201. /* Test infrastructure */
  202. int
  203. setup_test(char *name)
  204. {
  205. fprintf(stdout, "%s", name);
  206. if (socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == -1) {
  207. fprintf(stderr, "%s: socketpair\n", __func__);
  208. exit(1);
  209. }
  210. #ifdef HAVE_FCNTL
  211. if (fcntl(pair[0], F_SETFL, O_NONBLOCK) == -1)
  212. fprintf(stderr, "fcntl(O_NONBLOCK)");
  213. if (fcntl(pair[1], F_SETFL, O_NONBLOCK) == -1)
  214. fprintf(stderr, "fcntl(O_NONBLOCK)");
  215. #endif
  216. test_ok = 0;
  217. called = 0;
  218. return (0);
  219. }
  220. int
  221. cleanup_test(void)
  222. {
  223. #ifndef WIN32
  224. close(pair[0]);
  225. close(pair[1]);
  226. #else
  227. CloseHandle((HANDLE)pair[0]);
  228. CloseHandle((HANDLE)pair[1]);
  229. #endif
  230. if (test_ok)
  231. fprintf(stdout, "OK\n");
  232. else {
  233. fprintf(stdout, "FAILED\n");
  234. exit(1);
  235. }
  236. return (0);
  237. }
  238. void
  239. test_simpleread(void)
  240. {
  241. struct event ev;
  242. /* Very simple read test */
  243. setup_test("Simple read: ");
  244. write(pair[0], TEST1, strlen(TEST1)+1);
  245. shutdown(pair[0], SHUT_WR);
  246. event_set(&ev, pair[1], EV_READ, simple_read_cb, &ev);
  247. if (event_add(&ev, NULL) == -1)
  248. exit(1);
  249. event_dispatch();
  250. cleanup_test();
  251. }
  252. void
  253. test_simplewrite(void)
  254. {
  255. struct event ev;
  256. /* Very simple write test */
  257. setup_test("Simple write: ");
  258. event_set(&ev, pair[0], EV_WRITE, simple_write_cb, &ev);
  259. if (event_add(&ev, NULL) == -1)
  260. exit(1);
  261. event_dispatch();
  262. cleanup_test();
  263. }
  264. void
  265. test_multiple(void)
  266. {
  267. struct event ev, ev2;
  268. int i;
  269. /* Multiple read and write test */
  270. setup_test("Multiple read/write: ");
  271. memset(rbuf, 0, sizeof(rbuf));
  272. for (i = 0; i < sizeof(wbuf); i++)
  273. wbuf[i] = i;
  274. roff = woff = 0;
  275. usepersist = 0;
  276. event_set(&ev, pair[0], EV_WRITE, multiple_write_cb, &ev);
  277. if (event_add(&ev, NULL) == -1)
  278. exit(1);
  279. event_set(&ev2, pair[1], EV_READ, multiple_read_cb, &ev2);
  280. if (event_add(&ev2, NULL) == -1)
  281. exit(1);
  282. event_dispatch();
  283. if (roff == woff)
  284. test_ok = memcmp(rbuf, wbuf, sizeof(wbuf)) == 0;
  285. cleanup_test();
  286. }
  287. void
  288. test_persistent(void)
  289. {
  290. struct event ev, ev2;
  291. int i;
  292. /* Multiple read and write test with persist */
  293. setup_test("Persist read/write: ");
  294. memset(rbuf, 0, sizeof(rbuf));
  295. for (i = 0; i < sizeof(wbuf); i++)
  296. wbuf[i] = i;
  297. roff = woff = 0;
  298. usepersist = 1;
  299. event_set(&ev, pair[0], EV_WRITE|EV_PERSIST, multiple_write_cb, &ev);
  300. if (event_add(&ev, NULL) == -1)
  301. exit(1);
  302. event_set(&ev2, pair[1], EV_READ|EV_PERSIST, multiple_read_cb, &ev2);
  303. if (event_add(&ev2, NULL) == -1)
  304. exit(1);
  305. event_dispatch();
  306. if (roff == woff)
  307. test_ok = memcmp(rbuf, wbuf, sizeof(wbuf)) == 0;
  308. cleanup_test();
  309. }
  310. void
  311. test_combined(void)
  312. {
  313. struct both r1, r2, w1, w2;
  314. setup_test("Combined read/write: ");
  315. memset(&r1, 0, sizeof(r1));
  316. memset(&r2, 0, sizeof(r2));
  317. memset(&w1, 0, sizeof(w1));
  318. memset(&w2, 0, sizeof(w2));
  319. w1.nread = 4096;
  320. w2.nread = 8192;
  321. event_set(&r1.ev, pair[0], EV_READ, combined_read_cb, &r1);
  322. event_set(&w1.ev, pair[0], EV_WRITE, combined_write_cb, &w1);
  323. event_set(&r2.ev, pair[1], EV_READ, combined_read_cb, &r2);
  324. event_set(&w2.ev, pair[1], EV_WRITE, combined_write_cb, &w2);
  325. if (event_add(&r1.ev, NULL) == -1)
  326. exit(1);
  327. if (event_add(&w1.ev, NULL))
  328. exit(1);
  329. if (event_add(&r2.ev, NULL))
  330. exit(1);
  331. if (event_add(&w2.ev, NULL))
  332. exit(1);
  333. event_dispatch();
  334. if (r1.nread == 8192 && r2.nread == 4096)
  335. test_ok = 1;
  336. cleanup_test();
  337. }
  338. void
  339. test_simpletimeout(void)
  340. {
  341. struct timeval tv;
  342. struct event ev;
  343. setup_test("Simple timeout: ");
  344. tv.tv_usec = 0;
  345. tv.tv_sec = SECONDS;
  346. evtimer_set(&ev, timeout_cb, NULL);
  347. evtimer_add(&ev, &tv);
  348. gettimeofday(&tset, NULL);
  349. event_dispatch();
  350. cleanup_test();
  351. }
  352. #ifndef WIN32
  353. void
  354. test_simplesignal(void)
  355. {
  356. struct event ev;
  357. struct itimerval itv;
  358. setup_test("Simple signal: ");
  359. signal_set(&ev, SIGALRM, signal_cb, &ev);
  360. signal_add(&ev, NULL);
  361. memset(&itv, 0, sizeof(itv));
  362. itv.it_value.tv_sec = 1;
  363. if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
  364. goto skip_simplesignal;
  365. event_dispatch();
  366. skip_simplesignal:
  367. if (signal_del(&ev) == -1)
  368. test_ok = 0;
  369. cleanup_test();
  370. }
  371. #endif
  372. void
  373. test_loopexit(void)
  374. {
  375. struct timeval tv, tv_start, tv_end;
  376. struct event ev;
  377. setup_test("Loop exit: ");
  378. tv.tv_usec = 0;
  379. tv.tv_sec = 60*60*24;
  380. evtimer_set(&ev, timeout_cb, NULL);
  381. evtimer_add(&ev, &tv);
  382. tv.tv_usec = 0;
  383. tv.tv_sec = 1;
  384. event_loopexit(&tv);
  385. gettimeofday(&tv_start, NULL);
  386. event_dispatch();
  387. gettimeofday(&tv_end, NULL);
  388. timersub(&tv_end, &tv_start, &tv_end);
  389. evtimer_del(&ev);
  390. if (tv.tv_sec < 2)
  391. test_ok = 1;
  392. cleanup_test();
  393. }
  394. void
  395. test_evbuffer(void) {
  396. setup_test("Evbuffer: ");
  397. struct evbuffer *evb = evbuffer_new();
  398. evbuffer_add_printf(evb, "%s/%d", "hello", 1);
  399. if (EVBUFFER_LENGTH(evb) == 7 &&
  400. strcmp(EVBUFFER_DATA(evb), "hello/1") == 0)
  401. test_ok = 1;
  402. cleanup_test();
  403. }
  404. void
  405. readcb(struct bufferevent *bev, void *arg)
  406. {
  407. if (EVBUFFER_LENGTH(bev->input) == 8333) {
  408. bufferevent_disable(bev, EV_READ);
  409. test_ok++;
  410. }
  411. }
  412. void
  413. writecb(struct bufferevent *bev, void *arg)
  414. {
  415. if (EVBUFFER_LENGTH(bev->output) == 0)
  416. test_ok++;
  417. }
  418. void
  419. errorcb(struct bufferevent *bev, short what, void *arg)
  420. {
  421. test_ok = -2;
  422. }
  423. void
  424. test_bufferevent(void)
  425. {
  426. struct bufferevent *bev1, *bev2;
  427. char buffer[8333];
  428. int i;
  429. setup_test("Bufferevent: ");
  430. bev1 = bufferevent_new(pair[0], readcb, writecb, errorcb, NULL);
  431. bev2 = bufferevent_new(pair[1], readcb, writecb, errorcb, NULL);
  432. bufferevent_disable(bev1, EV_READ);
  433. bufferevent_enable(bev2, EV_READ);
  434. for (i = 0; i < sizeof(buffer); i++)
  435. buffer[0] = i;
  436. bufferevent_write(bev1, buffer, sizeof(buffer));
  437. event_dispatch();
  438. bufferevent_free(bev1);
  439. bufferevent_free(bev2);
  440. if (test_ok != 2)
  441. test_ok = 0;
  442. cleanup_test();
  443. }
  444. struct test_pri_event {
  445. struct event ev;
  446. int count;
  447. };
  448. void
  449. test_priorities_cb(int fd, short what, void *arg)
  450. {
  451. struct test_pri_event *pri = arg;
  452. struct timeval tv;
  453. if (pri->count == 3) {
  454. event_loopexit(NULL);
  455. return;
  456. }
  457. pri->count++;
  458. timerclear(&tv);
  459. event_add(&pri->ev, &tv);
  460. }
  461. void
  462. test_priorities(int npriorities)
  463. {
  464. char buf[32];
  465. struct test_pri_event one, two;
  466. struct timeval tv;
  467. snprintf(buf, sizeof(buf), "Priorities %d: ", npriorities);
  468. setup_test(buf);
  469. event_base_priority_init(event_base, npriorities);
  470. memset(&one, 0, sizeof(one));
  471. memset(&two, 0, sizeof(two));
  472. timeout_set(&one.ev, test_priorities_cb, &one);
  473. if (event_priority_set(&one.ev, 0) == -1) {
  474. fprintf(stderr, "%s: failed to set priority", __func__);
  475. exit(1);
  476. }
  477. timeout_set(&two.ev, test_priorities_cb, &two);
  478. if (event_priority_set(&two.ev, npriorities - 1) == -1) {
  479. fprintf(stderr, "%s: failed to set priority", __func__);
  480. exit(1);
  481. }
  482. timerclear(&tv);
  483. if (event_add(&one.ev, &tv) == -1)
  484. exit(1);
  485. if (event_add(&two.ev, &tv) == -1)
  486. exit(1);
  487. event_dispatch();
  488. event_del(&one.ev);
  489. event_del(&two.ev);
  490. if (npriorities == 1) {
  491. if (one.count == 3 && two.count == 3)
  492. test_ok = 1;
  493. } else if (npriorities == 2) {
  494. /* Two is called once because event_loopexit is priority 1 */
  495. if (one.count == 3 && two.count == 1)
  496. test_ok = 1;
  497. } else {
  498. if (one.count == 3 && two.count == 0)
  499. test_ok = 1;
  500. }
  501. cleanup_test();
  502. }
  503. static void
  504. test_multiple_cb(int fd, short event, void *arg)
  505. {
  506. if (event & EV_READ)
  507. test_ok |= 1;
  508. else if (event & EV_WRITE)
  509. test_ok |= 2;
  510. }
  511. void
  512. test_multiple_events_for_same_fd(void)
  513. {
  514. struct event e1, e2;
  515. setup_test("Multiple events for same fd: ");
  516. event_set(&e1, pair[0], EV_READ, test_multiple_cb, NULL);
  517. event_add(&e1, NULL);
  518. event_set(&e2, pair[0], EV_WRITE, test_multiple_cb, NULL);
  519. event_add(&e2, NULL);
  520. event_loop(EVLOOP_ONCE);
  521. event_del(&e2);
  522. write(pair[1], TEST1, strlen(TEST1)+1);
  523. event_loop(EVLOOP_ONCE);
  524. event_del(&e1);
  525. if (test_ok != 3)
  526. test_ok = 0;
  527. cleanup_test();
  528. }
  529. int decode_int(u_int32_t *pnumber, struct evbuffer *evbuf);
  530. void
  531. read_once_cb(int fd, short event, void *arg)
  532. {
  533. char buf[256];
  534. int len;
  535. len = read(fd, buf, sizeof(buf));
  536. if (called) {
  537. test_ok = 0;
  538. } else if (len) {
  539. /* Assumes global pair[0] can be used for writing */
  540. write(pair[0], TEST1, strlen(TEST1)+1);
  541. test_ok = 1;
  542. }
  543. called++;
  544. }
  545. void
  546. test_want_only_once(void)
  547. {
  548. struct event ev;
  549. struct timeval tv;
  550. /* Very simple read test */
  551. setup_test("Want read only once: ");
  552. write(pair[0], TEST1, strlen(TEST1)+1);
  553. /* Setup the loop termination */
  554. timerclear(&tv);
  555. tv.tv_sec = 1;
  556. event_loopexit(&tv);
  557. event_set(&ev, pair[1], EV_READ, read_once_cb, &ev);
  558. if (event_add(&ev, NULL) == -1)
  559. exit(1);
  560. event_dispatch();
  561. cleanup_test();
  562. }
  563. #define TEST_MAX_INT 6
  564. void
  565. evtag_int_test(void)
  566. {
  567. struct evbuffer *tmp = evbuffer_new();
  568. u_int32_t integers[TEST_MAX_INT] = {
  569. 0xaf0, 0x1000, 0x1, 0xdeadbeef, 0x00, 0xbef000
  570. };
  571. u_int32_t integer;
  572. int i;
  573. for (i = 0; i < TEST_MAX_INT; i++) {
  574. int oldlen, newlen;
  575. oldlen = EVBUFFER_LENGTH(tmp);
  576. encode_int(tmp, integers[i]);
  577. newlen = EVBUFFER_LENGTH(tmp);
  578. fprintf(stdout, "\t\tencoded 0x%08x with %d bytes\n",
  579. integers[i], newlen - oldlen);
  580. }
  581. for (i = 0; i < TEST_MAX_INT; i++) {
  582. if (decode_int(&integer, tmp) == -1) {
  583. fprintf(stderr, "decode %d failed", i);
  584. exit(1);
  585. }
  586. if (integer != integers[i]) {
  587. fprintf(stderr, "got %x, wanted %x",
  588. integer, integers[i]);
  589. exit(1);
  590. }
  591. }
  592. if (EVBUFFER_LENGTH(tmp) != 0) {
  593. fprintf(stderr, "trailing data");
  594. exit(1);
  595. }
  596. evbuffer_free(tmp);
  597. fprintf(stdout, "\t%s: OK\n", __func__);
  598. }
  599. void
  600. evtag_fuzz()
  601. {
  602. u_char buffer[4096];
  603. struct evbuffer *tmp = evbuffer_new();
  604. struct timeval tv;
  605. int i, j;
  606. int not_failed = 0;
  607. for (j = 0; j < 100; j++) {
  608. for (i = 0; i < sizeof(buffer); i++)
  609. buffer[i] = rand();
  610. evbuffer_drain(tmp, -1);
  611. evbuffer_add(tmp, buffer, sizeof(buffer));
  612. if (evtag_unmarshal_timeval(tmp, 0, &tv) != -1)
  613. not_failed++;
  614. }
  615. /* The majority of decodes should fail */
  616. if (not_failed >= 10) {
  617. fprintf(stderr, "evtag_unmarshal should have failed");
  618. exit(1);
  619. }
  620. /* Now insert some corruption into the tag length field */
  621. evbuffer_drain(tmp, -1);
  622. timerclear(&tv);
  623. tv.tv_sec = 1;
  624. evtag_marshal_timeval(tmp, 0, &tv);
  625. evbuffer_add(tmp, buffer, sizeof(buffer));
  626. EVBUFFER_DATA(tmp)[1] = 0xff;
  627. if (evtag_unmarshal_timeval(tmp, 0, &tv) != -1) {
  628. fprintf(stderr, "evtag_unmarshal_timeval should have failed");
  629. exit(1);
  630. }
  631. evbuffer_free(tmp);
  632. fprintf(stdout, "\t%s: OK\n", __func__);
  633. }
  634. void
  635. evtag_test(void)
  636. {
  637. fprintf(stdout, "Testing Tagging:\n");
  638. evtag_init();
  639. evtag_int_test();
  640. evtag_fuzz();
  641. fprintf(stdout, "OK\n");
  642. }
  643. void
  644. rpc_test(void)
  645. {
  646. struct msg *msg, *msg2;
  647. struct kill *kill;
  648. struct run *run;
  649. struct evbuffer *tmp = evbuffer_new();
  650. int i;
  651. fprintf(stdout, "Testing RPC: ");
  652. msg = msg_new();
  653. EVTAG_ASSIGN(msg, from_name, "niels");
  654. EVTAG_ASSIGN(msg, to_name, "phoenix");
  655. if (EVTAG_GET(msg, kill, &kill) == -1) {
  656. fprintf(stderr, "Failed to set kill message.\n");
  657. exit(1);
  658. }
  659. EVTAG_ASSIGN(kill, weapon, "feather");
  660. EVTAG_ASSIGN(kill, action, "tickle");
  661. for (i = 0; i < 3; ++i) {
  662. run = EVTAG_ADD(msg, run);
  663. if (run == NULL) {
  664. fprintf(stderr, "Failed to add run message.\n");
  665. exit(1);
  666. }
  667. EVTAG_ASSIGN(run, how, "very fast");
  668. }
  669. if (msg_complete(msg) == -1) {
  670. fprintf(stderr, "Failed to make complete message.\n");
  671. exit(1);
  672. }
  673. evtag_marshal_msg(tmp, 0, msg);
  674. msg2 = msg_new();
  675. if (evtag_unmarshal_msg(tmp, 0, msg2) == -1) {
  676. fprintf(stderr, "Failed to unmarshal message.\n");
  677. exit(1);
  678. }
  679. if (!EVTAG_HAS(msg2, from_name) ||
  680. !EVTAG_HAS(msg2, to_name) ||
  681. !EVTAG_HAS(msg2, kill)) {
  682. fprintf(stderr, "Missing data structures.\n");
  683. exit(1);
  684. }
  685. if (EVTAG_LEN(msg2, run) != 3) {
  686. fprintf(stderr, "Wrong number of run messages.\n");
  687. exit(1);
  688. }
  689. msg_free(msg);
  690. msg_free(msg2);
  691. fprintf(stdout, "OK\n");
  692. }
  693. int
  694. main (int argc, char **argv)
  695. {
  696. #ifdef WIN32
  697. WORD wVersionRequested;
  698. WSADATA wsaData;
  699. int err;
  700. wVersionRequested = MAKEWORD( 2, 2 );
  701. err = WSAStartup( wVersionRequested, &wsaData );
  702. #endif
  703. setvbuf(stdout, NULL, _IONBF, 0);
  704. /* Initalize the event library */
  705. event_base = event_init();
  706. http_suite();
  707. dns_suite();
  708. test_simpleread();
  709. test_simplewrite();
  710. test_multiple();
  711. test_persistent();
  712. test_combined();
  713. test_simpletimeout();
  714. #ifndef WIN32
  715. test_simplesignal();
  716. #endif
  717. test_loopexit();
  718. test_evbuffer();
  719. test_bufferevent();
  720. test_priorities(1);
  721. test_priorities(2);
  722. test_priorities(3);
  723. test_multiple_events_for_same_fd();
  724. test_want_only_once();
  725. evtag_test();
  726. rpc_test();
  727. return (0);
  728. }