14 #include "kdbus-test.h"
15 #include "kdbus-util.h"
16 #include "kdbus-enum.h"
18 int kdbus_test_chat(struct kdbus_test_env *env)
21 struct kdbus_conn *conn_a, *conn_b;
26 conn_a = kdbus_hello(env->buspath, 0, NULL, 0);
27 conn_b = kdbus_hello(env->buspath, 0, NULL, 0);
28 ASSERT_RETURN(conn_a && conn_b);
30 flags = KDBUS_NAME_ALLOW_REPLACEMENT;
31 ret = kdbus_name_acquire(conn_a, "foo.bar.test", &flags);
32 ASSERT_RETURN(ret == 0);
34 ret = kdbus_name_acquire(conn_a, "foo.bar.baz", NULL);
35 ASSERT_RETURN(ret == 0);
37 flags = KDBUS_NAME_QUEUE;
38 ret = kdbus_name_acquire(conn_b, "foo.bar.baz", &flags);
39 ASSERT_RETURN(ret == 0);
41 ret = kdbus_name_acquire(conn_a, "foo.bar.double", NULL);
42 ASSERT_RETURN(ret == 0);
44 ret = kdbus_name_acquire(conn_a, "foo.bar.double", NULL);
45 ASSERT_RETURN(ret == -EALREADY);
47 ret = kdbus_name_release(conn_a, "foo.bar.double");
48 ASSERT_RETURN(ret == 0);
50 ret = kdbus_name_release(conn_a, "foo.bar.double");
51 ASSERT_RETURN(ret == -ESRCH);
53 ret = kdbus_list(conn_b, KDBUS_LIST_UNIQUE |
56 KDBUS_LIST_ACTIVATORS);
57 ASSERT_RETURN(ret == 0);
59 ret = kdbus_add_match_empty(conn_a);
60 ASSERT_RETURN(ret == 0);
62 ret = kdbus_add_match_empty(conn_b);
63 ASSERT_RETURN(ret == 0);
66 ret = kdbus_msg_send(conn_b, NULL, 0xc0000000 | cookie, 0, 0, 0,
67 KDBUS_DST_ID_BROADCAST, 0, NULL);
68 ASSERT_RETURN(ret == 0);
70 fds[0].fd = conn_a->fd;
71 fds[1].fd = conn_b->fd;
73 kdbus_printf("-- entering poll loop ...\n");
75 for (count = 0;; count++) {
76 int i, nfds = sizeof(fds) / sizeof(fds[0]);
78 for (i = 0; i < nfds; i++) {
79 fds[i].events = POLLIN | POLLPRI | POLLHUP;
83 ret = poll(fds, nfds, 3000);
84 ASSERT_RETURN(ret >= 0);
86 if (fds[0].revents & POLLIN) {
88 kdbus_name_release(conn_a, "foo.bar.baz");
90 ret = kdbus_msg_recv(conn_a, NULL, NULL);
91 ASSERT_RETURN(ret == 0);
92 ret = kdbus_msg_send(conn_a, NULL,
93 0xc0000000 | cookie++,
94 0, 0, 0, conn_b->id, 0, NULL);
95 ASSERT_RETURN(ret == 0);
98 if (fds[1].revents & POLLIN) {
99 ret = kdbus_msg_recv(conn_b, NULL, NULL);
100 ASSERT_RETURN(ret == 0);
101 ret = kdbus_msg_send(conn_b, NULL,
102 0xc0000000 | cookie++,
103 0, 0, 0, conn_a->id, 0, NULL);
104 ASSERT_RETURN(ret == 0);
107 ret = kdbus_list(conn_b, KDBUS_LIST_UNIQUE |
110 KDBUS_LIST_ACTIVATORS);
111 ASSERT_RETURN(ret == 0);
117 kdbus_printf("-- closing bus connections\n");
118 kdbus_conn_free(conn_a);
119 kdbus_conn_free(conn_b);