From: Konrad Lipinski Date: Mon, 28 Nov 2016 15:01:33 +0000 (+0100) Subject: kdbus-test: policy-priv: account for self-broadcasts X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17e438391e6c348030e901e78ca57b993ad2ca8b;p=platform%2Fkernel%2Flinux-exynos.git kdbus-test: policy-priv: account for self-broadcasts --- diff --git a/tools/testing/selftests/kdbus/test-policy-priv.c b/tools/testing/selftests/kdbus/test-policy-priv.c index 12d6817d35ea..0d9d476732d5 100644 --- a/tools/testing/selftests/kdbus/test-policy-priv.c +++ b/tools/testing/selftests/kdbus/test-policy-priv.c @@ -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"));