device-notifier: find existing notifier only 84/277684/2
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 12 Jul 2022 06:16:53 +0000 (15:16 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 12 Jul 2022 06:34:00 +0000 (06:34 +0000)
It only finds a notifier that has not been deleted.

Change-Id: Ica945fb57cfe09cf4c82c94e07558abe23704b32
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/shared/device-notifier.c
tests/deviced-common-private-test/test-device-notifier.c

index e2ea3c1..e9190d6 100644 (file)
@@ -45,7 +45,7 @@ static guint idl;
 
 #define FIND_NOTIFIER(a, b, d, e, f) \
        SYS_G_LIST_FOREACH(a, b, d) \
-               if (e == d->e && f == (d->f))
+               if (e == d->e && f == (d->f) && !d->deleted)
 
 #define NOTIFY_STR(x)  [(x)] = __stringify((x))
 
index d049317..050e814 100644 (file)
@@ -184,6 +184,28 @@ static void test_destroy_callback_p2(void **state)
        device_notify_once(DEVICE_NOTIFIER_LOWBAT, (void *)(intptr_t) 0x9a9a9a9a);
 }
 
+static void test_destroy_callback_p3(void **state)
+{
+       int retval;
+
+       retval = register_notifier(DEVICE_NOTIFIER_UPSM, notify_callback);
+       assert_int_equal(retval, 0);
+       expect_value(notify_callback, data, (void *)(intptr_t) 0x3f3f3f3f);
+       device_notify(DEVICE_NOTIFIER_UPSM, (void *)(intptr_t) 0x3f3f3f3f);
+
+       /* notify_callback() should not be invoked */
+       unregister_notifier(DEVICE_NOTIFIER_UPSM, notify_callback);
+       device_notify(DEVICE_NOTIFIER_UPSM, (void *)(intptr_t) 0x34ab34ab);
+
+       /* if a notifier have successfully been deleted,
+        * re-registering the notifier must be successful */
+       retval = register_notifier(DEVICE_NOTIFIER_UPSM, notify_callback);
+       assert_int_equal(retval, 0);
+
+       expect_value(notify_callback, data, (void *)(intptr_t) 0x7878444);
+       device_notify(DEVICE_NOTIFIER_UPSM, (void *)(intptr_t) 0x7878444);
+}
+
 static void test_device_notify_priority_p1(void **state)
 {
        int id1, id2, id3;
@@ -223,6 +245,7 @@ static int run_device_notifier_test(void)
                cmocka_unit_test(test_device_notify_once_p),
                cmocka_unit_test(test_destroy_callback_p1),
                cmocka_unit_test(test_destroy_callback_p2),
+               cmocka_unit_test(test_destroy_callback_p3),
                cmocka_unit_test(test_device_notify_priority_p1),
        };