]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
host cache test.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 15 May 2007 13:21:10 +0000 (13:21 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 15 May 2007 13:21:10 +0000 (13:21 +0000)
git-svn-id: file:///svn/unbound/trunk@321 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
testcode/unitmain.c

index 5a7e9a61de9942fee74d33ec00c5990d72b69c31..5eefcff8c0cf3bbd03c9a75350b94936cea5a5ad 100644 (file)
@@ -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.
index 82041d0e3244f6b1d204d7ed90eeb788c757d6d7..5c107557dd4d1b1af1a1e2be683637d564f04d53 100644 (file)
@@ -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);