From cdc7a6be6475abf9b22c88a0aabb8f6772b267c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Tue, 21 May 2019 20:35:19 +0200 Subject: [PATCH] TODO tests: ipc: check deadlock-like situation due to mixing priorities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit XXX needs the actual assertions to highlight the problem Signed-off-by: Jan Pokorný --- tests/check_ipc.c | 98 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 15 deletions(-) diff --git a/tests/check_ipc.c b/tests/check_ipc.c index d26dff638..c728b6c6a 100644 --- a/tests/check_ipc.c +++ b/tests/check_ipc.c @@ -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, @@ -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); } @@ -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 (); @@ -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); } @@ -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 { @@ -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 { @@ -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 { @@ -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); @@ -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++) { @@ -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 { @@ -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); @@ -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(); @@ -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 { @@ -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 { @@ -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 { @@ -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(); @@ -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 { @@ -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); @@ -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; }