diff options
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/core/test_core_api.c | 2 | ||||
-rw-r--r-- | src/hello/test_hello.c | 4 | ||||
-rw-r--r-- | src/hostlist/Makefile.am | 16 | ||||
-rw-r--r-- | src/hostlist/hostlist-server.c | 2 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 135 | ||||
-rw-r--r-- | src/include/Makefile.am | 1 | ||||
-rw-r--r-- | src/include/gnunet_testing_lib.h | 343 | ||||
-rw-r--r-- | src/testing/Makefile.am | 30 | ||||
-rw-r--r-- | src/testing/testing.c | 193 | ||||
-rw-r--r-- | src/testing/testing_testbed.c | 134 |
11 files changed, 855 insertions, 6 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index c366ce20c..78e48e110 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -18,6 +18,7 @@ SUBDIRS = \ | |||
18 | resolver \ | 18 | resolver \ |
19 | statistics \ | 19 | statistics \ |
20 | template \ | 20 | template \ |
21 | testing \ | ||
21 | transport \ | 22 | transport \ |
22 | core \ | 23 | core \ |
23 | $(HOSTLIST_DIR) \ | 24 | $(HOSTLIST_DIR) \ |
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index a2924be79..53e031306 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c | |||
@@ -50,7 +50,7 @@ struct PeerContext | |||
50 | { | 50 | { |
51 | struct GNUNET_CONFIGURATION_Handle *cfg; | 51 | struct GNUNET_CONFIGURATION_Handle *cfg; |
52 | struct GNUNET_CORE_Handle *ch; | 52 | struct GNUNET_CORE_Handle *ch; |
53 | struct GNUNET_PeerIdentity id; /* FIXME: this is always all-zeros! */ | 53 | struct GNUNET_PeerIdentity id; |
54 | struct GNUNET_TRANSPORT_Handle *th; | 54 | struct GNUNET_TRANSPORT_Handle *th; |
55 | struct GNUNET_MessageHeader *hello; | 55 | struct GNUNET_MessageHeader *hello; |
56 | #if START_ARM | 56 | #if START_ARM |
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c index 728afd63f..51da7fc75 100644 --- a/src/hello/test_hello.c +++ b/src/hello/test_hello.c | |||
@@ -22,10 +22,6 @@ | |||
22 | * @brief test for hello.c | 22 | * @brief test for hello.c |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | |||
26 | /** | ||
27 | * Testcase for HELLO code. | ||
28 | */ | ||
29 | #include "platform.h" | 25 | #include "platform.h" |
30 | #include "gnunet_hello_lib.h" | 26 | #include "gnunet_hello_lib.h" |
31 | 27 | ||
diff --git a/src/hostlist/Makefile.am b/src/hostlist/Makefile.am index c1398891c..0ff4c4d3d 100644 --- a/src/hostlist/Makefile.am +++ b/src/hostlist/Makefile.am | |||
@@ -28,3 +28,19 @@ gnunet_daemon_hostlist_CPPFLAGS = \ | |||
28 | @LIBCURL_CPPFLAGS@ | 28 | @LIBCURL_CPPFLAGS@ |
29 | 29 | ||
30 | 30 | ||
31 | |||
32 | check_PROGRAMS = \ | ||
33 | test_gnunet_daemon_hostlist | ||
34 | |||
35 | TESTS = $(check_PROGRAMS) $(check_SCRIPTS) | ||
36 | |||
37 | test_gnunet_daemon_hostlist_SOURCES = \ | ||
38 | test_gnunet_daemon_hostlist.c | ||
39 | test_gnunet_daemon_hostlist_LDADD = \ | ||
40 | $(top_builddir)/src/arm/libgnunetarm.la \ | ||
41 | $(top_builddir)/src/util/libgnunetutil.la | ||
42 | |||
43 | EXTRA_DIST = \ | ||
44 | test_gnunet_daemon_hostlist_data_peer1.conf \ | ||
45 | test_gnunet_daemon_hostlist_data_peer2.conf | ||
46 | |||
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index be0fa84df..8512a4b4e 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c | |||
@@ -269,7 +269,7 @@ GNUNET_HOSTLIST_server_start (struct GNUNET_CONFIGURATION_Handle *c, | |||
269 | cfg = c; | 269 | cfg = c; |
270 | if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg, | 270 | if (-1 == GNUNET_CONFIGURATION_get_value_number (cfg, |
271 | "HOSTLIST", | 271 | "HOSTLIST", |
272 | "PORT", | 272 | "HTTPPORT", |
273 | &port)) | 273 | &port)) |
274 | return GNUNET_SYSERR; | 274 | return GNUNET_SYSERR; |
275 | daemon_handle = MHD_start_daemon (MHD_USE_IPv6, | 275 | daemon_handle = MHD_start_daemon (MHD_USE_IPv6, |
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c new file mode 100644 index 000000000..443a0d17e --- /dev/null +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file hostlist/test_gnunet_daemon_hostlist.c | ||
22 | * @brief test for gnunet_daemon_hostslist.c | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_arm_lib.h" | ||
28 | |||
29 | #define VERBOSE GNUNET_YES | ||
30 | |||
31 | #define START_ARM GNUNET_YES | ||
32 | |||
33 | struct PeerContext | ||
34 | { | ||
35 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
36 | struct GNUNET_CORE_Handle *ch; | ||
37 | struct GNUNET_PeerIdentity id; | ||
38 | struct GNUNET_TRANSPORT_Handle *th; | ||
39 | struct GNUNET_MessageHeader *hello; | ||
40 | #if START_ARM | ||
41 | pid_t arm_pid; | ||
42 | #endif | ||
43 | }; | ||
44 | |||
45 | |||
46 | |||
47 | static void | ||
48 | setup_peer (struct PeerContext *p, const char *cfgname) | ||
49 | { | ||
50 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
51 | #if START_ARM | ||
52 | p->arm_pid = GNUNET_OS_start_process ("gnunet-service-arm", | ||
53 | "gnunet-service-arm", | ||
54 | #if VERBOSE | ||
55 | "-L", "DEBUG", | ||
56 | #endif | ||
57 | "-c", cfgname, NULL); | ||
58 | sleep (1); /* allow ARM to start */ | ||
59 | #endif | ||
60 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
61 | GNUNET_ARM_start_service ("core", p->cfg, sched, TIMEOUT, NULL, NULL); | ||
62 | p->th = GNUNET_TRANSPORT_connect (sched, p->cfg, p, NULL, NULL, NULL); | ||
63 | GNUNET_assert (p->th != NULL); | ||
64 | GNUNET_TRANSPORT_get_hello (p->th, TIMEOUT, &process_hello, p); | ||
65 | } | ||
66 | |||
67 | |||
68 | static void | ||
69 | run (void *cls, | ||
70 | struct GNUNET_SCHEDULER_Handle *s, | ||
71 | char *const *args, | ||
72 | const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg) | ||
73 | { | ||
74 | GNUNET_assert (ok == 1); | ||
75 | OKPP; | ||
76 | sched = s; | ||
77 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | ||
78 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | ||
79 | } | ||
80 | |||
81 | |||
82 | static void | ||
83 | stop_arm (struct PeerContext *p) | ||
84 | { | ||
85 | #if START_ARM | ||
86 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) | ||
87 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
88 | if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) | ||
89 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
91 | "ARM process %u stopped\n", p->arm_pid); | ||
92 | #endif | ||
93 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
94 | } | ||
95 | |||
96 | |||
97 | static int | ||
98 | check () | ||
99 | { | ||
100 | char *const argv[] = { "test-gnunet-daemon-hostlist", | ||
101 | "-c", "test_gnunet_daemon_hostlist.conf", | ||
102 | #if VERBOSE | ||
103 | "-L", "DEBUG", | ||
104 | #endif | ||
105 | NULL | ||
106 | }; | ||
107 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
108 | GNUNET_GETOPT_OPTION_END | ||
109 | }; | ||
110 | ok = 1; | ||
111 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | ||
112 | argv, "test-gnunet-daemon-hostlist", | ||
113 | "nohelp", options, &run, &ok); | ||
114 | stop_arm (&p1); | ||
115 | stop_arm (&p2); | ||
116 | return ok; | ||
117 | } | ||
118 | |||
119 | |||
120 | int | ||
121 | main (int argc, char *argv[]) | ||
122 | { | ||
123 | |||
124 | int ret; | ||
125 | |||
126 | GNUNET_log_setup ("test-gnunet-daemon-hostlist", | ||
127 | #if VERBOSE | ||
128 | "DEBUG", | ||
129 | #else | ||
130 | "WARNING", | ||
131 | #endif | ||
132 | NULL); | ||
133 | ret = check (); | ||
134 | return 0; | ||
135 | } | ||
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index bc832c444..2a0ef3729 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -37,6 +37,7 @@ gnunetinclude_HEADERS = \ | |||
37 | gnunet_signatures.h \ | 37 | gnunet_signatures.h \ |
38 | gnunet_statistics_service.h \ | 38 | gnunet_statistics_service.h \ |
39 | gnunet_strings_lib.h \ | 39 | gnunet_strings_lib.h \ |
40 | gnunet_testing_lib.h \ | ||
40 | gnunet_time_lib.h \ | 41 | gnunet_time_lib.h \ |
41 | gnunet_transport_service.h \ | 42 | gnunet_transport_service.h \ |
42 | gnunet_upnp_service.h \ | 43 | gnunet_upnp_service.h \ |
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h new file mode 100644 index 000000000..f0e7d34a0 --- /dev/null +++ b/src/include/gnunet_testing_lib.h | |||
@@ -0,0 +1,343 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file include/gnunet_testing_lib.h | ||
23 | * @brief convenience API for writing testcases for GNUnet | ||
24 | * Many testcases need to start and stop gnunetd, | ||
25 | * and this library is supposed to make that easier | ||
26 | * for TESTCASES. Normal programs should always | ||
27 | * use functions from gnunet_{util,arm}_lib.h. This API is | ||
28 | * ONLY for writing testcases! | ||
29 | * @author Christian Grothoff | ||
30 | */ | ||
31 | |||
32 | #ifndef GNUNET_TESTING_LIB_H | ||
33 | #define GNUNET_TESTING_LIB_H | ||
34 | |||
35 | #include "gnunet_util_lib.h" | ||
36 | |||
37 | #ifdef __cplusplus | ||
38 | extern "C" | ||
39 | { | ||
40 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
41 | } | ||
42 | #endif | ||
43 | #endif | ||
44 | |||
45 | |||
46 | |||
47 | /** | ||
48 | * Handle for a GNUnet daemon (technically a set of | ||
49 | * daemons; the handle is really for the master ARM | ||
50 | * daemon) started by the testing library. | ||
51 | */ | ||
52 | struct GNUNET_TESTING_Daemon; | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Prototype of a function that will be called whenever | ||
57 | * a daemon was started by the testing library. | ||
58 | * | ||
59 | * @param cls closure | ||
60 | * @param id identifier for the daemon, NULL on error | ||
61 | * @param d handle to the daemon, NULL if starting the daemon failed | ||
62 | */ | ||
63 | typedef void (*GNUNET_TESTING_NotifyDaemonRunning)(void *cls, | ||
64 | const struct GNUNET_PeerIdentity *id, | ||
65 | struct GNUNET_TESTING_Daemon *d); | ||
66 | |||
67 | |||
68 | /** | ||
69 | * Starts a GNUnet daemon. | ||
70 | * | ||
71 | * @param service_home directory to use as the service home directory | ||
72 | * @param transports transport services that should be loaded | ||
73 | * @param applications application services and daemons that should be started | ||
74 | * @param port_offset offset to add to all ports for all services | ||
75 | * @param hostname name of the machine where to run GNUnet | ||
76 | * (use NULL for localhost). | ||
77 | * @param cb function to call with the result | ||
78 | * @param cb_cls closure for cb | ||
79 | */ | ||
80 | void | ||
81 | GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, | ||
82 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
83 | const char *service_home, | ||
84 | const char *transports, | ||
85 | const char *applications, | ||
86 | uint16_t port_offset, | ||
87 | const char *hostname, | ||
88 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
89 | void *cb_cls); | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Prototype of a function that will be called when a | ||
94 | * particular operation was completed the testing library. | ||
95 | * | ||
96 | * @param cls closure | ||
97 | * @param success GNUNET_YES on success | ||
98 | */ | ||
99 | typedef void (*GNUNET_TESTING_NotifyCompletion)(void *cls, | ||
100 | int success); | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Stops a GNUnet daemon. | ||
105 | * | ||
106 | * @param d the daemon that should be stopped | ||
107 | * @param cb function called once the daemon was stopped | ||
108 | * @param cb_cls closure for cb | ||
109 | */ | ||
110 | void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | ||
111 | GNUNET_TESTING_NotifyCompletion cb, | ||
112 | void * cb_cls); | ||
113 | |||
114 | |||
115 | |||
116 | /** | ||
117 | * Establish a connection between two GNUnet daemons. | ||
118 | * | ||
119 | * @param d1 handle for the first daemon | ||
120 | * @param d2 handle for the second daemon | ||
121 | * @param cb function to call at the end | ||
122 | * @param cb_cls closure for cb | ||
123 | */ | ||
124 | void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | ||
125 | struct GNUNET_TESTING_Daemon *d2, | ||
126 | GNUNET_TESTING_NotifyCompletion cb, | ||
127 | void *cb_cls); | ||
128 | |||
129 | |||
130 | |||
131 | /** | ||
132 | * Start count gnunetd processes with the same set of | ||
133 | * transports and applications. The port numbers will | ||
134 | * be computed by adding delta each time (zero | ||
135 | * times for the first peer). | ||
136 | * | ||
137 | * @param total number of daemons to start | ||
138 | * @param service_home_prefix path to use as the prefix for the home of the services | ||
139 | * @param transports which transports should all peers use | ||
140 | * @param applications which applications should be used? | ||
141 | * @param timeout how long is this allowed to take? | ||
142 | * @param cb function to call on each daemon that was started | ||
143 | * @param cb_cls closure for cb | ||
144 | * @param cbe function to call at the end | ||
145 | * @param cbe_cls closure for cbe | ||
146 | * @param hostname where to run the peers; can be NULL (to run | ||
147 | * everything on localhost). Additional | ||
148 | * hosts can be specified using a NULL-terminated list of | ||
149 | * varargs, hosts will then be used round-robin from that | ||
150 | * list. | ||
151 | */ | ||
152 | void | ||
153 | GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, | ||
154 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
155 | unsigned int total, | ||
156 | const char *service_home_prefix, | ||
157 | const char *transports, | ||
158 | const char *applications, | ||
159 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
160 | void *cb_cls, | ||
161 | GNUNET_TESTING_NotifyCompletion cbe, | ||
162 | void *cbe_cls, | ||
163 | const char *hostname, | ||
164 | ...); | ||
165 | |||
166 | |||
167 | /** | ||
168 | * Handle to an entire testbed of GNUnet peers. | ||
169 | */ | ||
170 | struct GNUNET_TESTING_Testbed; | ||
171 | |||
172 | /** | ||
173 | * Prototype of a function that will be called when | ||
174 | * a testbed is being created. | ||
175 | * | ||
176 | * @param cls closure | ||
177 | * @param tb NULL on error | ||
178 | */ | ||
179 | typedef void (*GNUNET_TESTING_NotifyTestbedRunning)(void *cls, | ||
180 | struct GNUNET_TESTING_Testbed *tb); | ||
181 | |||
182 | |||
183 | /** | ||
184 | * Topologies supported for testbeds. | ||
185 | */ | ||
186 | enum GNUNET_TESTING_Topology | ||
187 | { | ||
188 | /** | ||
189 | * A clique (everyone connected to everyone else). | ||
190 | */ | ||
191 | GNUNET_TESTING_TOPOLOGY_CLIQUE, | ||
192 | |||
193 | /** | ||
194 | * Small-world network (2d torus plus random links). | ||
195 | */ | ||
196 | GNUNET_TESTING_TOPOLOGY_SMALL_WORLD, | ||
197 | |||
198 | /** | ||
199 | * Ring topology. | ||
200 | */ | ||
201 | GNUNET_TESTING_TOPOLOGY_RING, | ||
202 | |||
203 | /** | ||
204 | * 2-d torus. | ||
205 | */ | ||
206 | GNUNET_TESTING_TOPOLOGY_2D_TORUS, | ||
207 | |||
208 | /** | ||
209 | * Random graph. | ||
210 | */ | ||
211 | GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI, | ||
212 | |||
213 | /** | ||
214 | * All peers are disconnected. | ||
215 | */ | ||
216 | GNUNET_TESTING_TOPOLOGY_NONE | ||
217 | }; | ||
218 | |||
219 | |||
220 | |||
221 | /** | ||
222 | * Start count GNUnet daemons with a particular | ||
223 | * topology. | ||
224 | * | ||
225 | * @param size number of peers the testbed should have | ||
226 | * @param topology desired topology (enforced via F2F) | ||
227 | * @param service_home_prefix path to use as the prefix for the home of the services | ||
228 | * @param transports which transports should all peers use | ||
229 | * @param applications which applications should be used? | ||
230 | * @param timeout how long is this allowed to take? | ||
231 | * @param cb function to call on each daemon that was started | ||
232 | * @param cb_cls closure for cb | ||
233 | * @param cte function to call at the end | ||
234 | * @param cte_cls closure for cbe | ||
235 | * @param hostname where to run the peers; can be NULL (to run | ||
236 | * everything on localhost). Additional | ||
237 | * hosts can be specified using a NULL-terminated list of | ||
238 | * varargs, hosts will then be used round-robin from that | ||
239 | * list. | ||
240 | */ | ||
241 | void | ||
242 | GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched, | ||
243 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
244 | unsigned int size, | ||
245 | enum GNUNET_TESTING_Topology topology, | ||
246 | const char *service_home_prefix, | ||
247 | const char *transports, | ||
248 | const char *applications, | ||
249 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
250 | void *cb_cls, | ||
251 | GNUNET_TESTING_NotifyTestbedRunning cte, | ||
252 | void *cte_cls, | ||
253 | const char *hostname, | ||
254 | ...); | ||
255 | |||
256 | |||
257 | /** | ||
258 | * Start count GNUnet daemons with a particular | ||
259 | * topology. | ||
260 | * | ||
261 | * @param size number of peers the testbed should have | ||
262 | * @param topology desired topology (enforced via F2F) | ||
263 | * @param service_home_prefix path to use as the prefix for the home of the services | ||
264 | * @param transports which transports should all peers use | ||
265 | * @param applications which applications should be used? | ||
266 | * @param timeout how long is this allowed to take? | ||
267 | * @param cb function to call on each daemon that was started | ||
268 | * @param cb_cls closure for cb | ||
269 | * @param cte function to call at the end | ||
270 | * @param cte_cls closure for cbe | ||
271 | * @param hostname where to run the peers; can be NULL (to run | ||
272 | * everything on localhost). | ||
273 | * @param va Additional hosts can be specified using a NULL-terminated list of | ||
274 | * varargs, hosts will then be used round-robin from that | ||
275 | * list; va only contains anything if hostname != NULL. | ||
276 | */ | ||
277 | void | ||
278 | GNUNET_TESTING_testbed_start_va (struct GNUNET_SCHEDULER_Handle *sched, | ||
279 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
280 | unsigned int size, | ||
281 | enum GNUNET_TESTING_Topology topology, | ||
282 | const char *service_home_prefix, | ||
283 | const char *transports, | ||
284 | const char *applications, | ||
285 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
286 | void *cb_cls, | ||
287 | GNUNET_TESTING_NotifyTestbedRunning cte, | ||
288 | void *cte_cls, | ||
289 | const char *hostname, | ||
290 | va_list ap); | ||
291 | |||
292 | |||
293 | /** | ||
294 | * Stop all of the daemons started with the start function. | ||
295 | * | ||
296 | * @param tb handle for the testbed | ||
297 | * @param cb function to call at the end | ||
298 | * @param cb_cls closure for cb | ||
299 | */ | ||
300 | void | ||
301 | GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb, | ||
302 | GNUNET_TESTING_NotifyCompletion cb, | ||
303 | void *cb_cls ); | ||
304 | |||
305 | |||
306 | |||
307 | /** | ||
308 | * Simulate churn in the testbed by stopping some peers (and possibly | ||
309 | * re-starting others if churn is called multiple times). This | ||
310 | * function can only be used to create leave-join churn (peers "never" | ||
311 | * leave for good). First "voff" random peers that are currently | ||
312 | * online will be taken offline; then "von" random peers that are then | ||
313 | * offline will be put back online. No notifications will be | ||
314 | * generated for any of these operations except for the callback upon | ||
315 | * completion. Note that the implementation is at liberty to keep | ||
316 | * the ARM service itself (but none of the other services or daemons) | ||
317 | * running even though the "peer" is being varied offline. | ||
318 | * | ||
319 | * @param tb handle for the testbed | ||
320 | * @param voff number of peers that should go offline | ||
321 | * @param von number of peers that should come back online; | ||
322 | * must be zero on first call (since "testbed_start" | ||
323 | * always starts all of the peers) | ||
324 | * @param cb function to call at the end | ||
325 | * @param cb_cls closure for cb | ||
326 | */ | ||
327 | void | ||
328 | GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb, | ||
329 | unsigned int voff, | ||
330 | unsigned int von, | ||
331 | GNUNET_TESTING_NotifyCompletion cb, | ||
332 | void *cb_cls); | ||
333 | |||
334 | |||
335 | |||
336 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
337 | { | ||
338 | #endif | ||
339 | #ifdef __cplusplus | ||
340 | } | ||
341 | #endif | ||
342 | |||
343 | #endif | ||
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am new file mode 100644 index 000000000..4d25d8b44 --- /dev/null +++ b/src/testing/Makefile.am | |||
@@ -0,0 +1,30 @@ | |||
1 | INCLUDES = -I$(top_srcdir)/src/include | ||
2 | |||
3 | if MINGW | ||
4 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | ||
5 | endif | ||
6 | |||
7 | if USE_COVERAGE | ||
8 | AM_CFLAGS = --coverage -O0 | ||
9 | XLIB = -lgcov | ||
10 | endif | ||
11 | |||
12 | lib_LTLIBRARIES = libgnunettesting.la | ||
13 | |||
14 | libgnunettesting_la_SOURCES = \ | ||
15 | testing.c \ | ||
16 | testing_testbed.c | ||
17 | libgnunettesting_la_LIBADD = \ | ||
18 | $(top_builddir)/src/util/libgnunetutil.la $(XLIB) | ||
19 | |||
20 | #check_PROGRAMS = \ | ||
21 | # test_testing | ||
22 | # | ||
23 | #TESTS = $(check_PROGRAMS) | ||
24 | # | ||
25 | #test_testing_SOURCES = \ | ||
26 | # test_testing.c | ||
27 | #test_testing_LDADD = \ | ||
28 | # $(top_builddir)/src/testing/libgnunettesting.la \ | ||
29 | # $(top_builddir)/src/util/libgnunetutil.la | ||
30 | |||
diff --git a/src/testing/testing.c b/src/testing/testing.c new file mode 100644 index 000000000..a91902423 --- /dev/null +++ b/src/testing/testing.c | |||
@@ -0,0 +1,193 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/testing.c | ||
23 | * @brief convenience API for writing testcases for GNUnet | ||
24 | * Many testcases need to start and stop gnunetd, | ||
25 | * and this library is supposed to make that easier | ||
26 | * for TESTCASES. Normal programs should always | ||
27 | * use functions from gnunet_{util,arm}_lib.h. This API is | ||
28 | * ONLY for writing testcases! | ||
29 | * @author Christian Grothoff | ||
30 | */ | ||
31 | #include "platform.h" | ||
32 | #include "gnunet_arm_service.h" | ||
33 | #include "gnunet_testing_lib.h" | ||
34 | |||
35 | /** | ||
36 | * Handle for a GNUnet daemon (technically a set of | ||
37 | * daemons; the handle is really for the master ARM | ||
38 | * daemon) started by the testing library. | ||
39 | */ | ||
40 | struct GNUNET_TESTING_Daemon | ||
41 | { | ||
42 | }; | ||
43 | |||
44 | |||
45 | /** | ||
46 | * Starts a GNUnet daemon. | ||
47 | * | ||
48 | * @param service_home directory to use as the service home directory | ||
49 | * @param transports transport services that should be loaded | ||
50 | * @param applications application services and daemons that should be started | ||
51 | * @param port_offset offset to add to all ports for all services | ||
52 | * @param hostname name of the machine where to run GNUnet | ||
53 | * (use NULL for localhost). | ||
54 | * @param cb function to call with the result | ||
55 | * @param cb_cls closure for cb | ||
56 | */ | ||
57 | void | ||
58 | GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, | ||
59 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
60 | const char *service_home, | ||
61 | const char *transports, | ||
62 | const char *applications, | ||
63 | uint16_t port_offset, | ||
64 | const char *hostname, | ||
65 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
66 | void *cb_cls) | ||
67 | { | ||
68 | } | ||
69 | |||
70 | |||
71 | /** | ||
72 | * Stops a GNUnet daemon. | ||
73 | * | ||
74 | * @param d the daemon that should be stopped | ||
75 | * @param cb function called once the daemon was stopped | ||
76 | * @param cb_cls closure for cb | ||
77 | */ | ||
78 | void GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, | ||
79 | GNUNET_TESTING_NotifyCompletion cb, | ||
80 | void * cb_cls) | ||
81 | { | ||
82 | } | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Establish a connection between two GNUnet daemons. | ||
87 | * | ||
88 | * @param d1 handle for the first daemon | ||
89 | * @param d2 handle for the second daemon | ||
90 | * @param cb function to call at the end | ||
91 | * @param cb_cls closure for cb | ||
92 | */ | ||
93 | void GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | ||
94 | struct GNUNET_TESTING_Daemon *d2, | ||
95 | GNUNET_TESTING_NotifyCompletion cb, | ||
96 | void *cb_cls) | ||
97 | { | ||
98 | } | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Start count GNUnet daemons with a particular | ||
103 | * topology. | ||
104 | * | ||
105 | * @param size number of peers the testbed should have | ||
106 | * @param topology desired topology (enforced via F2F) | ||
107 | * @param service_home_prefix path to use as the prefix for the home of the services | ||
108 | * @param transports which transports should all peers use | ||
109 | * @param applications which applications should be used? | ||
110 | * @param timeout how long is this allowed to take? | ||
111 | * @param cb function to call on each daemon that was started | ||
112 | * @param cb_cls closure for cb | ||
113 | * @param cte function to call at the end | ||
114 | * @param cte_cls closure for cbe | ||
115 | * @param hostname where to run the peers; can be NULL (to run | ||
116 | * everything on localhost). | ||
117 | * @param va Additional hosts can be specified using a NULL-terminated list of | ||
118 | * varargs, hosts will then be used round-robin from that | ||
119 | * list; va only contains anything if hostname != NULL. | ||
120 | */ | ||
121 | void | ||
122 | GNUNET_TESTING_testbed_start_va (struct GNUNET_SCHEDULER_Handle *sched, | ||
123 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
124 | unsigned int size, | ||
125 | enum GNUNET_TESTING_Topology topology, | ||
126 | const char *service_home_prefix, | ||
127 | const char *transports, | ||
128 | const char *applications, | ||
129 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
130 | void *cb_cls, | ||
131 | GNUNET_TESTING_NotifyTestbedRunning cte, | ||
132 | void *cte_cls, | ||
133 | const char *hostname, | ||
134 | va_list ap) | ||
135 | { | ||
136 | } | ||
137 | |||
138 | |||
139 | /** | ||
140 | * Start count gnunetd processes with the same set of | ||
141 | * transports and applications. The port numbers will | ||
142 | * be computed by adding delta each time (zero | ||
143 | * times for the first peer). | ||
144 | * | ||
145 | * @param total number of daemons to start | ||
146 | * @param service_home_prefix path to use as the prefix for the home of the services | ||
147 | * @param transports which transports should all peers use | ||
148 | * @param applications which applications should be used? | ||
149 | * @param timeout how long is this allowed to take? | ||
150 | * @param cb function to call on each daemon that was started | ||
151 | * @param cb_cls closure for cb | ||
152 | * @param cbe function to call at the end | ||
153 | * @param cbe_cls closure for cbe | ||
154 | * @param hostname where to run the peers; can be NULL (to run | ||
155 | * everything on localhost). Additional | ||
156 | * hosts can be specified using a NULL-terminated list of | ||
157 | * varargs, hosts will then be used round-robin from that | ||
158 | * list. | ||
159 | */ | ||
160 | void | ||
161 | GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched, | ||
162 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
163 | unsigned int total, | ||
164 | const char *service_home_prefix, | ||
165 | const char *transports, | ||
166 | const char *applications, | ||
167 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
168 | void *cb_cls, | ||
169 | GNUNET_TESTING_NotifyCompletion cbe, | ||
170 | void *cbe_cls, | ||
171 | const char *hostname, | ||
172 | ...) | ||
173 | { | ||
174 | va_list va; | ||
175 | |||
176 | va_start (va, hostname); | ||
177 | GNUNET_TESTING_daemons_start_va (sched, cfg, | ||
178 | total, service_home_prefix, | ||
179 | transports, applications, | ||
180 | cb, cb_cls, cbe, cbe_cls, hostname, | ||
181 | va); | ||
182 | va_end (va); | ||
183 | } | ||
184 | |||
185 | |||
186 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
187 | { | ||
188 | #endif | ||
189 | #ifdef __cplusplus | ||
190 | } | ||
191 | #endif | ||
192 | |||
193 | #endif | ||
diff --git a/src/testing/testing_testbed.c b/src/testing/testing_testbed.c new file mode 100644 index 000000000..4bf89e5c1 --- /dev/null +++ b/src/testing/testing_testbed.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008, 2009 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/testing_testbed.c | ||
23 | * @brief convenience API for writing testcases for GNUnet | ||
24 | * Many testcases need to start and stop gnunetd, | ||
25 | * and this library is supposed to make that easier | ||
26 | * for TESTCASES. Normal programs should always | ||
27 | * use functions from gnunet_{util,arm}_lib.h. This API is | ||
28 | * ONLY for writing testcases! | ||
29 | * @author Christian Grothoff | ||
30 | */ | ||
31 | #include "platform.h" | ||
32 | #include "gnunet_arm_service.h" | ||
33 | #include "gnunet_testing_lib.h" | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Handle to an entire testbed of GNUnet peers. | ||
38 | */ | ||
39 | struct GNUNET_TESTING_Testbed | ||
40 | { | ||
41 | }; | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Start count GNUnet daemons with a particular | ||
46 | * topology. | ||
47 | * | ||
48 | * @param size number of peers the testbed should have | ||
49 | * @param topology desired topology (enforced via F2F) | ||
50 | * @param service_home_prefix path to use as the prefix for the home of the services | ||
51 | * @param transports which transports should all peers use | ||
52 | * @param applications which applications should be used? | ||
53 | * @param timeout how long is this allowed to take? | ||
54 | * @param cb function to call on each daemon that was started | ||
55 | * @param cb_cls closure for cb | ||
56 | * @param cte function to call at the end | ||
57 | * @param cte_cls closure for cbe | ||
58 | * @param hostname where to run the peers; can be NULL (to run | ||
59 | * everything on localhost). Additional | ||
60 | * hosts can be specified using a NULL-terminated list of | ||
61 | * varargs, hosts will then be used round-robin from that | ||
62 | * list. | ||
63 | */ | ||
64 | void | ||
65 | GNUNET_TESTING_testbed_start (struct GNUNET_SCHEDULER_Handle *sched, | ||
66 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
67 | unsigned int size, | ||
68 | enum GNUNET_TESTING_Topology topology, | ||
69 | const char *service_home_prefix, | ||
70 | const char *transports, | ||
71 | const char *applications, | ||
72 | GNUNET_TESTING_NotifyDaemonRunning cb, | ||
73 | void *cb_cls, | ||
74 | GNUNET_TESTING_NotifyTestbedRunning cte, | ||
75 | void *cte_cls, | ||
76 | const char *hostname, | ||
77 | ...) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Stop all of the daemons started with the start function. | ||
84 | * | ||
85 | * @param tb handle for the testbed | ||
86 | * @param cb function to call at the end | ||
87 | * @param cb_cls closure for cb | ||
88 | */ | ||
89 | void | ||
90 | GNUNET_TESTING_testbed_stop (struct GNUNET_TESTING_Testbed *tb, | ||
91 | GNUNET_TESTING_NotifyCompletion cb, | ||
92 | void *cb_cls ) | ||
93 | { | ||
94 | } | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Simulate churn in the testbed by stopping some peers (and possibly | ||
99 | * re-starting others if churn is called multiple times). This | ||
100 | * function can only be used to create leave-join churn (peers "never" | ||
101 | * leave for good). First "voff" random peers that are currently | ||
102 | * online will be taken offline; then "von" random peers that are then | ||
103 | * offline will be put back online. No notifications will be | ||
104 | * generated for any of these operations except for the callback upon | ||
105 | * completion. Note that the implementation is at liberty to keep | ||
106 | * the ARM service itself (but none of the other services or daemons) | ||
107 | * running even though the "peer" is being varied offline. | ||
108 | * | ||
109 | * @param tb handle for the testbed | ||
110 | * @param voff number of peers that should go offline | ||
111 | * @param von number of peers that should come back online; | ||
112 | * must be zero on first call (since "testbed_start" | ||
113 | * always starts all of the peers) | ||
114 | * @param cb function to call at the end | ||
115 | * @param cb_cls closure for cb | ||
116 | */ | ||
117 | void | ||
118 | GNUNET_TESTING_testbed_churn (struct GNUNET_TESTING_Testbed *tb, | ||
119 | unsigned int voff, | ||
120 | unsigned int von, | ||
121 | GNUNET_TESTING_NotifyCompletion cb, | ||
122 | void *cb_cls) | ||
123 | { | ||
124 | } | ||
125 | |||
126 | |||
127 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
128 | { | ||
129 | #endif | ||
130 | #ifdef __cplusplus | ||
131 | } | ||
132 | #endif | ||
133 | |||
134 | #endif | ||