test-monitor: add KDBUS_CMD_CONN_UPDATE tests for monitor connections
authorDjalal Harouni <tixxdz@opendz.org>
Sat, 25 Oct 2014 11:31:10 +0000 (12:31 +0100)
committerDjalal Harouni <tixxdz@opendz.org>
Sat, 25 Oct 2014 11:31:10 +0000 (12:31 +0100)
Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
test/test-monitor.c

index 59a6ab088401130daaccf915633e9568914e7727..dfda5dccb7af27c90d68b693cd1cb6235afc2922 100644 (file)
 #include "kdbus-enum.h"
 #include "kdbus-test.h"
 
+static bool kdbus_item_in_message(struct kdbus_msg *msg,
+                                 uint64_t type)
+{
+       const struct kdbus_item *item;
+
+       KDBUS_ITEM_FOREACH(item, msg, items)
+               if (item->type == type)
+                       return true;
+
+       return false;
+}
+
 int kdbus_test_monitor(struct kdbus_test_env *env)
 {
        struct kdbus_conn *monitor, *conn;
@@ -83,6 +95,60 @@ int kdbus_test_monitor(struct kdbus_test_env *env)
        kdbus_msg_free(msg);
        kdbus_free(monitor, offset);
 
+       /*
+        * Since we are the only monitor, update the attach flags
+        * and tell we are not interessted in attach flags
+       */
+
+       ret = kdbus_conn_update_attach_flags(monitor, 0);
+       ASSERT_RETURN(ret == 0);
+
+       cookie++;
+       ret = kdbus_msg_send(env->conn, NULL, cookie, 0, 0, 0,
+                            KDBUS_DST_ID_BROADCAST);
+       ASSERT_RETURN(ret == 0);
+
+       ret = kdbus_msg_recv_poll(monitor, 100, &msg, &offset);
+       ASSERT_RETURN(ret == 0);
+       ASSERT_RETURN(msg->cookie == cookie);
+
+       ret = kdbus_item_in_message(msg, KDBUS_ITEM_TIMESTAMP);
+       ASSERT_RETURN(ret == 0);
+
+       kdbus_msg_free(msg);
+       kdbus_free(monitor, offset);
+
+       /*
+        * Now we are interested in KDBUS_ITEM_TIMESTAMP and
+        * KDBUS_ITEM_CREDS
+        */
+       ret = kdbus_conn_update_attach_flags(monitor,
+                                            KDBUS_ATTACH_TIMESTAMP |
+                                            KDBUS_ATTACH_CREDS);
+       ASSERT_RETURN(ret == 0);
+
+       cookie++;
+       ret = kdbus_msg_send(env->conn, NULL, cookie, 0, 0, 0,
+                            KDBUS_DST_ID_BROADCAST);
+       ASSERT_RETURN(ret == 0);
+
+       ret = kdbus_msg_recv_poll(monitor, 100, &msg, &offset);
+       ASSERT_RETURN(ret == 0);
+       ASSERT_RETURN(msg->cookie == cookie);
+
+       ret = kdbus_item_in_message(msg, KDBUS_ITEM_TIMESTAMP);
+       ASSERT_RETURN(ret == 1);
+
+       ret = kdbus_item_in_message(msg, KDBUS_ITEM_CREDS);
+       ASSERT_RETURN(ret == 1);
+
+       /* the KDBUS_ITEM_PID_COMM was not requested */
+       ret = kdbus_item_in_message(msg, KDBUS_ITEM_PID_COMM);
+       ASSERT_RETURN(ret == 0);
+
+       kdbus_msg_free(msg);
+       kdbus_free(monitor, offset);
+
        kdbus_conn_free(monitor);
        kdbus_conn_free(conn);