aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-09-16 13:50:31 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-09-16 13:50:31 +0000
commit2bd330db5edb23508e99d4a22a7f1c81754625ac (patch)
treed54ab3bdaa646471a017020481881e896b9ca833 /src/testbed
parent92bc91f21ea5f201526775cd67df755eb50a0a78 (diff)
downloadgnunet-2bd330db5edb23508e99d4a22a7f1c81754625ac.tar.gz
gnunet-2bd330db5edb23508e99d4a22a7f1c81754625ac.zip
new test case (not working)
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am8
-rw-r--r--src/testbed/test_testbed_api_2peers_2controllers.c603
-rw-r--r--src/testbed/testbed_api_peers.c1
3 files changed, 611 insertions, 1 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 5f149d905..fbc437511 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -72,6 +72,7 @@ check_PROGRAMS = \
72 test_testbed_api_hosts \ 72 test_testbed_api_hosts \
73 test_testbed_api_controllerlink \ 73 test_testbed_api_controllerlink \
74 test_testbed_api_2peers_1controller \ 74 test_testbed_api_2peers_1controller \
75 test_testbed_api_2peers_2controllers \
75 test_testbed_api \ 76 test_testbed_api \
76 test_testbed_api_operations \ 77 test_testbed_api_operations \
77 test_testbed_api_testbed_run \ 78 test_testbed_api_testbed_run \
@@ -111,6 +112,13 @@ test_testbed_api_2peers_1controller_LDADD = \
111 $(top_builddir)/src/testing/libgnunettesting.la \ 112 $(top_builddir)/src/testing/libgnunettesting.la \
112 libgnunettestbed.la 113 libgnunettestbed.la
113 114
115test_testbed_api_2peers_2controllers_SOURCES = \
116 test_testbed_api_2peers_2controllers.c
117test_testbed_api_2peers_2controllers_LDADD = \
118 $(top_builddir)/src/util/libgnunetutil.la \
119 $(top_builddir)/src/testing/libgnunettesting.la \
120 libgnunettestbed.la
121
114test_testbed_api_operations_SOURCES = \ 122test_testbed_api_operations_SOURCES = \
115 test_testbed_api_operations.c 123 test_testbed_api_operations.c
116test_testbed_api_operations_LDADD = \ 124test_testbed_api_operations_LDADD = \
diff --git a/src/testbed/test_testbed_api_2peers_2controllers.c b/src/testbed/test_testbed_api_2peers_2controllers.c
new file mode 100644
index 000000000..c702dde01
--- /dev/null
+++ b/src/testbed/test_testbed_api_2peers_2controllers.c
@@ -0,0 +1,603 @@
1/*
2 This file is part of GNUnet
3 (C) 2008--2012 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 3, 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 testbed/test_testbed_api_2peers_2controllers.c
23 * @brief testcases for the testbed api: 2 peers are configured, started and
24 * connected together. Each peer resides on its own controller
25 * @author Sree Harsha Totakura
26 */
27
28#include "platform.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib-new.h"
31#include "gnunet_testbed_service.h"
32
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind,...) \
38 GNUNET_log (kind, __VA_ARGS__)
39
40/**
41 * Relative time seconds shorthand
42 */
43#define TIME_REL_SECS(sec) \
44 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
45
46
47/**
48 * Peer context
49 */
50struct PeerContext
51{
52 /**
53 * The peer handle
54 */
55 struct GNUNET_TESTBED_Peer *peer;
56
57 /**
58 * Operations involving this peer
59 */
60 struct GNUNET_TESTBED_Operation *operation;
61
62 /**
63 * set to GNUNET_YES when peer is started
64 */
65 int is_running;
66};
67
68/**
69 * Our localhost
70 */
71static struct GNUNET_TESTBED_Host *host;
72
73/**
74 * The controller process of one controller
75 */
76static struct GNUNET_TESTBED_ControllerProc *cp1;
77
78/**
79 * The controller process of another controller
80 */
81static struct GNUNET_TESTBED_ControllerProc *cp2;
82
83/**
84 * A neighbouring host
85 */
86static struct GNUNET_TESTBED_Host *neighbour;
87
88/**
89 * Handle for neighbour registration
90 */
91static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
92
93/**
94 * The controller handle of one controller
95 */
96static struct GNUNET_TESTBED_Controller *controller1;
97
98/**
99 * The controller handle of another controller
100 */
101static struct GNUNET_TESTBED_Controller *controller2;
102
103/**
104 * peer 1
105 */
106static struct PeerContext peer1;
107
108/**
109 * peer2
110 */
111static struct PeerContext peer2;
112
113/**
114 * Handle to starting configuration
115 */
116static struct GNUNET_CONFIGURATION_Handle *cfg;
117
118/**
119 * Handle to controller2 configuration, used to establish lateral link from
120 * controller 1
121 */
122static struct GNUNET_CONFIGURATION_Handle *cfg2;
123
124/**
125 * Handle to operations involving both peers
126 */
127static struct GNUNET_TESTBED_Operation *common_operation;
128
129/**
130 * Abort task identifier
131 */
132static GNUNET_SCHEDULER_TaskIdentifier abort_task;
133
134/**
135 * Delayed connect job identifier
136 */
137static GNUNET_SCHEDULER_TaskIdentifier delayed_connect_task;
138
139/**
140 * Different stages in testing
141 */
142enum Stage
143{
144
145 /**
146 * Initial stage
147 */
148 INIT,
149
150 /**
151 * Controller 1 has started
152 */
153 CONTROLLER1_UP,
154
155 /**
156 * peer1 is created
157 */
158 PEER1_CREATED,
159
160 /**
161 * peer1 is started
162 */
163 PEER1_STARTED,
164
165 /**
166 * Controller 2 has started
167 */
168 CONTROLLER2_UP,
169
170 /**
171 * peer2 is created
172 */
173 PEER2_CREATED,
174
175 /**
176 * peer2 is started
177 */
178 PEER2_STARTED,
179
180 /**
181 * peers are connected
182 */
183 PEERS_CONNECTED,
184
185 /**
186 * Peers are connected once again (this should not fail as they are already connected)
187 */
188 PEERS_CONNECTED_2,
189
190 /**
191 * peers are stopped
192 */
193 PEERS_STOPPED,
194
195 /**
196 * Final success stage
197 */
198 SUCCESS
199};
200
201/**
202 * The testing result
203 */
204static enum Stage result;
205
206
207/**
208 * Shutdown nicely
209 *
210 * @param cls NULL
211 * @param tc the task context
212 */
213static void
214do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
215{
216 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
217 GNUNET_SCHEDULER_cancel (abort_task);
218 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task);
219 if (NULL != reg_handle)
220 GNUNET_TESTBED_cancel_registration (reg_handle);
221 if (NULL != controller1)
222 GNUNET_TESTBED_controller_disconnect (controller1);
223 if (NULL != controller2)
224 GNUNET_TESTBED_controller_disconnect (controller2);
225 GNUNET_CONFIGURATION_destroy (cfg);
226 if (NULL != cfg2)
227 GNUNET_CONFIGURATION_destroy (cfg2);
228 if (NULL != cp1)
229 GNUNET_TESTBED_controller_stop (cp1);
230 if (NULL != cp2)
231 GNUNET_TESTBED_controller_stop (cp2);
232 GNUNET_TESTBED_host_destroy (host);
233}
234
235
236/**
237 * abort task to run on test timed out
238 *
239 * @param cls NULL
240 * @param tc the task context
241 */
242static void
243do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
244{
245 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
246 abort_task = GNUNET_SCHEDULER_NO_TASK;
247 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == delayed_connect_task);
248 do_shutdown (cls, tc);
249}
250
251
252/**
253 * Callback to be called when an operation is completed
254 *
255 * @param cls the callback closure from functions generating an operation
256 * @param op the operation that has been finished
257 * @param emsg error message in case the operation has failed; will be NULL if
258 * operation has executed successfully.
259 */
260static void
261op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg);
262
263
264/**
265 * task for delaying a connect
266 *
267 * @param cls NULL
268 * @param tc the task context
269 */
270static void
271do_delayed_connect (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
272{
273 delayed_connect_task = GNUNET_SCHEDULER_NO_TASK;
274 GNUNET_assert (NULL == common_operation);
275 common_operation = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL,
276 peer1.peer, peer2.peer);
277}
278
279
280/**
281 * Callback to be called when an operation is completed
282 *
283 * @param cls the callback closure from functions generating an operation
284 * @param op the operation that has been finished
285 * @param emsg error message in case the operation has failed; will be NULL if
286 * operation has executed successfully.
287 */
288static void
289op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
290{
291 GNUNET_assert (common_operation == op);
292 switch(result)
293 {
294 case PEER2_STARTED:
295 GNUNET_assert (NULL == peer1.operation);
296 GNUNET_assert (NULL == peer2.operation);
297 GNUNET_assert (NULL != common_operation);
298 GNUNET_TESTBED_operation_done (common_operation);
299 common_operation = NULL;
300 result = PEERS_CONNECTED;
301 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n");
302 delayed_connect_task =
303 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (3),
304 &do_delayed_connect, NULL);
305 break;
306 case PEERS_CONNECTED:
307 GNUNET_assert (NULL == peer1.operation);
308 GNUNET_assert (NULL == peer2.operation);
309 GNUNET_assert (NULL != common_operation);
310 GNUNET_TESTBED_operation_done (common_operation);
311 common_operation = NULL;
312 result = PEERS_CONNECTED_2;
313 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected again\n");
314 peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer, NULL, NULL);
315 peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer, NULL, NULL);
316 break;
317 default:
318 GNUNET_assert (0);
319 }
320}
321
322
323/**
324 * Functions of this signature are called when a peer has been successfully
325 * created
326 *
327 * @param cls NULL
328 * @param peer the handle for the created peer; NULL on any error during
329 * creation
330 * @param emsg NULL if peer is not NULL; else MAY contain the error description
331 */
332static void
333peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
334{
335 switch (result)
336 {
337 case CONTROLLER1_UP:
338 GNUNET_assert (NULL != peer1.operation);
339 GNUNET_assert (NULL != peer);
340 GNUNET_assert (NULL == peer1.peer);
341 peer1.peer = peer;
342 GNUNET_TESTBED_operation_done (peer1.operation);
343 result = PEER1_CREATED;
344 peer1.operation = GNUNET_TESTBED_peer_start (peer, NULL, NULL);
345 break;
346 case CONTROLLER2_UP:
347 GNUNET_assert (NULL != peer2.operation);
348 GNUNET_assert (NULL != peer);
349 GNUNET_assert (NULL == peer2.peer);
350 peer2.peer = peer;
351 GNUNET_TESTBED_operation_done (peer2.operation);
352 result = PEER2_CREATED;
353 peer2.operation = GNUNET_TESTBED_peer_start (peer, NULL, NULL);
354 break;
355 default:
356 GNUNET_assert (0);
357 }
358}
359
360
361/**
362 * Callback to signal successfull startup of the controller process
363 *
364 * @param cls the closure from GNUNET_TESTBED_controller_start()
365 * @param cfg the configuration with which the controller has been started;
366 * NULL if status is not GNUNET_OK
367 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
368 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
369 */
370static void
371status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status);
372
373
374/**
375 * Signature of the event handler function called by the
376 * respective event controller.
377 *
378 * @param cls closure
379 * @param event information about the event
380 */
381static void
382controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
383{
384 switch (event->type)
385 {
386 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
387 GNUNET_assert (NULL == event->details.operation_finished.op_cls);
388 GNUNET_assert (NULL == event->details.operation_finished.emsg);
389 GNUNET_assert (NULL == event->details.operation_finished.generic);
390 switch (result)
391 {
392 case PEERS_STOPPED:
393 if (event->details.operation_finished.operation == peer1.operation)
394 {
395 GNUNET_TESTBED_operation_done (peer1.operation);
396 peer1.operation = NULL;
397 peer1.peer = NULL;
398 }
399 else if (event->details.operation_finished.operation == peer2.operation)
400 {
401 GNUNET_TESTBED_operation_done (peer2.operation);
402 peer2.operation = NULL;
403 peer2.peer = NULL;
404 }
405 else
406 GNUNET_assert (0);
407 if ((NULL == peer1.peer) && (NULL == peer2.peer))
408 {
409 result = SUCCESS;
410 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
411 }
412 break;
413 case PEER1_STARTED:
414 GNUNET_assert (NULL != common_operation);
415 GNUNET_TESTBED_operation_done (common_operation);
416 common_operation = NULL;
417 result = CONTROLLER2_UP;
418 peer2.operation =
419 GNUNET_TESTBED_peer_create (controller1, neighbour, cfg, &peer_create_cb,
420 NULL);
421 GNUNET_assert (NULL != peer2.operation);
422 break;
423 default:
424 GNUNET_assert (0);
425 }
426 break;
427 case GNUNET_TESTBED_ET_PEER_START:
428 switch (result)
429 {
430 case PEER1_CREATED:
431 GNUNET_assert (event->details.peer_start.host == host);
432 peer1.is_running = GNUNET_YES;
433 GNUNET_TESTBED_operation_done (peer1.operation);
434 peer1.operation = NULL;
435 result = PEER1_STARTED;
436 common_operation =
437 GNUNET_TESTBED_controller_link (controller1, neighbour, NULL, cfg, GNUNET_YES);
438 break;
439 case PEER2_CREATED:
440 GNUNET_assert (event->details.peer_start.host == neighbour);
441 peer2.is_running = GNUNET_YES;
442 GNUNET_TESTBED_operation_done (peer2.operation);
443 peer2.operation = NULL;
444 result = PEER2_STARTED;
445 common_operation =
446 GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer,
447 peer2.peer);
448 break;
449 default:
450 GNUNET_assert (0);
451 }
452 break;
453 case GNUNET_TESTBED_ET_PEER_STOP:
454 GNUNET_assert (PEERS_CONNECTED_2 == result);
455 if (event->details.peer_stop.peer == peer1.peer)
456 {
457 peer1.is_running = GNUNET_NO;
458 GNUNET_TESTBED_operation_done (peer1.operation);
459 peer1.operation = GNUNET_TESTBED_peer_destroy (peer1.peer);
460 }
461 else if (event->details.peer_stop.peer == peer2.peer)
462 {
463 peer2.is_running = GNUNET_NO;
464 GNUNET_TESTBED_operation_done (peer2.operation);
465 peer2.operation = GNUNET_TESTBED_peer_destroy (peer2.peer);
466 }
467 else
468 GNUNET_assert (0);
469 if ((GNUNET_NO == peer1.is_running) && (GNUNET_NO == peer2.is_running))
470 result = PEERS_STOPPED;
471 break;
472 case GNUNET_TESTBED_ET_CONNECT:
473 switch (result)
474 {
475 case PEER2_STARTED:
476 case PEERS_CONNECTED:
477 GNUNET_assert (NULL == peer1.operation);
478 GNUNET_assert (NULL == peer2.operation);
479 GNUNET_assert (NULL != common_operation);
480 GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) &&
481 (event->details.peer_connect.peer2 == peer2.peer));
482 break;
483 default:
484 GNUNET_assert (0);
485 }
486 break;
487 default:
488 GNUNET_assert (0);
489 };
490}
491
492
493/**
494 * Callback which will be called to after a host registration succeeded or failed
495 *
496 * @param cls the host which has been registered
497 * @param emsg the error message; NULL if host registration is successful
498 */
499static void
500registration_comp (void *cls, const char *emsg)
501{
502 GNUNET_assert (cls == neighbour);
503 reg_handle = NULL;
504 peer1.operation =
505 GNUNET_TESTBED_peer_create (controller1, host, cfg, &peer_create_cb,
506 &peer1);
507 GNUNET_assert (NULL != peer1.operation);
508}
509
510
511/**
512 * Callback to signal successfull startup of the controller process
513 *
514 * @param cls the closure from GNUNET_TESTBED_controller_start()
515 * @param cfg the configuration with which the controller has been started;
516 * NULL if status is not GNUNET_OK
517 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
518 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
519 */
520static void
521status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
522{
523 uint64_t event_mask;
524
525 GNUNET_assert (GNUNET_OK == status);
526 event_mask = 0;
527 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_START);
528 event_mask |= (1L << GNUNET_TESTBED_ET_PEER_STOP);
529 event_mask |= (1L << GNUNET_TESTBED_ET_CONNECT);
530 event_mask |= (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED);
531 switch (result)
532 {
533 case INIT:
534 controller1 =
535 GNUNET_TESTBED_controller_connect (config, host, event_mask, &controller_cb,
536 NULL);
537 GNUNET_assert (NULL != controller1);
538 result = CONTROLLER1_UP;
539 neighbour = GNUNET_TESTBED_host_create ("127.0.0.1", NULL, 0);
540 GNUNET_assert (NULL != neighbour);
541 reg_handle =
542 GNUNET_TESTBED_register_host (controller1, neighbour, &registration_comp,
543 neighbour);
544 GNUNET_assert (NULL != reg_handle);
545 break;
546 default:
547 GNUNET_assert (0);
548 }
549
550}
551
552
553
554/**
555 * Main run function.
556 *
557 * @param cls NULL
558 * @param args arguments passed to GNUNET_PROGRAM_run
559 * @param cfgfile the path to configuration file
560 * @param cfg the configuration file handle
561 */
562static void
563run (void *cls, char *const *args, const char *cfgfile,
564 const struct GNUNET_CONFIGURATION_Handle *config)
565{
566 host = GNUNET_TESTBED_host_create (NULL, NULL, 0);
567 GNUNET_assert (NULL != host);
568 cfg = GNUNET_CONFIGURATION_dup (config);
569 cp1 = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb,
570 NULL);
571 abort_task =
572 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
573 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
574 NULL);
575}
576
577
578/**
579 * Main function
580 */
581int
582main (int argc, char **argv)
583{
584 int ret;
585
586 char *const argv2[] = { "test_testbed_api_2peers_2controllers",
587 "-c", "test_testbed_api.conf",
588 NULL
589 };
590 struct GNUNET_GETOPT_CommandLineOption options[] = {
591 GNUNET_GETOPT_OPTION_END
592 };
593 result = INIT;
594 ret =
595 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
596 "test_testbed_api_2peers_2controllers", "nohelp",
597 options, &run, NULL);
598 if ((GNUNET_OK != ret) || (SUCCESS != result))
599 return 1;
600 return 0;
601}
602
603/* end of test_testbed_api_2peers_2controllers.c */
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index b5f55b8f8..65d4ffbd9 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -700,7 +700,6 @@ GNUNET_TESTBED_overlay_connect (void *op_cls,
700 struct OverlayConnectData *data; 700 struct OverlayConnectData *data;
701 701
702 GNUNET_assert ((PS_STARTED == p1->state) && (PS_STARTED == p2->state)); 702 GNUNET_assert ((PS_STARTED == p1->state) && (PS_STARTED == p2->state));
703 GNUNET_assert (p1->controller == p2->controller);
704 data = GNUNET_malloc (sizeof (struct OverlayConnectData)); 703 data = GNUNET_malloc (sizeof (struct OverlayConnectData));
705 data->p1 = p1; 704 data->p1 = p1;
706 data->p2 = p2; 705 data->p2 = p2;