Replace () with (void) in function prototypes
[platform/core/system/dlog.git] / src / tests / fdi_pipe_neg.c
1 /*
2  * Copyright (c) 2019-2020, Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "fdi_pipe_wrap.c"
18
19 int main(void)
20 {
21         struct fd_info info = {
22                 .ops = &ops_pipe,
23                 .id = 123,
24         };
25
26         struct log_config conf = {};
27
28         list_head *fake_list = (list_head *)54321; // It's not used anyway :)
29
30         assert(ops_pipe.create(&info, &conf, LOG_ID_RADIO, fake_list, &(log_id_t){ LOG_ID_INVALID }) == -ENOENT);
31
32         log_config_set(&conf, "radio_ctl_sock", "the_wrong_path");
33         assert(ops_pipe.create(&info, &conf, LOG_ID_RADIO, fake_list, &(log_id_t){ LOG_ID_INVALID }) == -ECONNREFUSED);
34         assert(last_sock == 0);
35         log_config_set(&conf, "radio_ctl_sock", the_right_path);
36
37         malloc_fail = true;
38         assert(ops_pipe.create(&info, &conf, LOG_ID_RADIO, fake_list, &(log_id_t){ LOG_ID_INVALID }) == -ENOMEM);
39         assert(last_sock == 1 && closed[0]);
40         malloc_fail = false;
41
42         assert(ops_pipe.create(&info, &conf, LOG_ID_RADIO, fake_list, &(log_id_t){ LOG_ID_INVALID }) == 0);
43
44         struct log_filter *filter = log_filter_new();
45         assert(filter);
46         log_filter_set_filterspec(filter, "filter0");
47
48         correct_sockfd = 2;
49         correct_request = DLOG_REQ_HANDLE_LOGUTIL;
50         correct_send_data = "dlogutil filter0:V *:S";
51         correct_send_datalen = strlen(correct_send_data) + 1;
52         send_return = -1;
53         assert(ops_pipe.prepare_print(&info, false, false, filter) == -1);
54
55         correct_send_data = "dlogutil -d filter0:V *:S";
56         correct_send_datalen = strlen(correct_send_data) + 1;
57         assert(ops_pipe.prepare_print(&info, true, false, filter) == -1);
58
59         log_filter_set_filterspec(filter, "filter1");
60         correct_send_data = "dlogutil filter1:V filter0:V *:S";
61         correct_send_datalen = strlen(correct_send_data) + 1;
62         assert(ops_pipe.prepare_print(&info, false, false, filter) == -1);
63
64         log_filter_set_tid(filter, 123);
65         log_filter_set_pid(filter, 456);
66         correct_send_data = "dlogutil --pid 456 --tid 123 filter1:V filter0:V *:S";
67         correct_send_datalen = strlen(correct_send_data) + 1;
68         assert(ops_pipe.prepare_print(&info, false, false, filter) == -1);
69
70         send_return = 0;
71         recv_pipe_fail = true;
72         assert(ops_pipe.prepare_print(&info, false, false, filter) == -EIO);
73         recv_pipe_fail = false;
74
75         log_filter_set_filterspec(filter, "This is a long and complicated filter. In fact, it's way too long to be accepted by ops_pipe.prepare_print, which should return -E2BIG.");
76         assert(ops_pipe.prepare_print(&info, false, false, filter) == -E2BIG);
77
78         log_filter_free(filter);
79         correct_sockfd = 0;
80
81         read_errno = EIO;
82         assert(ops_pipe.read(&info) == -EIO);
83         read_errno = 0;
84
85         malloc_fail = true;
86         assert(!ops_pipe.extract_entry(&info));
87         malloc_fail = false;
88
89         correct_sockfd = 2;
90         correct_request = DLOG_REQ_CLEAR;
91         correct_send_data = NULL;
92         correct_send_datalen = 0;
93         send_return = -1;
94         assert(ops_pipe.clear(&info) == -1);
95
96         correct_request = DLOG_REQ_GET_CAPACITY;
97         correct_send_data = NULL;
98         correct_send_datalen = 0;
99         unsigned int size_target = 0, usage_target = 0;
100
101         send_return = -1;
102         assert(ops_pipe.get_capacity(&info, &size_target) == -1);
103
104         correct_request = DLOG_REQ_GET_USAGE;
105         assert(ops_pipe.get_usage(&info, &usage_target) == -1);
106
107         send_return = 0;
108         recv_return = -1;
109         correct_request = DLOG_REQ_GET_CAPACITY;
110         assert(ops_pipe.get_capacity(&info, &size_target) == -1);
111         correct_request = DLOG_REQ_GET_USAGE;
112         assert(ops_pipe.get_usage(&info, &usage_target) == -1);
113
114         recv_return = 0;
115         const char *wrong_ans = "I won't tell you the pipe size :)";
116         recv_datalen = strlen(wrong_ans) + 1;
117         recv_data = malloc(recv_datalen);
118         assert(recv_data);
119         memcpy(recv_data, wrong_ans, recv_datalen);
120         ptr_to_free = recv_data;
121         correct_request = DLOG_REQ_GET_CAPACITY;
122         assert(ops_pipe.get_capacity(&info, &size_target) == -EINVAL);
123         assert(ptr_to_free == NULL);
124
125         recv_data = malloc(recv_datalen);
126         assert(recv_data);
127         memcpy(recv_data, wrong_ans, recv_datalen);
128         ptr_to_free = recv_data;
129         correct_request = DLOG_REQ_GET_USAGE;
130         assert(ops_pipe.get_usage(&info, &usage_target) == -EINVAL);
131         assert(ptr_to_free == NULL);
132
133         recv_datalen = 0;
134         recv_data = NULL;
135         correct_request = DLOG_REQ_GET_CAPACITY;
136         assert(ops_pipe.get_capacity(&info, &size_target) == -EINVAL);
137         correct_request = DLOG_REQ_GET_USAGE;
138         assert(ops_pipe.get_usage(&info, &usage_target) == -EINVAL);
139
140         ops_pipe.destroy(&info);
141         ops_pipe.destroy(&info);
142 }