2 This file is part of GNUnet
3 (C) 2008--2012 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 testbed/test_testbed_api_testbed_run.c
23 * @brief Test cases for testing high-level testbed management
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
37 * The array of peers; we fill this as the peers are given to us by the testbed
39 static struct GNUNET_TESTBED_Peer *peers[NUM_PEERS];
42 * Abort task identifier
44 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
61 * @param tc the task context
64 do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
66 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
67 GNUNET_SCHEDULER_cancel (abort_task);
68 GNUNET_SCHEDULER_shutdown ();
73 * abort task to run on test timed out
76 * @param tc the task context
79 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
82 abort_task = GNUNET_SCHEDULER_NO_TASK;
83 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
84 GNUNET_SCHEDULER_shutdown (); /* Stop the scheduler */
89 * Task to be executed when peers are ready
92 * @param tc the task context
95 master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
98 /* Artificial delay */
99 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL);
104 * Controller event callback
107 * @param event the controller event
110 controller_event_cb (void *cls,
111 const struct GNUNET_TESTBED_EventInformation *event)
116 case GNUNET_TESTBED_ET_PEER_START:
117 GNUNET_assert (NULL == peers[peer_id]);
118 GNUNET_assert (NULL != event->details.peer_start.peer);
119 peers[peer_id++] = event->details.peer_start.peer;
131 * @param args arguments passed to GNUNET_PROGRAM_run
132 * @param cfgfile the path to configuration file
133 * @param cfg the configuration file handle
136 run (void *cls, char *const *args, const char *cfgfile,
137 const struct GNUNET_CONFIGURATION_Handle *config)
142 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
143 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
144 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
145 event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
146 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
147 GNUNET_TESTBED_run (NULL, config, 2, event_mask, &controller_event_cb,
148 NULL, &master_task, NULL);
149 abort_task = GNUNET_SCHEDULER_add_delayed
150 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort, NULL);
157 int main (int argc, char **argv)
160 char *const argv2[] = {
161 "test_testbed_api_testbed_run",
162 "-c", "test_testbed_api.conf",
165 struct GNUNET_GETOPT_CommandLineOption options[] = {
166 GNUNET_GETOPT_OPTION_END
169 result = GNUNET_SYSERR;
170 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
171 "test_testbed_api_testbed_run", "nohelp", options,
173 if ((GNUNET_OK != ret) || (GNUNET_OK != result))