}
}
+#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.
alloc_test();
lruhash_test();
slabhash_test();
+ infra_test();
msgparse_test();
checklock_stop();
printf("%d checks ok.\n", testcount);