Commit 9b0a0ba9 authored by Ondrej Zajicek (work)'s avatar Ondrej Zajicek (work)
Browse files

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.
parent 8860e991
Loading
Loading
Loading
Loading
+27 −6
Original line number Diff line number Diff line
@@ -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)
+2 −0
Original line number Diff line number Diff line
@@ -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
+3 −4
Original line number Diff line number Diff line
@@ -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;
+5 −1
Original line number Diff line number Diff line
@@ -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 */
+4 −1
Original line number Diff line number Diff line
@@ -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
Loading