From 5419d2a3c5b69dc1199497b6c72b6434501143d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Tvrd=C3=ADk?= Date: Wed, 15 Apr 2015 15:42:43 +0200 Subject: [PATCH] Birdtest: Compability bug fixes Tested on Ubuntu & FreeBSD & NetBSD & OpenBSD --- lib/bitops_test.c | 3 ++- lib/buffer.h | 1 + lib/buffer_test.c | 5 +++-- lib/checksum_test.c | 2 +- lib/heap_test.c | 1 + test/birdtest.c | 5 +++++ test/birdtest.h | 6 +++--- test/birdtest_support.h | 1 + tools/run_tests.sh | 25 ++++++++++++++++++++++--- 9 files changed, 39 insertions(+), 10 deletions(-) diff --git a/lib/bitops_test.c b/lib/bitops_test.c index 4ab978e1..59c0cd56 100644 --- a/lib/bitops_test.c +++ b/lib/bitops_test.c @@ -19,7 +19,8 @@ t_mkmask(void) int i; u32 compute, expect; - for (i = 0; i <= 32; i++) + bt_assert(u32_mkmask(0) == 0x00000000); + for (i = 1; i <= 32; i++) { compute = u32_mkmask(i); expect = (u32) (0xffffffff << (32-i)); diff --git a/lib/buffer.h b/lib/buffer.h index f01eaeeb..6fa6a789 100644 --- a/lib/buffer.h +++ b/lib/buffer.h @@ -8,6 +8,7 @@ #define _BIRD_BUFFER_H_ #include "lib/resource.h" +#include "sysdep/config.h" #define BUFFER(type) struct { type *data; uint used, size; } diff --git a/lib/buffer_test.c b/lib/buffer_test.c index 77e161a5..1298233e 100644 --- a/lib/buffer_test.c +++ b/lib/buffer_test.c @@ -8,6 +8,7 @@ #include #include "test/birdtest.h" +#include "sysdep/config.h" #include "lib/resource.h" #include "lib/buffer.h" @@ -24,8 +25,8 @@ show_buf(buffer_int *b) int i; bt_debug(".used = %d, .size = %d\n", b->used, b->size); - for (i = 0; i < b->size; i++) - bt_debug(" .data[%3i] = %-16d expected %-16d %s\n", i, b->data[i], expected[i], (b->data[i] == expected[i] ? "OK" : "FAIL!")); + for (i = 0; i < b->used; i++) + bt_debug(" .data[%3d] = %-16d expected %-16d %s\n", i, b->data[i], expected[i], (b->data[i] == expected[i] ? "OK" : "FAIL!")); } static void diff --git a/lib/checksum_test.c b/lib/checksum_test.c index 690cd2e2..8306d262 100644 --- a/lib/checksum_test.c +++ b/lib/checksum_test.c @@ -80,7 +80,7 @@ t_verify(void) a[MAX_NUM] = sum; - bt_assert(ipsum_verify(a, sizeof(a) + sizeof(u32), NULL)); + bt_assert(ipsum_verify(a, sizeof(a), NULL)); return BT_SUCCESS; } diff --git a/lib/heap_test.c b/lib/heap_test.c index 8fde031e..2e324ec9 100644 --- a/lib/heap_test.c +++ b/lib/heap_test.c @@ -7,6 +7,7 @@ */ #include "test/birdtest.h" +#include "sysdep/config.h" #include "lib/heap.h" #define MAX_NUM 1000 diff --git a/test/birdtest.c b/test/birdtest.c index 13499269..722be0fb 100644 --- a/test/birdtest.c +++ b/test/birdtest.c @@ -11,7 +11,10 @@ #include #include #include + +#ifdef HAVE_EXECINFO #include +#endif #include #include @@ -106,11 +109,13 @@ bt_init(int argc, char *argv[]) static void dump_stack(void) { +#ifdef HAVE_EXECINFO static void *backbuf[50]; int levels; levels = backtrace(backbuf, 50); backtrace_symbols_fd(backbuf, levels, STDERR_FILENO); +#endif } void diff --git a/test/birdtest.h b/test/birdtest.h index 7edfa52a..ff3010fa 100644 --- a/test/birdtest.h +++ b/test/birdtest.h @@ -117,11 +117,11 @@ void bt_strncat_(char *buf, size_t buf_size, const char *str, ...); #define bt_dump_struct(buf, data) \ do \ { \ - unsigned int i; \ + unsigned int k; \ u32 *pc = (u32*) data; \ bt_strncat(buf, "{"); \ - for (i = 0; i < (sizeof(*data) / sizeof(typeof(*pc))); i++) \ - bt_strncat(buf, "%s0x%08X", (i ? ", " : ""), pc[i]); \ + for (k = 0; k < (sizeof(*data) / sizeof(typeof(*pc))); k++) \ + bt_strncat(buf, "%s0x%08X", (k ? ", " : ""), pc[k]); \ bt_strncat(buf, "}"); \ } while (0) diff --git a/test/birdtest_support.h b/test/birdtest_support.h index 4554cf02..1f5985c0 100644 --- a/test/birdtest_support.h +++ b/test/birdtest_support.h @@ -1,3 +1,4 @@ +#include "sysdep/config.h" #include "lib/event.c" /* REMOVE ME */ #include "lib/ip.c" /* REMOVE ME */ #include "lib/resource.c" /* REMOVE ME */ diff --git a/tools/run_tests.sh b/tools/run_tests.sh index 9d06061f..03c3e78c 100755 --- a/tools/run_tests.sh +++ b/tools/run_tests.sh @@ -3,6 +3,24 @@ objdir=$1 srcdir=$2 +# see if it supports colors... +ncolors=$(tput colors) + +if test -n "$ncolors" && test $ncolors -ge 8; then + bold="$(tput bold)" + underline="$(tput smul)" + standout="$(tput smso)" + normal="$(tput sgr0)" + black="$(tput setaf 0)" + red="$(tput setaf 1)" + green="$(tput setaf 2)" + yellow="$(tput setaf 3)" + blue="$(tput setaf 4)" + magenta="$(tput setaf 5)" + cyan="$(tput setaf 6)" + white="$(tput setaf 7)" +fi + all_tests=$(find "$objdir" -name '*_test') num_all_tests=0 @@ -17,12 +35,13 @@ for test in $all_tests ; do cols=$(tput cols) offset=$((cols-17)) fmt=" [%2d/%-2d] %-${offset}s" - printf "$fmt" $((num_test++)) $num_all_tests "$test" + printf "$fmt" $num_test $num_all_tests "$test" + num_test=$((num_test+1)) if [ $exit_code -eq 0 ]; then - printf "[\e[1;32m OK \e[0m]" + printf "[${green}${bold} OK ${normal}]" num_succ_tests=$((num_succ_tests+1)) else - printf "[\e[1;31mFAIL\e[0m]" + printf "[${red}${bold}FAIL${normal}]" num_fail_tests=$((num_fail_tests+1)) fi printf "\n"