diff mbox series

[v2,14/14] unit: Add unit test for QRTR dedicated services

Message ID 20240625164158.1170937-14-denkenz@gmail.com (mailing list archive)
State Accepted
Commit 19a0671b111ebdf0b56e40adbb1364fab3f6d5c0
Headers show
Series [v2,01/14] qmi: Introduce SERVICE_VERSION macro | expand

Commit Message

Denis Kenzior June 25, 2024, 4:41 p.m. UTC
While here, also add a couple of helper functions that perform
boiler-plate operations.  The service_common_setup helper
takes a 'dedicated' parameter which is used to select whether
qmi_qrtr_node_get_service or qmi_qrtr_node_get_service_dedicated
is used for service creation.
---
 unit/test-qmimodem-qmi.c | 73 +++++++++++++++++++++++++---------------
 1 file changed, 46 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/unit/test-qmimodem-qmi.c b/unit/test-qmimodem-qmi.c
index e68f5a7bdd8f..bc021901ce74 100644
--- a/unit/test-qmimodem-qmi.c
+++ b/unit/test-qmimodem-qmi.c
@@ -413,26 +413,45 @@  static void send_response_to_client(struct test_info *info, struct l_io *io)
 		l_main_iterate(-1);
 }
 
-/*
- * Initiates a send of the TLV data payload to the test service. The test
- * service will respond with the same data payload.
- */
-static void test_send_data(const void *data)
+static struct qmi_service *service_common_setup(struct test_info *info,
+								bool dedicated)
 {
-	_auto_(test_cleanup) struct test_info *info = test_setup();
-	struct l_io *io;
 	uint32_t service_type;
 	struct qmi_service *service;
 
 	perform_lookup(info);
 
 	service_type = unique_service_type(0); /* Use the first service */
-	service = qmi_qrtr_node_get_service(info->node, service_type);
+
+	if (dedicated)
+		service = qmi_qrtr_node_get_dedicated_service(info->node,
+								service_type);
+	else
+		service = qmi_qrtr_node_get_service(info->node, service_type);
+
 	assert(service);
 
-	io = l_io_new(info->service_fds[0]);
+	return service;
+}
+
+static struct l_io *setup_io(int fd, void *user_data)
+{
+	struct l_io *io = l_io_new(fd);
+
 	assert(io);
-	l_io_set_read_handler(io, received_data, info, NULL);
+	l_io_set_read_handler(io, received_data, user_data, NULL);
+	return io;
+}
+
+/*
+ * Initiates a send of the TLV data payload to the test service. The test
+ * service will respond with the same data payload.
+ */
+static void test_send_data(const void *data)
+{
+	_auto_(test_cleanup) struct test_info *info = test_setup();
+	struct l_io *io = setup_io(info->service_fds[0], info);
+	struct qmi_service *service = service_common_setup(info, false);
 
 	send_request_via_qmi(info, service);
 	send_response_to_client(info, io);
@@ -441,7 +460,6 @@  static void test_send_data(const void *data)
 	qmi_service_free(service);
 }
 
-
 static void notify_cb(struct qmi_result *result, void *user_data)
 {
 	struct test_info *info = user_data;
@@ -464,21 +482,10 @@  static void internal_timeout_cb(struct l_timeout *timeout, void *user_data)
 static void test_notifications(const void *data)
 {
 	_auto_(test_cleanup) struct test_info *info = test_setup();
-	struct l_io *io;
-	uint32_t service_type;
-	struct qmi_service *service;
+	struct qmi_service *service = service_common_setup(info, false);
+	struct l_io *io = setup_io(info->service_fds[0], info);
 	struct l_timeout *receive_timeout;
 
-	perform_lookup(info);
-
-	service_type = unique_service_type(0); /* Use the first service */
-	service = qmi_qrtr_node_get_service(info->node, service_type);
-	assert(service);
-
-	io = l_io_new(info->service_fds[0]);
-	assert(io);
-	l_io_set_read_handler(io, received_data, info, NULL);
-
 	send_request_via_qmi(info, service);
 	send_response_to_client(info, io);
 
@@ -525,9 +532,7 @@  static void test_service_notification_independence(const void *data)
 
 	service_type = unique_service_type(0); /* Use the first service */
 
-	io = l_io_new(info->service_fds[0]);
-	assert(io);
-	l_io_set_read_handler(io, received_data, info, NULL);
+	io = setup_io(info->service_fds[0], info);
 
 	for (i = 0; i < L_ARRAY_SIZE(services); i++) {
 		services[i] = qmi_qrtr_node_get_service(info->node,
@@ -558,6 +563,19 @@  static void test_service_notification_independence(const void *data)
 	l_io_destroy(io);
 }
 
+static void test_dedicated(const void *data)
+{
+	_auto_(test_cleanup) struct test_info *info = test_setup();
+	struct qmi_service *service = service_common_setup(info, true);
+	struct l_io *io = setup_io(info->service_fds[0], info);
+
+	send_request_via_qmi(info, service);
+	send_response_to_client(info, io);
+
+	l_io_destroy(io);
+	qmi_service_free(service);
+}
+
 static void exit_if_qrtr_not_supported(void)
 {
 	int fd;
@@ -590,6 +608,7 @@  int main(int argc, char **argv)
 	l_test_add("QRTR notifications", test_notifications, NULL);
 	l_test_add("QRTR service notifications are independent",
 				test_service_notification_independence, NULL);
+	l_test_add("QRTR dedicated service", test_dedicated, NULL);
 	result = l_test_run();
 
 	__ofono_log_cleanup();