Changes to update Tomato RAF.
[tomato.git] / release / src / router / dnscrypt / src / libevent / test / regress_rpc.c
blob922fdc1031c557546666c992a05d7a08e3e8b22f
1 /*
2 * Copyright (c) 2003-2007 Niels Provos <provos@citi.umich.edu>
3 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
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.
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.
28 /* The old tests here need assertions to work. */
29 #undef NDEBUG
31 #ifdef WIN32
32 #include <winsock2.h>
33 #include <windows.h>
34 #endif
36 #include "event2/event-config.h"
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #ifdef _EVENT_HAVE_SYS_TIME_H
41 #include <sys/time.h>
42 #endif
43 #include <sys/queue.h>
44 #ifndef WIN32
45 #include <sys/socket.h>
46 #include <signal.h>
47 #include <unistd.h>
48 #include <netdb.h>
49 #endif
50 #include <fcntl.h>
51 #include <stdlib.h>
52 #include <stdio.h>
53 #include <string.h>
54 #include <errno.h>
55 #include <assert.h>
57 #include "event2/buffer.h"
58 #include "event2/event.h"
59 #include "event2/event_compat.h"
60 #include "event2/http.h"
61 #include "event2/http_compat.h"
62 #include "event2/http_struct.h"
63 #include "event2/rpc.h"
64 #include "event2/rpc.h"
65 #include "event2/rpc_struct.h"
66 #include "event2/tag.h"
67 #include "log-internal.h"
69 #include "regress.gen.h"
71 #include "regress.h"
72 #include "regress_testutils.h"
74 #ifndef NO_PYTHON_EXISTS
76 static struct evhttp *
77 http_setup(ev_uint16_t *pport)
79 struct evhttp *myhttp;
80 ev_uint16_t port;
81 struct evhttp_bound_socket *sock;
83 myhttp = evhttp_new(NULL);
84 if (!myhttp)
85 event_errx(1, "Could not start web server");
87 /* Try a few different ports */
88 sock = evhttp_bind_socket_with_handle(myhttp, "127.0.0.1", 0);
89 if (!sock)
90 event_errx(1, "Couldn't open web port");
92 port = regress_get_socket_port(evhttp_bound_socket_get_fd(sock));
94 *pport = port;
95 return (myhttp);
98 EVRPC_HEADER(Message, msg, kill)
99 EVRPC_HEADER(NeverReply, msg, kill)
101 EVRPC_GENERATE(Message, msg, kill)
102 EVRPC_GENERATE(NeverReply, msg, kill)
104 static int need_input_hook = 0;
105 static int need_output_hook = 0;
107 static void
108 MessageCb(EVRPC_STRUCT(Message)* rpc, void *arg)
110 struct kill* kill_reply = rpc->reply;
112 if (need_input_hook) {
113 struct evhttp_request* req = EVRPC_REQUEST_HTTP(rpc);
114 const char *header = evhttp_find_header(
115 req->input_headers, "X-Hook");
116 assert(strcmp(header, "input") == 0);
119 /* we just want to fill in some non-sense */
120 EVTAG_ASSIGN(kill_reply, weapon, "dagger");
121 EVTAG_ASSIGN(kill_reply, action, "wave around like an idiot");
123 /* no reply to the RPC */
124 EVRPC_REQUEST_DONE(rpc);
127 static EVRPC_STRUCT(NeverReply) *saved_rpc;
129 static void
130 NeverReplyCb(EVRPC_STRUCT(NeverReply)* rpc, void *arg)
132 test_ok += 1;
133 saved_rpc = rpc;
136 static void
137 rpc_setup(struct evhttp **phttp, ev_uint16_t *pport, struct evrpc_base **pbase)
139 ev_uint16_t port;
140 struct evhttp *http = NULL;
141 struct evrpc_base *base = NULL;
143 http = http_setup(&port);
144 base = evrpc_init(http);
146 EVRPC_REGISTER(base, Message, msg, kill, MessageCb, NULL);
147 EVRPC_REGISTER(base, NeverReply, msg, kill, NeverReplyCb, NULL);
149 *phttp = http;
150 *pport = port;
151 *pbase = base;
153 need_input_hook = 0;
154 need_output_hook = 0;
157 static void
158 rpc_teardown(struct evrpc_base *base)
160 assert(EVRPC_UNREGISTER(base, Message) == 0);
161 assert(EVRPC_UNREGISTER(base, NeverReply) == 0);
163 evrpc_free(base);
166 static void
167 rpc_postrequest_failure(struct evhttp_request *req, void *arg)
169 if (req->response_code != HTTP_SERVUNAVAIL) {
171 fprintf(stderr, "FAILED (response code)\n");
172 exit(1);
175 test_ok = 1;
176 event_loopexit(NULL);
180 * Test a malformed payload submitted as an RPC
183 static void
184 rpc_basic_test(void)
186 ev_uint16_t port;
187 struct evhttp *http = NULL;
188 struct evrpc_base *base = NULL;
189 struct evhttp_connection *evcon = NULL;
190 struct evhttp_request *req = NULL;
192 rpc_setup(&http, &port, &base);
194 evcon = evhttp_connection_new("127.0.0.1", port);
195 tt_assert(evcon);
198 * At this point, we want to schedule an HTTP POST request
199 * server using our make request method.
202 req = evhttp_request_new(rpc_postrequest_failure, NULL);
203 tt_assert(req);
205 /* Add the information that we care about */
206 evhttp_add_header(req->output_headers, "Host", "somehost");
207 evbuffer_add_printf(req->output_buffer, "Some Nonsense");
209 if (evhttp_make_request(evcon, req,
210 EVHTTP_REQ_POST,
211 "/.rpc.Message") == -1) {
212 tt_abort();
215 test_ok = 0;
217 event_dispatch();
219 evhttp_connection_free(evcon);
221 rpc_teardown(base);
223 tt_assert(test_ok == 1);
225 end:
226 evhttp_free(http);
229 static void
230 rpc_postrequest_done(struct evhttp_request *req, void *arg)
232 struct kill* kill_reply = NULL;
234 if (req->response_code != HTTP_OK) {
235 fprintf(stderr, "FAILED (response code)\n");
236 exit(1);
239 kill_reply = kill_new();
241 if ((kill_unmarshal(kill_reply, req->input_buffer)) == -1) {
242 fprintf(stderr, "FAILED (unmarshal)\n");
243 exit(1);
246 kill_free(kill_reply);
248 test_ok = 1;
249 event_loopexit(NULL);
252 static void
253 rpc_basic_message(void)
255 ev_uint16_t port;
256 struct evhttp *http = NULL;
257 struct evrpc_base *base = NULL;
258 struct evhttp_connection *evcon = NULL;
259 struct evhttp_request *req = NULL;
260 struct msg *msg;
262 rpc_setup(&http, &port, &base);
264 evcon = evhttp_connection_new("127.0.0.1", port);
265 tt_assert(evcon);
268 * At this point, we want to schedule an HTTP POST request
269 * server using our make request method.
272 req = evhttp_request_new(rpc_postrequest_done, NULL);
273 if (req == NULL) {
274 fprintf(stdout, "FAILED\n");
275 exit(1);
278 /* Add the information that we care about */
279 evhttp_add_header(req->output_headers, "Host", "somehost");
281 /* set up the basic message */
282 msg = msg_new();
283 EVTAG_ASSIGN(msg, from_name, "niels");
284 EVTAG_ASSIGN(msg, to_name, "tester");
285 msg_marshal(req->output_buffer, msg);
286 msg_free(msg);
288 if (evhttp_make_request(evcon, req,
289 EVHTTP_REQ_POST,
290 "/.rpc.Message") == -1) {
291 fprintf(stdout, "FAILED\n");
292 exit(1);
295 test_ok = 0;
297 event_dispatch();
299 evhttp_connection_free(evcon);
301 rpc_teardown(base);
303 end:
304 evhttp_free(http);
307 static struct evrpc_pool *
308 rpc_pool_with_connection(ev_uint16_t port)
310 struct evhttp_connection *evcon;
311 struct evrpc_pool *pool;
313 pool = evrpc_pool_new(NULL);
314 assert(pool != NULL);
316 evcon = evhttp_connection_new("127.0.0.1", port);
317 assert(evcon != NULL);
319 evrpc_pool_add_connection(pool, evcon);
321 return (pool);
324 static void
325 GotKillCb(struct evrpc_status *status,
326 struct msg *msg, struct kill *kill, void *arg)
328 char *weapon;
329 char *action;
331 if (need_output_hook) {
332 struct evhttp_request *req = status->http_req;
333 const char *header = evhttp_find_header(
334 req->input_headers, "X-Pool-Hook");
335 assert(strcmp(header, "ran") == 0);
338 if (status->error != EVRPC_STATUS_ERR_NONE)
339 goto done;
341 if (EVTAG_GET(kill, weapon, &weapon) == -1) {
342 fprintf(stderr, "get weapon\n");
343 goto done;
345 if (EVTAG_GET(kill, action, &action) == -1) {
346 fprintf(stderr, "get action\n");
347 goto done;
350 if (strcmp(weapon, "dagger"))
351 goto done;
353 if (strcmp(action, "wave around like an idiot"))
354 goto done;
356 test_ok += 1;
358 done:
359 event_loopexit(NULL);
362 static void
363 GotKillCbTwo(struct evrpc_status *status,
364 struct msg *msg, struct kill *kill, void *arg)
366 char *weapon;
367 char *action;
369 if (status->error != EVRPC_STATUS_ERR_NONE)
370 goto done;
372 if (EVTAG_GET(kill, weapon, &weapon) == -1) {
373 fprintf(stderr, "get weapon\n");
374 goto done;
376 if (EVTAG_GET(kill, action, &action) == -1) {
377 fprintf(stderr, "get action\n");
378 goto done;
381 if (strcmp(weapon, "dagger"))
382 goto done;
384 if (strcmp(action, "wave around like an idiot"))
385 goto done;
387 test_ok += 1;
389 done:
390 if (test_ok == 2)
391 event_loopexit(NULL);
394 static int
395 rpc_hook_add_header(void *ctx, struct evhttp_request *req,
396 struct evbuffer *evbuf, void *arg)
398 const char *hook_type = arg;
399 if (strcmp("input", hook_type) == 0)
400 evhttp_add_header(req->input_headers, "X-Hook", hook_type);
401 else
402 evhttp_add_header(req->output_headers, "X-Hook", hook_type);
404 assert(evrpc_hook_get_connection(ctx) != NULL);
406 return (EVRPC_CONTINUE);
409 static int
410 rpc_hook_add_meta(void *ctx, struct evhttp_request *req,
411 struct evbuffer *evbuf, void *arg)
413 evrpc_hook_add_meta(ctx, "meta", "test", 5);
415 assert(evrpc_hook_get_connection(ctx) != NULL);
417 return (EVRPC_CONTINUE);
420 static int
421 rpc_hook_remove_header(void *ctx, struct evhttp_request *req,
422 struct evbuffer *evbuf, void *arg)
424 const char *header = evhttp_find_header(req->input_headers, "X-Hook");
425 void *data = NULL;
426 size_t data_len = 0;
428 assert(header != NULL);
429 assert(strcmp(header, arg) == 0);
431 evhttp_remove_header(req->input_headers, "X-Hook");
432 evhttp_add_header(req->input_headers, "X-Pool-Hook", "ran");
434 assert(evrpc_hook_find_meta(ctx, "meta", &data, &data_len) == 0);
435 assert(data != NULL);
436 assert(data_len == 5);
438 assert(evrpc_hook_get_connection(ctx) != NULL);
440 return (EVRPC_CONTINUE);
443 static void
444 rpc_basic_client(void)
446 ev_uint16_t port;
447 struct evhttp *http = NULL;
448 struct evrpc_base *base = NULL;
449 struct evrpc_pool *pool = NULL;
450 struct msg *msg = NULL;
451 struct kill *kill = NULL;
453 rpc_setup(&http, &port, &base);
455 need_input_hook = 1;
456 need_output_hook = 1;
458 assert(evrpc_add_hook(base, EVRPC_INPUT, rpc_hook_add_header, (void*)"input")
459 != NULL);
460 assert(evrpc_add_hook(base, EVRPC_OUTPUT, rpc_hook_add_header, (void*)"output")
461 != NULL);
463 pool = rpc_pool_with_connection(port);
465 assert(evrpc_add_hook(pool, EVRPC_OUTPUT, rpc_hook_add_meta, NULL));
466 assert(evrpc_add_hook(pool, EVRPC_INPUT, rpc_hook_remove_header, (void*)"output"));
468 /* set up the basic message */
469 msg = msg_new();
470 EVTAG_ASSIGN(msg, from_name, "niels");
471 EVTAG_ASSIGN(msg, to_name, "tester");
473 kill = kill_new();
475 EVRPC_MAKE_REQUEST(Message, pool, msg, kill, GotKillCb, NULL);
477 test_ok = 0;
479 event_dispatch();
481 tt_assert(test_ok == 1);
483 /* we do it twice to make sure that reuse works correctly */
484 kill_clear(kill);
486 EVRPC_MAKE_REQUEST(Message, pool, msg, kill, GotKillCb, NULL);
488 event_dispatch();
490 tt_assert(test_ok == 2);
492 /* we do it trice to make sure other stuff works, too */
493 kill_clear(kill);
496 struct evrpc_request_wrapper *ctx =
497 EVRPC_MAKE_CTX(Message, msg, kill,
498 pool, msg, kill, GotKillCb, NULL);
499 evrpc_make_request(ctx);
502 event_dispatch();
504 rpc_teardown(base);
506 tt_assert(test_ok == 3);
508 end:
509 if (msg)
510 msg_free(msg);
511 if (kill)
512 kill_free(kill);
514 if (pool)
515 evrpc_pool_free(pool);
516 if (http)
517 evhttp_free(http);
519 need_input_hook = 0;
520 need_output_hook = 0;
524 * We are testing that the second requests gets send over the same
525 * connection after the first RPCs completes.
527 static void
528 rpc_basic_queued_client(void)
530 ev_uint16_t port;
531 struct evhttp *http = NULL;
532 struct evrpc_base *base = NULL;
533 struct evrpc_pool *pool = NULL;
534 struct msg *msg=NULL;
535 struct kill *kill_one=NULL, *kill_two=NULL;
537 rpc_setup(&http, &port, &base);
539 pool = rpc_pool_with_connection(port);
541 /* set up the basic message */
542 msg = msg_new();
543 EVTAG_ASSIGN(msg, from_name, "niels");
544 EVTAG_ASSIGN(msg, to_name, "tester");
546 kill_one = kill_new();
547 kill_two = kill_new();
549 EVRPC_MAKE_REQUEST(Message, pool, msg, kill_one, GotKillCbTwo, NULL);
550 EVRPC_MAKE_REQUEST(Message, pool, msg, kill_two, GotKillCb, NULL);
552 test_ok = 0;
554 event_dispatch();
556 rpc_teardown(base);
558 tt_assert(test_ok == 2);
560 end:
561 if (msg)
562 msg_free(msg);
563 if (kill_one)
564 kill_free(kill_one);
565 if (kill_two)
566 kill_free(kill_two);
568 if (pool)
569 evrpc_pool_free(pool);
570 if (http)
571 evhttp_free(http);
574 static void
575 GotErrorCb(struct evrpc_status *status,
576 struct msg *msg, struct kill *kill, void *arg)
578 if (status->error != EVRPC_STATUS_ERR_TIMEOUT)
579 goto done;
581 /* should never be complete but just to check */
582 if (kill_complete(kill) == 0)
583 goto done;
585 test_ok += 1;
587 done:
588 event_loopexit(NULL);
591 /* we just pause the rpc and continue it in the next callback */
593 struct _rpc_hook_ctx {
594 void *vbase;
595 void *ctx;
598 static int hook_pause_cb_called=0;
600 static void
601 rpc_hook_pause_cb(evutil_socket_t fd, short what, void *arg)
603 struct _rpc_hook_ctx *ctx = arg;
604 ++hook_pause_cb_called;
605 evrpc_resume_request(ctx->vbase, ctx->ctx, EVRPC_CONTINUE);
606 free(arg);
609 static int
610 rpc_hook_pause(void *ctx, struct evhttp_request *req, struct evbuffer *evbuf,
611 void *arg)
613 struct _rpc_hook_ctx *tmp = malloc(sizeof(*tmp));
614 struct timeval tv;
616 assert(tmp != NULL);
617 tmp->vbase = arg;
618 tmp->ctx = ctx;
620 memset(&tv, 0, sizeof(tv));
621 event_once(-1, EV_TIMEOUT, rpc_hook_pause_cb, tmp, &tv);
622 return EVRPC_PAUSE;
625 static void
626 rpc_basic_client_with_pause(void)
628 ev_uint16_t port;
629 struct evhttp *http = NULL;
630 struct evrpc_base *base = NULL;
631 struct evrpc_pool *pool = NULL;
632 struct msg *msg = NULL;
633 struct kill *kill= NULL;
635 rpc_setup(&http, &port, &base);
637 assert(evrpc_add_hook(base, EVRPC_INPUT, rpc_hook_pause, base));
638 assert(evrpc_add_hook(base, EVRPC_OUTPUT, rpc_hook_pause, base));
640 pool = rpc_pool_with_connection(port);
642 assert(evrpc_add_hook(pool, EVRPC_INPUT, rpc_hook_pause, pool));
643 assert(evrpc_add_hook(pool, EVRPC_OUTPUT, rpc_hook_pause, pool));
645 /* set up the basic message */
646 msg = msg_new();
647 EVTAG_ASSIGN(msg, from_name, "niels");
648 EVTAG_ASSIGN(msg, to_name, "tester");
650 kill = kill_new();
652 EVRPC_MAKE_REQUEST(Message, pool, msg, kill, GotKillCb, NULL);
654 test_ok = 0;
656 event_dispatch();
658 tt_int_op(test_ok, ==, 1);
659 tt_int_op(hook_pause_cb_called, ==, 4);
661 end:
662 if (base)
663 rpc_teardown(base);
665 if (msg)
666 msg_free(msg);
667 if (kill)
668 kill_free(kill);
670 if (pool)
671 evrpc_pool_free(pool);
672 if (http)
673 evhttp_free(http);
676 static void
677 rpc_client_timeout(void)
679 ev_uint16_t port;
680 struct evhttp *http = NULL;
681 struct evrpc_base *base = NULL;
682 struct evrpc_pool *pool = NULL;
683 struct msg *msg = NULL;
684 struct kill *kill = NULL;
686 rpc_setup(&http, &port, &base);
688 pool = rpc_pool_with_connection(port);
690 /* set the timeout to 5 seconds */
691 evrpc_pool_set_timeout(pool, 5);
693 /* set up the basic message */
694 msg = msg_new();
695 EVTAG_ASSIGN(msg, from_name, "niels");
696 EVTAG_ASSIGN(msg, to_name, "tester");
698 kill = kill_new();
700 EVRPC_MAKE_REQUEST(NeverReply, pool, msg, kill, GotErrorCb, NULL);
702 test_ok = 0;
704 event_dispatch();
706 /* free the saved RPC structure up */
707 EVRPC_REQUEST_DONE(saved_rpc);
709 rpc_teardown(base);
711 tt_assert(test_ok == 2);
713 end:
714 if (msg)
715 msg_free(msg);
716 if (kill)
717 kill_free(kill);
719 if (pool)
720 evrpc_pool_free(pool);
721 if (http)
722 evhttp_free(http);
725 static void
726 rpc_test(void)
728 struct msg *msg = NULL, *msg2 = NULL;
729 struct kill *attack = NULL;
730 struct run *run = NULL;
731 struct evbuffer *tmp = evbuffer_new();
732 struct timeval tv_start, tv_end;
733 ev_uint32_t tag;
734 int i;
736 msg = msg_new();
737 EVTAG_ASSIGN(msg, from_name, "niels");
738 EVTAG_ASSIGN(msg, to_name, "phoenix");
740 if (EVTAG_GET(msg, attack, &attack) == -1) {
741 tt_abort_msg("Failed to set kill message.");
744 EVTAG_ASSIGN(attack, weapon, "feather");
745 EVTAG_ASSIGN(attack, action, "tickle");
746 for (i = 0; i < 3; ++i) {
747 if (EVTAG_ARRAY_ADD_VALUE(attack, how_often, i) == NULL) {
748 tt_abort_msg("Failed to add how_often.");
752 evutil_gettimeofday(&tv_start, NULL);
753 for (i = 0; i < 1000; ++i) {
754 run = EVTAG_ARRAY_ADD(msg, run);
755 if (run == NULL) {
756 tt_abort_msg("Failed to add run message.");
758 EVTAG_ASSIGN(run, how, "very fast but with some data in it");
759 EVTAG_ASSIGN(run, fixed_bytes,
760 (ev_uint8_t*)"012345678901234567890123");
762 if (EVTAG_ARRAY_ADD_VALUE(
763 run, notes, "this is my note") == NULL) {
764 tt_abort_msg("Failed to add note.");
766 if (EVTAG_ARRAY_ADD_VALUE(run, notes, "pps") == NULL) {
767 tt_abort_msg("Failed to add note");
770 EVTAG_ASSIGN(run, large_number, 0xdead0a0bcafebeefLL);
771 EVTAG_ARRAY_ADD_VALUE(run, other_numbers, 0xdead0a0b);
772 EVTAG_ARRAY_ADD_VALUE(run, other_numbers, 0xbeefcafe);
775 if (msg_complete(msg) == -1)
776 tt_abort_msg("Failed to make complete message.");
778 evtag_marshal_msg(tmp, 0xdeaf, msg);
780 if (evtag_peek(tmp, &tag) == -1)
781 tt_abort_msg("Failed to peak tag.");
783 if (tag != 0xdeaf)
784 TT_DIE(("Got incorrect tag: %0x.", (unsigned)tag));
786 msg2 = msg_new();
787 if (evtag_unmarshal_msg(tmp, 0xdeaf, msg2) == -1)
788 tt_abort_msg("Failed to unmarshal message.");
790 evutil_gettimeofday(&tv_end, NULL);
791 evutil_timersub(&tv_end, &tv_start, &tv_end);
792 TT_BLATHER(("(%.1f us/add) ",
793 (float)tv_end.tv_sec/(float)i * 1000000.0 +
794 tv_end.tv_usec / (float)i));
796 if (!EVTAG_HAS(msg2, from_name) ||
797 !EVTAG_HAS(msg2, to_name) ||
798 !EVTAG_HAS(msg2, attack)) {
799 tt_abort_msg("Missing data structures.");
802 if (EVTAG_GET(msg2, attack, &attack) == -1) {
803 tt_abort_msg("Could not get attack.");
806 if (EVTAG_ARRAY_LEN(msg2, run) != i) {
807 tt_abort_msg("Wrong number of run messages.");
810 /* get the very first run message */
811 if (EVTAG_ARRAY_GET(msg2, run, 0, &run) == -1) {
812 tt_abort_msg("Failed to get run msg.");
813 } else {
814 /* verify the notes */
815 char *note_one, *note_two;
816 ev_uint64_t large_number;
817 ev_uint32_t short_number;
819 if (EVTAG_ARRAY_LEN(run, notes) != 2) {
820 tt_abort_msg("Wrong number of note strings.");
823 if (EVTAG_ARRAY_GET(run, notes, 0, &note_one) == -1 ||
824 EVTAG_ARRAY_GET(run, notes, 1, &note_two) == -1) {
825 tt_abort_msg("Could not get note strings.");
828 if (strcmp(note_one, "this is my note") ||
829 strcmp(note_two, "pps")) {
830 tt_abort_msg("Incorrect note strings encoded.");
833 if (EVTAG_GET(run, large_number, &large_number) == -1 ||
834 large_number != 0xdead0a0bcafebeefLL) {
835 tt_abort_msg("Incorrrect large_number.");
838 if (EVTAG_ARRAY_LEN(run, other_numbers) != 2) {
839 tt_abort_msg("Wrong number of other_numbers.");
842 if (EVTAG_ARRAY_GET(
843 run, other_numbers, 0, &short_number) == -1) {
844 tt_abort_msg("Could not get short number.");
846 tt_uint_op(short_number, ==, 0xdead0a0b);
849 tt_int_op(EVTAG_ARRAY_LEN(attack, how_often), ==, 3);
851 for (i = 0; i < 3; ++i) {
852 ev_uint32_t res;
853 if (EVTAG_ARRAY_GET(attack, how_often, i, &res) == -1) {
854 TT_DIE(("Cannot get %dth how_often msg.", i));
856 if ((int)res != i) {
857 TT_DIE(("Wrong message encoded %d != %d", i, res));
861 test_ok = 1;
862 end:
863 if (msg)
864 msg_free(msg);
865 if (msg2)
866 msg_free(msg2);
867 if (tmp)
868 evbuffer_free(tmp);
871 #define RPC_LEGACY(name) \
872 { #name, run_legacy_test_fn, TT_FORK|TT_NEED_BASE|TT_LEGACY, \
873 &legacy_setup, \
874 rpc_##name }
875 #else
876 /* NO_PYTHON_EXISTS */
878 #define RPC_LEGACY(name) \
879 { #name, NULL, TT_SKIP, NULL, NULL }
881 #endif
883 struct testcase_t rpc_testcases[] = {
884 RPC_LEGACY(basic_test),
885 RPC_LEGACY(basic_message),
886 RPC_LEGACY(basic_client),
887 RPC_LEGACY(basic_queued_client),
888 RPC_LEGACY(basic_client_with_pause),
889 RPC_LEGACY(client_timeout),
890 RPC_LEGACY(test),
892 END_OF_TESTCASES,