kdbus: test suite changed to common format
[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 wur 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         print("Created connection %llu on bus '%s'\n",
29                 (unsigned long long) env->conn->id, env->buspath);
30
31         ASSERT_ZERO(kdbus_name_acquire(env->conn, "com.example.kdbus-test", NULL));
32         print("  Aquired name: com.example.kdbus-test\n");
33
34         fds[0].fd = env->conn->fd;
35         fds[1].fd = STDIN_FILENO;
36
37         print("Monitoring connections:\n");
38
39         for (count = 0;; count++) {
40                 int i, nfds = sizeof(fds) / sizeof(fds[0]);
41
42                 for (i = 0; i < nfds; i++) {
43                         fds[i].events = POLLIN | POLLPRI | POLLHUP;
44                         fds[i].revents = 0;
45                 }
46
47                 ret = poll(fds, nfds, -1);
48                 if (ret <= 0)
49                         break;
50
51                 if (fds[0].revents & POLLIN)
52                         ASSERT_ZERO(kdbus_msg_recv(env->conn, NULL, NULL));
53
54                 /* stdin */
55                 if (fds[1].revents & POLLIN)
56                         break;
57         }
58
59         print("Closing bus connection\n");
60
61         return TEST_OK;
62 }