7 static bool fail_strdup;
8 static char *strdup_ret;
9 char *__real_strdup(const char *s);
10 char *__wrap_strdup(const char *s)
13 return __real_strdup(s);
19 static void *expect_free;
20 void __real_free(void *ptr);
21 void __wrap_free(void *ptr)
26 assert(ptr == expect_free);
29 static size_t rename_calls;
30 int __wrap_rename(const char *oldpath, const char *newpath)
37 int __wrap_dlogutil_entry_get_timestamp(const dlogutil_entry_s *le, dlogutil_sorting_order_e stamp_type, struct timespec *ts)
39 assert(stamp_type == DLOGUTIL_SORT_SENT_MONO);
40 assert(le == (dlogutil_entry_s *) 0xBA5EBALL);
41 *ts = (struct timespec) {
48 int __wrap_dlogutil_entry_get_tag(const dlogutil_entry_s *entry, const char **tag)
50 assert(entry == (dlogutil_entry_s *) 0xBA5EBALL);
55 static bool custom_memcpy;
56 void *__real_memcpy(void *dest, const void *src, size_t n);
57 void *__wrap_memcpy(void *dest, const void *src, size_t n)
60 return __real_memcpy(dest, src, n);
62 assert(src == (void *) 0xBA5EBALL);
63 assert(n == sizeof(dlogutil_entry_s));
67 static bool fail_snprintf;
68 int __wrap_snprintf(char *str, size_t size, const char *format, ...)
70 return -fail_snprintf;
73 static int log_print_log_line_ret;
74 static bool log_print_log_line_correct_color;
75 int __wrap_log_print_log_line(struct log_format p_format, int fd, const dlogutil_entry_s *entry)
78 assert(p_format.color == log_print_log_line_correct_color);
79 return log_print_log_line_ret;
82 static bool fake_open;
83 static const char *open_pathname;
84 static int open_errno;
85 static size_t open_calls;
86 int __real_open(const char *pathname, int flags, mode_t mode);
87 int __wrap_open(const char *pathname, int flags, mode_t mode)
90 return __real_open(pathname, flags, mode);
92 assert(pathname == open_pathname);
101 int __wrap_open64(const char *pathname, int flags, mode_t mode)
103 return __wrap_open(pathname, flags, mode);
106 static bool fail_fstat;
107 int __wrap_fstat(int fd, struct stat *buf)
111 buf->st_size = 7654321;
114 int __wrap_fstat64(int fd, struct stat *buf)
116 return __wrap_fstat(fd, buf);
119 static int isatty_ret;
120 int __wrap_isatty(int fd) {
122 // We should also set errno, but we won't
134 logfile_set_fd(&lf, -10, 0);
135 assert(lf.fd == -10);
137 assert(!lf.should_close);
140 logfile_set_fd(&lf, -10, 0);
141 assert(lf.fd == -10);
143 assert(!lf.should_close);
146 logfile_set_fd(&lf, 15, 3);
149 assert(lf.should_close);
152 assert(-EINPROGRESS == logfile_set_path(&lf, "x"));
155 expect_free = lf.path = (char *) 0xDEAD50UL;
156 strdup_ret = (char *) 0xF007BALL;
157 assert(!logfile_set_path(&lf, "y"));
158 assert(lf.path == strdup_ret);
159 expect_free = strdup_ret;
162 assert(!logfile_set_path(&lf, "pathetic"));
163 assert(!strcmp(lf.path, "pathetic"));
166 open_pathname = lf.path;
169 assert(-456 == logfile_open(&lf));
175 assert(!logfile_open(&lf));
176 assert(lf.fd == 0xFD);
177 assert(lf.size == 9999);
178 assert(open_calls == 1);
182 lf.rotate_size_kbytes = 0;
183 assert(!logfile_open(&lf));
184 assert(lf.fd == 0xFD);
185 assert(lf.size == 7654321);
186 assert(open_calls == 1);
188 lf.rotate_size_kbytes = 10;
191 assert(1 == logfile_open(&lf));
192 assert(rename_calls == 3);
193 assert(open_calls == 2);
195 custom_memcpy = true;
198 isatty_ret = lf.isatty = false;
199 log_print_log_line_ret = -1;
200 log_print_log_line_correct_color = false;
201 assert(logfile_write_with_rotation((dlogutil_entry_s *) 0xBA5EBALL, &lf, DLOGUTIL_SORT_SENT_MONO));
202 assert(lf.prev_sec == 4444);
203 assert(lf.prev_nsec == 6666);
205 log_print_log_line_ret = 1;
206 fail_snprintf = true;
207 assert(!logfile_write_with_rotation((dlogutil_entry_s *) 0xBA5EBALL, &lf, DLOGUTIL_SORT_SENT_MONO));
208 assert(lf.prev_sec == 3333);
209 assert(lf.prev_nsec == 9999);
211 lf.colors_auto = true;
212 assert(!logfile_write_with_rotation((dlogutil_entry_s *) 0xBA5EBALL, &lf, DLOGUTIL_SORT_SENT_MONO));
213 assert(lf.prev_sec == 3333);
214 assert(lf.prev_nsec == 9999);
216 isatty_ret = lf.isatty = true;
217 lf.colors_auto = false;
218 assert(!logfile_write_with_rotation((dlogutil_entry_s *) 0xBA5EBALL, &lf, DLOGUTIL_SORT_SENT_MONO));
219 assert(lf.prev_sec == 3333);
220 assert(lf.prev_nsec == 9999);
222 lf.colors_auto = true;
223 log_print_log_line_correct_color = true;
224 assert(!logfile_write_with_rotation((dlogutil_entry_s *) 0xBA5EBALL, &lf, DLOGUTIL_SORT_SENT_MONO));
225 assert(lf.prev_sec == 3333);
226 assert(lf.prev_nsec == 9999);
228 isatty_ret = lf.isatty = false;
229 lf.format.color = true;
230 lf.colors_auto = false;
231 assert(!logfile_write_with_rotation((dlogutil_entry_s *) 0xBA5EBALL, &lf, DLOGUTIL_SORT_SENT_MONO));
232 assert(lf.prev_sec == 3333);
233 assert(lf.prev_nsec == 9999);
235 lf.colors_auto = true;
236 log_print_log_line_correct_color = false;
237 assert(!logfile_write_with_rotation((dlogutil_entry_s *) 0xBA5EBALL, &lf, DLOGUTIL_SORT_SENT_MONO));
238 assert(lf.prev_sec == 3333);
239 assert(lf.prev_nsec == 9999);
241 fail_snprintf = false;
242 assert(!logfile_write_with_rotation((dlogutil_entry_s *) 0xBA5EBALL, &lf, DLOGUTIL_SORT_SENT_MONO));
243 custom_memcpy = false;
247 // some extra work is done (by lcov?) after main finishes
250 open_pathname = NULL;