2 * Copyright (c) 2019-2020, Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "fdi_pipe_wrap.c"
21 struct fd_info info = {
26 struct log_config conf = {};
28 list_head *fake_list = (list_head *)54321; // It's not used anyway :)
30 assert(ops_pipe.create(&info, &conf, LOG_ID_RADIO, fake_list, &(log_id_t){ LOG_ID_INVALID }) == -ENOENT);
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);
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]);
42 assert(ops_pipe.create(&info, &conf, LOG_ID_RADIO, fake_list, &(log_id_t){ LOG_ID_INVALID }) == 0);
44 struct log_filter *filter = log_filter_new();
46 log_filter_set_filterspec(filter, "filter0");
49 correct_request = DLOG_REQ_HANDLE_LOGUTIL;
50 correct_send_data = "dlogutil filter0:V *:S";
51 correct_send_datalen = strlen(correct_send_data) + 1;
53 assert(ops_pipe.prepare_print(&info, false, false, filter) == -1);
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);
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);
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);
71 recv_pipe_fail = true;
72 assert(ops_pipe.prepare_print(&info, false, false, filter) == -EIO);
73 recv_pipe_fail = false;
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);
78 log_filter_free(filter);
82 assert(ops_pipe.read(&info) == -EIO);
86 assert(!ops_pipe.extract_entry(&info));
90 correct_request = DLOG_REQ_CLEAR;
91 correct_send_data = NULL;
92 correct_send_datalen = 0;
94 assert(ops_pipe.clear(&info) == -1);
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;
102 assert(ops_pipe.get_capacity(&info, &size_target) == -1);
104 correct_request = DLOG_REQ_GET_USAGE;
105 assert(ops_pipe.get_usage(&info, &usage_target) == -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);
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);
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);
125 recv_data = malloc(recv_datalen);
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);
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);
140 ops_pipe.destroy(&info);
141 ops_pipe.destroy(&info);