aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Schrock <steve.schrock@getcruise.com>2024-04-19 16:44:57 +0000
committerDenis Kenzior <denkenz@gmail.com>2024-04-22 11:23:07 -0500
commit2d4e571d15980954de1b671e97535a8dedad5a06 (patch)
tree6ada83876e9edc9ebeb964b4b2db0fb9714cfaec
parentaf2718346a2825e2264d9ca7fd63f13b3f1ff479 (diff)
downloadofono-2d4e571d15980954de1b671e97535a8dedad5a06.tar.gz
qmi unit: Validate destroyed services do not notify
Confirm that client notifications do occur after unref'ing (destroying) the service.
-rw-r--r--unit/test-qmimodem-qmi.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/unit/test-qmimodem-qmi.c b/unit/test-qmimodem-qmi.c
index 8df8b56a7..43e1bad08 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);
}