]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Fake event start.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 8 Feb 2007 16:03:26 +0000 (16:03 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 8 Feb 2007 16:03:26 +0000 (16:03 +0000)
git-svn-id: file:///svn/unbound/trunk@82 be551aaa-1e26-0410-a405-d3ace91eadb9

Makefile.in
doc/Changelog
testcode/fake_event.c [new file with mode: 0644]
testcode/fake_event.h [new file with mode: 0644]
testcode/replay.c
testcode/replay.h

index 405cb8e1fe581ec256549e572b74ad86d938e6cd..d10901e6b81fcfb430b078659d8bc5b4a4526dae 100644 (file)
@@ -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))
index af8b6172966937fbd1f565fcb718450c35cdc573..607b61c7f6cd0e7bed7e92087c32b38a583d24a7 100644 (file)
@@ -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 (file)
index 0000000..cad1aea
--- /dev/null
@@ -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 (file)
index 0000000..fdec009
--- /dev/null
@@ -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 */
index 7e1b747feaabcdac36ea2de944f77a0f852d387c..3eb5fc4fbceb88e5239debdfccc0f78128da57c9 100644 (file)
 
 #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)
+{
+}
index 85c939627b3b3ccc1788a5fe5d26c97409c65eab..79eaf77c62c6775c1061112c17946875842b349c 100644 (file)
  * 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:
  *     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
  * 
  * </pre>
  */
@@ -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 */