aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/test_testbed_api_barriers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_testbed_api_barriers.c')
-rw-r--r--src/testbed/test_testbed_api_barriers.c163
1 files changed, 83 insertions, 80 deletions
diff --git a/src/testbed/test_testbed_api_barriers.c b/src/testbed/test_testbed_api_barriers.c
index 9383ab85b..b07dd5339 100644
--- a/src/testbed/test_testbed_api_barriers.c
+++ b/src/testbed/test_testbed_api_barriers.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -33,8 +33,8 @@
33/** 33/**
34 * logging short hand 34 * logging short hand
35 */ 35 */
36#define LOG(type,...) \ 36#define LOG(type, ...) \
37 GNUNET_log (type, __VA_ARGS__); 37 GNUNET_log(type, __VA_ARGS__);
38 38
39/** 39/**
40 * Number of peers we start in this test case 40 * Number of peers we start in this test case
@@ -65,10 +65,10 @@ static void
65shutdown_handler(void *cls) 65shutdown_handler(void *cls)
66{ 66{
67 if (NULL != timeout_task) 67 if (NULL != timeout_task)
68 { 68 {
69 GNUNET_SCHEDULER_cancel(timeout_task); 69 GNUNET_SCHEDULER_cancel(timeout_task);
70 timeout_task = NULL; 70 timeout_task = NULL;
71 } 71 }
72} 72}
73 73
74 74
@@ -78,12 +78,12 @@ shutdown_handler(void *cls)
78 * @param cls NULL 78 * @param cls NULL
79 */ 79 */
80static void 80static void
81do_timeout (void *cls) 81do_timeout(void *cls)
82{ 82{
83 timeout_task = NULL; 83 timeout_task = NULL;
84 if (barrier != NULL) 84 if (barrier != NULL)
85 GNUNET_TESTBED_barrier_cancel (barrier); 85 GNUNET_TESTBED_barrier_cancel(barrier);
86 GNUNET_SCHEDULER_shutdown (); 86 GNUNET_SCHEDULER_shutdown();
87} 87}
88 88
89 89
@@ -101,40 +101,43 @@ do_timeout (void *cls)
101 * error messsage 101 * error messsage
102 */ 102 */
103static void 103static void
104barrier_cb (void *cls, 104barrier_cb(void *cls,
105 const char *name, 105 const char *name,
106 struct GNUNET_TESTBED_Barrier *_barrier, 106 struct GNUNET_TESTBED_Barrier *_barrier,
107 enum GNUNET_TESTBED_BarrierStatus status, 107 enum GNUNET_TESTBED_BarrierStatus status,
108 const char *emsg) 108 const char *emsg)
109{ 109{
110 static enum GNUNET_TESTBED_BarrierStatus old_status; 110 static enum GNUNET_TESTBED_BarrierStatus old_status;
111 111
112 GNUNET_assert (NULL == cls); 112 GNUNET_assert(NULL == cls);
113 GNUNET_assert (_barrier == barrier); 113 GNUNET_assert(_barrier == barrier);
114 switch (status) 114 switch (status)
115 { 115 {
116 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: 116 case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED:
117 LOG (GNUNET_ERROR_TYPE_INFO, 117 LOG(GNUNET_ERROR_TYPE_INFO,
118 "Barrier initialised\n"); 118 "Barrier initialised\n");
119 old_status = status; 119 old_status = status;
120 return; 120 return;
121 case GNUNET_TESTBED_BARRIERSTATUS_ERROR: 121
122 LOG (GNUNET_ERROR_TYPE_ERROR, 122 case GNUNET_TESTBED_BARRIERSTATUS_ERROR:
123 "Barrier initialisation failed: %s", 123 LOG(GNUNET_ERROR_TYPE_ERROR,
124 (NULL == emsg) ? "unknown reason" : emsg); 124 "Barrier initialisation failed: %s",
125 break; 125 (NULL == emsg) ? "unknown reason" : emsg);
126 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: 126 break;
127 LOG (GNUNET_ERROR_TYPE_INFO, 127
128 "Barrier crossed\n"); 128 case GNUNET_TESTBED_BARRIERSTATUS_CROSSED:
129 if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED) 129 LOG(GNUNET_ERROR_TYPE_INFO,
130 result = GNUNET_OK; 130 "Barrier crossed\n");
131 break; 131 if (old_status == GNUNET_TESTBED_BARRIERSTATUS_INITIALISED)
132 default: 132 result = GNUNET_OK;
133 GNUNET_assert (0); 133 break;
134 return; 134
135 } 135 default:
136 GNUNET_assert(0);
137 return;
138 }
136 barrier = NULL; 139 barrier = NULL;
137 GNUNET_SCHEDULER_shutdown (); 140 GNUNET_SCHEDULER_shutdown();
138} 141}
139 142
140 143
@@ -151,34 +154,34 @@ barrier_cb (void *cls,
151 * failed 154 * failed
152 */ 155 */
153static void 156static void
154test_master (void *cls, 157test_master(void *cls,
155 struct GNUNET_TESTBED_RunHandle *h, 158 struct GNUNET_TESTBED_RunHandle *h,
156 unsigned int num_peers, 159 unsigned int num_peers,
157 struct GNUNET_TESTBED_Peer **peers_, 160 struct GNUNET_TESTBED_Peer **peers_,
158 unsigned int links_succeeded, 161 unsigned int links_succeeded,
159 unsigned int links_failed) 162 unsigned int links_failed)
160{ 163{
161 struct GNUNET_TESTBED_Controller *c; 164 struct GNUNET_TESTBED_Controller *c;
162 165
163 GNUNET_assert (NULL == cls); 166 GNUNET_assert(NULL == cls);
164 if (NULL == peers_) 167 if (NULL == peers_)
165 { 168 {
166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 169 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
167 "Failing test due to timeout\n"); 170 "Failing test due to timeout\n");
168 return; 171 return;
169 } 172 }
170 GNUNET_assert (NUM_PEERS == num_peers); 173 GNUNET_assert(NUM_PEERS == num_peers);
171 c = GNUNET_TESTBED_run_get_controller_handle (h); 174 c = GNUNET_TESTBED_run_get_controller_handle(h);
172 barrier = GNUNET_TESTBED_barrier_init (c, 175 barrier = GNUNET_TESTBED_barrier_init(c,
173 TEST_BARRIER_NAME, 176 TEST_BARRIER_NAME,
174 100, 177 100,
175 &barrier_cb, 178 &barrier_cb,
176 NULL); 179 NULL);
177 timeout_task = 180 timeout_task =
178 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 181 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply
179 (GNUNET_TIME_UNIT_SECONDS, 182 (GNUNET_TIME_UNIT_SECONDS,
180 10 * (NUM_PEERS + 1)), 183 10 * (NUM_PEERS + 1)),
181 &do_timeout, NULL); 184 &do_timeout, NULL);
182 GNUNET_SCHEDULER_add_shutdown(&shutdown_handler, NULL); 185 GNUNET_SCHEDULER_add_shutdown(&shutdown_handler, NULL);
183} 186}
184 187
@@ -195,7 +198,7 @@ test_master (void *cls,
195 * Main function 198 * Main function
196 */ 199 */
197int 200int
198main (int argc, char **argv) 201main(int argc, char **argv)
199{ 202{
200 struct GNUNET_CONFIGURATION_Handle *cfg; 203 struct GNUNET_CONFIGURATION_Handle *cfg;
201 char pwd[PATH_MAX]; 204 char pwd[PATH_MAX];
@@ -204,26 +207,26 @@ main (int argc, char **argv)
204 207
205 result = GNUNET_SYSERR; 208 result = GNUNET_SYSERR;
206 event_mask = 0; 209 event_mask = 0;
207 cfg = GNUNET_CONFIGURATION_create (); 210 cfg = GNUNET_CONFIGURATION_create();
208 GNUNET_assert (GNUNET_YES == 211 GNUNET_assert(GNUNET_YES ==
209 GNUNET_CONFIGURATION_parse (cfg, 212 GNUNET_CONFIGURATION_parse(cfg,
210 "test_testbed_api_barriers.conf.in")); 213 "test_testbed_api_barriers.conf.in"));
211 if (NULL == getcwd (pwd, PATH_MAX)) 214 if (NULL == getcwd(pwd, PATH_MAX))
212 return 1; 215 return 1;
213 GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd, 216 GNUNET_assert(0 < GNUNET_asprintf(&binary, "%s/%s", pwd,
214 "gnunet-service-test-barriers")); 217 "gnunet-service-test-barriers"));
215 GNUNET_CONFIGURATION_set_value_string (cfg, "test-barriers","BINARY", binary); 218 GNUNET_CONFIGURATION_set_value_string(cfg, "test-barriers", "BINARY", binary);
216 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write 219 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_write
217 (cfg, "test_testbed_api_barriers.conf")); 220 (cfg, "test_testbed_api_barriers.conf"));
218 GNUNET_CONFIGURATION_destroy (cfg); 221 GNUNET_CONFIGURATION_destroy(cfg);
219 cfg = NULL; 222 cfg = NULL;
220 GNUNET_free (binary); 223 GNUNET_free(binary);
221 binary = NULL; 224 binary = NULL;
222 (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers", 225 (void)GNUNET_TESTBED_test_run("test_testbed_api_barriers",
223 "test_testbed_api_barriers.conf", NUM_PEERS, 226 "test_testbed_api_barriers.conf", NUM_PEERS,
224 event_mask, NULL, NULL, 227 event_mask, NULL, NULL,
225 &test_master, NULL); 228 &test_master, NULL);
226 (void) unlink ("test_testbed_api_barriers.conf"); 229 (void)unlink("test_testbed_api_barriers.conf");
227 if (GNUNET_OK != result) 230 if (GNUNET_OK != result)
228 return 1; 231 return 1;
229 return 0; 232 return 0;