Skip to content

Commit

Permalink
TODO tests: ipc: check deadlock-like situation due to mixing priorities
Browse files Browse the repository at this point in the history
XXX needs the actual assertions to highlight the problem

Signed-off-by: Jan Pokorný <[email protected]>
  • Loading branch information
jnpkrn committed May 21, 2019
1 parent eff9151 commit cdc7a6b
Showing 1 changed file with 83 additions and 15 deletions.
98 changes: 83 additions & 15 deletions tests/check_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ static const int MAX_MSG_SIZE = DEFAULT_MAX_MSG_SIZE;
* this the largests msg we can successfully send. */
#define GIANT_MSG_DATA_SIZE MAX_MSG_SIZE - sizeof(struct qb_ipc_response_header) - 8

static int enforce_server_buffer=0;
static int enforce_server_buffer;
static qb_ipcc_connection_t *conn;
static enum qb_ipc_type ipc_type;
static enum qb_ipcs_rate_limit global_ratelimit;

enum my_msg_ids {
IPC_MSG_REQ_TX_RX,
Expand Down Expand Up @@ -433,6 +434,10 @@ run_ipc_server(ready_signaller_fn ready_signaller)
s1 = qb_ipcs_create(ipc_name, 4, ipc_type, &sh);
fail_if(s1 == 0);

if (global_ratelimit != QB_IPCS_RATE_NORMAL) {
qb_ipcs_request_rate_limit(s1, global_ratelimit);
}

if (enforce_server_buffer) {
qb_ipcs_enforce_buffer_size(s1, max_size);
}
Expand All @@ -457,12 +462,13 @@ static void usr1_bit_setter(int signal) {
}
}

#define NEW_PROCESS_RUNNER(name) void (name)(ready_signaller_fn)
#define NEW_PROCESS_RUNNER(name) void (name)(ready_signaller_fn, void *data)
typedef NEW_PROCESS_RUNNER(new_process_runner_fn);

static pid_t
run_function_in_new_process(const char *role,
new_process_runner_fn new_process_runner)
new_process_runner_fn new_process_runner,
void *data)
{
char formatbuf[1024];
pid_t pid = fork ();
Expand Down Expand Up @@ -500,7 +506,7 @@ run_function_in_new_process(const char *role,
qb_log_format_set(QB_LOG_STDERR, formatbuf);
}

new_process_runner(usr1_signaller);
new_process_runner(usr1_signaller, data);
exit(0);
}

Expand Down Expand Up @@ -660,7 +666,7 @@ test_ipc_txrx_timeout(void)
pid_t pid;
uint32_t max_size = MAX_MSG_SIZE;

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

do {
Expand Down Expand Up @@ -708,7 +714,7 @@ test_ipc_txrx(void)
pid_t pid;
uint32_t max_size = MAX_MSG_SIZE;

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

do {
Expand Down Expand Up @@ -758,7 +764,7 @@ test_ipc_exit(void)
pid_t pid;
uint32_t max_size = MAX_MSG_SIZE;

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

do {
Expand Down Expand Up @@ -952,7 +958,7 @@ test_ipc_dispatch(void)
{
pid_t pid;

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

client_dispatch(NULL, (void *) &pid);
Expand Down Expand Up @@ -1059,7 +1065,7 @@ test_ipc_stress_connections(void)
QB_LOG_FILTER_FILE, "*", LOG_INFO);
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE);

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

for (connections = 1; connections < 70000; connections++) {
Expand Down Expand Up @@ -1106,7 +1112,7 @@ test_ipc_bulk_events(void)
int32_t fd;
uint32_t max_size = MAX_MSG_SIZE;

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

do {
Expand Down Expand Up @@ -1170,7 +1176,7 @@ test_ipc_stress_test(void)
int32_t real_buf_size;

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

Expand Down Expand Up @@ -1248,6 +1254,36 @@ START_TEST(test_ipc_stress_connections_us)
}
END_TEST

START_TEST(test_ipc_dispatch_us_deadlock_provoke)
{
pid_t server_pid, alphaclient_pid;

qb_enter();
ipc_type = QB_IPC_SOCKET;
set_ipc_name(__func__);
global_ratelimit = QB_IPCS_RATE_FAST;
multiple_connections = QB_TRUE;

server_pid = run_function_in_new_process("server", run_ipc_server,
NULL);
fail_if(server_pid == -1);
alphaclient_pid = run_function_in_new_process("alphaclient",
client_dispatch,
&server_pid);
fail_if(alphaclient_pid == -1);

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

verify_graceful_stop(alphaclient_pid);
request_server_exit();
verify_graceful_stop(server_pid);
qb_ipcc_disconnect(conn);

global_ratelimit = QB_IPCS_RATE_NORMAL;
qb_leave();
}
END_TEST

START_TEST(test_ipc_bulk_events_us)
{
qb_enter();
Expand All @@ -1272,7 +1308,7 @@ test_ipc_event_on_created(void)

num_bulk_events = 1;

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

do {
Expand Down Expand Up @@ -1326,7 +1362,7 @@ test_ipc_disconnect_after_created(void)
int32_t res;
uint32_t max_size = MAX_MSG_SIZE;

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

do {
Expand Down Expand Up @@ -1383,7 +1419,7 @@ test_ipc_server_fail(void)
pid_t pid;
uint32_t max_size = MAX_MSG_SIZE;

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

do {
Expand Down Expand Up @@ -1450,6 +1486,36 @@ START_TEST(test_ipc_stress_connections_shm)
}
END_TEST

START_TEST(test_ipc_dispatch_shm_deadlock_provoke)
{
pid_t server_pid, alphaclient_pid;

qb_enter();
ipc_type = QB_IPC_SHM;
set_ipc_name(__func__);
global_ratelimit = QB_IPCS_RATE_FAST;
multiple_connections = QB_TRUE;

server_pid = run_function_in_new_process("server", run_ipc_server,
NULL);
fail_if(server_pid == -1);
alphaclient_pid = run_function_in_new_process("alphaclient",
client_dispatch,
&server_pid);
fail_if(alphaclient_pid == -1);

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

verify_graceful_stop(alphaclient_pid);
request_server_exit();
verify_graceful_stop(server_pid);
qb_ipcc_disconnect(conn);

global_ratelimit = QB_IPCS_RATE_NORMAL;
qb_leave();
}
END_TEST

START_TEST(test_ipc_bulk_events_shm)
{
qb_enter();
Expand Down Expand Up @@ -1512,7 +1578,7 @@ test_ipc_service_ref_count(void)

reference_count_test = QB_TRUE;

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

do {
Expand Down Expand Up @@ -1616,6 +1682,7 @@ make_shm_suite(void)
add_tcase(s, tc, test_ipc_event_on_created_shm, 10);
add_tcase(s, tc, test_ipc_service_ref_count_shm, 10);
add_tcase(s, tc, test_ipc_stress_connections_shm, 3600);
add_tcase(s, tc, test_ipc_dispatch_shm_deadlock_provoke, 16);

#ifdef HAVE_FAILURE_INJECTION
add_tcase(s, tc, test_ipcc_truncate_when_unlink_fails_shm, 8);
Expand Down Expand Up @@ -1648,6 +1715,7 @@ make_soc_suite(void)
add_tcase(s, tc, test_ipc_disconnect_after_created_us, 10);
add_tcase(s, tc, test_ipc_service_ref_count_us, 10);
add_tcase(s, tc, test_ipc_stress_connections_us, 3600);
add_tcase(s, tc, test_ipc_dispatch_us_deadlock_provoke, 16);

return s;
}
Expand Down

0 comments on commit cdc7a6b

Please sign in to comment.