summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2014-10-17 13:43:14 +0200
committerDaniel Mack <daniel@zonque.org>2014-10-18 21:00:16 +0200
commit017f56c7e53f81c0cc559acafd4f446abd935d19 (patch)
tree508e283035f0c7c4571fce155c0b64bfd6608211 /test
parentedf96a5e4328bf12c0c29323bc9c0ec55cab129a (diff)
downloadkdbus-bus-017f56c7e53f81c0cc559acafd4f446abd935d19.tar.gz
kdbus-bus-017f56c7e53f81c0cc559acafd4f446abd935d19.tar.bz2
kdbus-bus-017f56c7e53f81c0cc559acafd4f446abd935d19.zip
tree-wide: rework flags negotiation (ABI break)
We are obliged to reject all bits in flags fields that are not known to the kernel. In order to let userspace know which flags the kernel knowns about, we agreed to always write back to the flags field in the ioctl buffer, even if the call succeeded. The kernel will, however, will always set the KDBUS_FLAG_KERNEL bit, which consequently is always invalid when submitted by userspace. Move some checks from other place to handle.c, and update the testsuite and documentation accordingly. Signed-off-by: Daniel Mack <daniel@zonque.org>
Diffstat (limited to 'test')
-rw-r--r--test/test-connection.c13
-rw-r--r--test/test-domain.c3
-rw-r--r--test/test-free.c4
3 files changed, 17 insertions, 3 deletions
diff --git a/test/test-connection.c b/test/test-connection.c
index bc397d9b6df..de74c34e186 100644
--- a/test/test-connection.c
+++ b/test/test-connection.c
@@ -57,6 +57,7 @@ int kdbus_test_bus_make(struct kdbus_test_env *env)
bus_make.n_size = KDBUS_ITEM_HEADER_SIZE + strlen(bus_make.name) + 1;
bus_make.head.size = sizeof(struct kdbus_cmd_make) +
sizeof(bus_make.bs) + bus_make.n_size;
+ bus_make.head.flags = 0;
ret = ioctl(env->control_fd, KDBUS_CMD_BUS_MAKE, &bus_make);
ASSERT_RETURN(ret == -1 && errno == EINVAL);
@@ -65,6 +66,7 @@ int kdbus_test_bus_make(struct kdbus_test_env *env)
bus_make.n_size = KDBUS_ITEM_HEADER_SIZE + strlen(bus_make.name) + 1;
bus_make.head.size = sizeof(struct kdbus_cmd_make) +
sizeof(bus_make.bs) + bus_make.n_size;
+ bus_make.head.flags = 0;
ret = ioctl(env->control_fd, KDBUS_CMD_BUS_MAKE, &bus_make);
ASSERT_RETURN(ret == -1 && errno == EINVAL);
@@ -73,6 +75,7 @@ int kdbus_test_bus_make(struct kdbus_test_env *env)
bus_make.n_size = KDBUS_ITEM_HEADER_SIZE + strlen(bus_make.name) + 1;
bus_make.head.size = sizeof(struct kdbus_cmd_make) +
sizeof(bus_make.bs) + bus_make.n_size;
+ bus_make.head.flags = 0;
ret = ioctl(env->control_fd, KDBUS_CMD_BUS_MAKE, &bus_make);
ASSERT_RETURN(ret == -1 && errno == EINVAL);
@@ -81,6 +84,7 @@ int kdbus_test_bus_make(struct kdbus_test_env *env)
bus_make.n_size = KDBUS_ITEM_HEADER_SIZE + strlen(bus_make.name) + 1;
bus_make.head.size = sizeof(struct kdbus_cmd_make) +
sizeof(bus_make.bs) + bus_make.n_size;
+ bus_make.head.flags = 0;
ret = ioctl(env->control_fd, KDBUS_CMD_BUS_MAKE, &bus_make);
ASSERT_RETURN(ret == 0);
snprintf(s, sizeof(s), "/dev/" KBUILD_MODNAME "/%u-blah-1/bus", uid);
@@ -115,6 +119,7 @@ int kdbus_test_hello(struct kdbus_test_env *env)
/* a size of 0 must return EMSGSIZE */
hello.size = 1;
+ hello.conn_flags = KDBUS_HELLO_ACCEPT_FD;
ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
ASSERT_RETURN(ret == -1 && errno == EINVAL);
@@ -123,22 +128,28 @@ int kdbus_test_hello(struct kdbus_test_env *env)
/* check faulty flags */
hello.conn_flags = 1ULL << 32;
ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
- ASSERT_RETURN(ret == -1 && errno == EOPNOTSUPP);
+ ASSERT_RETURN(ret == -1 && errno == EINVAL);
+
+ /* kernel must have set its bit in the ioctl buffer */
+ ASSERT_RETURN(hello.conn_flags & KDBUS_FLAG_KERNEL);
hello.conn_flags = KDBUS_HELLO_ACCEPT_FD;
/* check for faulty pool sizes */
hello.pool_size = 0;
+ hello.conn_flags = KDBUS_HELLO_ACCEPT_FD;
ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
ASSERT_RETURN(ret == -1 && errno == EFAULT);
hello.pool_size = 4097;
+ hello.conn_flags = KDBUS_HELLO_ACCEPT_FD;
ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
ASSERT_RETURN(ret == -1 && errno == EFAULT);
hello.pool_size = POOL_SIZE;
/* success test */
+ hello.conn_flags = KDBUS_HELLO_ACCEPT_FD;
ret = ioctl(fd, KDBUS_CMD_HELLO, &hello);
ASSERT_RETURN(ret == 0);
diff --git a/test/test-domain.c b/test/test-domain.c
index c223e487a37..9d7b08ae91d 100644
--- a/test/test-domain.c
+++ b/test/test-domain.c
@@ -38,6 +38,7 @@ int kdbus_test_domain_make(struct kdbus_test_env *env)
snprintf(domain_make.name, sizeof(domain_make.name), "blah");
domain_make.n_size = KDBUS_ITEM_HEADER_SIZE + strlen(domain_make.name) + 1;
domain_make.head.size = sizeof(struct kdbus_cmd_make) + domain_make.n_size;
+ domain_make.head.flags = 0;
ret = ioctl(fd, KDBUS_CMD_DOMAIN_MAKE, &domain_make);
if (ret < 0 && errno == EPERM)
return TEST_SKIP;
@@ -47,11 +48,13 @@ int kdbus_test_domain_make(struct kdbus_test_env *env)
F_OK) == 0);
/* can't use the same fd for domain make twice */
+ domain_make.head.flags = 0;
ret = ioctl(fd, KDBUS_CMD_DOMAIN_MAKE, &domain_make);
ASSERT_RETURN(ret == -1 && errno == EBADFD);
/* can't register the same name twice */
fd2 = open("/dev/" KBUILD_MODNAME "/control", O_RDWR|O_CLOEXEC);
+ domain_make.head.flags = 0;
ret = ioctl(fd2, KDBUS_CMD_DOMAIN_MAKE, &domain_make);
ASSERT_RETURN(ret == -1 && errno == EEXIST);
close(fd2);
diff --git a/test/test-free.c b/test/test-free.c
index 5a14e2b3513..abac022d29d 100644
--- a/test/test-free.c
+++ b/test/test-free.c
@@ -19,14 +19,14 @@ int kdbus_test_free(struct kdbus_test_env *env)
int ret;
struct kdbus_cmd_free cmd_free;
+ /* free an unallocated buffer */
cmd_free.flags = 0;
cmd_free.offset = 0;
-
- /* free an unallocated buffer */
ret = ioctl(env->conn->fd, KDBUS_CMD_FREE, &cmd_free);
ASSERT_RETURN(ret == -1 && errno == ENXIO);
/* free a buffer out of the pool's bounds */
+ cmd_free.flags = 0;
cmd_free.offset = POOL_SIZE + 1;
ret = ioctl(env->conn->fd, KDBUS_CMD_FREE, &cmd_free);
ASSERT_RETURN(ret == -1 && errno == ENXIO);