From cb0d7805e2944075ed9e0f173cddab8cfcf2b4fb Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Tue, 15 May 2007 13:21:10 +0000 Subject: [PATCH] host cache test. git-svn-id: file:///svn/unbound/trunk@321 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 1 + testcode/unitmain.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/doc/Changelog b/doc/Changelog index 5a7e9a61d..5eefcff8c 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,6 @@ 15 May 2007: Wouter - host cache code. + - unit test for host cache. 14 May 2007: Wouter - Port to OS/X and Dec Alpha. Printf format and alignment fixes. diff --git a/testcode/unitmain.c b/testcode/unitmain.c index 82041d0e3..5c107557d 100644 --- a/testcode/unitmain.c +++ b/testcode/unitmain.c @@ -143,6 +143,60 @@ rtt_test() } } +#include "services/cache/infra.h" +#include "util/config_file.h" +/** test host cache */ +static void +infra_test() +{ + int one = 1; + uint8_t* zone = (uint8_t*)"\007example\003com\000"; + size_t zonelen = 13; + struct slabhash* slab; + struct config_file* cfg = config_create(); + time_t now = 0; + int vs, to; + struct infra_host_key* k; + struct infra_host_data* d; + + slab = infra_create(cfg); + unit_assert( infra_host(slab, (struct sockaddr_storage*)&one, + sizeof(int), now, &vs, &to) ); + unit_assert( vs == 0 && to == 3000 ); + + unit_assert( infra_rtt_update(slab, (struct sockaddr_storage*)&one, + sizeof(int), -1, now) ); + unit_assert( infra_host(slab, (struct sockaddr_storage*)&one, + sizeof(int), now, &vs, &to) ); + unit_assert( vs == 0 && to == 6000 ); + + unit_assert( infra_edns_update(slab, (struct sockaddr_storage*)&one, + sizeof(int), -1, now) ); + unit_assert( infra_host(slab, (struct sockaddr_storage*)&one, + sizeof(int), now, &vs, &to) ); + unit_assert( vs == -1 && to == 6000 ); + + now += HOST_TTL + 10; + unit_assert( infra_host(slab, (struct sockaddr_storage*)&one, + sizeof(int), now, &vs, &to) ); + unit_assert( vs == 0 && to == 3000 ); + + unit_assert( infra_set_lame(slab, (struct sockaddr_storage*)&one, + sizeof(int), zone, zonelen, now) ); + unit_assert( (d=infra_lookup_host(slab, (struct sockaddr_storage*)&one, + sizeof(int), 0, now, &k)) ); + unit_assert( d->ttl == now+HOST_TTL ); + unit_assert( d->edns_version == 0 ); + unit_assert( infra_lookup_lame(d, zone, zonelen, now) ); + unit_assert( !infra_lookup_lame(d, zone, zonelen, + now+HOST_LAME_TTL+10) ); + unit_assert( !infra_lookup_lame(d, (uint8_t*)"\000", 1, now) ); + lock_rw_unlock(&k->entry.lock); + + infra_delete(slab); + config_delete(cfg); +} + /** * Main unit test program. Setup, teardown and report errors. * @param argc: arg count. @@ -165,6 +219,7 @@ main(int argc, char* argv[]) alloc_test(); lruhash_test(); slabhash_test(); + infra_test(); msgparse_test(); checklock_stop(); printf("%d checks ok.\n", testcount); -- 2.47.2