replay work.

git-svn-id: file:///svn/unbound/trunk@88 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-02-09 16:39:47 +00:00
parent df47ba04d7
commit 71f1b12009
4 changed files with 168 additions and 19 deletions

View file

@ -1,5 +1,8 @@
9 February 2007: Wouter
- replay file reading.
- fake event setup, it creates fake structures, and teardowns,
added signal callbacks to reply to be able to fake those,
and main structure of event replay routines.
8 February 2007: Wouter
- added tcp test.

View file

@ -50,56 +50,163 @@
#include "services/listen_dnsport.h"
#include "services/outside_network.h"
#include "testcode/replay.h"
#include "testcode/ldns-testpkts.h"
/** Global variable: the scenario */
static struct replay_scenario* scenario = NULL;
/** Global variable: the scenario. Saved here for when event_init is done. */
static struct replay_scenario* saved_scenario = NULL;
void
fake_event_init(struct replay_scenario* scen)
{
scenario = scen;
saved_scenario = scen;
}
void
fake_event_cleanup()
{
replay_scenario_delete(scenario);
scenario = NULL;
replay_scenario_delete(saved_scenario);
saved_scenario = NULL;
}
/**
* return: true if pending query matches the now event.
*/
static int
pending_matches_current(struct replay_runtime* runtime)
{
struct fake_pending* p;
if(!runtime->now || runtime->now->evt_type != repevt_back_query
|| !runtime->pending_list)
return 0;
/* see if any of the pending queries matches */
for(p = runtime->pending_list; p; p = p->next) {
if(find_match(runtime->now->match, p->pkt, p->transport))
return 1;
}
return 0;
}
/**
* See if outgoing pending query matches an entry.
* @param runtime: runtime.
* @param entry: if true, the entry that matches is returned.
* @param pend: if true, the outgoing message that matches is returned.
* return: true if pending query matches the now event.
*/
static int
pending_matches_range(struct replay_runtime* runtime,
struct entry** entry, struct fake_pending** pend)
{
}
/**
* Perform range entry on pending message.
* @param runtime: runtime, needed?.
* @param entry: entry that codes for the reply to do.
* @param pend: pending query that is answered, callback called.
*/
static void
answer_callback_from_entry(struct replay_runtime* runtime,
struct entry* entry, struct fake_pending* pend)
{
}
/**
* Perform actions or checks determined by the moment.
*/
static void
do_moment(struct replay_runtime* runtime)
{
if(!runtime->now)
return;
}
/**
* Advance to the next moment.
*/
static void
advance_moment(struct replay_runtime* runtime)
{
if(!runtime->now)
runtime->now = runtime->scenario->mom_first;
else runtime->now = runtime->now->mom_next;
}
/** run the scenario in event callbacks */
static void
run_scenario(struct replay_runtime* runtime)
{
struct entry* entry = NULL;
struct fake_pending* pending = NULL;
runtime->now = NULL;
do {
/* if moment matches pending query do it. */
/* else if precoded_range matches pending, do it */
/* else do the current moment */
if(pending_matches_current(runtime)) {
advance_moment(runtime);
} else if(pending_matches_range(runtime, &entry, &pending)) {
answer_callback_from_entry(runtime, entry, pending);
} else {
do_moment(runtime);
advance_moment(runtime);
}
} while(runtime->now);
}
/*********** Dummy routines ***********/
struct listen_dnsport*
listen_create(struct comm_base* ATTR_UNUSED(base),
listen_create(struct comm_base* base,
int ATTR_UNUSED(num_ifs), const char* ATTR_UNUSED(ifs[]),
const char* ATTR_UNUSED(port),
int ATTR_UNUSED(do_ip4), int ATTR_UNUSED(do_ip6),
int ATTR_UNUSED(do_udp), int ATTR_UNUSED(do_tcp),
size_t ATTR_UNUSED(bufsize), comm_point_callback_t* ATTR_UNUSED(cb),
void* ATTR_UNUSED(cb_arg))
size_t bufsize, comm_point_callback_t* cb, void* cb_arg)
{
return malloc(1);
struct replay_runtime* runtime = (struct replay_runtime*)base;
struct listen_dnsport* l= calloc(1, sizeof(struct listen_dnsport));
if(!l)
return NULL;
l->base = base;
l->udp_buff = ldns_buffer_new(bufsize);
if(!l->udp_buff) {
free(l);
return NULL;
}
runtime->callback_query = cb;
runtime->cb_arg = cb_arg;
return l;
}
void
listen_delete(struct listen_dnsport* listen)
{
if(!listen)
return;
ldns_buffer_free(listen->udp_buff);
free(listen);
}
struct comm_base* comm_base_create()
{
return malloc(1);
/* we return the runtime structure instead. */
struct replay_runtime* runtime = (struct replay_runtime*)
calloc(1, sizeof(struct replay_runtime));
runtime->scenario = saved_scenario;
return (struct comm_base*)runtime;
}
void comm_base_delete(struct comm_base* b)
{
free(b);
struct replay_runtime* runtime = (struct replay_runtime*)b;
free(runtime);
}
void comm_base_dispatch(struct comm_base* b)
{
/* TODO run the scenario ! */
struct replay_runtime* runtime = (struct replay_runtime*)b;
run_scenario(runtime);
}
void comm_base_exit(struct comm_base* ATTR_UNUSED(b))
@ -108,10 +215,13 @@ void comm_base_exit(struct comm_base* ATTR_UNUSED(b))
exit(1);
}
struct comm_signal* comm_signal_create(struct comm_base* ATTR_UNUSED(base),
void ATTR_UNUSED((*callback)(int, void*)), void* ATTR_UNUSED(cb_arg))
struct comm_signal* comm_signal_create(struct comm_base* base,
void (*callback)(int, void*), void* cb_arg)
{
return malloc(1);
struct replay_runtime* runtime = (struct replay_runtime*)base;
runtime->sig_cb = callback;
runtime->sig_cb_arg = cb_arg;
return calloc(1, sizeof(struct comm_signal));
}
int comm_signal_bind(struct comm_signal* ATTR_UNUSED(comsig), int
@ -138,18 +248,29 @@ comm_point_drop_reply(struct comm_reply* repinfo)
}
struct outside_network*
outside_network_create(struct comm_base* ATTR_UNUSED(base),
size_t ATTR_UNUSED(bufsize), size_t ATTR_UNUSED(num_ports),
outside_network_create(struct comm_base* base, size_t bufsize,
size_t ATTR_UNUSED(num_ports),
const char** ATTR_UNUSED(ifs), int ATTR_UNUSED(num_ifs),
int ATTR_UNUSED(do_ip4), int ATTR_UNUSED(do_ip6),
int ATTR_UNUSED(port_base))
{
return malloc(1);
struct outside_network* outnet = calloc(1,
sizeof(struct outside_network));
if(!outnet)
return NULL;
outnet->base = base;
outnet->udp_buff = ldns_buffer_new(bufsize);
if(!outnet->udp_buff)
return NULL;
return outnet;
}
void
outside_network_delete(struct outside_network* outnet)
{
if(!outnet)
return;
ldns_buffer_free(outnet->udp_buff);
free(outnet);
}
@ -157,6 +278,7 @@ void pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
struct sockaddr_storage* addr, socklen_t addrlen, int timeout,
comm_point_callback_t* callback, void* callback_arg)
{
/* TODO create it */
}
/*********** End of Dummy routines ***********/

