From d16050108f072341c915ac2c298e317a988e4f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Tvrd=C3=ADk?= Date: Tue, 4 Aug 2015 10:25:47 +0200 Subject: [PATCH] Birdtest: Tunning IP tests, Hash tests --- lib/hash_test.c | 4 ++++ lib/ip_test.c | 50 ++++++++++++++++--------------------------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/lib/hash_test.c b/lib/hash_test.c index b325f967..e6412431 100644 --- a/lib/hash_test.c +++ b/lib/hash_test.c @@ -6,6 +6,8 @@ * Can be freely distributed and used under the terms of the GNU GPL. */ +#undef LOCAL_DEBUG + #include "test/birdtest.h" #include "test/birdtest_support.h" /* REMOVE ME */ @@ -47,6 +49,7 @@ print_rate_of_fulfilment(void) bt_debug("%d (%.2f %%) chained of %d hashes \n", num_stacked_items, percent_stacked_items, MAX_NUM); } +#ifdef LOCAL_DEBUG static void dump_nodes(void) { @@ -54,6 +57,7 @@ dump_nodes(void) for (i = 0; i < MAX_NUM; i++) bt_debug("nodes[%3d] is at address %14p has .key %3d, .next %14p \n", i, &nodes[i], nodes[i].key, nodes[i].next); } +#endif static void init_hash_(uint order) diff --git a/lib/ip_test.c b/lib/ip_test.c index 8bab9eaf..90ce3ade 100644 --- a/lib/ip_test.c +++ b/lib/ip_test.c @@ -13,88 +13,70 @@ #define IP4_MAX_LEN 16 -static u32 -ip4_pton_(char *s) -{ - ip4_addr ip; - ip4_pton(s,&ip); - return ip4_to_u32(ip); -} - static int t_ip4_pton(void) { struct in_out { char in[IP4_MAX_LEN]; - u32 out; + ip4_addr out; } in_out[] = { { .in = "192.168.1.128", - .out = ip4_to_u32(ip4_build(192, 168, 1, 128)), + .out = ip4_build(192, 168, 1, 128), }, { .in = "255.255.255.255", - .out = ip4_to_u32(ip4_build(255, 255, 255, 255)), + .out = ip4_build(255, 255, 255, 255), }, { .in = "0.0.0.0", - .out = ip4_to_u32(ip4_build(0, 0, 0, 0)), + .out = ip4_build(0, 0, 0, 0), }, }; - bt_assert_out_fn_in(ip4_pton_, in_out, "'%s'", NULL); + bt_assert_fn_in_out(ip4_pton, in_out, "'%s'", NULL); return bt_test_suite_success; } -static void -ip6_pton_(char *s, u32 (*addr)[4]) -{ - static ip6_addr ip; - ip6_pton(s, &ip); - int i; - for (i = 0; i < 4; i++) - (*addr)[i] = ip.addr[i]; -} - static int t_ip6_pton(void) { struct in_out { char *in; - u32 out[4]; + ip6_addr out; } in_out[] = { { .in = "2001:0db8:0000:0000:0000:0000:1428:57ab", - .out = {0x20010DB8, 0x00000000, 0x00000000, 0x142857AB}, + .out = ip6_build(0x20010DB8, 0x00000000, 0x00000000, 0x142857AB), }, { .in = "2001:0db8:0000:0000:0000::1428:57ab", - .out = {0x20010DB8, 0x00000000, 0x00000000, 0x142857AB}, + .out = ip6_build(0x20010DB8, 0x00000000, 0x00000000, 0x142857AB), }, { .in = "2001:0db8::1428:57ab", - .out = {0x20010DB8, 0x00000000, 0x00000000, 0x142857AB}, + .out = ip6_build(0x20010DB8, 0x00000000, 0x00000000, 0x142857AB), }, { .in = "2001:db8::1428:57ab", - .out = {0x20010DB8, 0x00000000, 0x00000000, 0x142857AB}, + .out = ip6_build(0x20010DB8, 0x00000000, 0x00000000, 0x142857AB), }, { .in = "::1", - .out = {0x00000000, 0x00000000, 0x00000000, 0x00000001}, + .out = ip6_build(0x00000000, 0x00000000, 0x00000000, 0x00000001), }, { .in = "::", - .out = {0x00000000, 0x00000000, 0x00000000, 0x00000000}, + .out = ip6_build(0x00000000, 0x00000000, 0x00000000, 0x00000000), }, { .in = "2605:2700:0:3::4713:93e3", - .out = {0x26052700, 0x00000003, 0x00000000, 0x471393E3}, + .out = ip6_build(0x26052700, 0x00000003, 0x00000000, 0x471393E3), }, }; - bt_assert_fn_in_out(ip6_pton_, in_out, "'%s'", NULL); + bt_assert_fn_in_out(ip6_pton, in_out, "'%s'", NULL); return bt_test_suite_success; } @@ -146,11 +128,11 @@ t_ip6_ntop(void) char out[INET6_ADDRSTRLEN]; } in_out[] = { { - .in = { .addr = {0x20010DB8, 0x00000000, 0x00000000, 0x142857AB}}, + .in = ip6_build(0x20010DB8, 0x00000000, 0x00000000, 0x142857AB), .out = "2001:db8::1428:57ab", }, { - .in = { .addr = {0x26052700, 0x00000003, 0x00000000, 0x471393E3}}, + .in = ip6_build(0x26052700, 0x00000003, 0x00000000, 0x471393E3), .out = "2605:2700:0:3::4713:93e3", }, };