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 :)
29 log_config_set(&conf, "kmsg_ctl_sock", the_right_path);
32 assert(ops_pipe.create(&info, &conf, LOG_ID_KMSG, fake_list, &(log_id_t){ LOG_ID_INVALID }) == 0);
33 assert(last_sock == 1 && !closed[0]);
35 struct pipe_priv_data *ppd = info.priv_data;
36 assert(ppd->data_len == 0);
37 assert(ppd->offset == 0);
38 assert(ppd->sock_fd == 1);
39 assert(!ops_pipe.has_log(&info));
41 struct log_filter *filter = log_filter_new();
43 log_filter_set_filterspec(filter, "filter0");
46 correct_request = DLOG_REQ_HANDLE_LOGUTIL;
48 log_filter_set_filterspec(filter, "filter1");
49 log_filter_set_tid(filter, 123);
50 log_filter_set_pid(filter, 456);
54 recv_pipe_fail = false;
55 correct_send_data = "dlogutil --pid 456 --tid 123 filter1:V filter0:V *:S";
56 correct_send_datalen = strlen(correct_send_data) + 1;
57 assert(ops_pipe.prepare_print(&info, false, false, filter) == 0);
60 log_filter_free(filter);
64 read_datalen = sizeof(dlogutil_entry_s) + 4;
65 dlogutil_entry_s *ent = read_data = malloc(read_datalen);
68 ent->len = read_datalen;
69 memcpy(ent->msg, "abc", 4);
70 assert(ops_pipe.read(&info) == read_datalen);
71 assert(read_pos == read_datalen);
73 assert(ops_pipe.has_log(&info));
74 assert(!memcmp(ent, ops_pipe.peek_entry(&info), ent->len));
77 dlogutil_entry_s *ent2 = ops_pipe.extract_entry(&info);
78 assert(!memcmp(ent, ent2, ent->len));
81 int multiplier = RECEIVE_BUFFER_SIZE / ent->len + 1;
82 read_datalen = ent->len * multiplier;
83 ent = read_data = realloc(ent, read_datalen);
86 for (int i = 1; i < multiplier; ++i)
87 memcpy(read_data + ent->len * i, ent, ent->len);
90 int ret = ops_pipe.read(&info);
94 assert(read_pos == read_datalen);
97 assert(ops_pipe.has_log(&info));
98 ent2 = ops_pipe.extract_entry(&info);
99 assert(!memcmp(ent, ent2, ent->len));
108 while (ops_pipe.has_log(&info)) {
109 ent2 = ops_pipe.extract_entry(&info);
110 assert(!memcmp(ent, ent2, ent->len));
115 read_datalen = sizeof(dlogutil_entry_s);
116 read_data = calloc(1, read_datalen);
118 assert(ops_pipe.read(&info) == read_datalen);
119 assert(read_pos == read_datalen);
120 assert(ops_pipe.has_log(&info));
121 assert(!ops_pipe.extract_entry(&info));
122 __real_free(read_data);
125 correct_request = DLOG_REQ_CLEAR;
126 correct_send_data = NULL;
127 correct_send_datalen = 0;
130 assert(ops_pipe.clear(&info) == 0);
132 correct_request = DLOG_REQ_GET_CAPACITY;
133 unsigned int size_target = 0, usage_target = 0;
136 recv_datalen = sizeof(unsigned int);
137 recv_data = malloc(recv_datalen);
139 *(int *)recv_data = (unsigned int)17;
140 ptr_to_free = recv_data;
141 assert(ops_pipe.get_capacity(&info, &size_target) == 0);
142 assert(ptr_to_free == NULL);
144 correct_request = DLOG_REQ_GET_USAGE;
145 recv_data = malloc(recv_datalen);
147 *(int *)recv_data = (unsigned int)235U;
148 ptr_to_free = recv_data;
149 assert(ops_pipe.get_usage(&info, &usage_target) == 0);
150 assert(ptr_to_free == NULL);
152 assert(size_target == 17);
153 assert(usage_target == 235U);
156 ops_pipe.destroy(&info);
158 assert(ptr_to_free == NULL);