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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file testbed/test_testbed_api_peers_manage_services.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;
50 static void *dummy_cls = (void *) 0xDEAD0001;
53 * Abort task identifier
55 static struct GNUNET_SCHEDULER_Task * abort_task;
63 * Test has just been initialized
68 * Peers have been started
73 * statistics service went down
78 * statistics service went up
83 * Testing completed successfully
91 #define FAIL_TEST(cond, ret) do { \
94 if (NULL != abort_task) \
95 GNUNET_SCHEDULER_cancel (abort_task); \
96 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Aborting\n");
114 GNUNET_TESTBED_operation_done (op);
117 GNUNET_SCHEDULER_shutdown();
122 * Callback to be called when an operation is completed
124 * @param cls the callback closure from functions generating an operation
125 * @param op the operation that has been finished
126 * @param emsg error message in case the operation has failed; will be NULL if
127 * operation has executed successfully.
130 op_comp_cb (void *cls,
131 struct GNUNET_TESTBED_Operation *op,
134 FAIL_TEST (cls == dummy_cls, return);
135 FAIL_TEST (NULL == emsg, return);
136 GNUNET_TESTBED_operation_done (op);
140 case STATE_PEERS_STARTED:
141 state = STATE_SERVICE_DOWN;
142 op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
148 GNUNET_assert (NULL != op);
150 case STATE_SERVICE_DOWN:
151 state = STATE_SERVICE_UP;
152 GNUNET_SCHEDULER_cancel (abort_task);
155 GNUNET_SCHEDULER_shutdown ();
158 FAIL_TEST (0, return);
164 * Signature of a main function for a testcase.
167 * @param h the run handle
168 * @param num_peers number of peers in 'peers'
169 * @param peers_ handle to peers run in the testbed
170 * @param links_succeeded the number of overlay link connection attempts that
172 * @param links_failed the number of overlay link connection attempts that
176 test_master (void *cls,
177 struct GNUNET_TESTBED_RunHandle *h,
178 unsigned int num_peers,
179 struct GNUNET_TESTBED_Peer **peers_,
180 unsigned int links_succeeded,
181 unsigned int links_failed)
183 FAIL_TEST (NUM_PEERS == num_peers, return);
184 state = STATE_PEERS_STARTED;
186 op = GNUNET_TESTBED_peer_manage_service (dummy_cls,
192 FAIL_TEST (NULL != op, return);
193 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
194 (GNUNET_TIME_UNIT_MINUTES, 1),
203 main (int argc, char **argv)
206 (void) GNUNET_TESTBED_test_run ("test_testbed_api_peers_manage_services",
207 "test_testbed_api.conf",
211 if (STATE_OK != state)