From: Pavel TvrdĂ­k Date: Wed, 5 Aug 2015 10:34:21 +0000 (+0200) Subject: Birdtest: Clean up unit tests from mock-ups X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0176f2639683cd5ecaa49642cab8779e42000f5;p=thirdparty%2Fbird.git Birdtest: Clean up unit tests from mock-ups --- diff --git a/lib/bitops_test.c b/lib/bitops_test.c index 59c0cd56f..ac103970b 100644 --- a/lib/bitops_test.c +++ b/lib/bitops_test.c @@ -8,7 +8,6 @@ #include "test/birdtest.h" #include "bitops.h" -#include "bitops.c" /* REMOVE ME */ #define MAX_NUM 1000 #define CHECK_BIT(var,pos) ((var) & (u32)(1<<(pos))) diff --git a/lib/buffer_test.c b/lib/buffer_test.c index 26db52294..f9049f347 100644 --- a/lib/buffer_test.c +++ b/lib/buffer_test.c @@ -7,6 +7,7 @@ */ #include + #include "test/birdtest.h" #include "sysdep/config.h" #include "lib/resource.h" @@ -41,16 +42,11 @@ fill_expected_array(void) static void init_buffer(void) { - buffer_pool = NULL; + resource_init(); + buffer_pool = &root_pool; BUFFER_INIT(buffer, buffer_pool, MAX_NUM); } -static void -free_buffer(void) -{ - free(buffer_pool); -} - static int is_buffer_as_expected(buffer_int *b) { @@ -73,7 +69,6 @@ t_buffer_push(void) BUFFER_PUSH(buffer) = expected[i]; is_buffer_as_expected(&buffer); - free_buffer(); return BT_SUCCESS; } @@ -102,7 +97,6 @@ t_buffer_pop(void) BUFFER_PUSH(buffer) = expected[i]; is_buffer_as_expected(&buffer); - free_buffer(); return BT_SUCCESS; } @@ -111,7 +105,7 @@ t_buffer_resize(void) { int i; - buffer_pool = NULL; + init_buffer(); BUFFER_INIT(buffer, buffer_pool, 0); fill_expected_array(); @@ -120,7 +114,6 @@ t_buffer_resize(void) is_buffer_as_expected(&buffer); bt_assert(buffer.size >= MAX_NUM); - free_buffer(); return BT_SUCCESS; } @@ -137,7 +130,6 @@ t_buffer_flush(void) BUFFER_FLUSH(buffer); bt_assert(buffer.used == 0); - free_buffer(); return BT_SUCCESS; } @@ -153,26 +145,3 @@ main(int argc, char *argv[]) return bt_end(); } - - -/* Mockup */ -void * -mb_alloc(pool *UNUSED, uint size) { - return (void *) malloc(size); -}; - -/* Mockup */ -#define STEP_UP(x) ((x) + (x)/2 + 4) -#define MIN_(a,b) (((a)<(b))?(a):(b)) -#define MIN(a,b) MIN_(a,b) -void -buffer_realloc(void **buf, uint *size, uint need, uint item_size) -{ - uint nsize = MIN(*size, need); - - while (nsize < need) - nsize = STEP_UP(nsize); - - *buf = realloc(*buf, nsize * item_size); - *size = nsize; -} diff --git a/lib/checksum_test.c b/lib/checksum_test.c index 8306d2629..52cecb13e 100644 --- a/lib/checksum_test.c +++ b/lib/checksum_test.c @@ -11,10 +11,7 @@ #include "test/birdtest.h" #include "sysdep/config.h" #include "lib/null.h" - -void bug(const char *msg, ...); #include "lib/checksum.h" -#include "lib/checksum.c" /* REMOVE ME */ #define MAX_NUM 10000 @@ -96,14 +93,3 @@ main(int argc, char *argv[]) return bt_end(); } - -/* Mockup */ -void -bug(const char *msg, ...) -{ - va_list argptr; - va_start(argptr, msg); - vfprintf(stderr, msg, argptr); - va_end(argptr); - abort(); -} diff --git a/lib/event_test.c b/lib/event_test.c index a461b92ef..70f05593e 100644 --- a/lib/event_test.c +++ b/lib/event_test.c @@ -8,9 +8,12 @@ #include "test/birdtest.h" -#include "test/birdtest_support.h" /* REMOVE ME */ - #include "lib/event.h" +#include "conf/conf.h" +#include "nest/locks.h" +#include "lib/unix.h" +#include "nest/iface.h" +#include "nest/route.h" #define MAX_NUM 4 @@ -29,7 +32,7 @@ static void event_hook_3(void *data) { event_hook_body(3); } #define schedule_event(num) \ do { \ - struct event *event_##num = ev_new(pool); \ + struct event *event_##num = ev_new(&root_pool); \ event_##num->hook = event_hook_##num; \ ev_schedule(event_##num); \ } while (0) @@ -49,8 +52,14 @@ t_ev_run_list(void) int i; resource_init(); - init_list(&global_event_list); - struct pool *pool = rp_new(&root_pool, "Test pool"); + olock_init(); + io_init(); + rt_init(); + if_init(); + roa_init(); + config_init(); + config = config_alloc(""); + init_event_check_points(); schedule_event(1); diff --git a/lib/fletcher16_test.c b/lib/fletcher16_test.c index f9c5b4c7e..905e23f26 100644 --- a/lib/fletcher16_test.c +++ b/lib/fletcher16_test.c @@ -1,15 +1,12 @@ /* * BIRD Library -- Fletcher-16 checksum Tests * - * (c) 2015 Ondrej Zajicek * (c) 2015 CZ.NIC z.s.p.o. * * Can be freely distributed and used under the terms of the GNU GPL. */ #include "test/birdtest.h" -#include "test/birdtest_support.h" /* REMOVE ME */ - #include "lib/fletcher16.h" struct in { diff --git a/lib/hash_test.c b/lib/hash_test.c index e6412431e..86d37174c 100644 --- a/lib/hash_test.c +++ b/lib/hash_test.c @@ -9,9 +9,8 @@ #undef LOCAL_DEBUG #include "test/birdtest.h" -#include "test/birdtest_support.h" /* REMOVE ME */ - #include "lib/hash.h" +#include "nest/bird.h" struct test_node { struct test_node *next; /* Hash chain */ diff --git a/lib/ip_test.c b/lib/ip_test.c index 90ce3adea..fe1d0ac30 100644 --- a/lib/ip_test.c +++ b/lib/ip_test.c @@ -7,8 +7,6 @@ */ #include "test/birdtest.h" -#include "test/birdtest_support.h" /* REMOVE ME */ - #include "lib/ip.h" #define IP4_MAX_LEN 16 diff --git a/lib/md5_test.c b/lib/md5_test.c index 700c324bb..5ffbd05bf 100644 --- a/lib/md5_test.c +++ b/lib/md5_test.c @@ -11,7 +11,6 @@ #include "test/birdtest.h" #include "sysdep/config.h" #include "lib/md5.h" -#include "lib/md5.c" /* REMOVE ME */ static void get_md5(const char *str, char (*out_hash)[MD5_HEX_SIZE]) diff --git a/lib/patmatch_test.c b/lib/patmatch_test.c index 2e781d494..932176820 100644 --- a/lib/patmatch_test.c +++ b/lib/patmatch_test.c @@ -7,9 +7,7 @@ */ #include "test/birdtest.h" -#include "test/birdtest_support.h" /* REMOVE ME */ - -#include "lib/patmatch.c" /* REMOVE ME */ +#include "lib/string.h" #define MATCH 1 #define NOMATCH 0 diff --git a/lib/sha256_test.c b/lib/sha256_test.c index 4abf246c4..05e0b2c6f 100644 --- a/lib/sha256_test.c +++ b/lib/sha256_test.c @@ -9,10 +9,8 @@ #include #include "test/birdtest.h" -#include "test/birdtest_support.h" #include "sysdep/config.h" #include "lib/sha256.h" -#include "lib/sha256.c" /* REMOVE ME */ static void diff --git a/lib/sha512_test.c b/lib/sha512_test.c index c059ca2b2..9983d6bd6 100644 --- a/lib/sha512_test.c +++ b/lib/sha512_test.c @@ -9,10 +9,8 @@ #include #include "test/birdtest.h" -#include "test/birdtest_support.h" #include "sysdep/config.h" #include "lib/sha512.h" -#include "lib/sha512.c" /* REMOVE ME */ static void byte_to_hex(char *out, const byte *in, uint len) diff --git a/lib/slist_test.c b/lib/slist_test.c index 5c8189627..b1ce080dc 100644 --- a/lib/slist_test.c +++ b/lib/slist_test.c @@ -7,10 +7,8 @@ */ #include "test/birdtest.h" -#include "test/birdtest_support.h" - #include "lib/slists.h" -#include "lib/slists.c" +#include "lib/resource.h" #define MAX_NUM 1000 diff --git a/test/birdtest_support.h b/test/birdtest_support.h deleted file mode 100644 index 8fb76fecf..000000000 --- a/test/birdtest_support.h +++ /dev/null @@ -1,34 +0,0 @@ -#include "sysdep/config.h" -#include "lib/event.c" /* REMOVE ME */ -#include "lib/ip.c" /* REMOVE ME */ -#include "lib/resource.c" /* REMOVE ME */ -#include "lib/printf.c" /* REMOVE ME */ -#include "lib/xmalloc.c" /* REMOVE ME */ -#include "lib/bitops.c" /* REMOVE ME */ - -#define bug(msg, ...) debug("BUG: " msg, ##__VA_ARGS__) - -void -debug(const char *msg, ...) -{ - va_list argptr; - va_start(argptr, msg); - vfprintf(stderr, msg, argptr); - va_end(argptr); -}; - -void -die(const char *msg, ...) -{ - va_list argptr; - va_start(argptr, msg); - vfprintf(stderr, msg, argptr); - va_end(argptr); - exit(3); -}; - -void -io_log_event(void *hook, void *data) -{ - bt_debug("This is io_log_event mockup. \n"); -};