0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-23 10:11:53 +00:00

Birdtest: Refactore tests and build system

Rename directory:
  birdtest/* -> test/*

Rename Makefile rule:
  build-tests -> tests

Move run-all-test shell script from Makefile to stand-alone shell script

Simplify Makefile test build system
This commit is contained in:
Pavel Tvrdík 2015-03-23 17:40:13 +01:00
parent 99d14b1ab3
commit f26cf70152
8 changed files with 76 additions and 71 deletions

View File

@ -6,7 +6,7 @@
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
#include "birdtest.h" #include "test/birdtest.h"
#include "lib/heap.h" #include "lib/heap.h"
#define MAX_NUM 1000 #define MAX_NUM 1000
@ -14,6 +14,12 @@
#define MY_CMP(x, y) ((x) < (y)) #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 num;
static int heap[MAX_NUM+1]; static int heap[MAX_NUM+1];
@ -29,16 +35,6 @@ static int heap[MAX_NUM+1];
bt_debug("NON-VALID HEAP! \n"); \ bt_debug("NON-VALID HEAP! \n"); \
} while(0) } 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 static int
is_heap_valid(int heap[], uint num) is_heap_valid(int heap[], uint num)
{ {
@ -79,7 +75,7 @@ t_heap_insert(void)
{ {
bt_debug("ins %d at pos %d ", MAX_NUM - i, i); bt_debug("ins %d at pos %d ", MAX_NUM - i, i);
heap[i] = MAX_NUM - 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); SHOW_HEAP(heap);
bt_assert(is_heap_valid(heap, num)); bt_assert(is_heap_valid(heap, num));
} }
@ -100,13 +96,13 @@ t_heap_increase_decrease(void)
{ {
bt_debug("inc %d ", i); bt_debug("inc %d ", i);
heap[i] = 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]) else if (i < heap[i])
{ {
bt_debug("dec %d ", i); bt_debug("dec %d ", i);
heap[i] = 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); SHOW_HEAP(heap);
bt_assert(is_heap_valid(heap, num)); bt_assert(is_heap_valid(heap, num));
@ -126,7 +122,7 @@ t_heap_delete(void)
for(i = 1; i <= num; i++) for(i = 1; i <= num; i++)
{ {
bt_debug("del at pos %d ", 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); SHOW_HEAP(heap);
bt_assert(is_heap_valid(heap, num)); bt_assert(is_heap_valid(heap, num));
} }

View File

@ -6,7 +6,7 @@
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
#include "birdtest.h" #include "test/birdtest.h"
#include "lib/lists.h" #include "lib/lists.h"
#define MAX_NUM 1000 #define MAX_NUM 1000
@ -70,7 +70,7 @@ is_empty_list_well_unlinked(void)
} }
static void static void
_init_list2(list *l, struct node nodes[]) init_list_2(list *l, struct node nodes[])
{ {
init_list(l); init_list(l);
@ -83,9 +83,9 @@ _init_list2(list *l, struct node nodes[])
} }
static void static void
_init_list(void) init_list_(void)
{ {
_init_list2(&l, (node *) nodes); init_list_2(&l, (node *) nodes);
} }
static int static int
@ -93,7 +93,7 @@ t_add_tail(void)
{ {
int i; int i;
_init_list(); init_list_();
for (i = 0; i < MAX_NUM; i++) for (i = 0; i < MAX_NUM; i++)
{ {
add_tail(&l, &nodes[i]); add_tail(&l, &nodes[i]);
@ -118,7 +118,7 @@ t_add_head(void)
{ {
int i; int i;
_init_list(); init_list_();
for (i = MAX_NUM-1; i >= 0; i--) for (i = MAX_NUM-1; i >= 0; i--)
{ {
add_head(&l, &nodes[i]); add_head(&l, &nodes[i]);
@ -138,7 +138,7 @@ t_add_head(void)
} }
static void static void
_insert_node(node *n, node *after) insert_node_(node *n, node *after)
{ {
insert_node(n, after); insert_node(n, after);
bt_debug("."); bt_debug(".");
@ -149,18 +149,18 @@ t_insert_node(void)
{ {
int i; int i;
_init_list(); init_list_();
// add first node // add first node
_insert_node(&nodes[0], NODE &l.head); insert_node_(&nodes[0], NODE &l.head);
// add odd nodes // add odd nodes
for (i = 2; i < MAX_NUM; i+=2) 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 // add even nodes
for (i = 1; i < MAX_NUM; i+=2) 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_debug("\n");
bt_assert(is_filled_list_well_linked()); bt_assert(is_filled_list_well_linked());
@ -187,7 +187,7 @@ t_remove_node(void)
{ {
int i; int i;
_init_list(); init_list_();
/* Fill & Remove & Check */ /* Fill & Remove & Check */
fill_list(); fill_list();
@ -223,7 +223,7 @@ t_remove_node(void)
static int static int
t_replace_node(void) t_replace_node(void)
{ {
_init_list(); init_list_();
show_list(); show_list();
fill_list(); fill_list();
@ -256,10 +256,10 @@ t_add_tail_list(void)
node nodes2[MAX_NUM]; node nodes2[MAX_NUM];
list l2; list l2;
_init_list2(&l, (node *) nodes); init_list_2(&l, (node *) nodes);
fill_list2(&l, (node *) nodes); fill_list2(&l, (node *) nodes);
_init_list2(&l2, (node *) nodes2); init_list_2(&l2, (node *) nodes2);
fill_list2(&l2, (node *) nodes2); fill_list2(&l2, (node *) nodes2);
add_tail_list(&l, &l2); add_tail_list(&l, &l2);

View File

@ -9,11 +9,12 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "birdtest.h" #include "test/birdtest.h"
static const char *request; static const char *request;

View File

@ -13,6 +13,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
// TODO: add a pseudo random number generator with fixed seed
extern int bt_verbose; extern int bt_verbose;
extern const char *bt_filename; extern const char *bt_filename;

View File

@ -3,32 +3,14 @@
objdir=@objdir@ objdir=@objdir@
all depend tags install install-docs build-tests: all depend tags install install-docs tests:
$(MAKE) -C $(objdir) $@ $(MAKE) -C $(objdir) $@
docs userdocs progdocs: docs userdocs progdocs:
$(MAKE) -C doc $@ $(MAKE) -C doc $@
check: build-tests check: tests
@all_tests=( `find . -name '*_test' -executable` ) ; \ tools/run_tests.sh $(objdir) $(srcdir)
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 "------------------------------"
clean: clean:
$(MAKE) -C $(objdir) clean $(MAKE) -C $(objdir) clean

View File

@ -1,22 +1,21 @@
# Makefile for the BIRD Internet Routing Daemon # Makefile for the BIRD Internet Routing Daemon
# (c) 1999--2000 Martin Mares <mj@ucw.cz> # (c) 1999--2000 Martin Mares <mj@ucw.cz>
root-rel=./
include Rules include Rules
.PHONY: all daemon birdc birdcl subdir depend clean distclean tags docs userdocs progdocs .PHONY: all daemon birdc birdcl subdir depend clean distclean tags docs userdocs progdocs
all: sysdep/paths.h .dep-stamp subdir daemon birdcl @CLIENT@ 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 $(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 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 test/birdtest.o: $(srcdir)/test/birdtest.c
$(AR) rcs $@ $^ mkdir -p test
$(CC) $(CFLAGS) $(TARGET_ARCH) -c $^ $(LDLIBS) -o $@
birdtest/birdtest.o: $(srcdir)/birdtest/birdtest.c
mkdir -p birdtest
$(CC) $(CFLAGS) -I$(srcdir)/birdtest $(TARGET_ARCH) -c $^ $(LDLIBS) -o $@
daemon: $(exedir)/bird daemon: $(exedir)/bird

View File

@ -41,19 +41,14 @@ sysconfdir=@sysconfdir@
localstatedir=@localstatedir@ localstatedir=@localstatedir@
docdir=@prefix@/doc docdir=@prefix@/doc
test-src-path := $(srcdir)/$(dir-name)/
build-tests: tests_sources := $(wildcard $(srcdir)/$(dir-name)/*_test.c)
@for i in `find $(test-src-path) -name '*_test.c'` ; do \ tests_executables := $(notdir $(basename $(tests_sources)))
testname=`basename $$i .c` ; \
testobj=$${testname}.o ; \ tests: $(tests_executables)
printf "$(CC) $(CFLAGS) -I $(srcdir)/birdtest/ -o $$testobj -c $$i && " ; \
printf "$(CC) $(LDFLAGS) $$testobj -o $$testname $(root-rel)birdtest/birdtest.a || " ; \ %_test: $(srcdir)/$(dir-name)/%_test.c
printf "rm -rf $$testname \n" ; \ $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(root-rel)test/birdtest.o
$(CC) $(CFLAGS) -I $(srcdir)/birdtest/ -o $$testobj -c $$i && \
$(CC) $(LDFLAGS) $$testobj -o $$testname $(root-rel)birdtest/birdtest.a || \
rm -rf $$testname ; \
done
ifdef source ifdef source

31
tools/run_tests.sh Executable file
View File

@ -0,0 +1,31 @@
#!/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 " ------------------------------"