Skip to content

Commit

Permalink
tests: ipc: refactor/split test_ipc_dispatch part into client_dispatch
Browse files Browse the repository at this point in the history
This way, this core part can be easily reused where needed.
Note that "ready_signaller" similarity with run_ipc_server is not
accidental, following commit will justify it.

Signed-off-by: Jan Pokorný <[email protected]>
  • Loading branch information
jnpkrn committed Jun 4, 2019
1 parent c54e271 commit 2ced1b4
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions tests/check_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,39 +926,51 @@ struct my_res {
char message[1024 * 1024];
};

static void
test_ipc_dispatch(void)
static inline
NEW_PROCESS_RUNNER(client_dispatch, ready_signaller, signaller_data)
{
int32_t j;
int32_t c = 0;
pid_t pid;
int32_t size;
uint32_t max_size = MAX_MSG_SIZE;

pid = run_function_in_new_process("server", run_ipc_server);
fail_if(pid == -1);
int32_t size;
int32_t c = 0;
int32_t j;
pid_t server_pid = *((pid_t *) signaller_data);

do {
conn = qb_ipcc_connect(ipc_name, max_size);
if (conn == NULL) {
j = waitpid(pid, NULL, WNOHANG);
j = waitpid(server_pid, NULL, WNOHANG);
ck_assert_int_eq(j, 0);
poll(NULL, 0, 400);
c++;
}
} while (conn == NULL && c < 5);
fail_if(conn == NULL);

if (ready_signaller != NULL) {
ready_signaller(signaller_data);
}

size = QB_MIN(sizeof(struct qb_ipc_request_header), 64);
for (j = 1; j < 19; j++) {
size *= 2;
if (size >= max_size)
break;
if (send_and_check(IPC_MSG_REQ_DISPATCH, size,
recv_timeout, QB_TRUE) < 0) {
recv_timeout, QB_TRUE) < 0) {
break;
}
}
}

static void
test_ipc_dispatch(void)
{
pid_t pid;

pid = run_function_in_new_process(NULL, run_ipc_server);
fail_if(pid == -1);

client_dispatch(NULL, (void *) &pid);

request_server_exit();
qb_ipcc_disconnect(conn);
Expand Down

0 comments on commit 2ced1b4

Please sign in to comment.