2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file src/testbed/test_testbed_api_topology.c
21 * @brief testing cases for testing high level testbed api helper functions
22 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
26 #include "gnunet_util_lib.h"
27 #include "gnunet_testbed_service.h"
30 * Number of peers we want to start
37 static struct GNUNET_TESTBED_Peer **peers;
42 static struct GNUNET_TESTBED_Operation *op;
47 static struct GNUNET_SCHEDULER_Task * shutdown_task;
55 * Counter for counting overlay connections
57 static unsigned int overlay_connects;
66 do_shutdown (void *cls)
71 GNUNET_TESTBED_operation_done (op);
74 GNUNET_SCHEDULER_shutdown ();
78 * Controller event callback
81 * @param event the controller event
84 controller_event_cb (void *cls,
85 const struct GNUNET_TESTBED_EventInformation *event)
89 case GNUNET_TESTBED_ET_CONNECT:
91 if ((NUM_PEERS) == overlay_connects)
94 GNUNET_SCHEDULER_cancel (shutdown_task);
95 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
98 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
99 GNUNET_assert (NULL != event->details.operation_finished.emsg);
103 if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) &&
104 (NULL != event->details.operation_finished.emsg))
105 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
106 "An operation failed with error: %s\n",
107 event->details.operation_finished.emsg);
108 result = GNUNET_SYSERR;
109 GNUNET_SCHEDULER_cancel (shutdown_task);
110 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
116 * Signature of a main function for a testcase.
119 * @param h the run handle
120 * @param num_peers number of peers in 'peers'
121 * @param peers_ handle to peers run in the testbed
122 * @param links_succeeded the number of overlay link connection attempts that
124 * @param links_failed the number of overlay link connection attempts that
128 test_master (void *cls,
129 struct GNUNET_TESTBED_RunHandle *h,
130 unsigned int num_peers,
131 struct GNUNET_TESTBED_Peer **peers_,
132 unsigned int links_succeeded,
133 unsigned int links_failed)
137 GNUNET_assert (NULL == cls);
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n");
143 GNUNET_assert (NUM_PEERS == num_peers);
144 for (peer = 0; peer < num_peers; peer++)
145 GNUNET_assert (NULL != peers_[peer]);
147 overlay_connects = 0;
148 op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL,
151 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
153 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
154 GNUNET_assert (NULL != op);
156 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
157 (GNUNET_TIME_UNIT_SECONDS, 300),
166 main (int argc, char **argv)
170 result = GNUNET_SYSERR;
172 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
173 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
174 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test",
175 "test_testbed_api.conf", NUM_PEERS,
176 event_mask, &controller_event_cb, NULL,
178 if (GNUNET_OK != result)
183 /* end of test_testbed_api_topology.c */