kdbus: the driver, original and non-working
[platform/kernel/linux-exynos.git] / tools / testing / selftests / kdbus / test-daemon.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <time.h>
4 #include <fcntl.h>
5 #include <stdlib.h>
6 #include <stddef.h>
7 #include <unistd.h>
8 #include <stdint.h>
9 #include <errno.h>
10 #include <assert.h>
11 #include <poll.h>
12 #include <stdbool.h>
13
14 #include "kdbus-test.h"
15 #include "kdbus-util.h"
16 #include "kdbus-enum.h"
17
18 int kdbus_test_daemon(struct kdbus_test_env *env)
19 {
20         struct pollfd fds[2];
21         int count;
22         int ret;
23
24         /* This test doesn't make any sense in non-interactive mode */
25         if (!kdbus_util_verbose)
26                 return TEST_OK;
27
28         printf("Created connection %llu on bus '%s'\n",
29                 (unsigned long long) env->conn->id, env->buspath);
30
31         ret = kdbus_name_acquire(env->conn, "com.example.kdbus-test", NULL);
32         ASSERT_RETURN(ret == 0);
33         printf("  Aquired name: com.example.kdbus-test\n");
34
35         fds[0].fd = env->conn->fd;
36         fds[1].fd = STDIN_FILENO;
37
38         printf("Monitoring connections:\n");
39
40         for (count = 0;; count++) {
41                 int i, nfds = sizeof(fds) / sizeof(fds[0]);
42
43                 for (i = 0; i < nfds; i++) {
44                         fds[i].events = POLLIN | POLLPRI | POLLHUP;
45                         fds[i].revents = 0;
46                 }
47
48                 ret = poll(fds, nfds, -1);
49                 if (ret <= 0)
50                         break;
51
52                 if (fds[0].revents & POLLIN) {
53                         ret = kdbus_msg_recv(env->conn, NULL, NULL);
54                         ASSERT_RETURN(ret == 0);
55                 }
56
57                 /* stdin */
58                 if (fds[1].revents & POLLIN)
59                         break;
60         }
61
62         printf("Closing bus connection\n");
63
64         return TEST_OK;
65 }