From: Wouter Wijngaards Date: Thu, 8 Feb 2007 16:03:26 +0000 (+0000) Subject: Fake event start. X-Git-Tag: release-0.0~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05d471c46e84ff265833a67b8cf751352e675417;p=thirdparty%2Funbound.git Fake event start. git-svn-id: file:///svn/unbound/trunk@82 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/Makefile.in b/Makefile.in index 405cb8e1f..d10901e6b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -52,7 +52,7 @@ UNITTEST_SRC=testcode/unitmain.c UNITTEST_OBJ=$(addprefix $(BUILD),$(UNITTEST_SRC:.c=.o)) DAEMON_SRC=$(wildcard daemon/*.c) DAEMON_OBJ=$(addprefix $(BUILD),$(DAEMON_SRC:.c=.o)) -TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c daemon/worker.c testcode/replay.c +TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c daemon/worker.c testcode/replay.c testcode/fake_event.c TESTBOUND_OBJ=$(addprefix $(BUILD),$(TESTBOUND_SRC:.c=.o)) ALL_SRC=$(COMMON_SRC) $(UNITTEST_SRC) $(DAEMON_SRC) $(TESTBOUND_SRC) ALL_OBJ=$(addprefix $(BUILD),$(ALL_SRC:.c=.o) $(LIBOBJS)) diff --git a/doc/Changelog b/doc/Changelog index af8b61729..607b61c7f 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ 8 February 2007: Wouter - added tcp test. - replay storage. + - testcode/fake_event work. 7 February 2007: Wouter - return answer with the same ID as query was sent with. diff --git a/testcode/fake_event.c b/testcode/fake_event.c new file mode 100644 index 000000000..cad1aeaec --- /dev/null +++ b/testcode/fake_event.c @@ -0,0 +1,72 @@ +/* + * testcode/fake_event.c - fake event handling that replays existing scenario. + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * This software is open source. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the NLNET LABS nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * Event service that replays a scenario. + * This implements the same exported symbols as the files: + * util/netevent.c + * services/listen_dnsport.c + * services/outside_network.c + * But these do not actually access the network or events, instead + * the scenario is played. + */ + +#include "config.h" +#include "testcode/fake_event.h" +#include "util/netevent.h" +#include "services/listen_dnsport.h" +#include "services/outside_network.h" +#include "testcode/replay.h" + +/** Global variable: the scenario */ +static struct replay_scenario* scenario = NULL; + +void +fake_event_init(struct replay_scenario* scen) +{ + scenario = scen; +} + +void +fake_event_cleanup() +{ + replay_scenario_delete(scenario); + scenario = NULL; +} + +/*********** Dummy routines ***********/ + +/*********** End of Dummy routines ***********/ diff --git a/testcode/fake_event.h b/testcode/fake_event.h new file mode 100644 index 000000000..fdec009a0 --- /dev/null +++ b/testcode/fake_event.h @@ -0,0 +1,63 @@ +/* + * testcode/fake_event.h - fake event handling that replays existing scenario. + * + * Copyright (c) 2007, NLnet Labs. All rights reserved. + * + * This software is open source. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of the NLNET LABS nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * Event service that replays a scenario. + * This implements the same exported symbols as the files: + * util/netevent.c + * services/listen_dnsport.c + * services/outside_network.c + * But these do not actually access the network or events, instead + * the scenario is played. + */ + +#ifndef TESTCODE_FAKE_EVENT_H +#define TESTCODE_FAKE_EVENT_H +struct replay_scenario; + +/** + * Initialise fake event services. + * + * @param scen: Set the scenario to use for upcoming event handling. + */ +void fake_event_init(struct replay_scenario* scen); + +/** + * Deinit fake event services. + */ +void fake_event_cleanup(); + +#endif /* TESTCODE_FAKE_EVENT_H */ diff --git a/testcode/replay.c b/testcode/replay.c index 7e1b747fe..3eb5fc4fb 100644 --- a/testcode/replay.c +++ b/testcode/replay.c @@ -41,4 +41,13 @@ #include "config.h" #include "testcode/replay.h" +struct replay_scenario* +replay_scenario_read(FILE* in) +{ + return NULL; +} +void +replay_scenario_delete(struct replay_scenario* scen) +{ +} diff --git a/testcode/replay.h b/testcode/replay.h index 85c939627..79eaf77c6 100644 --- a/testcode/replay.h +++ b/testcode/replay.h @@ -42,10 +42,12 @@ * File format for replay files. * * ; comment line. - * And then a number of entries: + * SCENARIO_BEGIN + * TITLE name_of_scenario * RANGE start_time end_time * match_entries * END_RANGE + * ; more RANGE items. * ; go to the next moment * STEP time_step event_type * ; event_type can be: @@ -55,10 +57,14 @@ * o CHECK_OUT_QUERY - followed by entry * o REPLY - followed by entry * o TIMEOUT + * o ERROR * ; following entry starts on the next line, ENTRY_BEGIN. + * SCENARIO_END * * * ; Example file + * SCENARIO_BEGIN + * TITLE Example scenario * RANGE 0 100 * ENTRY_BEGIN * ; precoded answers to queries. @@ -78,6 +84,7 @@ * ; what the reply should look like * ENTRY_END * ; successful termination. (if the answer was OK). + * SCENARIO_END * * */ @@ -92,10 +99,13 @@ struct replay_answer; struct replay_range; struct entry; + /** * A replay scenario. */ struct replay_scenario { + /** name of replay scenario. malloced string. */ + const char* title; /** The list of replay moments. Linked list. Time increases in list. */ struct replay_moment* mom_first; @@ -110,23 +120,6 @@ struct replay_scenario { * So: timestep, parts of query, destination --> answer. */ struct replay_range* range_list; - - /** - * List of pending queries in order they were sent out. First - * one has been sent out most recently. Last one in list is oldest. - */ - struct fake_pending* pending_list; - - /** - * List of answers from the matching list, that need to be returned - * to the program. - */ - struct replay_answer* answer_list; - - /** callback for incoming queries */ - comm_point_callback_t* callback_query; - /** user argument for incoming query callback */ - void *cb_arg; }; /** @@ -158,6 +151,8 @@ struct replay_moment { repevt_back_reply, /** test fails if query to the network does not match */ repevt_back_query, + /** an error happens to outbound query */ + repevt_error, } evt_type; /** The sent packet must match this. Incoming events, the data. */ @@ -168,6 +163,44 @@ struct replay_moment { ldns_rr* qname; }; +/** + * Range of timesteps, and canned replies to matching queries. + */ +struct replay_range { + /** time range when this is valid. Including start and end step. */ + size_t start_step; + /** end step of time range. */ + size_t end_step; + + /** Matching list */ + struct entry* match; + + /** next in list of time ranges. */ + struct replay_range* next_range; +}; + +/** + * Replay storage of runtime information. + */ +struct replay_runtime { + /** + * List of pending queries in order they were sent out. First + * one has been sent out most recently. Last one in list is oldest. + */ + struct fake_pending* pending_list; + + /** + * List of answers from the matching list, that need to be returned + * to the program. + */ + struct replay_answer* answer_list; + + /** callback for incoming queries */ + comm_point_callback_t* callback_query; + /** user argument for incoming query callback */ + void *cb_arg; +}; + /** * Pending queries to network, fake replay version. */ @@ -178,7 +211,7 @@ struct fake_pending { struct sockaddr_storage addr; /** len of addr */ socklen_t addrlen; - /** The callback function to call */ + /** The callback function to call when answer arrives (or timeout) */ comm_point_callback_t* callback; /** callback user argument */ void* cb_arg; @@ -197,19 +230,16 @@ struct replay_answer { }; /** - * Range of timesteps, and canned replies to matching queries. + * Read a replay scenario from the file. + * @param in: file to read from. + * @return: Scenario. NULL if no scenario read. */ -struct replay_range { - /** time range when this is valid. Including start and end step. */ - size_t start_step; - /** end step of time range. */ - size_t end_step; +struct replay_scenario* replay_scenario_read(FILE* in); - /** Matching list */ - struct entry* match; - - /** next in list of time ranges. */ - struct replay_range* next_range; -}; +/** + * Delete scenario. + * @param scen: to delete. + */ +void replay_scenario_delete(struct replay_scenario* scen); #endif /* TESTCODE_REPLAY_H */