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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file testbed/test_testbed_api_peer_reconfiguration.c
23 * @brief testcase for testing GNUNET_TESTBED_peer_manage_service()
25 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testbed_service.h"
33 * Number of peers we want to start
38 * The array of peers; we get them from the testbed
40 static struct GNUNET_TESTBED_Peer **peers;
45 static struct GNUNET_TESTBED_Operation *op;
48 * Abort task identifier
50 static struct GNUNET_SCHEDULER_Task * abort_task;
58 * Test has just been initialized
63 * Peers have been started
68 * Peer has been reconfigured. Test completed successfully
70 STATE_PEER_RECONFIGURED
77 #define FAIL_TEST(cond, ret) do { \
80 if (NULL != abort_task) \
81 GNUNET_SCHEDULER_cancel (abort_task); \
82 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
96 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n");
100 GNUNET_TESTBED_operation_done (op);
103 GNUNET_SCHEDULER_shutdown();
108 * Signature of the event handler function called by the
109 * respective event controller.
112 * @param event information about the event
115 controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
117 if (STATE_PEER_STARTED != state)
119 if (GNUNET_TESTBED_ET_OPERATION_FINISHED != event->type)
121 GNUNET_TESTBED_operation_done (op);
123 FAIL_TEST (0, return);
125 if (NULL != event->details.operation_finished.emsg)
127 fprintf (stderr, "Operation failed: %s\n",
128 event->details.operation_finished.emsg);
129 GNUNET_TESTBED_operation_done (op);
131 FAIL_TEST (0, return);
133 GNUNET_TESTBED_operation_done (op);
134 state = STATE_PEER_RECONFIGURED;
135 GNUNET_SCHEDULER_cancel (abort_task);
137 GNUNET_SCHEDULER_shutdown ();
142 * Signature of a main function for a testcase.
145 * @param h the run handle
146 * @param num_peers number of peers in 'peers'
147 * @param peers_ handle to peers run in the testbed
148 * @param links_succeeded the number of overlay link connection attempts that
150 * @param links_failed the number of overlay link connection attempts that
154 test_master (void *cls,
155 struct GNUNET_TESTBED_RunHandle *h,
156 unsigned int num_peers,
157 struct GNUNET_TESTBED_Peer **peers_,
158 unsigned int links_succeeded,
159 unsigned int links_failed)
161 struct GNUNET_CONFIGURATION_Handle *cfg;
163 FAIL_TEST (NUM_PEERS == num_peers, return);
164 state = STATE_PEER_STARTED;
166 cfg = GNUNET_CONFIGURATION_create ();
167 FAIL_TEST (GNUNET_OK == GNUNET_CONFIGURATION_load
168 (cfg, "test_testbed_api_testbed_run_topologyrandom.conf"), return);
169 op = GNUNET_TESTBED_peer_update_configuration (peers[0], cfg);
170 GNUNET_CONFIGURATION_destroy (cfg);
171 FAIL_TEST (NULL != op, return);
172 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
173 (GNUNET_TIME_UNIT_SECONDS, 30),
182 main (int argc, char **argv)
185 (void) GNUNET_TESTBED_test_run ("test_testbed_api_peer_reconfiguration",
186 "test_testbed_api.conf",
188 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED,
189 &controller_cb, NULL,
191 if (STATE_PEER_RECONFIGURED != state)