mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-01-03 05:19:34 -05:00
host cache test.
git-svn-id: file:///svn/unbound/trunk@321 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
7a4e1baca9
commit
cb0d7805e2
2 changed files with 56 additions and 0 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue