* Can be freely distributed and used under the terms of the GNU GPL.
*/
-#include "birdtest.h"
+#include "test/birdtest.h"
#include "lib/heap.h"
#define MAX_NUM 1000
#define MY_CMP(x, y) ((x) < (y))
+#define MY_HEAP_SWAP(heap,a,b,t) \
+ do { \
+ bt_debug("swap(%d %d) ", a, b); \
+ HEAP_SWAP(heap,a,b,t); \
+ } while(0)
+
static int num;
static int heap[MAX_NUM+1];
bt_debug("NON-VALID HEAP! \n"); \
} while(0)
-
-#undef HEAP_SWAP
-#define HEAP_SWAP(heap,a,b,t) \
- do { \
- t=heap[a]; \
- heap[a]=heap[b]; \
- heap[b]=t; \
- bt_debug("swap(%d %d) ", a, b); \
- } while(0)
-
static int
is_heap_valid(int heap[], uint num)
{
{
bt_debug("ins %d at pos %d ", MAX_NUM - i, i);
heap[i] = MAX_NUM - i;
- HEAP_INSERT(heap, ++num, int, MY_CMP, HEAP_SWAP);
+ HEAP_INSERT(heap, ++num, int, MY_CMP, MY_HEAP_SWAP);
SHOW_HEAP(heap);
bt_assert(is_heap_valid(heap, num));
}
{
bt_debug("inc %d ", i);
heap[i] = i;
- HEAP_INCREASE(heap, num, int, MY_CMP, HEAP_SWAP, i);
+ HEAP_INCREASE(heap, num, int, MY_CMP, MY_HEAP_SWAP, i);
}
else if (i < heap[i])
{
bt_debug("dec %d ", i);
heap[i] = i;
- HEAP_INCREASE(heap, num, int, MY_CMP, HEAP_SWAP, i);
+ HEAP_INCREASE(heap, num, int, MY_CMP, MY_HEAP_SWAP, i);
}
SHOW_HEAP(heap);
bt_assert(is_heap_valid(heap, num));
for(i = 1; i <= num; i++)
{
bt_debug("del at pos %d ", i);
- HEAP_DELETE(heap, num, int, MY_CMP, HEAP_SWAP, i);
+ HEAP_DELETE(heap, num, int, MY_CMP, MY_HEAP_SWAP, i);
SHOW_HEAP(heap);
bt_assert(is_heap_valid(heap, num));
}
* Can be freely distributed and used under the terms of the GNU GPL.
*/
-#include "birdtest.h"
+#include "test/birdtest.h"
#include "lib/lists.h"
#define MAX_NUM 1000
}
static void
-_init_list2(list *l, struct node nodes[])
+init_list_2(list *l, struct node nodes[])
{
init_list(l);
}
static void
-_init_list(void)
+init_list_(void)
{
- _init_list2(&l, (node *) nodes);
+ init_list_2(&l, (node *) nodes);
}
static int
{
int i;
- _init_list();
+ init_list_();
for (i = 0; i < MAX_NUM; i++)
{
add_tail(&l, &nodes[i]);
{
int i;
- _init_list();
+ init_list_();
for (i = MAX_NUM-1; i >= 0; i--)
{
add_head(&l, &nodes[i]);
}
static void
-_insert_node(node *n, node *after)
+insert_node_(node *n, node *after)
{
insert_node(n, after);
bt_debug(".");
{
int i;
- _init_list();
+ init_list_();
// add first node
- _insert_node(&nodes[0], NODE &l.head);
+ insert_node_(&nodes[0], NODE &l.head);
// add odd nodes
for (i = 2; i < MAX_NUM; i+=2)
- _insert_node(&nodes[i], &nodes[i-2]);
+ insert_node_(&nodes[i], &nodes[i-2]);
// add even nodes
for (i = 1; i < MAX_NUM; i+=2)
- _insert_node(&nodes[i], &nodes[i-1]);
+ insert_node_(&nodes[i], &nodes[i-1]);
bt_debug("\n");
bt_assert(is_filled_list_well_linked());
{
int i;
- _init_list();
+ init_list_();
/* Fill & Remove & Check */
fill_list();
static int
t_replace_node(void)
{
- _init_list();
+ init_list_();
show_list();
fill_list();
node nodes2[MAX_NUM];
list l2;
- _init_list2(&l, (node *) nodes);
+ init_list_2(&l, (node *) nodes);
fill_list2(&l, (node *) nodes);
- _init_list2(&l2, (node *) nodes2);
+ init_list_2(&l2, (node *) nodes2);
fill_list2(&l2, (node *) nodes2);
add_tail_list(&l, &l2);
#include <stdint.h>
#include <string.h>
#include <unistd.h>
+#include <signal.h>
#include <sys/resource.h>
#include <sys/wait.h>
-#include "birdtest.h"
+#include "test/birdtest.h"
static const char *request;
#include <string.h>
#include <errno.h>
+// TODO: add a pseudo random number generator with fixed seed
extern int bt_verbose;
extern const char *bt_filename;
objdir=@objdir@
-all depend tags install install-docs build-tests:
+all depend tags install install-docs tests:
$(MAKE) -C $(objdir) $@
docs userdocs progdocs:
$(MAKE) -C doc $@
-check: build-tests
- @all_tests=( `find . -name '*_test' -executable` ) ; \
- all_tests_source=( `find . -name '*_test.c'` ) ; \
- num_build_fail_tests=$$(($${#all_tests_source[@]} - $${#all_tests[@]})) ; \
- test_num=1 ; \
- num_succ_tests=0 ; \
- num_fail_tests=0 ; \
- echo -e "\n== Start all $${#all_tests[@]} unit tests ==\n" ; \
- for test in "$${all_tests[@]}" ; do \
- echo -e "[$$((test_num++))/$${#all_tests[@]}] $$test" ; \
- ./$$test \
- && num_succ_tests=$$((num_succ_tests+1)) \
- || num_fail_tests=$$((num_fail_tests+1)) ; \
- done ; \
- echo "" ; \
- echo "------------------------------" ; \
- echo " Success: $$num_succ_tests" ; \
- echo " Failure: $$num_fail_tests" ; \
- echo " Build-Failure: $$num_build_fail_tests" ; \
- echo "------------------------------"
+check: tests
+ tools/run_tests.sh $(objdir) $(srcdir)
clean:
$(MAKE) -C $(objdir) clean
# Makefile for the BIRD Internet Routing Daemon
# (c) 1999--2000 Martin Mares <mj@ucw.cz>
+root-rel=./
+
include Rules
.PHONY: all daemon birdc birdcl subdir depend clean distclean tags docs userdocs progdocs
all: sysdep/paths.h .dep-stamp subdir daemon birdcl @CLIENT@
-build-tests: birdtest/birdtest.a
+tests: test/birdtest.o
set -e ; for a in $(dynamic-dirs) ; do $(MAKE) -C $$a $@ ; done
set -e ; for a in $(static-dirs) $(client-dirs) ; do $(MAKE) -C $$a -f $(srcdir_abs)/$$a/Makefile $@ ; done
-birdtest/birdtest.a: birdtest/birdtest.o
- $(AR) rcs $@ $^
-
-birdtest/birdtest.o: $(srcdir)/birdtest/birdtest.c
- mkdir -p birdtest
- $(CC) $(CFLAGS) -I$(srcdir)/birdtest $(TARGET_ARCH) -c $^ $(LDLIBS) -o $@
+test/birdtest.o: $(srcdir)/test/birdtest.c
+ mkdir -p test
+ $(CC) $(CFLAGS) $(TARGET_ARCH) -c $^ $(LDLIBS) -o $@
daemon: $(exedir)/bird
localstatedir=@localstatedir@
docdir=@prefix@/doc
-test-src-path := $(srcdir)/$(dir-name)/
-
-build-tests:
- @for i in `find $(test-src-path) -name '*_test.c'` ; do \
- testname=`basename $$i .c` ; \
- testobj=$${testname}.o ; \
- printf "$(CC) $(CFLAGS) -I $(srcdir)/birdtest/ -o $$testobj -c $$i && " ; \
- printf "$(CC) $(LDFLAGS) $$testobj -o $$testname $(root-rel)birdtest/birdtest.a || " ; \
- printf "rm -rf $$testname \n" ; \
- $(CC) $(CFLAGS) -I $(srcdir)/birdtest/ -o $$testobj -c $$i && \
- $(CC) $(LDFLAGS) $$testobj -o $$testname $(root-rel)birdtest/birdtest.a || \
- rm -rf $$testname ; \
- done
+
+tests_sources := $(wildcard $(srcdir)/$(dir-name)/*_test.c)
+tests_executables := $(notdir $(basename $(tests_sources)))
+
+tests: $(tests_executables)
+
+%_test: $(srcdir)/$(dir-name)/%_test.c
+ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(root-rel)test/birdtest.o
ifdef source
--- /dev/null
+#!/bin/sh
+
+objdir=$1
+srcdir=$2
+
+all_tests=$(find $objdir -name '*_test')
+
+num_all_tests=0
+for i in $all_tests; do num_all_tests=$((num_all_tests + 1)); done
+
+num_test=1
+num_succ_tests=0
+num_fail_tests=0
+echo -e " == Start all $num_all_tests unit tests ==\n"
+for test in $all_tests ; do
+ echo -e " [$((num_test++))/$num_all_tests] $test"
+ ./$test \
+ && num_succ_tests=$((num_succ_tests+1)) \
+ || num_fail_tests=$((num_fail_tests+1))
+done
+
+num_all_tests_src=0
+for i in $(find $srcdir -name '*_test.c'); do num_all_tests_src=$((num_all_tests_src + 1)); done
+num_build_fail_tests=$((num_all_tests_src - num_all_tests))
+
+echo ""
+echo " ------------------------------"
+echo " Success: $num_succ_tests"
+echo " Failure: $num_fail_tests"
+echo " Build-Failure: $num_build_fail_tests"
+echo " ------------------------------"