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.
17 * @file testbed/test_testbed_api_peer_reconfiguration.c
18 * @brief testcase for testing GNUNET_TESTBED_peer_manage_service()
20 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
24 #include "gnunet_util_lib.h"
25 #include "gnunet_testbed_service.h"
28 * Number of peers we want to start
33 * The array of peers; we get them from the testbed
35 static struct GNUNET_TESTBED_Peer **peers;
40 static struct GNUNET_TESTBED_Operation *op;
43 * Abort task identifier
45 static struct GNUNET_SCHEDULER_Task * abort_task;
53 * Test has just been initialized
58 * Peers have been started
63 * Peer has been reconfigured. Test completed successfully
65 STATE_PEER_RECONFIGURED
72 #define FAIL_TEST(cond, ret) do { \
75 if (NULL != abort_task) \
76 GNUNET_SCHEDULER_cancel (abort_task); \
77 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
91 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n");
95 GNUNET_TESTBED_operation_done (op);
98 GNUNET_SCHEDULER_shutdown();
103 * Signature of the event handler function called by the
104 * respective event controller.
107 * @param event information about the event
110 controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
112 if (STATE_PEER_STARTED != state)
114 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
116 GNUNET_TESTBED_operation_done (op);
118 FAIL_TEST (0, return);
120 if (NULL != event->details.operation_finished.emsg)
122 fprintf (stderr, "Operation failed: %s\n",
123 event->details.operation_finished.emsg);
124 GNUNET_TESTBED_operation_done (op);
126 FAIL_TEST (0, return);
128 GNUNET_TESTBED_operation_done (op);
129 state = STATE_PEER_RECONFIGURED;
130 GNUNET_SCHEDULER_cancel (abort_task);
132 GNUNET_SCHEDULER_shutdown ();
137 * Signature of a main function for a testcase.
140 * @param h the run handle
141 * @param num_peers number of peers in 'peers'
142 * @param peers_ handle to peers run in the testbed
143 * @param links_succeeded the number of overlay link connection attempts that
145 * @param links_failed the number of overlay link connection attempts that
149 test_master (void *cls,
150 struct GNUNET_TESTBED_RunHandle *h,
151 unsigned int num_peers,
152 struct GNUNET_TESTBED_Peer **peers_,
153 unsigned int links_succeeded,
154 unsigned int links_failed)
156 struct GNUNET_CONFIGURATION_Handle *cfg;
158 FAIL_TEST (NUM_PEERS == num_peers, return);
159 state = STATE_PEER_STARTED;
161 cfg = GNUNET_CONFIGURATION_create ();
162 FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_load
163 (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return);
164 op = GNUNET_TESTBED_peer_update_configuration (peers[0], cfg);
165 GNUNET_CONFIGURATION_destroy (cfg);
166 FAIL_TEST (NULL != op, return);
167 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
168 (GNUNET_TIME_UNIT_SECONDS, 30),
177 main (int argc, char **argv)
180 (void) GNUNET_TESTBED_test_run ("test_testbed_api_peer_reconfiguration",
181 "test_testbed_api.conf",
183 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED,
184 &controller_cb, NULL,
186 if (STATE_PEER_RECONFIGURED != state)