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 src/testbed/test_testbed_api_test.c
18 * @brief testing cases for testing high level testbed api helper functions
19 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
23 #include "gnunet_util_lib.h"
24 #include "gnunet_testbed_service.h"
28 * Generic logging shortcut
30 #define LOG(kind,...) \
31 GNUNET_log (kind, __VA_ARGS__)
34 * Number of peers we want to start
41 static struct GNUNET_TESTBED_Peer **peers;
46 static struct GNUNET_TESTBED_Operation *op;
49 * Abort task identifier
51 static struct GNUNET_SCHEDULER_Task * abort_task;
54 * shutdown task identifier
56 static struct GNUNET_SCHEDULER_Task * shutdown_task;
70 do_shutdown (void *cls)
73 if (NULL != abort_task)
74 GNUNET_SCHEDULER_cancel (abort_task);
76 GNUNET_TESTBED_operation_done (op);
77 GNUNET_SCHEDULER_shutdown ();
81 * shortcut to exit during failure
83 #define FAIL_TEST(cond) do { \
86 if (NULL != abort_task) \
87 GNUNET_SCHEDULER_cancel (abort_task); \
89 if (NULL == shutdown_task) \
90 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \
97 * abort task to run on test timed out
104 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
106 if (NULL != shutdown_task)
107 GNUNET_SCHEDULER_cancel (shutdown_task);
113 * Callback to be called when the requested peer information is available
115 * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information()
116 * @param op the operation this callback corresponds to
117 * @param pinfo the result; will be NULL if the operation has failed
118 * @param emsg error message if the operation has failed; will be NULL if the
119 * operation is successfull
122 peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_,
123 const struct GNUNET_TESTBED_PeerInformation *pinfo,
126 FAIL_TEST (op == op_);
127 FAIL_TEST (NULL == cb_cls);
128 FAIL_TEST (NULL == emsg);
129 FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit);
130 FAIL_TEST (NULL != pinfo->result.id);
131 GNUNET_TESTBED_operation_done (op);
134 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
139 * Callback to be called when an operation is completed
141 * @param cls the callback closure from functions generating an operation
142 * @param op the operation that has been finished
143 * @param emsg error message in case the operation has failed; will be NULL if
144 * operation has executed successfully.
147 op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg)
149 FAIL_TEST (NULL == cls);
150 FAIL_TEST (op == op_);
153 LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
156 GNUNET_TESTBED_operation_done (op);
157 op = GNUNET_TESTBED_peer_get_information (peers[0],
158 GNUNET_TESTBED_PIT_IDENTITY,
164 * Controller event callback
167 * @param event the controller event
170 controller_event_cb (void *cls,
171 const struct GNUNET_TESTBED_EventInformation *event)
175 case GNUNET_TESTBED_ET_CONNECT:
176 FAIL_TEST (event->details.peer_connect.peer1 == peers[0]);
177 FAIL_TEST (event->details.peer_connect.peer2 == peers[1]);
186 * Signature of a main function for a testcase.
189 * @param h the run handle
190 * @param num_peers number of peers in 'peers'
191 * @param peers- handle to peers run in the testbed
192 * @param links_succeeded the number of overlay link connection attempts that
194 * @param links_failed the number of overlay link connection attempts that
198 test_master (void *cls,
199 struct GNUNET_TESTBED_RunHandle *h,
200 unsigned int num_peers,
201 struct GNUNET_TESTBED_Peer **peers_,
202 unsigned int links_succeeded,
203 unsigned int links_failed)
207 FAIL_TEST (NULL == cls);
208 FAIL_TEST (NUM_PEERS == num_peers);
209 FAIL_TEST (NULL != peers_);
210 for (peer = 0; peer < num_peers; peer++)
211 FAIL_TEST (NULL != peers_[peer]);
213 op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0],
216 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
217 (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort,
226 main (int argc, char **argv)
230 result = GNUNET_SYSERR;
232 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
233 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
234 (void) GNUNET_TESTBED_test_run ("test_testbed_api_test",
235 "test_testbed_api.conf", NUM_PEERS,
236 event_mask, &controller_event_cb, NULL,
238 if (GNUNET_OK != result)
243 /* end of test_testbed_api_test.c */