Branch Coverage

log.h
Criterion Covered Total %
branch 89 188 47.3


line true false branch
82 0 2 if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; }
90 2 1 if (rem->tv_nsec < 0) { rem->tv_sec--; rem->tv_nsec += 1000000000L; }
99 0 81 if (len == 0) return -1; /* 0 is the uncommitted marker */
102 0 81 if (len > UINT32_MAX - LOG_ENTRY_HDR - 3U) return -1;
109 4 77 if (t + entry_size > hdr->data_size) return -1;
111 77 0 if (__atomic_compare_exchange_n(&hdr->tail, &t, t + entry_size,
123 0 77 if (__atomic_load_n(&hdr->waiters, __ATOMIC_RELAXED) > 0)
139 1 239 if (offset < trunc) return 0; /* truncated */
141 10 229 if (offset >= t) return 0;
142 0 229 if (offset + LOG_ENTRY_HDR > h->hdr->data_size) return 0;
147 0 229 if (len == 0) return 0; /* uncommitted */
149 0 229 if (offset + LOG_ENTRY_HDR + len > t) return 0;
179 0 2 if (log_entry_count(h) != expected_count) return 1;
180 0 2 if (timeout == 0) return 0;
184 2 0 if (has_dl) log_make_deadline(timeout, &dl);
191 2 0 if (cur == expected_count) {
193 2 0 if (has_dl) {
194 0 2 if (!log_remaining(&dl, &rem)) {
204 1 1 if (log_entry_count(h) != expected_count) return 1;
205 1 0 if (has_dl && !log_remaining(&dl, &rem)) {
1 0 if (has_dl && !log_remaining(&dl, &rem)) {
231 0 2 if (hdr->magic != LOG_MAGIC) return 0;
232 0 2 if (hdr->version != LOG_VERSION) return 0;
233 0 2 if (hdr->data_size == 0) return 0;
234 0 2 if (hdr->data_size > UINT64_MAX - sizeof(LogHeader)) return 0;
235 0 2 if (hdr->total_size != file_size) return 0;
236 0 2 if (hdr->data_off != sizeof(LogHeader)) return 0;
237 0 2 if (hdr->total_size != sizeof(LogHeader) + hdr->data_size) return 0;
239 0 2 if (hdr->tail > hdr->data_size) return 0;
240 0 2 if (hdr->truncation > hdr->data_size) return 0;
247 0 14 if (!h) { munmap(base, ms); return NULL; }
251 3 11 h->path = path ? strdup(path) : NULL;
261 6 0 if (errbuf) errbuf[0] = '\0';
262 0 6 if (data_size == 0) { LOG_ERR("data_size must be > 0"); return NULL; }
0 0 if (data_size == 0) { LOG_ERR("data_size must be > 0"); return NULL; }
263 0 6 if (data_size > UINT64_MAX - sizeof(LogHeader)) { LOG_ERR("data_size too large"); return NULL; }
0 0 if (data_size > UINT64_MAX - sizeof(LogHeader)) { LOG_ERR("data_size too large"); return NULL; }
271 3 3 if (anonymous) {
274 0 3 if (base == MAP_FAILED) { LOG_ERR("mmap: %s", strerror(errno)); return NULL; }
0 0 if (base == MAP_FAILED) { LOG_ERR("mmap: %s", strerror(errno)); return NULL; }
277 0 3 if (fd < 0) { LOG_ERR("open: %s", strerror(errno)); return NULL; }
0 0 if (fd < 0) { LOG_ERR("open: %s", strerror(errno)); return NULL; }
278 0 3 if (flock(fd, LOCK_EX) < 0) { LOG_ERR("flock: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (flock(fd, LOCK_EX) < 0) { LOG_ERR("flock: %s", strerror(errno)); close(fd); return NULL; }
280 0 3 if (fstat(fd, &st) < 0) {
281 0 0 LOG_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL;
284 1 2 if (!is_new && (uint64_t)st.st_size < sizeof(LogHeader)) {
0 1 if (!is_new && (uint64_t)st.st_size < sizeof(LogHeader)) {
285 0 0 LOG_ERR("%s: file too small (%lld)", path, (long long)st.st_size);
288 2 1 if (is_new && ftruncate(fd, (off_t)total) < 0) {
0 2 if (is_new && ftruncate(fd, (off_t)total) < 0) {
289 0 0 LOG_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL;
291 1 2 map_size = is_new ? (size_t)total : (size_t)st.st_size;
293 0 3 if (base == MAP_FAILED) { LOG_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
0 0 if (base == MAP_FAILED) { LOG_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
294 1 2 if (!is_new) {
295 0 1 if (!log_validate_header((LogHeader *)base, (uint64_t)st.st_size)) {
296 0 0 LOG_ERR("invalid log file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL;
303 2 3 if (fd >= 0) { flock(fd, LOCK_UN); close(fd); }
308 7 0 if (errbuf) errbuf[0] = '\0';
309 0 7 if (data_size == 0) { LOG_ERR("data_size must be > 0"); return NULL; }
0 0 if (data_size == 0) { LOG_ERR("data_size must be > 0"); return NULL; }
310 0 7 if (data_size > UINT64_MAX - sizeof(LogHeader)) { LOG_ERR("data_size too large"); return NULL; }
0 0 if (data_size > UINT64_MAX - sizeof(LogHeader)) { LOG_ERR("data_size too large"); return NULL; }
312 7 0 int fd = memfd_create(name ? name : "log", MFD_CLOEXEC | MFD_ALLOW_SEALING);
313 0 7 if (fd < 0) { LOG_ERR("memfd_create: %s", strerror(errno)); return NULL; }
0 0 if (fd < 0) { LOG_ERR("memfd_create: %s", strerror(errno)); return NULL; }
314 0 7 if (ftruncate(fd, (off_t)total) < 0) { LOG_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (ftruncate(fd, (off_t)total) < 0) { LOG_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; }
317 0 7 if (base == MAP_FAILED) { LOG_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (base == MAP_FAILED) { LOG_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; }
323 1 0 if (errbuf) errbuf[0] = '\0';
325 0 1 if (fstat(fd, &st) < 0) { LOG_ERR("fstat: %s", strerror(errno)); return NULL; }
0 0 if (fstat(fd, &st) < 0) { LOG_ERR("fstat: %s", strerror(errno)); return NULL; }
326 0 1 if ((uint64_t)st.st_size < sizeof(LogHeader)) { LOG_ERR("too small"); return NULL; }
0 0 if ((uint64_t)st.st_size < sizeof(LogHeader)) { LOG_ERR("too small"); return NULL; }
329 0 1 if (base == MAP_FAILED) { LOG_ERR("mmap: %s", strerror(errno)); return NULL; }
0 0 if (base == MAP_FAILED) { LOG_ERR("mmap: %s", strerror(errno)); return NULL; }
330 0 1 if (!log_validate_header((LogHeader *)base, (uint64_t)st.st_size)) {
331 0 0 LOG_ERR("invalid log"); munmap(base, ms); return NULL;
334 0 1 if (myfd < 0) { LOG_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; }
0 0 if (myfd < 0) { LOG_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; }
339 0 14 if (!h) return;
340 2 12 if (h->notify_fd >= 0) close(h->notify_fd);
341 8 6 if (h->backing_fd >= 0) close(h->backing_fd);
342 14 0 if (h->hdr) munmap(h->hdr, h->mmap_size);
353 0 7 if (__atomic_load_n(&h->hdr->waiters, __ATOMIC_RELAXED) > 0)
363 1 3 if (offset <= cur) return; /* can only advance, not retreat */
364 3 0 if (__atomic_compare_exchange_n(&h->hdr->truncation, &cur, offset,
375 0 2 if (h->notify_fd >= 0) return h->notify_fd;
377 0 2 if (efd < 0) return -1;
381 0 2 if (h->notify_fd < 0) return 0;
385 0 2 if (h->notify_fd < 0) return -1;
387 0 2 if (read(h->notify_fd, &v, sizeof(v)) != sizeof(v)) return -1;