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_barriers.c
23 * @brief testcase binary for testing testbed barriers API
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
30 #include "test_testbed_api_barriers.h"
36 #define LOG(type,...) \
37 GNUNET_log (type, __VA_ARGS__);
40 * Number of peers we start in this test case
48 struct GNUNET_TESTBED_Barrier *barrier;
51 * Identifier for the shutdown task
53 static struct GNUNET_SCHEDULER_Task *shutdown_task;
56 * Result of this test case
62 * Shutdown this test case when it takes too long
67 do_shutdown (void *cls)
72 GNUNET_TESTBED_barrier_cancel (barrier);
76 GNUNET_SCHEDULER_shutdown ();
81 * Functions of this type are to be given as callback argument to
82 * GNUNET_TESTBED_barrier_init(). The callback will be called when status
83 * information is available for the barrier.
85 * @param cls the closure given to GNUNET_TESTBED_barrier_init()
86 * @param name the name of the barrier
87 * @param barrier the barrier handle
88 * @param status status of the barrier; #GNUNET_OK if the barrier is crossed;
89 * #GNUNET_SYSERR upon error
90 * @param emsg if the status were to be #GNUNET_SYSERR, this parameter has the
94 barrier_cb (void *cls,
96 struct GNUNET_TESTBED_Barrier *_barrier,
97 enum GNUNET_TESTBED_BarrierStatus status,
100 static enum GNUNET_TESTBED_BarrierStatus old_status;
102 GNUNET_assert (NULL == cls);
103 GNUNET_assert (_barrier == barrier);
106 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED:
107 LOG (GNUNET_ERROR_TYPE_INFO,
108 "Barrier initialised\n");
111 case GNUNET_TESTBED_BARRIERSTATUS_ERROR:
112 LOG (GNUNET_ERROR_TYPE_ERROR,
113 "Barrier initialisation failed: %s",
114 (NULL == emsg) ? "unknown reason" : emsg);
116 GNUNET_SCHEDULER_shutdown ();
118 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
119 LOG (GNUNET_ERROR_TYPE_INFO,
120 "Barrier crossed\n");
121 if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED)
124 GNUNET_SCHEDULER_shutdown ();
133 * Signature of a main function for a testcase.
136 * @param h the run handle
137 * @param num_peers number of peers in 'peers'
138 * @param peers_ handle to peers run in the testbed
139 * @param links_succeeded the number of overlay link connection attempts that
141 * @param links_failed the number of overlay link connection attempts that
145 test_master (void *cls,
146 struct GNUNET_TESTBED_RunHandle *h,
147 unsigned int num_peers,
148 struct GNUNET_TESTBED_Peer **peers_,
149 unsigned int links_succeeded,
150 unsigned int links_failed)
152 struct GNUNET_TESTBED_Controller *c;
154 GNUNET_assert (NULL == cls);
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158 "Failing test due to timeout\n");
161 GNUNET_assert (NUM_PEERS == num_peers);
162 c = GNUNET_TESTBED_run_get_controller_handle (h);
163 barrier = GNUNET_TESTBED_barrier_init (c,
169 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
170 (GNUNET_TIME_UNIT_SECONDS,
171 10 * (NUM_PEERS + 1)),
178 * Assumed maximum path length (for the log file name).
180 #define PATH_MAX 4096
188 main (int argc, char **argv)
190 struct GNUNET_CONFIGURATION_Handle *cfg;
195 result = GNUNET_SYSERR;
197 cfg = GNUNET_CONFIGURATION_create ();
198 GNUNET_assert (GNUNET_YES ==
199 GNUNET_CONFIGURATION_parse (cfg,
200 "test_testbed_api_barriers.conf.in"));
201 if (NULL == getcwd (pwd, PATH_MAX))
203 GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd,
204 "gnunet-service-test-barriers"));
205 GNUNET_CONFIGURATION_set_value_string (cfg, "test-barriers","BINARY", binary);
206 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write
207 (cfg, "test_testbed_api_barriers.conf"));
208 GNUNET_CONFIGURATION_destroy (cfg);
210 GNUNET_free (binary);
212 (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers",
213 "test_testbed_api_barriers.conf", NUM_PEERS,
214 event_mask, NULL, NULL,
216 (void) unlink ("test_testbed_api_barriers.conf");
217 if (GNUNET_OK != result)