diff mbox series

[7/8] qmi unit: Validate destroyed services do not notify

Message ID 20240419164458.36078-7-steve.schrock@getcruise.com (mailing list archive)
State Accepted
Commit 2d4e571d15980954de1b671e97535a8dedad5a06
Headers show
Series [1/8] qmi unit: Link to dl | expand

Commit Message

Steve Schrock April 19, 2024, 4:44 p.m. UTC
Confirm that client notifications do occur after unref'ing (destroying)
the service.
---
 unit/test-qmimodem-qmi.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/unit/test-qmimodem-qmi.c b/unit/test-qmimodem-qmi.c
index 8df8b56a79eb..43e1bad082ba 100644
--- a/unit/test-qmimodem-qmi.c
+++ b/unit/test-qmimodem-qmi.c
@@ -23,6 +23,13 @@ 
 #define TEST_SERVICE_COUNT	2
 #define TEST_TIMEOUT		5
 
+/*
+ * The amount of time to wait to validate that something did NOT occur. The
+ * value is fairly arbitrary -- the longer it is, the longer the tests will take
+ * to complete.
+ */
+#define ALLOWED_QRTR_TRANSFER_TIME 100 /* ms */
+
 struct test_info {
 	int service_fds[TEST_SERVICE_COUNT];
 	struct qmi_device *device;
@@ -36,6 +43,7 @@  struct test_info {
 
 	bool discovery_callback_called		: 1;
 	bool service_send_callback_called	: 1;
+	bool internal_timeout_callback_called	: 1;
 	bool notify_callback_called		: 1;
 };
 
@@ -473,12 +481,20 @@  static void notify_cb(struct qmi_result *result, void *user_data)
 	info->notify_callback_called = true;
 }
 
+static void internal_timeout_cb(struct l_timeout *timeout, void *user_data)
+{
+	struct test_info *info = user_data;
+
+	info->internal_timeout_callback_called = true;
+}
+
 static void test_notifications(const void *data)
 {
 	struct test_info *info = test_setup();
 	struct l_io *io;
 	uint32_t service_type;
 	struct qmi_service *service;
+	struct l_timeout *receive_timeout;
 
 	perform_discovery(info);
 
@@ -505,9 +521,26 @@  static void test_notifications(const void *data)
 	while (!info->notify_callback_called)
 		l_main_iterate(-1);
 
-	l_io_destroy(io);
 	qmi_service_unref(service);
 
+	/* Confirm no notifications received after the service is destroyed */
+	info->notify_callback_called = false;
+	send_message_to_client(&info->sender, io, QMI_MESSAGE_TYPE_IND, 0,
+						TEST_IND_MESSAGE_ID,
+						TEST_IND_DATA_VALUE);
+
+	receive_timeout = l_timeout_create_ms(ALLOWED_QRTR_TRANSFER_TIME,
+						internal_timeout_cb, info,
+						NULL);
+
+	while (!info->internal_timeout_callback_called)
+		perform_all_pending_work();
+
+	assert(!info->notify_callback_called);
+
+	l_timeout_remove(receive_timeout);
+
+	l_io_destroy(io);
 	test_cleanup(info);
 }