2 This file is part of GNUnet
3 (C) 2008--2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
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>
28 #include "gnunet_common.h"
29 #include "gnunet_testbed_service.h"
32 * Number of peers we want to start
39 static struct GNUNET_TESTBED_Peer **peers;
44 static struct GNUNET_TESTBED_Operation *op;
49 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
57 * Counter for counting overlay connections
59 static unsigned int overlay_connects;
66 * @param tc the task context
69 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
71 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
74 GNUNET_TESTBED_operation_done (op);
77 GNUNET_SCHEDULER_shutdown ();
81 * Controller event callback
84 * @param event the controller event
87 controller_event_cb (void *cls,
88 const struct GNUNET_TESTBED_EventInformation *event)
92 case GNUNET_TESTBED_ET_CONNECT:
94 if ((NUM_PEERS) == overlay_connects)
97 GNUNET_SCHEDULER_cancel (shutdown_task);
98 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
101 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
102 GNUNET_assert (NULL != event->details.operation_finished.emsg);
106 if ((GNUNET_TESTBED_ET_OPERATION_FINISHED == event->type) &&
107 (NULL != event->details.operation_finished.emsg))
108 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
109 "An operation failed with error: %s\n",
110 event->details.operation_finished.emsg);
111 result = GNUNET_SYSERR;
112 GNUNET_SCHEDULER_cancel (shutdown_task);
113 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
119 * Signature of a main function for a testcase.
122 * @param num_peers number of peers in 'peers'
123 * @param peers_ handle to peers run in the testbed
124 * @param links_succeeded the number of overlay link connection attempts that
126 * @param links_failed the number of overlay link connection attempts that
130 test_master (void *cls, 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);
138 GNUNET_assert (NUM_PEERS == num_peers);
139 GNUNET_assert (NULL != peers_);
140 for (peer = 0; peer < num_peers; peer++)
141 GNUNET_assert (NULL != peers_[peer]);
143 overlay_connects = 0;
144 op = GNUNET_TESTBED_overlay_configure_topology (NULL, NUM_PEERS, peers, NULL,
147 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
149 GNUNET_TESTBED_TOPOLOGY_OPTION_END);
150 GNUNET_assert (NULL != op);
152 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
153 (GNUNET_TIME_UNIT_SECONDS, 300),
162 main (int argc, char **argv)
166 result = GNUNET_SYSERR;
168 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
169 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
170 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test",
171 "test_testbed_api.conf", NUM_PEERS,
172 event_mask, &controller_event_cb, NULL,
174 if (GNUNET_OK != result)
179 /* end of test_testbed_api_topology.c */