aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-09-28 10:06:44 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-09-28 10:06:44 +0000
commitb764304d2ebf70d837e0636e3c34cd172285110f (patch)
treee1c7848c2a64dea46b0b70de6c33dff942af2e09 /src/testbed
parent07b2bab7ce6800ca399f49e1821f274a8150355b (diff)
downloadgnunet-b764304d2ebf70d837e0636e3c34cd172285110f.tar.gz
gnunet-b764304d2ebf70d837e0636e3c34cd172285110f.zip
topology test case
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am12
-rw-r--r--src/testbed/test_testbed_api_topology.c146
-rw-r--r--src/testbed/testbed_api.c2
-rw-r--r--src/testbed/testbed_api_topology.c5
4 files changed, 161 insertions, 4 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 5c42ec8e8..7889346f2 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -77,7 +77,8 @@ check_PROGRAMS = \
77 test_testbed_api_operations \ 77 test_testbed_api_operations \
78 test_testbed_api_testbed_run \ 78 test_testbed_api_testbed_run \
79 test_testbed_api_test \ 79 test_testbed_api_test \
80 test_gnunet_helper_testbed 80 test_gnunet_helper_testbed \
81 test_testbed_api_topology
81 82
82if ENABLE_TEST_RUN 83if ENABLE_TEST_RUN
83 TESTS = \ 84 TESTS = \
@@ -89,7 +90,8 @@ if ENABLE_TEST_RUN
89 test_gnunet_helper_testbed \ 90 test_gnunet_helper_testbed \
90 test_testbed_api_controllerlink \ 91 test_testbed_api_controllerlink \
91 test_testbed_api_testbed_run \ 92 test_testbed_api_testbed_run \
92 test_testbed_api_test 93 test_testbed_api_test \
94 test_testbed_api_topology
93endif 95endif
94 96
95test_testbed_api_hosts_SOURCES = \ 97test_testbed_api_hosts_SOURCES = \
@@ -144,6 +146,12 @@ test_testbed_api_test_LDADD = \
144 $(top_builddir)/src/util/libgnunetutil.la \ 146 $(top_builddir)/src/util/libgnunetutil.la \
145 libgnunettestbed.la 147 libgnunettestbed.la
146 148
149test_testbed_api_topology_SOURCES = \
150 test_testbed_api_topology.c
151test_testbed_api_topology_LDADD = \
152 $(top_builddir)/src/util/libgnunetutil.la \
153 libgnunettestbed.la
154
147test_gnunet_helper_testbed_SOURCES = \ 155test_gnunet_helper_testbed_SOURCES = \
148 test_gnunet_helper_testbed.c 156 test_gnunet_helper_testbed.c
149test_gnunet_helper_testbed_LDADD = \ 157test_gnunet_helper_testbed_LDADD = \
diff --git a/src/testbed/test_testbed_api_topology.c b/src/testbed/test_testbed_api_topology.c
new file mode 100644
index 000000000..10be26887
--- /dev/null
+++ b/src/testbed/test_testbed_api_topology.c
@@ -0,0 +1,146 @@
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 src/testbed/test_testbed_api_topology.c
23 * @brief testing cases for testing high level testbed api helper functions
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 */
26
27#include "platform.h"
28#include "gnunet_common.h"
29#include "gnunet_testbed_service.h"
30
31/**
32 * Number of peers we want to start
33 */
34#define NUM_PEERS 5
35
36/**
37 * Array of peers
38 */
39static struct GNUNET_TESTBED_Peer **peers;
40
41/**
42 * Operation handle
43 */
44static struct GNUNET_TESTBED_Operation *op;
45
46/**
47 * Testing result
48 */
49static int result;
50
51/**
52 * Counter for counting overlay connections
53 */
54static unsigned int overlay_connects;
55
56
57/**
58 * Shutdown nicely
59 *
60 * @param cls NULL
61 * @param tc the task context
62 */
63static void
64do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
65{
66 if (NULL != op)
67 {
68 GNUNET_TESTBED_operation_done (op);
69 op = NULL;
70 }
71 GNUNET_SCHEDULER_shutdown ();
72}
73
74/**
75 * Controller event callback
76 *
77 * @param cls NULL
78 * @param event the controller event
79 */
80static void
81controller_event_cb (void *cls,
82 const struct GNUNET_TESTBED_EventInformation *event)
83{
84 switch (event->type)
85 {
86 case GNUNET_TESTBED_ET_CONNECT:
87 overlay_connects++;
88 if ((NUM_PEERS - 1) == overlay_connects)
89 {
90 result = GNUNET_OK;
91 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
92 }
93 break;
94 default:
95 GNUNET_assert (0);
96 }
97}
98
99
100/**
101 * Signature of a main function for a testcase.
102 *
103 * @param cls closure
104 * @param num_peers number of peers in 'peers'
105 * @param peers handle to peers run in the testbed
106 */
107static void
108test_master (void *cls, unsigned int num_peers,
109 struct GNUNET_TESTBED_Peer **peers_)
110{
111 unsigned int peer;
112
113 GNUNET_assert (NULL == cls);
114 GNUNET_assert (NUM_PEERS == num_peers);
115 GNUNET_assert (NULL != peers_);
116 for (peer = 0; peer < num_peers; peer++)
117 GNUNET_assert (NULL != peers_[peer]);
118 peers = peers_;
119 overlay_connects = 0;
120 op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers,
121 GNUNET_TESTBED_TOPOLOGY_LINE);
122 GNUNET_assert (NULL != op);
123}
124
125
126/**
127 * Main function
128 */
129int
130main (int argc, char **argv)
131{
132 uint64_t event_mask;
133
134 result = GNUNET_SYSERR;
135 event_mask = 0;
136 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
137 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
138 GNUNET_TESTBED_test_run ("test_testbed_api_test", "test_testbed_api.conf",
139 NUM_PEERS, event_mask, &controller_event_cb, NULL,
140 &test_master, NULL);
141 if (GNUNET_OK != result)
142 return 1;
143 return 0;
144}
145
146/* end of test_testbed_api_topology.c */
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index be8c68fce..c16ac0168 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -1431,6 +1431,8 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller
1431 GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_parallel_operations); 1431 GNUNET_TESTBED_operation_queue_destroy_ (controller->opq_parallel_operations);
1432 GNUNET_TESTBED_operation_queue_destroy_ 1432 GNUNET_TESTBED_operation_queue_destroy_
1433 (controller->opq_parallel_service_connections); 1433 (controller->opq_parallel_service_connections);
1434 GNUNET_TESTBED_operation_queue_destroy_
1435 (controller->opq_parallel_topology_config_operations);
1434 GNUNET_free (controller); 1436 GNUNET_free (controller);
1435} 1437}
1436 1438
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index 04fea74b3..f7aa2ed5b 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -145,8 +145,8 @@ oprelease_overlay_configure_topology (void *cls)
145 { 145 {
146 for (p = 0; p < tc->link_array_size; p++) 146 for (p = 0; p < tc->link_array_size; p++)
147 if (NULL != tc->link_ops[p]) 147 if (NULL != tc->link_ops[p])
148 GNUNET_TESTBED_operation_cancel (tc->link_ops[p]); 148 GNUNET_TESTBED_operation_cancel (tc->link_ops[p]);
149 GNUNET_free (tc->link_ops); 149 GNUNET_free (tc->link_ops);
150 } 150 }
151 GNUNET_free_non_null (tc->link_array); 151 GNUNET_free_non_null (tc->link_array);
152 GNUNET_free (tc); 152 GNUNET_free (tc);
@@ -231,6 +231,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls,
231 return NULL; 231 return NULL;
232 c = peers[0]->controller; 232 c = peers[0]->controller;
233 tc = GNUNET_malloc (sizeof (struct TopologyContext)); 233 tc = GNUNET_malloc (sizeof (struct TopologyContext));
234 tc->peers = peers;
234 switch (topo) 235 switch (topo)
235 { 236 {
236 case GNUNET_TESTBED_TOPOLOGY_LINE: 237 case GNUNET_TESTBED_TOPOLOGY_LINE: