MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

lightningd/test/run-log-pruning.c:74–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72/* AUTOGENERATED MOCKS END */
73
74int main(int argc, char *argv[])
75{
76 struct log_book *lb;
77 struct logger *l;
78 size_t prev_avail = -1ULL, num = 0, off, i;
79 const u8 *io;
80 const char *msg;
81 struct log_hdr lhdr;
82
83 common_setup(argv[0]);
84
85 lb = new_log_book(NULL);
86 l = new_logger(lb, lb, NULL, "test %s", "prefix");
87
88 assert(streq(log_prefix(l), "test prefix"));
89
90 /* Push one off the end. */
91 while (ringbuf_avail(lb) < prev_avail) {
92 prev_avail = ringbuf_avail(lb);
93 log_debug(l, "test %06zi", num++);
94 }
95
96 assert(ringbuf_used(lb) <= sizeof(lb->ringbuf));
97 assert(ringbuf_avail(lb) < sizeof(struct log_hdr) + strlen("test 000000"));
98
99 off = 0;
100 i = 1;
101 while (get_log_entry(tmpctx, lb, &lhdr, &msg, &io, &off)) {
102 assert(lhdr.level == LOG_DBG);
103 assert(lhdr.nc == NULL);
104 assert(streq(lhdr.prefix->prefix, "test prefix"));
105 assert(lhdr.msglen == strlen("test 000000"));
106 assert(lhdr.iolen == 0);
107 assert(strncmp(msg, tal_fmt(lb, "test %06zi", i++), lhdr.msglen) == 0);
108 assert(lhdr.prefix->refcnt == num);
109 assert(io == NULL);
110 }
111
112 /* Freeing (last) log frees logbook */
113 tal_free(l);
114 common_shutdown();
115}

Callers

nothing calls this directly

Calls 9

common_setupFunction · 0.85
ringbuf_availFunction · 0.85
ringbuf_usedFunction · 0.85
get_log_entryFunction · 0.85
tal_freeFunction · 0.85
common_shutdownFunction · 0.85
new_log_bookFunction · 0.70
new_loggerFunction · 0.70
log_prefixFunction · 0.70

Tested by

no test coverage detected