5 #include <dlog_ioctl.h>
6 #include <fdi_logger.h>
8 static int open_buf_ret;
9 static const char *open_buf_path;
10 int __wrap_logger_open_buffer_from_config_get_path(int buf_id, const struct log_config *conf, int open_flags, int *fd, char *actual_path, size_t path_size)
12 assert(buf_id == LOG_ID_RADIO);
13 assert(conf == (struct log_config *) 0xABDUL);
14 assert(open_flags == O_RDWR);
17 strncpy(actual_path, open_buf_path, path_size);
23 static size_t filters_added;
24 static char *const filter_strs[] = {"H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne"};
25 int __wrap_dlogutil_filter_options_set_filterspec(dlogutil_filter_options_s *p_filter, const char *filterString)
28 assert(p_filter == (dlogutil_filter_options_s *) 0xCA5CADE);
31 for (size_t i = 0; i < NELEMS(filter_strs); ++i)
32 if (!strcmp(filter_strs[i], filterString))
38 void __wrap_parse_androidlogger_message(struct android_logger_entry *ale, dlogutil_entry_s *le, size_t dgram_size) { }
39 void __wrap_copy_recv_timestamp(dlogutil_entry_s *le) { }
41 static bool use_real_close;
42 int __real_close(int fd);
43 int __wrap_close(int fd)
46 return __real_close(fd);
52 static const size_t READS[] = {
53 113, 259, 325, 207, 130, 281, 261, 169, 179, 379, 394, 390, 155, 228, 399,
54 288, 341, 1, 320, 221, 185, 255, 88, 108, 391, 299, 243, 382, 7, 41, 163, 7,
55 62, 288, 279, 350, 139, 29, 167, 28, 230, 172, 383, 329, 369, 263, 391, 37,
56 383, 186, 48, 369, 238, 227, 99, 217, 261, 313, 294, 253, 151, 325, 326, 21,
57 210, 350, 388, 97, 347, 348, 340, 3, 185, 98, 212, 74, 144, 52, 110, 202, 2,
58 202, 282, 103, 90, 150, 182, 145, 104, 159, 49, 69, 69, 69, 163, 184, 358,
59 50, 124, 205, 187, 139, 329, 361, 224, 263, 345, 99, 87, 127, 184, 231, 290,
60 192, 31, 239, 370, 324, 362, 58, 54, 214, 115, 352, 228, 161, 137, 240, 207,
61 273, 200, 154, 364, 310, 38, 332, 92, 334, 238, 52, 181, 205, 343, 312, 230,
62 164, 306, 187, 181, 346, 233, 274, 325, 129, 79, 282, 82, 304, 48, 95, 312,
63 151, 87, 212, 308, 96, 201, 274, 92, 212, 283, 173, 74, 237, 137, 49, 239,
64 155, 192, 222, 88, 267, 229, 383, 96, 3, 46, 146, 182, 182, 155, 151, 106,
65 195, 226, 112, 231, 294, 84, 115, 386, 116, 243, 54, 396, 324, 240, 203, 89,
67 static size_t read_cnt = 0;
68 static bool use_real_read;
69 static bool fail_read;
70 ssize_t __real_read(int fd, void *buf, size_t count);
71 ssize_t __wrap_read(int fd, void *buf, size_t count)
74 return __real_read(fd, buf, count);
81 if (read_cnt == NELEMS(READS))
84 const size_t current_read = READS[read_cnt++];
85 assert(current_read < count);
86 ((char *)buf)[current_read] = '\0';
90 static int fail_malloc;
91 void *__real_malloc(size_t size);
92 void *__wrap_malloc(size_t size)
94 void *const ret = (fail_malloc & 1) ? NULL : __real_malloc(size);
99 static bool fail_calloc;
100 void *__real_calloc(size_t nmemb, size_t size);
101 void *__wrap_calloc(size_t nmemb, size_t size)
103 return fail_calloc ? NULL : __real_calloc(nmemb, size);
106 static int expected_ioctl;
107 static int ioctl_ret;
108 int __real_ioctl(int fd, int request, char *argp);
109 int __wrap_ioctl(int fd, int request, char *argp)
112 assert(expected_ioctl == request);
124 struct fd_info fdi = {
128 list_head used_paths = NULL;
130 ops_logger.destroy(&fdi);
133 assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
136 assert(-536 == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
138 assert(-EINVAL == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
140 open_buf_path = "abc";
143 assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
145 assert(!fdi.priv_data);
148 assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
150 assert(!fdi.priv_data);
153 assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
154 assert(fdi.fd == 0xFD);
155 assert(fdi.priv_data);
157 ops_logger.destroy(&fdi);
158 assert(!fdi.priv_data);
161 assert(-EALREADY == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
162 assert(fdi.fd == -1);
163 assert(!fdi.priv_data);
165 open_buf_path = "def";
166 assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
168 expected_ioctl = LOGGER_FLUSH_LOG;
170 assert(-77 == ops_logger.clear(&fdi));
172 assert(0 == ops_logger.clear(&fdi));
175 expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
176 ioctl_ret = -EALREADY;
177 assert(-EALREADY == ops_logger.getsize(&fdi, &sz));
179 assert(0 == ops_logger.getsize(&fdi, &sz));
182 expected_ioctl = LOGGER_GET_LOG_LEN;
184 assert(-67 == ops_logger.prepare_print(&fdi, 123, false, (dlogutil_filter_options_s *) 0xCA5CADE));
185 expected_ioctl = LOGGER_GET_LOG_LEN;
187 assert(1 == ops_logger.prepare_print(&fdi, 123, false, (dlogutil_filter_options_s *) 0xCA5CADE));
190 assert(!ops_logger.prepare_print(&fdi, DLOGUTIL_MODE_CONTINUOUS, false, (dlogutil_filter_options_s *) 0xCA5CADE));
193 assert(-334 == ops_logger.read(&fdi));
196 for (size_t i = 0; i < NELEMS(READS) + 15; ++i) {
197 assert(!ops_logger.has_log(&fdi));
198 assert(NULL == ops_logger.extract_entry(&fdi));
199 assert(NULL == ops_logger.peek_entry(&fdi));
200 assert(NULL == ops_logger.extract_entry(&fdi));
201 fail_malloc = !(rand() % 4) * 3;
202 ops_logger.read(&fdi);
203 if (!fail_malloc && i < NELEMS(READS) && READS[i] > sizeof(struct android_logger_entry)) {
204 assert(ops_logger.has_log(&fdi));
205 assert(-EAGAIN == ops_logger.read(&fdi));
206 const dlogutil_entry_s *const le = ops_logger.peek_entry(&fdi);
208 assert(le == ops_logger.peek_entry(&fdi));
209 assert(le == ops_logger.extract_entry(&fdi));
210 free((dlogutil_entry_s *) le);
213 assert(!ops_logger.has_log(&fdi));
214 assert(NULL == ops_logger.peek_entry(&fdi));
215 assert(NULL == ops_logger.extract_entry(&fdi));
218 ops_logger.destroy(&fdi);