5172df7d2cb69cd9deffd0035717255b0ad5fc4a
[platform/core/system/dlog.git] / src / tests / fdi_logger_pos.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_logger_wrap.c"
18
19 static void monitor_more_reads(size_t N, struct fd_info *fdi)
20 {
21         struct logger_priv_data *const lpd = (struct logger_priv_data *)fdi->priv_data;
22         read_cnt = 0;
23         lpd->log_len = 0;
24         lpd->entry = NULL;
25         lpd->monitor = true;
26
27         for(size_t i = 0; i < N; ++i)
28                 lpd->log_len += READS[i];
29
30         assert(READS[N] == ops_logger.read(fdi));
31 }
32
33 int main()
34 {
35         struct fd_info fdi = {
36                 .fd = -1,
37                 .priv_data = NULL,
38         };
39         list_head used_paths = NULL;
40
41         open_buf_ret = 1;
42         assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, LOG_ID_RADIO, &used_paths, &(log_id_t){ LOG_ID_INVALID }));
43         assert(fdi.fd == 0xFD);
44         assert(fdi.priv_data);
45
46         ops_logger.destroy(&fdi);
47         assert(!fdi.priv_data);
48
49         open_buf_path = "def";
50         assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, LOG_ID_RADIO, &used_paths, &(log_id_t){ LOG_ID_INVALID }));
51
52         expected_ioctl = LOGGER_FLUSH_LOG;
53         ioctl_ret = 15;
54         assert(0 == ops_logger.clear(&fdi));
55
56         unsigned int us, sz;
57         expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
58         ioctl_ret = -EALREADY;
59         assert(-EALREADY == ops_logger.get_capacity(&fdi, &sz));
60         assert(-EALREADY == ops_logger.get_usage(&fdi, &us));
61
62         expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
63         ioctl_ret = 2019;
64         assert(0 == ops_logger.get_capacity(&fdi, &sz));
65         assert(0 == ops_logger.get_usage(&fdi, &us));
66         assert(2019 == sz);
67         assert(2020 == us);
68
69         expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
70         fail_next_ioctl = true;
71         sz = 0xBAADF00D;
72         us = 0xDEADBEEF;
73
74         assert(0 == ops_logger.get_capacity(&fdi, &sz));
75         assert(-4665 == ops_logger.get_usage(&fdi, &us));
76         assert(2021 == sz);
77         assert(0xDEADBEEF == us);
78         fail_next_ioctl = false;
79
80         expected_ioctl = LOGGER_GET_LOG_LEN;
81         ioctl_ret = 0;
82         assert(1 == ops_logger.prepare_print(&fdi, 123, false, (struct log_filter *) 0xCA5CADE));
83
84         monitor_more_reads(3, &fdi);
85         monitor_more_reads(6, &fdi);
86         monitor_more_reads(34, &fdi);
87         monitor_more_reads(55, &fdi);
88         monitor_more_reads(77, &fdi);
89
90         ops_logger.destroy(&fdi);
91 }