diff options
author | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2015-09-08 01:01:14 -0300 |
---|---|---|
committer | André Fabian Silva Delgado <emulatorman@parabola.nu> | 2015-09-08 01:01:14 -0300 |
commit | e5fd91f1ef340da553f7a79da9540c3db711c937 (patch) | |
tree | b11842027dc6641da63f4bcc524f8678263304a3 /tools/testing/selftests/kdbus | |
parent | 2a9b0348e685a63d97486f6749622b61e9e3292f (diff) |
Linux-libre 4.2-gnu
Diffstat (limited to 'tools/testing/selftests/kdbus')
-rw-r--r-- | tools/testing/selftests/kdbus/kdbus-test.c | 6 | ||||
-rw-r--r-- | tools/testing/selftests/kdbus/kdbus-test.h | 1 | ||||
-rw-r--r-- | tools/testing/selftests/kdbus/test-activator.c | 5 | ||||
-rw-r--r-- | tools/testing/selftests/kdbus/test-chat.c | 6 | ||||
-rw-r--r-- | tools/testing/selftests/kdbus/test-message.c | 4 | ||||
-rw-r--r-- | tools/testing/selftests/kdbus/test-names.c | 137 |
6 files changed, 123 insertions, 36 deletions
diff --git a/tools/testing/selftests/kdbus/kdbus-test.c b/tools/testing/selftests/kdbus/kdbus-test.c index db732e596..db5738157 100644 --- a/tools/testing/selftests/kdbus/kdbus-test.c +++ b/tools/testing/selftests/kdbus/kdbus-test.c @@ -118,6 +118,12 @@ static const struct kdbus_test tests[] = { .flags = TEST_CREATE_BUS | TEST_CREATE_CONN, }, { + .name = "name-takeover", + .desc = "takeover of names", + .func = kdbus_test_name_takeover, + .flags = TEST_CREATE_BUS | TEST_CREATE_CONN, + }, + { .name = "message-basic", .desc = "basic message handling", .func = kdbus_test_message_basic, diff --git a/tools/testing/selftests/kdbus/kdbus-test.h b/tools/testing/selftests/kdbus/kdbus-test.h index a5c6ae81b..ee937f9a8 100644 --- a/tools/testing/selftests/kdbus/kdbus-test.h +++ b/tools/testing/selftests/kdbus/kdbus-test.h @@ -72,6 +72,7 @@ int kdbus_test_monitor(struct kdbus_test_env *env); int kdbus_test_name_basic(struct kdbus_test_env *env); int kdbus_test_name_conflict(struct kdbus_test_env *env); int kdbus_test_name_queue(struct kdbus_test_env *env); +int kdbus_test_name_takeover(struct kdbus_test_env *env); int kdbus_test_policy(struct kdbus_test_env *env); int kdbus_test_policy_ns(struct kdbus_test_env *env); int kdbus_test_policy_priv(struct kdbus_test_env *env); diff --git a/tools/testing/selftests/kdbus/test-activator.c b/tools/testing/selftests/kdbus/test-activator.c index 3d1b76370..c576a30ad 100644 --- a/tools/testing/selftests/kdbus/test-activator.c +++ b/tools/testing/selftests/kdbus/test-activator.c @@ -47,7 +47,7 @@ static int kdbus_priv_activator(struct kdbus_test_env *env) int ret; struct kdbus_msg *msg = NULL; uint64_t cookie = 0xdeadbeef; - uint64_t flags = KDBUS_NAME_REPLACE_EXISTING; + uint64_t flags; struct kdbus_conn *activator; struct kdbus_conn *service; struct kdbus_conn *client; @@ -119,12 +119,14 @@ static int kdbus_priv_activator(struct kdbus_test_env *env) /* Policies are still checked, access denied */ ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({ + flags = KDBUS_NAME_REPLACE_EXISTING; ret = kdbus_name_acquire(unpriv, "foo.priv.activator", &flags); ASSERT_RETURN(ret == -EPERM); })); ASSERT_RETURN(ret >= 0); + flags = KDBUS_NAME_REPLACE_EXISTING; ret = kdbus_name_acquire(service, "foo.priv.activator", &flags); ASSERT_RETURN(ret == 0); @@ -216,6 +218,7 @@ static int kdbus_priv_activator(struct kdbus_test_env *env) ASSERT_RETURN(ret == 0); ret = RUN_UNPRIVILEGED_CONN(unpriv, env->buspath, ({ + flags = KDBUS_NAME_REPLACE_EXISTING; ret = kdbus_name_acquire(unpriv, "foo.priv.activator", &flags); ASSERT_RETURN(ret == -EPERM); diff --git a/tools/testing/selftests/kdbus/test-chat.c b/tools/testing/selftests/kdbus/test-chat.c index 71a92d8b7..41e5b53fe 100644 --- a/tools/testing/selftests/kdbus/test-chat.c +++ b/tools/testing/selftests/kdbus/test-chat.c @@ -41,8 +41,10 @@ int kdbus_test_chat(struct kdbus_test_env *env) ret = kdbus_name_acquire(conn_a, "foo.bar.double", NULL); ASSERT_RETURN(ret == 0); - ret = kdbus_name_acquire(conn_a, "foo.bar.double", NULL); - ASSERT_RETURN(ret == -EALREADY); + flags = 0; + ret = kdbus_name_acquire(conn_a, "foo.bar.double", &flags); + ASSERT_RETURN(ret == 0); + ASSERT_RETURN(!(flags & KDBUS_NAME_ACQUIRED)); ret = kdbus_name_release(conn_a, "foo.bar.double"); ASSERT_RETURN(ret == 0); diff --git a/tools/testing/selftests/kdbus/test-message.c b/tools/testing/selftests/kdbus/test-message.c index 563dc8590..33d349bb2 100644 --- a/tools/testing/selftests/kdbus/test-message.c +++ b/tools/testing/selftests/kdbus/test-message.c @@ -293,7 +293,7 @@ static int kdbus_test_activator_quota(struct kdbus_test_env *env) struct kdbus_conn *sender; struct kdbus_conn *activator; struct kdbus_msg *msg; - uint64_t flags = KDBUS_NAME_REPLACE_EXISTING; + uint64_t flags; struct kdbus_cmd_recv recv = { .size = sizeof(recv) }; struct kdbus_policy_access access = { .type = KDBUS_POLICY_ACCESS_USER, @@ -375,6 +375,7 @@ static int kdbus_test_activator_quota(struct kdbus_test_env *env) kdbus_msg_free(msg); /* Try to acquire the name now */ + flags = KDBUS_NAME_REPLACE_EXISTING; ret = kdbus_name_acquire(conn, "foo.test.activator", &flags); ASSERT_RETURN(ret == 0); @@ -431,6 +432,7 @@ static int kdbus_test_activator_quota(struct kdbus_test_env *env) ASSERT_RETURN(ret == -ENOBUFS); /* Acquire the name again */ + flags = KDBUS_NAME_REPLACE_EXISTING; ret = kdbus_name_acquire(conn, "foo.test.activator", &flags); ASSERT_RETURN(ret == 0); diff --git a/tools/testing/selftests/kdbus/test-names.c b/tools/testing/selftests/kdbus/test-names.c index fd4ac5adc..e400dc86a 100644 --- a/tools/testing/selftests/kdbus/test-names.c +++ b/tools/testing/selftests/kdbus/test-names.c @@ -17,44 +17,68 @@ #include "kdbus-enum.h" #include "kdbus-test.h" -static int conn_is_name_owner(const struct kdbus_conn *conn, - const char *needle) +struct test_name { + const char *name; + __u64 owner_id; + __u64 flags; +}; + +static bool conn_test_names(const struct kdbus_conn *conn, + const struct test_name *tests, + unsigned int n_tests) { - struct kdbus_cmd_list cmd_list = { .size = sizeof(cmd_list) }; + struct kdbus_cmd_list cmd_list = {}; struct kdbus_info *name, *list; - bool found = false; + unsigned int i; int ret; - cmd_list.flags = KDBUS_LIST_NAMES; + cmd_list.size = sizeof(cmd_list); + cmd_list.flags = KDBUS_LIST_NAMES | + KDBUS_LIST_ACTIVATORS | + KDBUS_LIST_QUEUED; ret = kdbus_cmd_list(conn->fd, &cmd_list); ASSERT_RETURN(ret == 0); list = (struct kdbus_info *)(conn->buf + cmd_list.offset); - KDBUS_FOREACH(name, list, cmd_list.list_size) { - struct kdbus_item *item; - const char *n = NULL; - KDBUS_ITEM_FOREACH(item, name, items) { - if (item->type == KDBUS_ITEM_OWNED_NAME) { - n = item->name.name; + for (i = 0; i < n_tests; i++) { + const struct test_name *t = tests + i; + bool found = false; + + KDBUS_FOREACH(name, list, cmd_list.list_size) { + struct kdbus_item *item; - if (name->id == conn->id && - n && strcmp(needle, n) == 0) { + KDBUS_ITEM_FOREACH(item, name, items) { + if (item->type != KDBUS_ITEM_OWNED_NAME || + strcmp(item->name.name, t->name) != 0) + continue; + + if (t->owner_id == name->id && + t->flags == item->name.flags) { found = true; break; } } } - if (found) - break; + if (!found) + return false; } - ret = kdbus_free(conn, cmd_list.offset); - ASSERT_RETURN(ret == 0); + return true; +} - return found ? 0 : -1; +static bool conn_is_name_primary_owner(const struct kdbus_conn *conn, + const char *needle) +{ + struct test_name t = { + .name = needle, + .owner_id = conn->id, + .flags = KDBUS_NAME_PRIMARY, + }; + + return conn_test_names(conn, &t, 1); } int kdbus_test_name_basic(struct kdbus_test_env *env) @@ -90,15 +114,15 @@ int kdbus_test_name_basic(struct kdbus_test_env *env) ret = kdbus_name_acquire(env->conn, name, NULL); ASSERT_RETURN(ret == 0); - ret = conn_is_name_owner(env->conn, name); - ASSERT_RETURN(ret == 0); + ret = conn_is_name_primary_owner(env->conn, name); + ASSERT_RETURN(ret == true); /* ... and release it again */ ret = kdbus_name_release(env->conn, name); ASSERT_RETURN(ret == 0); - ret = conn_is_name_owner(env->conn, name); - ASSERT_RETURN(ret != 0); + ret = conn_is_name_primary_owner(env->conn, name); + ASSERT_RETURN(ret == false); /* check that we can't release it again */ ret = kdbus_name_release(env->conn, name); @@ -140,12 +164,8 @@ int kdbus_test_name_conflict(struct kdbus_test_env *env) ret = kdbus_name_acquire(env->conn, name, NULL); ASSERT_RETURN(ret == 0); - ret = conn_is_name_owner(env->conn, name); - ASSERT_RETURN(ret == 0); - - /* check that we can't acquire it again from the 1st connection */ - ret = kdbus_name_acquire(env->conn, name, NULL); - ASSERT_RETURN(ret == -EALREADY); + ret = conn_is_name_primary_owner(env->conn, name); + ASSERT_RETURN(ret == true); /* check that we also can't acquire it again from the 2nd connection */ ret = kdbus_name_acquire(conn, name, NULL); @@ -159,13 +179,14 @@ int kdbus_test_name_conflict(struct kdbus_test_env *env) int kdbus_test_name_queue(struct kdbus_test_env *env) { struct kdbus_conn *conn; + struct test_name t[2]; const char *name; uint64_t flags; int ret; name = "foo.bla.blaz"; - flags = KDBUS_NAME_ALLOW_REPLACEMENT; + flags = 0; /* create a 2nd connection */ conn = kdbus_hello(env->buspath, 0, NULL, 0); @@ -176,8 +197,8 @@ int kdbus_test_name_queue(struct kdbus_test_env *env) ret = kdbus_name_acquire(env->conn, name, &flags); ASSERT_RETURN(ret == 0); - ret = conn_is_name_owner(env->conn, name); - ASSERT_RETURN(ret == 0); + ret = conn_is_name_primary_owner(env->conn, name); + ASSERT_RETURN(ret == true); /* queue the 2nd connection as waiting owner */ flags = KDBUS_NAME_QUEUE; @@ -185,14 +206,66 @@ int kdbus_test_name_queue(struct kdbus_test_env *env) ASSERT_RETURN(ret == 0); ASSERT_RETURN(flags & KDBUS_NAME_IN_QUEUE); + t[0].name = name; + t[0].owner_id = env->conn->id; + t[0].flags = KDBUS_NAME_PRIMARY; + t[1].name = name; + t[1].owner_id = conn->id; + t[1].flags = KDBUS_NAME_QUEUE | KDBUS_NAME_IN_QUEUE; + ret = conn_test_names(conn, t, 2); + ASSERT_RETURN(ret == true); + /* release name from 1st connection */ ret = kdbus_name_release(env->conn, name); ASSERT_RETURN(ret == 0); /* now the name should be owned by the 2nd connection */ - ret = conn_is_name_owner(conn, name); + t[0].name = name; + t[0].owner_id = conn->id; + t[0].flags = KDBUS_NAME_PRIMARY | KDBUS_NAME_QUEUE; + ret = conn_test_names(conn, t, 1); + ASSERT_RETURN(ret == true); + + kdbus_conn_free(conn); + + return TEST_OK; +} + +int kdbus_test_name_takeover(struct kdbus_test_env *env) +{ + struct kdbus_conn *conn; + struct test_name t; + const char *name; + uint64_t flags; + int ret; + + name = "foo.bla.blaz"; + + flags = KDBUS_NAME_ALLOW_REPLACEMENT; + + /* create a 2nd connection */ + conn = kdbus_hello(env->buspath, 0, NULL, 0); + ASSERT_RETURN(conn != NULL); + + /* acquire name for 1st connection */ + ret = kdbus_name_acquire(env->conn, name, &flags); ASSERT_RETURN(ret == 0); + t.name = name; + t.owner_id = env->conn->id; + t.flags = KDBUS_NAME_ALLOW_REPLACEMENT | KDBUS_NAME_PRIMARY; + ret = conn_test_names(conn, &t, 1); + ASSERT_RETURN(ret == true); + + /* now steal name with 2nd connection */ + flags = KDBUS_NAME_REPLACE_EXISTING; + ret = kdbus_name_acquire(conn, name, &flags); + ASSERT_RETURN(ret == 0); + ASSERT_RETURN(flags & KDBUS_NAME_ACQUIRED); + + ret = conn_is_name_primary_owner(conn, name); + ASSERT_RETURN(ret == true); + kdbus_conn_free(conn); return TEST_OK; |