Signed-off-by: Angus Salkeld asalkeld@redhat.com --- tests/check_ipc.c | 60 +++++++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 36 deletions(-)
diff --git a/tests/check_ipc.c b/tests/check_ipc.c index 191d005..d15eea1 100644 --- a/tests/check_ipc.c +++ b/tests/check_ipc.c @@ -222,13 +222,14 @@ struct my_req {
static struct my_req request; static int32_t -send_and_check(uint32_t size, int32_t ms_timeout, int32_t expect_perfection) +send_and_check(int32_t req_id, uint32_t size, + int32_t ms_timeout, int32_t expect_perfection) { struct qb_ipc_response_header res_header; int32_t res; int32_t try_times = 0;
- request.hdr.id = IPC_MSG_REQ_TX_RX; + request.hdr.id = req_id; request.hdr.size = sizeof(struct qb_ipc_request_header) + size;
repeat_send: @@ -247,8 +248,15 @@ repeat_send: return res; } } - res = qb_ipcc_recv(conn, &res_header, - sizeof(struct qb_ipc_response_header), ms_timeout); + if (req_id == IPC_MSG_REQ_TX_RX) { + res = qb_ipcc_recv(conn, &res_header, + sizeof(struct qb_ipc_response_header), + ms_timeout); + } else { + res = qb_ipcc_event_recv(conn, &res_header, + sizeof(struct qb_ipc_response_header), + ms_timeout); + } if (res == -EINTR) { return -1; } @@ -259,7 +267,7 @@ repeat_send: } if (expect_perfection) { ck_assert_int_eq(res, sizeof(struct qb_ipc_response_header)); - ck_assert_int_eq(res_header.id, IPC_MSG_RES_TX_RX); + ck_assert_int_eq(res_header.id, req_id + 1); ck_assert_int_eq(res_header.size, sizeof(struct qb_ipc_response_header)); } return res; @@ -294,7 +302,8 @@ test_ipc_txrx(void) size *= 2; if (size >= MAX_MSG_SIZE) break; - if (send_and_check(size, recv_timeout, QB_TRUE) < 0) { + if (send_and_check(IPC_MSG_REQ_TX_RX, size, + recv_timeout, QB_TRUE) < 0) { break; } } @@ -463,11 +472,10 @@ static struct my_res response; static void test_ipc_dispatch(void) { - int32_t res; int32_t j; int32_t c = 0; pid_t pid; - struct qb_ipc_request_header req_header; + int32_t size;
pid = run_function_in_new_process(run_ipc_server); fail_if(pid == -1); @@ -484,36 +492,16 @@ test_ipc_dispatch(void) } while (conn == NULL && c < 5); fail_if(conn == NULL);
- req_header.id = IPC_MSG_REQ_DISPATCH; - req_header.size = sizeof(struct qb_ipc_request_header); - - repeat_send: - res = qb_ipcc_send(conn, &req_header, req_header.size); - if (res < 0) { - if (res == -EAGAIN) { - goto repeat_send; - } else if (res == -EINVAL || res == -EINTR) { - qb_perror(LOG_INFO, "qb_ipcc_send"); - return; - } else { - errno = -res; - qb_perror(LOG_INFO, "qb_ipcc_send"); - goto repeat_send; - } - } - repeat_event_recv: - res = qb_ipcc_event_recv(conn, &response, sizeof(struct my_res), 0); - if (res < 0) { - if (res == -EAGAIN || res == -ETIMEDOUT) { - goto repeat_event_recv; - } else { - errno = -res; - qb_perror(LOG_INFO, "qb_ipcc_event_recv"); - goto repeat_send; + size = QB_MIN(sizeof(struct qb_ipc_request_header), 64); + for (j = 1; j < 19; j++) { + size *= 2; + if (size >= MAX_MSG_SIZE) + break; + if (send_and_check(IPC_MSG_REQ_DISPATCH, size, + recv_timeout, QB_TRUE) < 0) { + break; } } - ck_assert_int_eq(res, sizeof(struct qb_ipc_response_header)); - ck_assert_int_eq(response.hdr.id, IPC_MSG_RES_DISPATCH);
qb_ipcc_disconnect(conn); stop_process(pid);
Signed-off-by: Angus Salkeld asalkeld@redhat.com --- tests/check_ipc.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 2 deletions(-)
diff --git a/tests/check_ipc.c b/tests/check_ipc.c index d15eea1..70e41ef 100644 --- a/tests/check_ipc.c +++ b/tests/check_ipc.c @@ -42,6 +42,8 @@ enum my_msg_ids { IPC_MSG_RES_TX_RX, IPC_MSG_REQ_DISPATCH, IPC_MSG_RES_DISPATCH, + IPC_MSG_REQ_BULK_EVENTS, + IPC_MSG_RES_BULK_EVENTS, IPC_MSG_REQ_SERVER_FAIL, IPC_MSG_RES_SERVER_FAIL, }; @@ -104,10 +106,24 @@ s1_msg_process_fn(qb_ipcs_connection_t *c, response.id = IPC_MSG_RES_DISPATCH; response.error = 0; res = qb_ipcs_event_send(c, &response, - sizeof(response)); + sizeof(response)); if (res < 0) { qb_perror(LOG_INFO, "qb_ipcs_event_send"); } + } else if (req_pt->id == IPC_MSG_REQ_BULK_EVENTS) { + int32_t m; + response.size = sizeof(struct qb_ipc_response_header); + response.id = IPC_MSG_RES_BULK_EVENTS; + response.error = 0; + qb_ipcs_response_send(c, &response, response.size); + + for (m = 0; m < 100; m++) { + res = qb_ipcs_event_send(c, &response, + sizeof(response)); + if (res < 0) { + qb_perror(LOG_INFO, "qb_ipcs_event_send"); + } + } } else if (req_pt->id == IPC_MSG_REQ_SERVER_FAIL) { exit(0); } @@ -468,7 +484,6 @@ struct my_res { char message[1024 * 1024]; };
-static struct my_res response; static void test_ipc_dispatch(void) { @@ -515,6 +530,76 @@ START_TEST(test_ipc_disp_us) } END_TEST
+static int32_t events_received; + +static int32_t +count_bulk_events(int32_t fd, int32_t revents, void *data) +{ + qb_loop_t *cl = (qb_loop_t*)data; + + events_received++; + + if (events_received >= 100) { + qb_loop_stop(cl); + return -1; + } + return 0; +} + +static void +test_ipc_bulk_events(void) +{ + int32_t c = 0; + int32_t j = 0; + pid_t pid; + int32_t res; + qb_loop_t *cl; + int32_t fd; + + pid = run_function_in_new_process(run_ipc_server); + fail_if(pid == -1); + sleep(1); + + do { + conn = qb_ipcc_connect(ipc_name, MAX_MSG_SIZE); + if (conn == NULL) { + j = waitpid(pid, NULL, WNOHANG); + ck_assert_int_eq(j, 0); + sleep(1); + c++; + } + } while (conn == NULL && c < 5); + fail_if(conn == NULL); + + events_received = 0; + cl = qb_loop_create(); + res = qb_ipcc_fd_get(conn, &fd), + ck_assert_int_eq(res, 0); + res = qb_loop_poll_add(cl, QB_LOOP_MED, + fd, POLLIN, + cl, count_bulk_events); + ck_assert_int_eq(res, 0); + + res = send_and_check(IPC_MSG_REQ_BULK_EVENTS, + sizeof(struct qb_ipc_request_header), + recv_timeout, QB_TRUE); + ck_assert_int_eq(res, sizeof(struct qb_ipc_response_header)); + + qb_loop_run(cl); + ck_assert_int_eq(events_received, 100); + + qb_ipcc_disconnect(conn); + stop_process(pid); +} + +START_TEST(test_ipc_bulk_events_us) +{ + ipc_type = QB_IPC_SOCKET; + ipc_name = __func__; + test_ipc_bulk_events(); +} +END_TEST + static void test_ipc_server_fail(void) { @@ -579,6 +664,14 @@ START_TEST(test_ipc_disp_shm) } END_TEST
+START_TEST(test_ipc_bulk_events_shm) +{ + ipc_type = QB_IPC_SHM; + ipc_name = __func__; + test_ipc_bulk_events(); +} +END_TEST + START_TEST(test_ipc_server_fail_shm) { ipc_type = QB_IPC_SHM; @@ -621,6 +714,11 @@ ipc_suite(void) tcase_set_timeout(tc, 16); suite_add_tcase(s, tc);
+ tc = tcase_create("ipc_bulk_events_shm"); + tcase_add_test(tc, test_ipc_bulk_events_shm); + tcase_set_timeout(tc, 16); + suite_add_tcase(s, tc); + tc = tcase_create("ipc_exit_shm"); tcase_add_test(tc, test_ipc_exit_shm); tcase_set_timeout(tc, 3); @@ -669,6 +767,11 @@ ipc_suite(void) tcase_set_timeout(tc, 16); suite_add_tcase(s, tc);
+ tc = tcase_create("ipc_bulk_events_us"); + tcase_add_test(tc, test_ipc_bulk_events_us); + tcase_set_timeout(tc, 16); + suite_add_tcase(s, tc); + return s; }
quarterback-devel@lists.fedorahosted.org