From 9b0a0ba9e671d9134b93c33ab73ccccb352acafa Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Wed, 9 Nov 2016 16:36:34 +0100 Subject: [PATCH] Unit Testing for BIRD - Unit Testing Framework (BirdTest) - Integration of BirdTest into the BIRD build system - Tests for several BIRD modules Based on squashed Pavel Tvrdik's int-test branch, updated for current int-new branch. --- Makefile.in | 33 +- conf/Makefile | 2 + conf/conf.c | 7 +- conf/conf.h | 6 +- configure.in | 5 +- doc/bird.sgml | 2 +- filter/Makefile | 4 + filter/config.Y | 98 ++- filter/filter.c | 17 +- filter/filter.h | 21 +- filter/filter_test.c | 87 +++ filter/test.conf | 1321 ++++++++++++++++++++++---------- filter/test.conf.inc | 1 + filter/test.conf2 | 94 +-- filter/test6.conf | 17 +- filter/test_bgp_filtering.conf | 113 +++ filter/tree_test.c | 304 ++++++++ filter/trie_test.c | 184 +++++ lib/Makefile | 4 + lib/birdlib.h | 3 +- lib/bitops.h | 2 + lib/bitops_test.c | 123 +++ lib/buffer_test.c | 147 ++++ lib/checksum_test.c | 94 +++ lib/event_test.c | 88 +++ lib/fletcher16_test.c | 169 ++++ lib/hash_test.c | 305 ++++++++ lib/heap_test.c | 186 +++++ lib/ip.c | 2 +- lib/ip_test.c | 161 ++++ lib/lists_test.c | 287 +++++++ lib/mac_test.c | 1159 ++++++++++++++++++++++++++++ lib/patmatch_test.c | 149 ++++ lib/printf_test.c | 70 ++ lib/slist_test.c | 384 ++++++++++ lib/slists.c | 82 -- nest/Makefile | 4 + nest/a-path.c | 3 +- nest/a-path_test.c | 214 ++++++ nest/a-set_test.c | 260 +++++++ nest/iface.h | 1 + nest/route.h | 2 +- proto/bfd/Makefile | 2 + proto/bgp/Makefile | 2 + proto/ospf/Makefile | 2 + proto/ospf/rt.c | 2 +- proto/pipe/Makefile | 2 + proto/radv/Makefile | 2 + proto/radv/radv.c | 2 +- proto/rip/Makefile | 2 + proto/static/Makefile | 2 + sysdep/autoconf.h.in | 3 + sysdep/bsd/Makefile | 1 + sysdep/linux/Makefile | 2 + sysdep/unix/Makefile | 3 + test/Makefile | 3 + test/birdtest.c | 488 ++++++++++++ test/birdtest.h | 183 +++++ test/bt-utils.c | 223 ++++++ test/bt-utils.h | 35 + 60 files changed, 6595 insertions(+), 579 deletions(-) create mode 100644 filter/filter_test.c create mode 100644 filter/test_bgp_filtering.conf create mode 100644 filter/tree_test.c create mode 100644 filter/trie_test.c create mode 100644 lib/bitops_test.c create mode 100644 lib/buffer_test.c create mode 100644 lib/checksum_test.c create mode 100644 lib/event_test.c create mode 100644 lib/fletcher16_test.c create mode 100644 lib/hash_test.c create mode 100644 lib/heap_test.c create mode 100644 lib/ip_test.c create mode 100644 lib/lists_test.c create mode 100644 lib/mac_test.c create mode 100644 lib/patmatch_test.c create mode 100644 lib/printf_test.c create mode 100644 lib/slist_test.c create mode 100644 nest/a-path_test.c create mode 100644 nest/a-set_test.c create mode 100644 test/Makefile create mode 100644 test/birdtest.c create mode 100644 test/birdtest.h create mode 100644 test/bt-utils.c create mode 100644 test/bt-utils.h diff --git a/Makefile.in b/Makefile.in index cee217be..63d3351f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -22,7 +22,7 @@ INSTALL_DATA=@INSTALL_DATA@ client=$(addprefix $(exedir)/,@CLIENT@) daemon=$(exedir)/bird -protocols = @protocols@ +protocols=@protocols@ prefix=@prefix@ exec_prefix=@exec_prefix@ @@ -49,24 +49,26 @@ else endif # Meta rules -cleangoals := clean distclean docgoals := docs userdocs progdocs -.PHONY: all daemon cli $(cleangoals) $(docgoals) tags +testgoals := check test tests tests_run +cleangoals := clean distclean testsclean +.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags all: daemon cli daemon: $(daemon) cli: $(client) # Include directories -dirs := client conf doc filter lib nest $(addprefix proto/,$(protocols)) @sysdep_dirs@ +dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@ conf-y-targets := $(addprefix $(objdir)/conf/,cf-parse.y keywords.h commands.h) cf-local = $(conf-y-targets): $(s)config.Y src-o-files = $(patsubst %.c,$(o)%.o,$(src)) +tests-target-files = $(patsubst %.c,$(o)%,$(tests_src)) -all-daemon = $(exedir)/bird: $(obj) -all-client = $(exedir)/birdc $(exedir)/birdcl: $(obj) +all-daemon = $(daemon): $(obj) +all-client = $(client): $(obj) s = $(dir $(lastword $(MAKEFILE_LIST))) ifeq ($(srcdir),.) @@ -109,6 +111,22 @@ $(objdir)/sysdep/paths.h: Makefile echo >>$@ "#define PATH_CONTROL_SOCKET \"@CONTROL_SOCKET@\"" if test -n "@iproutedir@" ; then echo >>$@ "#define PATH_IPROUTE_DIR \"@iproutedir@\"" ; fi +# Unit tests rules + +tests_targets_ok = $(addsuffix .ok,$(tests_targets)) + +$(tests_targets): %: %.o $(tests_objs) + $(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS) + $(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + +$(tests_targets_ok): %.ok: % + $(Q)$* 2>/dev/null && touch $*.ok + +test: testsclean check +check: tests tests_run +tests: $(tests_targets) +tests_run: $(tests_targets_ok) + # Finally include the computed dependencies ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),) @@ -147,6 +165,9 @@ clean:: rm -f $(addprefix $(exedir)/,bird birdc birdcl) find $(objdir) -name "*.[od]" -exec rm -f '{}' '+' +testsclean: + rm -f $(tests_targets_ok) + ifeq ($(objdir),obj) distclean: clean rm -rf $(objdir) diff --git a/conf/Makefile b/conf/Makefile index e5828538..cc2b13c6 100644 --- a/conf/Makefile +++ b/conf/Makefile @@ -3,6 +3,8 @@ obj := $(src-o-files) $(all-daemon) +tests_objs := $(tests_objs) $(src-o-files) + ifdef DEBUG BISON_DEBUG=-t #FLEX_DEBUG=-d diff --git a/conf/conf.c b/conf/conf.c index b6f41b2c..3ae85cb2 100644 --- a/conf/conf.c +++ b/conf/conf.c @@ -49,12 +49,10 @@ #include "nest/route.h" #include "nest/protocol.h" #include "nest/iface.h" -#include "lib/resource.h" -#include "lib/string.h" #include "lib/event.h" #include "sysdep/unix/timer.h" #include "conf/conf.h" -#include "filter/filter.h" + static jmp_buf conf_jmpbuf; @@ -85,7 +83,7 @@ int undo_available; /* Undo was not requested from last reconfiguration */ * further use. Returns a pointer to the structure. */ struct config * -config_alloc(const byte *name) +config_alloc(const char *name) { pool *p = rp_new(&root_pool, "Config"); linpool *l = lp_new(p, 4080); @@ -96,6 +94,7 @@ config_alloc(const byte *name) char *ndup = lp_allocu(l, nlen); memcpy(ndup, name, nlen); + init_list(&c->tests); c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */ c->pool = p; c->mem = l; diff --git a/conf/conf.h b/conf/conf.h index 593a5f13..cb5ade47 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -9,6 +9,8 @@ #ifndef _BIRD_CONF_H_ #define _BIRD_CONF_H_ +#include "sysdep/config.h" +#include "lib/ip.h" #include "lib/resource.h" #include "sysdep/unix/timer.h" @@ -21,6 +23,7 @@ struct config { list protos; /* Configured protocol instances (struct proto_config) */ list tables; /* Configured routing tables (struct rtable_config) */ list logfiles; /* Configured log files (sysdep) */ + list tests; /* Configured unit tests */ int mrtdump_file; /* Configured MRTDump file (sysdep, fd in unix) */ char *syslog_name; /* Name used for syslog (NULL -> no syslog) */ @@ -60,7 +63,7 @@ struct config { extern struct config *config; /* Currently active configuration */ extern struct config *new_config; /* Configuration being parsed */ -struct config *config_alloc(const byte *name); +struct config *config_alloc(const char *name); int config_parse(struct config *); int cli_parse(struct config *); void config_free(struct config *); @@ -161,6 +164,7 @@ static inline int cf_symbol_is_constant(struct symbol *sym) /* Parser */ +extern char *cf_text; int cf_parse(void); /* Sysdep hooks */ diff --git a/configure.in b/configure.in index 58f865c4..912598b8 100644 --- a/configure.in +++ b/configure.in @@ -56,7 +56,7 @@ if test "$ac_test_CFLAGS" != set ; then bird_cflags_default=yes fi -AC_PROG_CC +AC_PROG_CC_C99 if test -z "$GCC" ; then AC_MSG_ERROR([This program requires the GNU C Compiler.]) fi @@ -220,6 +220,9 @@ BIRD_CHECK_STRUCT_IP_MREQN if test "$enable_debug" = yes ; then AC_DEFINE(DEBUGGING) + AC_CHECK_HEADER(execinfo.h, [AC_SEARCH_LIBS([backtrace, backtrace_symbols], [c execinfo], [AC_DEFINE(HAVE_EXECINFO_H)])]) + LDFLAGS="$LDFLAGS -rdynamic" + CFLAGS="$CFLAGS -O0 -ggdb -g3 -gdwarf-4" if test "$enable_memcheck" = yes ; then AC_CHECK_LIB(dmalloc, dmalloc_debug) if test $ac_cv_lib_dmalloc_dmalloc_debug != yes ; then diff --git a/doc/bird.sgml b/doc/bird.sgml index 6af0e0f6..e70232d1 100644 --- a/doc/bird.sgml +++ b/doc/bird.sgml @@ -1253,7 +1253,7 @@ foot).