View file

@ -91,6 +91,7 @@
#define TESTCODE_REPLAY_H
#include "config.h"
#include "util/netevent.h"
#include "testcode/ldns-testpkts.h"
struct replay_moment;
struct fake_pending;
struct replay_answer;
@ -181,6 +182,15 @@ struct replay_range {
* Replay storage of runtime information.
*/
struct replay_runtime {
/**
* The scenario
*/
struct replay_scenario* scenario;
/**
* Current moment.
*/
struct replay_moment* now;
/**
* List of pending queries in order they were sent out. First
* one has been sent out most recently. Last one in list is oldest.
@ -197,6 +207,11 @@ struct replay_runtime {
comm_point_callback_t* callback_query;
/** user argument for incoming query callback */
void *cb_arg;
/** signal handler callback */
void (*sig_cb)(int, void*);
/** signal handler user arg */
void *sig_cb_arg;
};
/**
@ -213,6 +228,13 @@ struct fake_pending {
comm_point_callback_t* callback;
/** callback user argument */
void* cb_arg;
/** next in pending list */
struct fake_pending* next;
/** the buffer parsed into a ldns_pkt */
ldns_pkt* pkt;
/** by what transport was the query sent out */
enum transport_type transport;
};
/**

View file

@ -41,6 +41,7 @@
#include "config.h"
#include "testcode/ldns-testpkts.h"
#include "testcode/replay.h"
#include "testcode/fake_event.h"
/**
* include the main program from the unbound daemon.
@ -184,6 +185,7 @@ main(int argc, char* argv[])
/* setup test environment */
scen = setup_playback(playback_file);
/* init fake event backend */
fake_event_init(scen);
pass_argv[pass_argc] = NULL;
echo_cmdline(pass_argc, pass_argv);
@ -195,7 +197,7 @@ main(int argc, char* argv[])
/* run the normal daemon */
res = daemon_main(pass_argc, pass_argv);
replay_scenario_delete(scen);
fake_event_cleanup();
for(c=1; c<pass_argc; c++)
free(pass_argv[c]);
return res;