kdbus: test suite changed to common format
[platform/kernel/linux-exynos.git] / tools / testing / selftests / kdbus / test-policy.c
1 #include <errno.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <fcntl.h>
5 #include <stdlib.h>
6 #include <stdint.h>
7 #include <stdbool.h>
8 #include <unistd.h>
9
10 #include "kdbus-test.h"
11 #include "kdbus-util.h"
12 #include "kdbus-enum.h"
13
14 wur int kdbus_test_policy(struct kdbus_test_env *env)
15 {
16         struct kdbus_conn *conn_a, *conn_b;
17         struct kdbus_policy_access access;
18
19         /* Invalid name */
20         ASSERT_ZERO(kdbus_hello_registrar(env->buspath, ".example.a", NULL, 0, KDBUS_HELLO_POLICY_HOLDER));
21         ASSERT_ZERO(kdbus_hello_registrar(env->buspath, "example", NULL, 0, KDBUS_HELLO_POLICY_HOLDER));
22
23         ASSERT_NONZERO(conn_a = kdbus_hello_registrar(env->buspath, "com.example.a", NULL, 0, KDBUS_HELLO_POLICY_HOLDER));
24         ASSERT_NONZERO(conn_b = kdbus_hello_registrar(env->buspath, "com.example.b", NULL, 0, KDBUS_HELLO_POLICY_HOLDER));
25
26         /*
27          * Verify there cannot be any duplicate entries, except for specific vs.
28          * wildcard entries.
29          */
30
31         access = (struct kdbus_policy_access){
32                 .type = KDBUS_POLICY_ACCESS_USER,
33                 .id = geteuid(),
34                 .access = KDBUS_POLICY_SEE,
35         };
36
37         ASSERT_ZERO(kdbus_conn_update_policy(conn_a, "com.example.a", &access, 1));
38
39         ASSERT_RETURN(-EEXIST,==,kdbus_conn_update_policy(conn_b, "com.example.a", &access, 1));
40
41         ASSERT_ZERO(kdbus_conn_update_policy(conn_b, "com.example.a.*", &access, 1));
42
43         ASSERT_RETURN(-EEXIST,==,kdbus_conn_update_policy(conn_a, "com.example.a.*", &access, 1));
44
45         ASSERT_ZERO(kdbus_conn_update_policy(conn_a, "com.example.*", &access, 1));
46
47         ASSERT_ZERO(kdbus_conn_update_policy(conn_b, "com.example.a", &access, 1));
48
49         ASSERT_RETURN(-EEXIST,==,kdbus_conn_update_policy(conn_b, "com.example.*", &access, 1));
50
51         /* Invalid name */
52         ASSERT_RETURN(-EINVAL,==,kdbus_conn_update_policy(conn_b, ".example.*", &access, 1));
53
54         ASSERT_RETURN(-EINVAL,==,kdbus_conn_update_policy(conn_b, "example", &access, 1));
55
56         kdbus_conn_free(conn_b);
57         kdbus_conn_free(conn_a);
58
59         return TEST_OK;
60 }