kdbus-test: policy-priv: account for self-broadcasts
authorKonrad Lipinski <konrad.l@samsung.com>
Mon, 28 Nov 2016 15:01:33 +0000 (16:01 +0100)
committerKonrad Lipinski <konrad.l@samsung.com>
Mon, 28 Nov 2016 15:01:33 +0000 (16:01 +0100)
tools/testing/selftests/kdbus/test-policy-priv.c

index 12d6817d35ea1cafa193e016792733bbdecd2031..0d9d476732d5a2a70870986be446ad001137571c 100644 (file)
@@ -96,6 +96,25 @@ static wur int test_policy_priv_by_broadcast(const char *bus,
                kdbus_conn_free(child);
        }),
        ({
+               bool got_own_broadcast = 0;
+               #define RECEIVE_FROM_PARENT() for (;;) {\
+                       /* Use a little bit high time */\
+                       ret = kdbus_msg_recv_poll(child_2, 1000, &msg, NULL);\
+                       if (!ret && child_2->id == msg->src_id) {\
+                               ASSERT_ZERO(got_own_broadcast);\
+                               got_own_broadcast = 1;\
+                               kdbus_msg_free(msg);\
+                               continue;\
+                       }\
+                       ASSERT_RETURN(parent_status,==,ret);\
+                       /* Check returned cookie in case we expect success. */\
+                       if (!ret) {\
+                               ASSERT_RETURN(msg->cookie,==,expected_cookie + 1);\
+                               kdbus_msg_free(msg);\
+                       }\
+                       break;\
+               }
+
                if (drop_second_user == DO_NOT_DROP) {
                        ASSERT_NONZERO(child_2);
 
@@ -104,18 +123,7 @@ static wur int test_policy_priv_by_broadcast(const char *bus,
 
                        ASSERT_ZERO(kdbus_msg_send(child_2, NULL, expected_cookie, 0, 0, 0, KDBUS_DST_ID_BROADCAST));
 
-                       /* Use a little bit high time */
-                       ret = kdbus_msg_recv_poll(child_2, 1000, &msg, NULL);
-                       ASSERT_RETURN(parent_status,==,ret);
-
-                       /*
-                        * Check returned cookie in case we expect
-                        * success.
-                        */
-                       if (!ret) {
-                               ASSERT_RETURN(msg->cookie,==,expected_cookie + 1);
-                               kdbus_msg_free(msg);
-                       }
+                       RECEIVE_FROM_PARENT();
                } else {
                        /*
                         * Two unprivileged users will try to
@@ -131,24 +139,13 @@ static wur int test_policy_priv_by_broadcast(const char *bus,
 
                                ASSERT_EXIT_ZERO(kdbus_msg_send(child_2, NULL, expected_cookie, 0, 0, 0, KDBUS_DST_ID_BROADCAST));
 
-                               /* Use a little bit high time */
-                               ret = kdbus_msg_recv_poll(child_2, 1000, &msg, NULL);
-                               ASSERT_EXIT(ret,==,parent_status);
-
-                               /*
-                                * Check returned cookie in case we expect
-                                * success.
-                                */
-                               if (!ret) {
-                                       ASSERT_EXIT(msg->cookie,==,expected_cookie + 1);
-                                       kdbus_msg_free(msg);
-                               }
-
+                               RECEIVE_FROM_PARENT();
                                kdbus_conn_free(child_2);
                        }),
                        ({}));
                }
        }));
+#undef RECEIVE_FROM_PARENT
 
        CLOSE(efd);
 
@@ -339,12 +336,16 @@ static wur int test_broadcast_after_policy_upload(struct kdbus_test_env *env)
 
        ASSERT_ZERO(kdbus_msg_recv_poll(owner_b, 100, &msg, NULL));
        ASSERT_RETURN(msg->cookie,==,expected_cookie);
-
        /* Check src ID */
        ASSERT_RETURN(msg->src_id,==,owner_a->id);
-
        kdbus_msg_free(msg);
 
+       /* purge self-broadcast */
+       ASSERT_ZERO(kdbus_msg_recv_poll(owner_a, 100, &msg, NULL));
+       ASSERT_RETURN(msg->cookie,==,expected_cookie);
+       /* Check src ID */
+       ASSERT_RETURN(msg->src_id,==,owner_a->id);
+
        /* Release name "com.example.broadcastB" */
 
        ASSERT_EXIT_ZERO(kdbus_name_release(owner_b, "com.example.broadcastB"));