From 8c46d66c974772b8cde84071f64c3216461de933 Mon Sep 17 00:00:00 2001 From: Christine Caulfield Date: Fri, 7 Jan 2022 14:02:56 +0000 Subject: [PATCH] Add async connect call for Pacemaker Also add gating tests copied over from RHEL Resolves: rhbz#bz2031865 --- bz2031865-add-async-connect.patch | 322 ++++++++++ ...2.0.1-remove-deprecated-check-macros.patch | 606 ------------------ libqb.spec | 33 +- tests/run-tests.sh | 41 ++ tests/tests.yml | 20 + 5 files changed, 411 insertions(+), 611 deletions(-) create mode 100644 bz2031865-add-async-connect.patch delete mode 100644 libqb-2.0.1-remove-deprecated-check-macros.patch create mode 100644 tests/run-tests.sh create mode 100644 tests/tests.yml diff --git a/bz2031865-add-async-connect.patch b/bz2031865-add-async-connect.patch new file mode 100644 index 0000000..4ead826 --- /dev/null +++ b/bz2031865-add-async-connect.patch @@ -0,0 +1,322 @@ +commit de5ab3029c796e51d246bab9a83c66bbb5602e86 +Author: Chrissie Caulfield +Date: Wed Jan 5 10:53:09 2022 +0000 + + ipcc: Add an async connect API (#450) + +diff --git a/include/qb/qbipcc.h b/include/qb/qbipcc.h +index de96c72..867ba04 100644 +--- a/include/qb/qbipcc.h ++++ b/include/qb/qbipcc.h +@@ -80,6 +80,36 @@ typedef struct qb_ipcc_connection qb_ipcc_connection_t; + qb_ipcc_connection_t* + qb_ipcc_connect(const char *name, size_t max_msg_size); + ++/** ++ * Asynchronously connect to an IPC service ++ * @param name name of the service. ++ * @param max_msg_size biggest msg size. ++ * @param connect_fd return FD to continue connection with ++ * @return NULL (error: see errno) or a connection object. ++ * ++ * qb_ipcc_connect_async() returns a connection FD which ++ * should be used added to the application's mainloop - when it is ++ * active, qb_ipcc_connect_continue() should be called for the ++ * connection to be finalised. ++ * NOTE: This is NOT the same FD that is used for normal applicaion ++ * polling. qb_ipcc_fd_get() must still be called once the connection ++ * is established. ++ */ ++qb_ipcc_connection_t * ++qb_ipcc_connect_async(const char *name, size_t max_msg_size, int *connect_fd); ++ ++/** ++ * Finish up an asynchonous IPC connection ++ * @param c connection handle as returned from qb_ipcc_connect_async() ++ * @return 0 or -errno. ++ * ++ * Finishes up a connection that was initiated by qb_ipcc_connect_async(), ++ * this should only be called when the fd returned by qb_ipcc_connect_async() ++ * becomes active, usually as a callback in the application's main loop. ++ */ ++int ++qb_ipcc_connect_continue(struct qb_ipcc_connection * c); ++ + /** + * Test kernel dgram socket buffers to verify the largest size up + * to the max_msg_size value a single msg can be. Rounds down to the +diff --git a/lib/ipc_int.h b/lib/ipc_int.h +index 03c5dab..87f1de1 100644 +--- a/lib/ipc_int.h ++++ b/lib/ipc_int.h +@@ -106,7 +106,8 @@ struct qb_ipcc_connection { + }; + + int32_t qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c, +- struct qb_ipc_connection_response *r); ++ struct qb_ipc_connection_response *r); ++int qb_ipcc_setup_connect_continue(struct qb_ipcc_connection *c, struct qb_ipc_connection_response *response); + ssize_t qb_ipc_us_send(struct qb_ipc_one_way *one_way, const void *msg, size_t len); + ssize_t qb_ipc_us_recv(struct qb_ipc_one_way *one_way, void *msg, size_t len, int32_t timeout); + int32_t qb_ipc_us_ready(struct qb_ipc_one_way *ow_data, struct qb_ipc_one_way *ow_conn, +diff --git a/lib/ipc_setup.c b/lib/ipc_setup.c +index c144a5e..0ef9bb6 100644 +--- a/lib/ipc_setup.c ++++ b/lib/ipc_setup.c +@@ -446,9 +446,7 @@ qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c, + { + int32_t res; + struct qb_ipc_connection_request request; +- struct ipc_auth_data *data; + #ifdef QB_LINUX +- int off = 0; + int on = 1; + #endif + +@@ -471,13 +469,24 @@ qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c, + return res; + } + ++ /* ... To be continued ... (when the FD is active) */ ++ return 0; ++} ++ ++/* Called from ipcc_connect_continue() when async connect socket is active */ ++int qb_ipcc_setup_connect_continue(struct qb_ipcc_connection *c, struct qb_ipc_connection_response *r) ++{ ++ struct ipc_auth_data *data; ++ int32_t res; ++#ifdef QB_LINUX ++ int off = 0; ++#endif + data = init_ipc_auth_data(c->setup.u.us.sock, sizeof(struct qb_ipc_connection_response)); + if (data == NULL) { + qb_ipcc_us_sock_close(c->setup.u.us.sock); + return -ENOMEM; + } + +- qb_ipc_us_ready(&c->setup, NULL, -1, POLLIN); + res = qb_ipc_us_recv_msghdr(data); + + #ifdef QB_LINUX +@@ -498,6 +507,7 @@ qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c, + c->server_pid = data->ugp.pid; + + destroy_ipc_auth_data(data); ++ + return r->hdr.error; + } + +diff --git a/lib/ipcc.c b/lib/ipcc.c +index a6cf409..c744ea1 100644 +--- a/lib/ipcc.c ++++ b/lib/ipcc.c +@@ -45,6 +45,70 @@ qb_ipcc_connect(const char *name, size_t max_msg_size) + if (res < 0) { + goto disconnect_and_cleanup; + } ++ qb_ipc_us_ready(&c->setup, NULL, -1, POLLIN); ++ res = qb_ipcc_connect_continue(c); ++ if (res != 0) { ++ /* qb_ipcc_connect_continue() has cleaned up for us */ ++ errno = -res; ++ return NULL; ++ } ++ ++ return c; ++ ++disconnect_and_cleanup: ++ if (c->setup.u.us.sock >= 0) { ++ qb_ipcc_us_sock_close(c->setup.u.us.sock); ++ } ++ free(c->receive_buf); ++ free(c); ++ errno = -res; ++ return NULL; ++} ++ ++qb_ipcc_connection_t * ++qb_ipcc_connect_async(const char *name, size_t max_msg_size, int *connect_fd) ++{ ++ int32_t res; ++ qb_ipcc_connection_t *c = NULL; ++ struct qb_ipc_connection_response response; ++ ++ c = calloc(1, sizeof(struct qb_ipcc_connection)); ++ if (c == NULL) { ++ return NULL; ++ } ++ ++ c->setup.max_msg_size = QB_MAX(max_msg_size, ++ sizeof(struct qb_ipc_connection_response)); ++ (void)strlcpy(c->name, name, NAME_MAX); ++ res = qb_ipcc_us_setup_connect(c, &response); ++ if (res < 0) { ++ goto disconnect_and_cleanup; ++ } ++ ++ *connect_fd = c->setup.u.us.sock; ++ return c; ++ ++disconnect_and_cleanup: ++ if (c->setup.u.us.sock >= 0) { ++ qb_ipcc_us_sock_close(c->setup.u.us.sock); ++ } ++ free(c->receive_buf); ++ free(c); ++ errno = -res; ++ return NULL; ++} ++ ++int qb_ipcc_connect_continue(struct qb_ipcc_connection * c) ++{ ++ struct qb_ipc_connection_response response; ++ int32_t res; ++ ++ /* Finish up the authentication part */ ++ res = qb_ipcc_setup_connect_continue(c, &response); ++ if (res != 0) { ++ goto disconnect_and_cleanup; ++ } ++ + c->response.type = response.connection_type; + c->request.type = response.connection_type; + c->event.type = response.connection_type; +@@ -79,7 +143,7 @@ qb_ipcc_connect(const char *name, size_t max_msg_size) + goto disconnect_and_cleanup; + } + c->is_connected = QB_TRUE; +- return c; ++ return 0; + + disconnect_and_cleanup: + if (c->setup.u.us.sock >= 0) { +@@ -88,7 +152,8 @@ disconnect_and_cleanup: + free(c->receive_buf); + free(c); + errno = -res; +- return NULL; ++ return -res; ++ + } + + static int32_t +diff --git a/tests/check_ipc.c b/tests/check_ipc.c +index e8f81f3..6090354 100644 +--- a/tests/check_ipc.c ++++ b/tests/check_ipc.c +@@ -1007,6 +1007,62 @@ repeat_send: + return res; + } + ++ ++static int32_t ++process_async_connect(int32_t fd, int32_t revents, void *data) ++{ ++ qb_loop_t *cl = (qb_loop_t *)data; ++ int res; ++ ++ res = qb_ipcc_connect_continue(conn); ++ ck_assert_int_eq(res, 0); ++ qb_loop_stop(cl); ++ return 0; ++} ++static void test_ipc_connect_async(void) ++{ ++ struct qb_ipc_request_header req_header; ++ struct qb_ipc_response_header res_header; ++ int32_t res; ++ pid_t pid; ++ uint32_t max_size = MAX_MSG_SIZE; ++ int connect_fd; ++ struct iovec iov[1]; ++ static qb_loop_t *cl; ++ ++ pid = run_function_in_new_process("server", run_ipc_server, NULL); ++ ck_assert(pid != -1); ++ ++ conn = qb_ipcc_connect_async(ipc_name, max_size, &connect_fd); ++ ck_assert(conn != NULL); ++ ++ cl = qb_loop_create(); ++ res = qb_loop_poll_add(cl, QB_LOOP_MED, ++ connect_fd, POLLIN, ++ cl, process_async_connect); ++ ck_assert_int_eq(res, 0); ++ qb_loop_run(cl); ++ ++ /* Send some data */ ++ req_header.id = IPC_MSG_REQ_TX_RX; ++ req_header.size = sizeof(struct qb_ipc_request_header); ++ ++ iov[0].iov_len = req_header.size; ++ iov[0].iov_base = &req_header; ++ ++ res = qb_ipcc_sendv_recv(conn, iov, 1, ++ &res_header, ++ sizeof(struct qb_ipc_response_header), 5000); ++ ++ ck_assert_int_ge(res, 0); ++ ++ request_server_exit(); ++ verify_graceful_stop(pid); ++ ++ ++ qb_ipcc_disconnect(conn); ++} ++ + static void + test_ipc_txrx_timeout(void) + { +@@ -1226,6 +1282,7 @@ START_TEST(test_ipc_txrx_shm_timeout) + } + END_TEST + ++ + START_TEST(test_ipc_txrx_us_timeout) + { + qb_enter(); +@@ -1236,6 +1293,25 @@ START_TEST(test_ipc_txrx_us_timeout) + } + END_TEST + ++START_TEST(test_ipc_shm_connect_async) ++{ ++ qb_enter(); ++ ipc_type = QB_IPC_SHM; ++ set_ipc_name(__func__); ++ test_ipc_connect_async(); ++ qb_leave(); ++} ++END_TEST ++ ++START_TEST(test_ipc_us_connect_async) ++{ ++ qb_enter(); ++ ipc_type = QB_IPC_SHM; ++ set_ipc_name(__func__); ++ test_ipc_connect_async(); ++ qb_leave(); ++} ++END_TEST + + START_TEST(test_ipc_txrx_shm_getauth) + { +@@ -2277,6 +2353,8 @@ make_shm_suite(void) + TCase *tc; + Suite *s = suite_create("shm"); + ++ add_tcase(s, tc, test_ipc_shm_connect_async, 7); ++ + add_tcase(s, tc, test_ipc_txrx_shm_getauth, 7); + add_tcase(s, tc, test_ipc_txrx_shm_timeout, 28); + add_tcase(s, tc, test_ipc_server_fail_shm, 7); +@@ -2308,6 +2386,8 @@ make_soc_suite(void) + Suite *s = suite_create("socket"); + TCase *tc; + ++ add_tcase(s, tc, test_ipc_us_connect_async, 7); ++ + add_tcase(s, tc, test_ipc_txrx_us_getauth, 7); + add_tcase(s, tc, test_ipc_txrx_us_timeout, 28); + /* Commented out for the moment as space in /dev/shm on the CI machines diff --git a/libqb-2.0.1-remove-deprecated-check-macros.patch b/libqb-2.0.1-remove-deprecated-check-macros.patch deleted file mode 100644 index 1fb3e26..0000000 --- a/libqb-2.0.1-remove-deprecated-check-macros.patch +++ /dev/null @@ -1,606 +0,0 @@ -From: Christine Caulfield - -diff --git a/tests/check_array.c b/tests/check_array.c -index e86cd44..1abfd73 100644 ---- a/tests/check_array.c -+++ b/tests/check_array.c -@@ -44,15 +44,15 @@ START_TEST(test_array_limits) - struct test_my_st *st; - - a = qb_array_create(INT_MAX, sizeof(struct test_my_st)); -- fail_unless(a == NULL); -+ ck_assert(a == NULL); - a = qb_array_create(-56, sizeof(struct test_my_st)); -- fail_unless(a == NULL); -+ ck_assert(a == NULL); - a = qb_array_create(67, 0); -- fail_unless(a == NULL); -+ ck_assert(a == NULL); - - /* working array */ - a = qb_array_create(10, sizeof(struct test_my_st)); -- fail_if(a == NULL); -+ ck_assert(a != NULL); - - /* out-of-bounds */ - res = qb_array_index(a, 10, (void**)&st); -@@ -129,7 +129,7 @@ START_TEST(test_array_static_memory) - /* confirm the pointer is the same after a grow */ - res = qb_array_index(a, 99, (void**)&st); - ck_assert_int_eq(res, 0); -- fail_unless(st == st_old); -+ ck_assert(st == st_old); - - qb_array_free(a); - } -diff --git a/tests/check_ipc.c b/tests/check_ipc.c -index 859c922..345c2af 100644 ---- a/tests/check_ipc.c -+++ b/tests/check_ipc.c -@@ -278,7 +278,7 @@ pipe_reader(int fd, int revents, void *data) { - rbytes_sum += rbytes; - } - if (rbytes_sum > 0) { -- fail_if(buf[0] == '\0'); /* avoid dead store elimination */ -+ ck_assert(buf[0] != '\0'); /* avoid dead store elimination */ - qb_log(LOG_DEBUG, "read %zd bytes", rbytes_sum); - sleep(1); - } -@@ -420,7 +420,7 @@ s1_msg_process_fn(qb_ipcs_connection_t *c, - } else if (req_pt->id == IPC_MSG_REQ_SELF_FEED) { - if (pipe(global_pipefd) != 0) { - perror("pipefd"); -- fail_if(1); -+ ck_assert(0); - } - fcntl(global_pipefd[0], F_SETFL, O_NONBLOCK); - fcntl(global_pipefd[1], F_SETFL, O_NONBLOCK); -@@ -429,7 +429,7 @@ s1_msg_process_fn(qb_ipcs_connection_t *c, - GSource *source_r, *source_w; - source_r = g_source_new(&gio_source_funcs, sizeof(GSource)); - source_w = g_source_new(&gio_source_funcs, sizeof(GSource)); -- fail_if(source_r == NULL || source_w == NULL); -+ ck_assert(source_r != NULL && source_w != NULL); - g_source_set_priority(source_r, conv_prio_libqb2glib(QB_LOOP_HIGH)); - g_source_set_priority(source_w, conv_prio_libqb2glib(QB_LOOP_HIGH)); - g_source_set_can_recurse(source_r, FALSE); -@@ -441,7 +441,7 @@ s1_msg_process_fn(qb_ipcs_connection_t *c, - g_source_attach(source_r, NULL); - g_source_attach(source_w, NULL); - #else -- fail_if(1); -+ ck_assert(0); - #endif - } else { - qb_loop_poll_add(my_loop, QB_LOOP_HIGH, global_pipefd[1], -@@ -759,7 +759,7 @@ NEW_PROCESS_RUNNER(run_ipc_server, ready_signaller, signaller_data, data) - - - s1 = qb_ipcs_create(ipc_name, 4, ipc_type, &sh); -- fail_if(s1 == 0); -+ ck_assert(s1 != 0); - - if (global_loop_prio != QB_LOOP_MED) { - qb_ipcs_request_rate_limit(s1, -@@ -775,9 +775,9 @@ NEW_PROCESS_RUNNER(run_ipc_server, ready_signaller, signaller_data, data) - }; - glib_loop = g_main_loop_new(NULL, FALSE); - gio_map = qb_array_create_2(16, sizeof(struct gio_to_qb_poll), 1); -- fail_if (gio_map == NULL); -+ ck_assert(gio_map != NULL); - #else -- fail_if(1); -+ ck_assert(0); - #endif - } else { - ph = (struct qb_ipcs_poll_handlers) { -@@ -936,7 +936,7 @@ verify_graceful_stop(pid_t pid) - rc = WEXITSTATUS(status); - ck_assert_int_eq(rc, 0); - } else { -- fail_if(rc == 0); -+ ck_assert(rc != 0); - } - - return 0; -@@ -1020,7 +1020,7 @@ test_ipc_txrx_timeout(void) - uint32_t max_size = MAX_MSG_SIZE; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -1031,7 +1031,7 @@ test_ipc_txrx_timeout(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - /* The dispatch response will only come over - * the event channel, we want to verify the receive times -@@ -1068,7 +1068,7 @@ test_ipc_txrx(void) - uint32_t max_size = MAX_MSG_SIZE; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -1079,7 +1079,7 @@ test_ipc_txrx(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - size = QB_MIN(sizeof(struct qb_ipc_request_header), 64); - for (j = 1; j < 19; j++) { -@@ -1118,7 +1118,7 @@ test_ipc_exit(void) - uint32_t max_size = MAX_MSG_SIZE; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -1129,7 +1129,7 @@ test_ipc_exit(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - req_header.id = IPC_MSG_REQ_TX_RX; - req_header.size = sizeof(struct qb_ipc_request_header); -@@ -1295,7 +1295,7 @@ NEW_PROCESS_RUNNER(client_dispatch, ready_signaller, signaller_data, data) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - if (ready_signaller != NULL) { - ready_signaller(signaller_data); -@@ -1324,7 +1324,7 @@ test_ipc_dispatch(void) - struct dispatch_data data; - - pid = run_function_in_new_process(NULL, run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - data = (struct dispatch_data){.server_pid = pid, - .msg_type = IPC_MSG_REQ_DISPATCH, - .repetitions = 1}; -@@ -1434,7 +1434,7 @@ test_ipc_stress_connections(void) - qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE); - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - for (connections = 1; connections < NUM_STRESS_CONNECTIONS; connections++) { - if (conn) { -@@ -1450,7 +1450,7 @@ test_ipc_stress_connections(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - if (((connections+1) % 1000) == 0) { - qb_log(LOG_INFO, "%d ipc connections made", connections+1); -@@ -1481,7 +1481,7 @@ test_ipc_bulk_events(void) - uint32_t max_size = MAX_MSG_SIZE; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -1492,7 +1492,7 @@ test_ipc_bulk_events(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - events_received = 0; - cl = qb_loop_create(); -@@ -1546,7 +1546,7 @@ test_ipc_stress_test(void) - enforce_server_buffer = 1; - pid = run_function_in_new_process("server", run_ipc_server, NULL); - enforce_server_buffer = 0; -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, client_buf_size); -@@ -1557,7 +1557,7 @@ test_ipc_stress_test(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - real_buf_size = qb_ipcc_get_buffer_size(conn); - ck_assert_int_eq(real_buf_size, max_size); -@@ -1655,14 +1655,14 @@ START_TEST(test_ipc_dispatch_us_native_prio_dlock) - - server_pid = run_function_in_new_process("server", run_ipc_server, - NULL); -- fail_if(server_pid == -1); -+ ck_assert(server_pid != -1); - data = (struct dispatch_data){.server_pid = server_pid, - .msg_type = IPC_MSG_REQ_SELF_FEED, - .repetitions = 1}; - alphaclient_pid = run_function_in_new_process("alphaclient", - client_dispatch, - (void *) &data); -- fail_if(alphaclient_pid == -1); -+ ck_assert(alphaclient_pid != -1); - - //sleep(1); - sched_yield(); -@@ -1695,14 +1695,14 @@ START_TEST(test_ipc_dispatch_us_glib_prio_dlock) - - server_pid = run_function_in_new_process("server", run_ipc_server, - NULL); -- fail_if(server_pid == -1); -+ ck_assert(server_pid != -1); - data = (struct dispatch_data){.server_pid = server_pid, - .msg_type = IPC_MSG_REQ_SELF_FEED, - .repetitions = 1}; - alphaclient_pid = run_function_in_new_process("alphaclient", - client_dispatch, - (void *) &data); -- fail_if(alphaclient_pid == -1); -+ ck_assert(alphaclient_pid != -1); - - //sleep(1); - sched_yield(); -@@ -1733,7 +1733,7 @@ test_ipc_event_on_created(void) - num_bulk_events = 1; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -1744,7 +1744,7 @@ test_ipc_event_on_created(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - events_received = 0; - cl = qb_loop_create(); -@@ -1787,7 +1787,7 @@ test_ipc_disconnect_after_created(void) - uint32_t max_size = MAX_MSG_SIZE; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -1798,7 +1798,7 @@ test_ipc_disconnect_after_created(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - ck_assert_int_eq(QB_TRUE, qb_ipcc_is_connected(conn)); - -@@ -1844,7 +1844,7 @@ test_ipc_server_fail(void) - uint32_t max_size = MAX_MSG_SIZE; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -1855,7 +1855,7 @@ test_ipc_server_fail(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - request_server_exit(); - if (_fi_unlink_inject_failure == QB_TRUE) { -@@ -1933,7 +1933,7 @@ START_TEST(test_ipc_server_perms) - max_size = MAX_MSG_SIZE; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -1944,7 +1944,7 @@ START_TEST(test_ipc_server_perms) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - /* Check perms - uses illegal access to libqb internals */ - -@@ -1990,14 +1990,14 @@ START_TEST(test_ipc_dispatch_shm_native_prio_dlock) - - server_pid = run_function_in_new_process("server", run_ipc_server, - NULL); -- fail_if(server_pid == -1); -+ ck_assert(server_pid != -1); - data = (struct dispatch_data){.server_pid = server_pid, - .msg_type = IPC_MSG_REQ_SELF_FEED, - .repetitions = 1}; - alphaclient_pid = run_function_in_new_process("alphaclient", - client_dispatch, - (void *) &data); -- fail_if(alphaclient_pid == -1); -+ ck_assert(alphaclient_pid != -1); - - //sleep(1); - sched_yield(); -@@ -2030,14 +2030,14 @@ START_TEST(test_ipc_dispatch_shm_glib_prio_dlock) - - server_pid = run_function_in_new_process("server", run_ipc_server, - NULL); -- fail_if(server_pid == -1); -+ ck_assert(server_pid != -1); - data = (struct dispatch_data){.server_pid = server_pid, - .msg_type = IPC_MSG_REQ_SELF_FEED, - .repetitions = 1}; - alphaclient_pid = run_function_in_new_process("alphaclient", - client_dispatch, - (void *) &data); -- fail_if(alphaclient_pid == -1); -+ ck_assert(alphaclient_pid != -1); - - //sleep(1); - sched_yield(); -@@ -2122,7 +2122,7 @@ test_ipc_service_ref_count(void) - reference_count_test = QB_TRUE; - - pid = run_function_in_new_process("server", run_ipc_server, NULL); -- fail_if(pid == -1); -+ ck_assert(pid != -1); - - do { - conn = qb_ipcc_connect(ipc_name, max_size); -@@ -2133,7 +2133,7 @@ test_ipc_service_ref_count(void) - c++; - } - } while (conn == NULL && c < 5); -- fail_if(conn == NULL); -+ ck_assert(conn != NULL); - - sleep(5); - -@@ -2175,7 +2175,7 @@ static void test_max_dgram_size(void) - QB_LOG_FILTER_FILE, "*", LOG_TRACE); - - init = qb_ipcc_verify_dgram_max_msg_size(1000000); -- fail_if(init <= 0); -+ ck_assert(init > 0); - for (i = 0; i < 100; i++) { - int try = qb_ipcc_verify_dgram_max_msg_size(1000000); - #if 0 -diff --git a/tests/check_loop.c b/tests/check_loop.c -index 81cc2ba..c017c2c 100644 ---- a/tests/check_loop.c -+++ b/tests/check_loop.c -@@ -148,7 +148,7 @@ START_TEST(test_loop_job_input) - ck_assert_int_eq(res, -EINVAL); - - l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - res = qb_loop_job_add(NULL, QB_LOOP_LOW, NULL, job_2); - ck_assert_int_eq(res, 0); -@@ -164,7 +164,7 @@ START_TEST(test_loop_job_1) - { - int32_t res; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - res = qb_loop_job_add(l, QB_LOOP_LOW, NULL, job_1); - ck_assert_int_eq(res, 0); -@@ -181,7 +181,7 @@ START_TEST(test_loop_job_4) - { - int32_t res; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - res = qb_loop_job_add(l, QB_LOOP_LOW, l, job_1_r); - ck_assert_int_eq(res, 0); -@@ -198,13 +198,13 @@ START_TEST(test_loop_job_nuts) - { - int32_t res; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - res = qb_loop_job_add(l, QB_LOOP_LOW, l, job_1_add_nuts); - ck_assert_int_eq(res, 0); - - qb_loop_run(l); -- fail_if(job_1_run_count < 500); -+ ck_assert(job_1_run_count >= 500); - qb_loop_destroy(l); - } - END_TEST -@@ -213,7 +213,7 @@ START_TEST(test_loop_job_order) - { - int32_t res; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - job_1_run_count = 0; - -@@ -267,10 +267,10 @@ START_TEST(test_job_rate_limit) - { - int32_t res; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - rl_sw = qb_util_stopwatch_create(); -- fail_if(rl_sw == NULL); -+ ck_assert(rl_sw != NULL); - - qb_util_stopwatch_start(rl_sw); - -@@ -303,7 +303,7 @@ START_TEST(test_job_add_del) - { - int32_t res; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - res = qb_loop_job_add(l, QB_LOOP_MED, l, job_1); - ck_assert_int_eq(res, 0); -@@ -374,7 +374,7 @@ START_TEST(test_loop_timer_input) - ck_assert_int_eq(res, -EINVAL); - - l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - res = qb_loop_timer_add(NULL, QB_LOOP_LOW, 5*QB_TIME_NS_IN_MSEC, NULL, job_2, &test_th); - ck_assert_int_eq(res, 0); -@@ -414,7 +414,7 @@ START_TEST(test_loop_timer_basic) - { - int32_t res; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - res = qb_loop_timer_add(l, QB_LOOP_LOW, 5*QB_TIME_NS_IN_MSEC, l, one_shot_tmo, &test_th); - ck_assert_int_eq(res, 0); -@@ -503,7 +503,7 @@ START_TEST(test_loop_timer_precision) - struct qb_stop_watch sw[11]; - qb_loop_t *l = qb_loop_create(); - -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - for (i = 0; i < 10; i++) { - tmo = ((1 + i * 9) * QB_TIME_NS_IN_MSEC) + 500000; -@@ -567,7 +567,7 @@ START_TEST(test_loop_timer_expire_leak) - qb_loop_timer_handle th; - qb_loop_t *l = qb_loop_create(); - -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - expire_leak_counter = 0; - for (i = 0; i < 300; i++) { -@@ -605,7 +605,7 @@ START_TEST(test_loop_sig_handling) - { - qb_loop_signal_handle handle; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - qb_loop_signal_add(l, QB_LOOP_HIGH, SIGINT, - l, sig_handler, &handle); -@@ -638,7 +638,7 @@ START_TEST(test_loop_dont_override_other_signals) - qb_loop_signal_handle handle; - - this_l = qb_loop_create(); -- fail_if(this_l == NULL); -+ ck_assert(this_l != NULL); - - signal(SIGUSR1, handle_nonqb_signal); - -@@ -659,7 +659,7 @@ START_TEST(test_loop_sig_only_get_one) - int res; - qb_loop_signal_handle handle; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - /* make sure we only get one call to the handler - * don't assume we are going to exit the loop. -@@ -708,7 +708,7 @@ START_TEST(test_loop_sig_delete) - { - int res; - qb_loop_t *l = qb_loop_create(); -- fail_if(l == NULL); -+ ck_assert(l != NULL); - - /* make sure we can remove a signal job from the job queue. - */ -diff --git a/tests/check_rb.c b/tests/check_rb.c -index 498cc71..7b6c01d 100644 ---- a/tests/check_rb.c -+++ b/tests/check_rb.c -@@ -45,7 +45,7 @@ START_TEST(test_ring_buffer1) - ssize_t avail; - - rb = qb_rb_open("test1", 200, QB_RB_FLAG_CREATE, 0); -- fail_if(rb == NULL); -+ ck_assert(rb != NULL); - - for (b = 0; b < 3; b++) { - memcpy(&hdr, my_buf, sizeof(struct qb_ipc_request_header)); -@@ -100,7 +100,7 @@ START_TEST(test_ring_buffer2) - ssize_t l; - - t = qb_rb_open("test2", 200 * sizeof(int64_t), QB_RB_FLAG_CREATE, 0); -- fail_if(t == NULL); -+ ck_assert(t != NULL); - for (i = 0; i < 200; i++) { - l = qb_rb_chunk_write(t, &v, sizeof(v)); - ck_assert_int_eq(l, sizeof(v)); -@@ -108,7 +108,7 @@ START_TEST(test_ring_buffer2) - for (i = 0; i < 100; i++) { - l = qb_rb_chunk_peek(t, (void **)&new_data, 0); - ck_assert_int_eq(l, sizeof(v)); -- fail_unless(v == *new_data); -+ ck_assert(v == *new_data); - qb_rb_chunk_reclaim(t); - } - for (i = 0; i < 100; i++) { -@@ -122,7 +122,7 @@ START_TEST(test_ring_buffer2) - break; - } - ck_assert_int_eq(l, sizeof(v)); -- fail_unless(v == *new_data); -+ ck_assert(v == *new_data); - qb_rb_chunk_reclaim(t); - } - qb_rb_close(t); -@@ -142,7 +142,7 @@ START_TEST(test_ring_buffer3) - size_t len = strlen(v) + 1; - - t = qb_rb_open("test3", 10, QB_RB_FLAG_CREATE | QB_RB_FLAG_OVERWRITE, 0); -- fail_if(t == NULL); -+ ck_assert(t != NULL); - for (i = 0; i < 9000; i++) { - l = qb_rb_chunk_write(t, v, len); - ck_assert_int_eq(l, len); -@@ -169,7 +169,7 @@ START_TEST(test_ring_buffer4) - ssize_t l; - - t = qb_rb_open("test4", 10, QB_RB_FLAG_CREATE | QB_RB_FLAG_OVERWRITE, 0); -- fail_if(t == NULL); -+ ck_assert(t != NULL); - for (i = 0; i < 2000; i++) { - l = qb_rb_chunk_write(t, data, strlen(data)); - ck_assert_int_eq(l, strlen(data)); diff --git a/libqb.spec b/libqb.spec index 3cb35e0..11346b4 100644 --- a/libqb.spec +++ b/libqb.spec @@ -1,15 +1,16 @@ %bcond_without check +%bcond_without testsrpm Name: libqb Version: 2.0.3 -Release: 3%{?dist} +Release: 4%{?dist} Summary: Library providing high performance logging, tracing, ipc, and poll License: LGPLv2+ URL: https://github.com/ClusterLabs/libqb Source0: https://github.com/ClusterLabs/libqb/releases/download/v%{version}/%{name}-%{version}.tar.xz -#Patch1: libqb-2.0.1-remove-deprecated-check-macros.patch +Patch0: bz2031865-add-async-connect.patch BuildRequires: autoconf automake libtool BuildRequires: check-devel @@ -30,11 +31,16 @@ architecture, such as logging, tracing, inter-process communication (IPC), and polling. %prep -%autosetup -p1 -S git_am # for when patches around +%setup -q -n %{name}-%{version} +%patch0 -p1 -b .bz2031865-add-async-connect %build ./autogen.sh -%configure --disable-static +%configure \ +%if %{with testsrpm} + --enable-install-tests \ + %endif + --disable-static %{make_build} %if 0%{?with_check} @@ -71,12 +77,25 @@ developing applications that use %{name}. %{_libdir}/pkgconfig/libqb.pc %{_mandir}/man3/qb*3* +%if %{with testsrpm} +%package tests +Summary: Test suite for %{name} +Group: Development/Libraries +Requires: %{name}%{?_isa} = %{version}-%{release} + +%files tests +%doc COPYING +%{_libdir}/libqb/tests/* + +%description tests +The %{name}-tests package contains the %{name} test suite. +%endif + %package -n doxygen2man Summary: Program to create nicely-formatted man pages from Doxygen XML files Requires: %{name}%{?_isa} = %{version}-%{release} - %description -n doxygen2man This package contains a program to create nicely-formatted man pages from Doxygen XML files @@ -86,6 +105,10 @@ This package contains a program to create nicely-formatted man pages from Doxyge %changelog +* Fri Jan 7 2022 Christine Caulfield 2.0.3-4 +- Add async connect call for Pacemaker + Resolves: rhbz#bz2031865 + * Mon Aug 09 2021 Mohan Boddu - 2.0.3-3 - Rebuilt for IMA sigs, glibc 2.34, aarch64 flags Related: rhbz#1991688 diff --git a/tests/run-tests.sh b/tests/run-tests.sh new file mode 100644 index 0000000..58938c5 --- /dev/null +++ b/tests/run-tests.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +TESTS="array.test map.test rb.test log.test blackbox-segfault.sh loop.test ipc.test" +TESTDIR=/usr/lib64/libqb/tests + +TESTS_RUN=0 +TESTS_FAILED=0 + +export PATH=$TESTDIR:$PATH + +for i in ${TESTS} +do + echo + echo "---- running $i" + + # Cope with non-executable scripts + if [ -z "`echo $i|grep \\.sh`" ] + then + ${TESTDIR}/${i} + else + sh ${TESTDIR}/${i} + fi + + # Did it succeed? + if [ $? != 0 ] + then + TESTS_FAILED=$((TESTS_FAILED + 1)) + echo "FAILED: $i" + fi + TESTS_RUN=$((TESTS_RUN + 1)) +done +echo +echo "Tests run: $TESTS_RUN" +echo "Tests failed: $TESTS_FAILED" + +if [ $TESTS_FAILED -gt 0 ] +then + exit 1 +else + exit 0 +fi diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..ad37569 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,20 @@ +- hosts: localhost + roles: + - role: standard-test-source # Fetch source tarball and unpack it into the test environment + tags: + - always + + - role: standard-test-basic + tags: + - atomic + - classic + required_packages: + - bash + - libqb-tests + - check + - words + + tests: + - check: # Run tests + dir: . + run: ./run-tests.sh