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"
34 static struct GNUNET_TESTBED_RunHandle *rh;
37 * Abort task identifier
39 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
51 * @param tc the task context
54 do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
56 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
57 GNUNET_SCHEDULER_cancel (abort_task);
59 GNUNET_TESTBED_shutdown_run (rh);
64 * abort task to run on test timed out
67 * @param tc the task context
70 do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
72 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
73 abort_task = GNUNET_SCHEDULER_NO_TASK;
74 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
75 GNUNET_SCHEDULER_shutdown (); /* Stop the scheduler */
80 * Task to be executed when peers are ready
83 * @param tc the task context
86 master_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89 /* Artificial delay */
90 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL);
95 * Controller event callback
98 * @param event the controller event
101 controller_event_cb (void *cls,
102 const struct GNUNET_TESTBED_EventInformation *event)
104 if (GNUNET_TESTBED_ET_PEER_START == event->type)
114 * @param args arguments passed to GNUNET_PROGRAM_run
115 * @param cfgfile the path to configuration file
116 * @param cfg the configuration file handle
119 run (void *cls, char *const *args, const char *cfgfile,
120 const struct GNUNET_CONFIGURATION_Handle *config)
125 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
126 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
127 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
128 event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
129 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
130 rh = GNUNET_TESTBED_run (NULL, config, 2, event_mask, &controller_event_cb,
131 NULL, &master_task, NULL);
132 abort_task = GNUNET_SCHEDULER_add_delayed
133 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort, NULL);
140 int main (int argc, char **argv)
143 char *const argv2[] = {
144 "test_testbed_api_testbed_run",
145 "-c", "test_testbed_api.conf",
148 struct GNUNET_GETOPT_CommandLineOption options[] = {
149 GNUNET_GETOPT_OPTION_END
152 result = GNUNET_SYSERR;
153 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
154 "test_testbed_api_testbed_run", "nohelp", options,
156 if ((GNUNET_OK != ret) || (GNUNET_OK != result))