summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/printfrr.h13
-rw-r--r--tests/lib/test_atomlist.c19
-rw-r--r--tests/lib/test_stream.c18
-rw-r--r--tests/lib/test_typelist.c5
-rw-r--r--tests/lib/test_typelist.h8
5 files changed, 38 insertions, 25 deletions
diff --git a/lib/printfrr.h b/lib/printfrr.h
index 6fcfbe31fa..7d9e288655 100644
--- a/lib/printfrr.h
+++ b/lib/printfrr.h
@@ -30,8 +30,7 @@ struct fbuf {
size_t len;
};
-#define at(a, b) \
- PRINTFRR(a, b)
+#define at(a, b) PRINTFRR(a, b)
#define atn(a, b) \
at(a, b) __attribute__((nonnull(1) _RET_NONNULL))
#define atm(a, b) \
@@ -73,6 +72,16 @@ char *vasnprintfrr(struct memtype *mt, char *out, size_t sz,
char *asnprintfrr(struct memtype *mt, char *out, size_t sz,
const char *fmt, ...) atn(4, 5);
+#define printfrr(fmt, ...) \
+ do { \
+ char buf[256], *out; \
+ out = asnprintfrr(MTYPE_TMP, buf, sizeof(buf), fmt, \
+ ##__VA_ARGS__); \
+ fputs(out, stdout); \
+ if (out != buf) \
+ XFREE(MTYPE_TMP, out); \
+ } while (0)
+
#undef at
#undef atm
#undef atn
diff --git a/tests/lib/test_atomlist.c b/tests/lib/test_atomlist.c
index 238ee9539e..40837b4722 100644
--- a/tests/lib/test_atomlist.c
+++ b/tests/lib/test_atomlist.c
@@ -29,6 +29,7 @@
#include "atomlist.h"
#include "seqlock.h"
#include "monotime.h"
+#include "printfrr.h"
/*
* maybe test:
@@ -288,7 +289,7 @@ static void run_tr(struct testrun *tr)
size_t c = 0, s = 0, n = 0;
struct item *item, *prev, dummy;
- printf("[%02u] %35s %s\n", seqlock_cur(&sqlo) >> 2, "", desc);
+ printfrr("[%02u] %35s %s\n", seqlock_cur(&sqlo) >> 2, "", desc);
fflush(stdout);
if (tr->prefill != NOCLEAR)
@@ -324,7 +325,7 @@ static void run_tr(struct testrun *tr)
}
assert(c == alist_count(&ahead));
}
- printf("\033[1A[%02u] %9"PRId64"us c=%5zu s=%5zu n=%5zu %s\n",
+ printfrr("\033[1A[%02u] %9"PRId64"us c=%5zu s=%5zu n=%5zu %s\n",
sv >> 2, delta, c, s, n, desc);
}
@@ -334,9 +335,9 @@ static void dump(const char *lbl)
struct item *item, *safe;
size_t ctr = 0;
- printf("dumping %s:\n", lbl);
+ printfrr("dumping %s:\n", lbl);
frr_each_safe(alist, &ahead, item) {
- printf("%s %3zu %p %3"PRIu64" %3"PRIu64"\n", lbl, ctr++,
+ printfrr("%s %3zu %p %3"PRIu64" %3"PRIu64"\n", lbl, ctr++,
(void *)item, item->val1, item->val2);
}
}
@@ -362,12 +363,12 @@ static void basic_tests(void)
dump("");
alist_del(&ahead, &itm[1]);
dump("");
- printf("POP: %p\n", alist_pop(&ahead));
+ printfrr("POP: %p\n", alist_pop(&ahead));
dump("");
- printf("POP: %p\n", alist_pop(&ahead));
- printf("POP: %p\n", alist_pop(&ahead));
- printf("POP: %p\n", alist_pop(&ahead));
- printf("POP: %p\n", alist_pop(&ahead));
+ printfrr("POP: %p\n", alist_pop(&ahead));
+ printfrr("POP: %p\n", alist_pop(&ahead));
+ printfrr("POP: %p\n", alist_pop(&ahead));
+ printfrr("POP: %p\n", alist_pop(&ahead));
dump("");
}
#else
diff --git a/tests/lib/test_stream.c b/tests/lib/test_stream.c
index 2ecfc87942..a45c2b4d54 100644
--- a/tests/lib/test_stream.c
+++ b/tests/lib/test_stream.c
@@ -23,6 +23,8 @@
#include <stream.h>
#include <thread.h>
+#include "printfrr.h"
+
static unsigned long long ham = 0xdeadbeefdeadbeef;
struct thread_master *master;
@@ -30,15 +32,15 @@ static void print_stream(struct stream *s)
{
size_t getp = stream_get_getp(s);
- printf("endp: %zu, readable: %zu, writeable: %zu\n", stream_get_endp(s),
- STREAM_READABLE(s), STREAM_WRITEABLE(s));
+ printfrr("endp: %zu, readable: %zu, writeable: %zu\n",
+ stream_get_endp(s), STREAM_READABLE(s), STREAM_WRITEABLE(s));
while (STREAM_READABLE(s)) {
- printf("0x%x ", *stream_pnt(s));
+ printfrr("0x%x ", *stream_pnt(s));
stream_forward_getp(s, 1);
}
- printf("\n");
+ printfrr("\n");
/* put getp back to where it was */
stream_set_getp(s, getp);
@@ -61,10 +63,10 @@ int main(void)
print_stream(s);
- printf("c: 0x%hhx\n", stream_getc(s));
- printf("w: 0x%hx\n", stream_getw(s));
- printf("l: 0x%x\n", stream_getl(s));
- printf("q: 0x%" PRIx64 "\n", stream_getq(s));
+ printfrr("c: 0x%hhx\n", stream_getc(s));
+ printfrr("w: 0x%hx\n", stream_getw(s));
+ printfrr("l: 0x%x\n", stream_getl(s));
+ printfrr("q: 0x%" PRIx64 "\n", stream_getq(s));
return 0;
}
diff --git a/tests/lib/test_typelist.c b/tests/lib/test_typelist.c
index 2438fb5f08..607e29e56b 100644
--- a/tests/lib/test_typelist.c
+++ b/tests/lib/test_typelist.c
@@ -35,6 +35,7 @@
#include "monotime.h"
#include "jhash.h"
#include "sha256.h"
+#include "printfrr.h"
#include "tests/helpers/c/prng.h"
@@ -90,14 +91,14 @@ static void ts_ref(const char *text)
{
int64_t us;
us = monotime_since(&ref, NULL);
- printf("%7"PRId64"us %s\n", us, text);
+ printfrr("%7"PRId64"us %s\n", us, text);
monotime(&ref);
}
static void ts_end(void)
{
int64_t us;
us = monotime_since(&ref0, NULL);
- printf("%7"PRId64"us total\n", us);
+ printfrr("%7"PRId64"us total\n", us);
}
#define TYPE LIST
diff --git a/tests/lib/test_typelist.h b/tests/lib/test_typelist.h
index 9039fa8a46..da3530e9c0 100644
--- a/tests/lib/test_typelist.h
+++ b/tests/lib/test_typelist.h
@@ -123,10 +123,10 @@ static void ts_hash(const char *text, const char *expect)
for (i = 0; i < sizeof(hash); i++)
sprintf(hashtext + i * 2, "%02x", hash[i]);
- printf("%7"PRId64"us %-25s %s%s\n", us, text,
+ printfrr("%7"PRId64"us %-25s %s%s\n", us, text,
expect ? " " : "*", hashtext);
if (expect && strcmp(expect, hashtext)) {
- printf("%-21s %s\n", "EXPECTED:", expect);
+ printfrr("%-21s %s\n", "EXPECTED:", expect);
assert(0);
}
monotime(&ref);
@@ -149,7 +149,7 @@ static void concat(test_, TYPE)(void)
for (i = 0; i < NITEM; i++)
itm[i].val = i;
- printf("%s start\n", str(TYPE));
+ printfrr("%s start\n", str(TYPE));
ts_start();
list_init(&head);
@@ -530,7 +530,7 @@ static void concat(test_, TYPE)(void)
list_fini(&head);
ts_ref("fini");
ts_end();
- printf("%s end\n", str(TYPE));
+ printfrr("%s end\n", str(TYPE));
}
#undef ts_hashx