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 src/testbed/test_testbed_api_test.c
23 * @brief testing cases for testing high level testbed api helper functions
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
33 * Generic logging shortcut
35 #define LOG(kind,...) \
36 GNUNET_log (kind, __VA_ARGS__)
39 * Number of peers we want to start
46 static struct GNUNET_TESTBED_Peer **peers;
51 static struct GNUNET_TESTBED_Operation *op;
54 * Abort task identifier
56 static struct GNUNET_SCHEDULER_Task * abort_task;
59 * shutdown task identifier
61 static struct GNUNET_SCHEDULER_Task * shutdown_task;
75 do_shutdown (void *cls)
78 if (NULL != abort_task)
79 GNUNET_SCHEDULER_cancel (abort_task);
81 GNUNET_TESTBED_operation_done (op);
82 GNUNET_SCHEDULER_shutdown ();
86 * shortcut to exit during failure
88 #define FAIL_TEST(cond) do { \
91 if (NULL != abort_task) \
92 GNUNET_SCHEDULER_cancel (abort_task); \
94 if (NULL == shutdown_task) \
95 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \
102 * abort task to run on test timed out
109 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
111 if (NULL != shutdown_task)
112 GNUNET_SCHEDULER_cancel (shutdown_task);
118 * Callback to be called when the requested peer information is available
120 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
121 * @param op the operation this callback corresponds to
122 * @param pinfo the result; will be NULL if the operation has failed
123 * @param emsg error message if the operation has failed; will be NULL if the
124 * operation is successfull
127 peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
128 const struct GNUNET_TESTBED_PeerInformation *pinfo,
131 FAIL_TEST (op == op_);
132 FAIL_TEST (NULL == cb_cls);
133 FAIL_TEST (NULL == emsg);
134 FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit);
135 FAIL_TEST (NULL != pinfo->result.id);
136 GNUNET_TESTBED_operation_done (op);
139 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
144 * Callback to be called when an operation is completed
146 * @param cls the callback closure from functions generating an operation
147 * @param op the operation that has been finished
148 * @param emsg error message in case the operation has failed; will be NULL if
149 * operation has executed successfully.
152 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg)
154 FAIL_TEST (NULL == cls);
155 FAIL_TEST (op == op_);
158 LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
161 GNUNET_TESTBED_operation_done (op);
162 op = GNUNET_TESTBED_peer_get_information (peers[0],
163 GNUNET_TESTBED_PIT_IDENTITY,
169 * Controller event callback
172 * @param event the controller event
175 controller_event_cb (void *cls,
176 const struct GNUNET_TESTBED_EventInformation *event)
180 case GNUNET_TESTBED_ET_CONNECT:
181 FAIL_TEST (event->details.peer_connect.peer1 == peers[0]);
182 FAIL_TEST (event->details.peer_connect.peer2 == peers[1]);
191 * Signature of a main function for a testcase.
194 * @param h the run handle
195 * @param num_peers number of peers in 'peers'
196 * @param peers- handle to peers run in the testbed
197 * @param links_succeeded the number of overlay link connection attempts that
199 * @param links_failed the number of overlay link connection attempts that
203 test_master (void *cls,
204 struct GNUNET_TESTBED_RunHandle *h,
205 unsigned int num_peers,
206 struct GNUNET_TESTBED_Peer **peers_,
207 unsigned int links_succeeded,
208 unsigned int links_failed)
212 FAIL_TEST (NULL == cls);
213 FAIL_TEST (NUM_PEERS == num_peers);
214 FAIL_TEST (NULL != peers_);
215 for (peer = 0; peer < num_peers; peer++)
216 FAIL_TEST (NULL != peers_[peer]);
218 op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0],
221 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
222 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
231 main (int argc, char **argv)
235 result = GNUNET_SYSERR;
237 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
238 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
239 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test",
240 "test_testbed_api.conf", NUM_PEERS,
241 event_mask, &controller_event_cb, NULL,
243 if (GNUNET_OK != result)
248 /* end of test_testbed_api_test.c */