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).