kdbus: the driver, original and non-working
[platform/kernel/linux-exynos.git] / tools / testing / selftests / kdbus / test-free.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <fcntl.h>
4 #include <stdlib.h>
5 #include <stddef.h>
6 #include <unistd.h>
7 #include <stdint.h>
8 #include <errno.h>
9 #include <assert.h>
10 #include <stdbool.h>
11
12 #include "kdbus-api.h"
13 #include "kdbus-util.h"
14 #include "kdbus-enum.h"
15 #include "kdbus-test.h"
16
17 static int sample_ioctl_call(struct kdbus_test_env *env)
18 {
19         int ret;
20         struct kdbus_cmd_list cmd_list = {
21                 .flags = KDBUS_LIST_QUEUED,
22                 .size = sizeof(cmd_list),
23         };
24
25         ret = kdbus_cmd_list(env->conn->fd, &cmd_list);
26         ASSERT_RETURN(ret == 0);
27
28         /* DON'T FREE THIS SLICE OF MEMORY! */
29
30         return TEST_OK;
31 }
32
33 int kdbus_test_free(struct kdbus_test_env *env)
34 {
35         int ret;
36         struct kdbus_cmd_free cmd_free = {};
37
38         /* free an unallocated buffer */
39         cmd_free.size = sizeof(cmd_free);
40         cmd_free.flags = 0;
41         cmd_free.offset = 0;
42         ret = kdbus_cmd_free(env->conn->fd, &cmd_free);
43         ASSERT_RETURN(ret == -ENXIO);
44
45         /* free a buffer out of the pool's bounds */
46         cmd_free.size = sizeof(cmd_free);
47         cmd_free.offset = POOL_SIZE + 1;
48         ret = kdbus_cmd_free(env->conn->fd, &cmd_free);
49         ASSERT_RETURN(ret == -ENXIO);
50
51         /*
52          * The user application is responsible for freeing the allocated
53          * memory with the KDBUS_CMD_FREE ioctl, so let's test what happens
54          * if we forget about it.
55          */
56
57         ret = sample_ioctl_call(env);
58         ASSERT_RETURN(ret == 0);
59
60         ret = sample_ioctl_call(env);
61         ASSERT_RETURN(ret == 0);
62
63         return TEST_OK;
64 }