diff options
-rw-r--r-- | test/regress.c | 176 | ||||
-rw-r--r-- | test/regress.h | 2 | ||||
-rw-r--r-- | test/regress_rpc.c | 156 |
3 files changed, 145 insertions, 189 deletions
diff --git a/test/regress.c b/test/regress.c index 488af2ac..20ffb9b3 100644 --- a/test/regress.c +++ b/test/regress.c @@ -2101,180 +2101,6 @@ evtag_test(void) } static void -rpc_test(void) -{ -#ifndef WIN32 - struct msg *msg, *msg2; - struct kill *attack; - struct run *run; - struct evbuffer *tmp = evbuffer_new(); - struct timeval tv_start, tv_end; - ev_uint32_t tag; - int i; - - fprintf(stdout, "Testing RPC: "); - - msg = msg_new(); - EVTAG_ASSIGN(msg, from_name, "niels"); - EVTAG_ASSIGN(msg, to_name, "phoenix"); - - if (EVTAG_GET(msg, attack, &attack) == -1) { - fprintf(stderr, "Failed to set kill message.\n"); - exit(1); - } - - EVTAG_ASSIGN(attack, weapon, "feather"); - EVTAG_ASSIGN(attack, action, "tickle"); - for (i = 0; i < 3; ++i) { - if (EVTAG_ADD(attack, how_often, i) == NULL) { - fprintf(stderr, "Failed to add how_often.\n"); - exit(1); - } - } - - evutil_gettimeofday(&tv_start, NULL); - for (i = 0; i < 1000; ++i) { - run = EVTAG_ADD(msg, run); - if (run == NULL) { - fprintf(stderr, "Failed to add run message.\n"); - exit(1); - } - EVTAG_ASSIGN(run, how, "very fast but with some data in it"); - EVTAG_ASSIGN(run, fixed_bytes, - (ev_uint8_t*)"012345678901234567890123"); - - if (EVTAG_ADD(run, notes, "this is my note") == NULL) { - fprintf(stderr, "Failed to add note.\n"); - exit(1); - } - if (EVTAG_ADD(run, notes, "pps") == NULL) { - fprintf(stderr, "Failed to add note.\n"); - exit(1); - } - - EVTAG_ASSIGN(run, large_number, 0xdead0a0bcafebeefLL); - EVTAG_ADD(run, other_numbers, 0xdead0a0b); - EVTAG_ADD(run, other_numbers, 0xbeefcafe); - } - - if (msg_complete(msg) == -1) { - fprintf(stderr, "Failed to make complete message.\n"); - exit(1); - } - - evtag_marshal_msg(tmp, 0xdeaf, msg); - - if (evtag_peek(tmp, &tag) == -1) { - fprintf(stderr, "Failed to peak tag.\n"); - exit (1); - } - - if (tag != 0xdeaf) { - fprintf(stderr, "Got incorrect tag: %0x.\n", (unsigned)tag); - exit (1); - } - - msg2 = msg_new(); - if (evtag_unmarshal_msg(tmp, 0xdeaf, msg2) == -1) { - fprintf(stderr, "Failed to unmarshal message.\n"); - exit(1); - } - - evutil_gettimeofday(&tv_end, NULL); - evutil_timersub(&tv_end, &tv_start, &tv_end); - fprintf(stdout, "(%.1f us/add) ", - (float)tv_end.tv_sec/(float)i * 1000000.0 + - tv_end.tv_usec / (float)i); - - if (!EVTAG_HAS(msg2, from_name) || - !EVTAG_HAS(msg2, to_name) || - !EVTAG_HAS(msg2, attack)) { - fprintf(stderr, "Missing data structures.\n"); - exit(1); - } - - if (EVTAG_GET(msg2, attack, &attack) == -1) { - fprintf(stderr, "Could not get attack.\n"); - exit(1); - } - - if (EVTAG_LEN(msg2, run) != i) { - fprintf(stderr, "Wrong number of run messages.\n"); - exit(1); - } - - /* get the very first run message */ - if (EVTAG_GET(msg2, run, 0, &run) == -1) { - fprintf(stderr, "Failed to get run msg.\n"); - exit(1); - } else { - /* verify the notes */ - char *note_one, *note_two; - ev_uint64_t large_number; - ev_uint32_t short_number; - - if (EVTAG_LEN(run, notes) != 2) { - fprintf(stderr, "Wrong number of note strings.\n"); - exit(1); - } - - if (EVTAG_GET(run, notes, 0, ¬e_one) == -1 || - EVTAG_GET(run, notes, 1, ¬e_two) == -1) { - fprintf(stderr, "Could not get note strings.\n"); - exit(1); - } - - if (strcmp(note_one, "this is my note") || - strcmp(note_two, "pps")) { - fprintf(stderr, "Incorrect note strings encoded.\n"); - exit(1); - } - - if (EVTAG_GET(run, large_number, &large_number) == -1 || - large_number != 0xdead0a0bcafebeefLL) { - fprintf(stderr, "Incorrrect large_number.\n"); - exit(1); - } - - if (EVTAG_LEN(run, other_numbers) != 2) { - fprintf(stderr, "Wrong number of other_numbers.\n"); - exit(1); - } - - if (EVTAG_GET(run, other_numbers, 0, &short_number) == -1) { - fprintf(stderr, "Could not get short number.\n"); - exit(1); - } - assert(short_number == 0xdead0a0b); - - } - if (EVTAG_LEN(attack, how_often) != 3) { - fprintf(stderr, "Wrong number of how_often ints.\n"); - exit(1); - } - - for (i = 0; i < 3; ++i) { - ev_uint32_t res; - if (EVTAG_GET(attack, how_often, i, &res) == -1) { - fprintf(stderr, "Cannot get %dth how_often msg.\n", i); - exit(1); - } - if (res != i) { - fprintf(stderr, "Wrong message encoded %d != %d\n", i, res); - exit(1); - } - } - - msg_free(msg); - msg_free(msg2); - - evbuffer_free(tmp); - - fprintf(stdout, "OK\n"); -#endif -} - -static void test_methods(void *ptr) { const char **methods = event_get_supported_methods(); @@ -2391,8 +2217,6 @@ legacy_main(void) evtag_test(); - rpc_test(); - return (0); } diff --git a/test/regress.h b/test/regress.h index 26113ad8..4a8c0432 100644 --- a/test/regress.h +++ b/test/regress.h @@ -43,8 +43,6 @@ extern struct testcase_t rpc_testcases[]; int legacy_main(void); -void rpc_suite(void); - void regress_pthread(void); void regress_zlib(void); diff --git a/test/regress_rpc.c b/test/regress_rpc.c index ba3ef4cf..f973c6c9 100644 --- a/test/regress_rpc.c +++ b/test/regress_rpc.c @@ -711,6 +711,150 @@ end: evhttp_free(http); } +static void +rpc_test(void) +{ + struct msg *msg = NULL, *msg2 = NULL; + struct kill *attack = NULL; + struct run *run = NULL; + struct evbuffer *tmp = evbuffer_new(); + struct timeval tv_start, tv_end; + ev_uint32_t tag; + int i; + + msg = msg_new(); + EVTAG_ASSIGN(msg, from_name, "niels"); + EVTAG_ASSIGN(msg, to_name, "phoenix"); + + if (EVTAG_GET(msg, attack, &attack) == -1) { + tt_abort_msg("Failed to set kill message."); + } + + EVTAG_ASSIGN(attack, weapon, "feather"); + EVTAG_ASSIGN(attack, action, "tickle"); + for (i = 0; i < 3; ++i) { + if (EVTAG_ADD(attack, how_often, i) == NULL) { + tt_abort_msg("Failed to add how_often."); + } + } + + evutil_gettimeofday(&tv_start, NULL); + for (i = 0; i < 1000; ++i) { + run = EVTAG_ADD(msg, run); + if (run == NULL) { + tt_abort_msg("Failed to add run message."); + } + EVTAG_ASSIGN(run, how, "very fast but with some data in it"); + EVTAG_ASSIGN(run, fixed_bytes, + (ev_uint8_t*)"012345678901234567890123"); + + if (EVTAG_ADD(run, notes, "this is my note") == NULL) { + tt_abort_msg("Failed to add note."); + } + if (EVTAG_ADD(run, notes, "pps") == NULL) { + tt_abort_msg("Failed to add note"); + } + + EVTAG_ASSIGN(run, large_number, 0xdead0a0bcafebeefLL); + EVTAG_ADD(run, other_numbers, 0xdead0a0b); + EVTAG_ADD(run, other_numbers, 0xbeefcafe); + } + + if (msg_complete(msg) == -1) + tt_abort_msg("Failed to make complete message."); + + evtag_marshal_msg(tmp, 0xdeaf, msg); + + if (evtag_peek(tmp, &tag) == -1) + tt_abort_msg("Failed to peak tag."); + + if (tag != 0xdeaf) + TT_DIE(("Got incorrect tag: %0x.", (unsigned)tag)); + + msg2 = msg_new(); + if (evtag_unmarshal_msg(tmp, 0xdeaf, msg2) == -1) + tt_abort_msg("Failed to unmarshal message."); + + evutil_gettimeofday(&tv_end, NULL); + evutil_timersub(&tv_end, &tv_start, &tv_end); + TT_BLATHER(("(%.1f us/add) ", + (float)tv_end.tv_sec/(float)i * 1000000.0 + + tv_end.tv_usec / (float)i)); + + if (!EVTAG_HAS(msg2, from_name) || + !EVTAG_HAS(msg2, to_name) || + !EVTAG_HAS(msg2, attack)) { + tt_abort_msg("Missing data structures."); + } + + if (EVTAG_GET(msg2, attack, &attack) == -1) { + tt_abort_msg("Could not get attack."); + } + + if (EVTAG_LEN(msg2, run) != i) { + tt_abort_msg("Wrong number of run messages."); + } + + /* get the very first run message */ + if (EVTAG_GET(msg2, run, 0, &run) == -1) { + tt_abort_msg("Failed to get run msg."); + } else { + /* verify the notes */ + char *note_one, *note_two; + ev_uint64_t large_number; + ev_uint32_t short_number; + + if (EVTAG_LEN(run, notes) != 2) { + tt_abort_msg("Wrong number of note strings."); + } + + if (EVTAG_GET(run, notes, 0, ¬e_one) == -1 || + EVTAG_GET(run, notes, 1, ¬e_two) == -1) { + tt_abort_msg("Could not get note strings."); + } + + if (strcmp(note_one, "this is my note") || + strcmp(note_two, "pps")) { + tt_abort_msg("Incorrect note strings encoded."); + } + + if (EVTAG_GET(run, large_number, &large_number) == -1 || + large_number != 0xdead0a0bcafebeefLL) { + tt_abort_msg("Incorrrect large_number."); + } + + if (EVTAG_LEN(run, other_numbers) != 2) { + tt_abort_msg("Wrong number of other_numbers."); + } + + if (EVTAG_GET(run, other_numbers, 0, &short_number) == -1) { + tt_abort_msg("Could not get short number."); + } + tt_uint_op(short_number, ==, 0xdead0a0b); + + } + tt_int_op(EVTAG_LEN(attack, how_often), ==, 3); + + for (i = 0; i < 3; ++i) { + ev_uint32_t res; + if (EVTAG_GET(attack, how_often, i, &res) == -1) { + TT_DIE(("Cannot get %dth how_often msg.", i)); + } + if (res != i) { + TT_DIE(("Wrong message encoded %d != %d", i, res)); + } + } + + test_ok = 1; +end: + if (msg) + msg_free(msg); + if (msg2) + msg_free(msg2); + if (tmp) + evbuffer_free(tmp); +} + #define RPC_LEGACY(name) \ { #name, run_legacy_test_fn, TT_FORK|TT_NEED_BASE, &legacy_setup, \ rpc_##name } @@ -722,17 +866,7 @@ struct testcase_t rpc_testcases[] = { RPC_LEGACY(basic_queued_client), RPC_LEGACY(basic_client_with_pause), RPC_LEGACY(client_timeout), + RPC_LEGACY(test), END_OF_TESTCASES, }; - -void -rpc_suite(void) -{ - rpc_basic_test(); - rpc_basic_message(); - rpc_basic_client(); - rpc_basic_queued_client(); - rpc_basic_client_with_pause(); - rpc_client_timeout(); -} |