]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tests: use printfrr-based printf()
authorDavid Lamparter <equinox@diac24.net>
Sun, 29 Mar 2020 08:17:13 +0000 (10:17 +0200)
committerDavid Lamparter <equinox@diac24.net>
Sun, 29 Mar 2020 08:45:46 +0000 (10:45 +0200)
Just a small hack to use printfrr() in tests, since otherwise the
redefined PRId64 trips some warnings.

Signed-off-by: David Lamparter <equinox@diac24.net>
lib/printfrr.h
tests/lib/test_atomlist.c
tests/lib/test_stream.c
tests/lib/test_typelist.c
tests/lib/test_typelist.h

index 6fcfbe31fab3a15311f5ddc7d7badb54b0d3b8a1..7d9e288655b40b7585bf545376da69e63589b3f2 100644 (file)
@@ -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
index 238ee9539e0add36592e4c0e7cf049fe250e5130..40837b4722835e8c9abd123fa23ddac9871a6a45 100644 (file)
@@ -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
index 2ecfc879428427451a33d93a2006f28a6c0ce9dc..a45c2b4d54ef6300d6418221f8bf40978b134025 100644 (file)
@@ -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;
 }
index 2438fb5f08554ce8311b2e0bbd03393faf0feed8..607e29e56b1fe8016f440c8b0d3c303032e5bd5c 100644 (file)
@@ -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
index 9039fa8a464d56647b9e3f1d6475fce0625d8e0f..da3530e9c010523b2ead32771fb68a5da0f224b8 100644 (file)
@@ -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