diff options
Diffstat (limited to 'src/testbed/test_testbed_api_test.c')
-rw-r--r-- | src/testbed/test_testbed_api_test.c | 173 |
1 files changed, 87 insertions, 86 deletions
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c index 372ac1ebe..3f8f536e7 100644 --- a/src/testbed/test_testbed_api_test.c +++ b/src/testbed/test_testbed_api_test.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2008--2013 GNUnet e.V. | 3 | Copyright (C) 2008--2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 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, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file src/testbed/test_testbed_api_test.c | 22 | * @file src/testbed/test_testbed_api_test.c |
@@ -32,8 +32,8 @@ | |||
32 | /** | 32 | /** |
33 | * Generic logging shortcut | 33 | * Generic logging shortcut |
34 | */ | 34 | */ |
35 | #define LOG(kind,...) \ | 35 | #define LOG(kind, ...) \ |
36 | GNUNET_log (kind, __VA_ARGS__) | 36 | GNUNET_log(kind, __VA_ARGS__) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Number of peers we want to start | 39 | * Number of peers we want to start |
@@ -72,29 +72,29 @@ static int result; | |||
72 | * @param cls NULL | 72 | * @param cls NULL |
73 | */ | 73 | */ |
74 | static void | 74 | static void |
75 | do_shutdown (void *cls) | 75 | do_shutdown(void *cls) |
76 | { | 76 | { |
77 | shutdown_task = NULL; | 77 | shutdown_task = NULL; |
78 | if (NULL != abort_task) | 78 | if (NULL != abort_task) |
79 | GNUNET_SCHEDULER_cancel (abort_task); | 79 | GNUNET_SCHEDULER_cancel(abort_task); |
80 | if (NULL != op) | 80 | if (NULL != op) |
81 | GNUNET_TESTBED_operation_done (op); | 81 | GNUNET_TESTBED_operation_done(op); |
82 | GNUNET_SCHEDULER_shutdown (); | 82 | GNUNET_SCHEDULER_shutdown(); |
83 | } | 83 | } |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * shortcut to exit during failure | 86 | * shortcut to exit during failure |
87 | */ | 87 | */ |
88 | #define FAIL_TEST(cond) do { \ | 88 | #define FAIL_TEST(cond) do { \ |
89 | if (!(cond)) { \ | 89 | if (!(cond)) { \ |
90 | GNUNET_break(0); \ | 90 | GNUNET_break(0); \ |
91 | if (NULL != abort_task) \ | 91 | if (NULL != abort_task) \ |
92 | GNUNET_SCHEDULER_cancel (abort_task); \ | 92 | GNUNET_SCHEDULER_cancel (abort_task); \ |
93 | abort_task = NULL; \ | 93 | abort_task = NULL; \ |
94 | if (NULL == shutdown_task) \ | 94 | if (NULL == shutdown_task) \ |
95 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \ | 95 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \ |
96 | return; \ | 96 | return; \ |
97 | } \ | 97 | } \ |
98 | } while (0) | 98 | } while (0) |
99 | 99 | ||
100 | 100 | ||
@@ -104,13 +104,13 @@ do_shutdown (void *cls) | |||
104 | * @param cls NULL | 104 | * @param cls NULL |
105 | */ | 105 | */ |
106 | static void | 106 | static void |
107 | do_abort (void *cls) | 107 | do_abort(void *cls) |
108 | { | 108 | { |
109 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | 109 | LOG(GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); |
110 | abort_task = NULL; | 110 | abort_task = NULL; |
111 | if (NULL != shutdown_task) | 111 | if (NULL != shutdown_task) |
112 | GNUNET_SCHEDULER_cancel (shutdown_task); | 112 | GNUNET_SCHEDULER_cancel(shutdown_task); |
113 | do_shutdown (cls); | 113 | do_shutdown(cls); |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
@@ -124,19 +124,19 @@ do_abort (void *cls) | |||
124 | * operation is successfull | 124 | * operation is successfull |
125 | */ | 125 | */ |
126 | static void | 126 | static void |
127 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | 127 | peerinfo_cb(void *cb_cls, struct GNUNET_TESTBED_Operation *op_, |
128 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 128 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
129 | const char *emsg) | 129 | const char *emsg) |
130 | { | 130 | { |
131 | FAIL_TEST (op == op_); | 131 | FAIL_TEST(op == op_); |
132 | FAIL_TEST (NULL == cb_cls); | 132 | FAIL_TEST(NULL == cb_cls); |
133 | FAIL_TEST (NULL == emsg); | 133 | FAIL_TEST(NULL == emsg); |
134 | FAIL_TEST (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); | 134 | FAIL_TEST(GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); |
135 | FAIL_TEST (NULL != pinfo->result.id); | 135 | FAIL_TEST(NULL != pinfo->result.id); |
136 | GNUNET_TESTBED_operation_done (op); | 136 | GNUNET_TESTBED_operation_done(op); |
137 | op = NULL; | 137 | op = NULL; |
138 | result = GNUNET_OK; | 138 | result = GNUNET_OK; |
139 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 139 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); |
140 | } | 140 | } |
141 | 141 | ||
142 | 142 | ||
@@ -149,19 +149,19 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | |||
149 | * operation has executed successfully. | 149 | * operation has executed successfully. |
150 | */ | 150 | */ |
151 | static void | 151 | static void |
152 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) | 152 | op_comp_cb(void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) |
153 | { | 153 | { |
154 | FAIL_TEST (NULL == cls); | 154 | FAIL_TEST(NULL == cls); |
155 | FAIL_TEST (op == op_); | 155 | FAIL_TEST(op == op_); |
156 | if (NULL != emsg) | 156 | if (NULL != emsg) |
157 | { | 157 | { |
158 | LOG (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); | 158 | LOG(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg); |
159 | FAIL_TEST (0); | 159 | FAIL_TEST(0); |
160 | } | 160 | } |
161 | GNUNET_TESTBED_operation_done (op); | 161 | GNUNET_TESTBED_operation_done(op); |
162 | op = GNUNET_TESTBED_peer_get_information (peers[0], | 162 | op = GNUNET_TESTBED_peer_get_information(peers[0], |
163 | GNUNET_TESTBED_PIT_IDENTITY, | 163 | GNUNET_TESTBED_PIT_IDENTITY, |
164 | &peerinfo_cb, NULL); | 164 | &peerinfo_cb, NULL); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
@@ -172,18 +172,19 @@ op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) | |||
172 | * @param event the controller event | 172 | * @param event the controller event |
173 | */ | 173 | */ |
174 | static void | 174 | static void |
175 | controller_event_cb (void *cls, | 175 | controller_event_cb(void *cls, |
176 | const struct GNUNET_TESTBED_EventInformation *event) | 176 | const struct GNUNET_TESTBED_EventInformation *event) |
177 | { | 177 | { |
178 | switch (event->type) | 178 | switch (event->type) |
179 | { | 179 | { |
180 | case GNUNET_TESTBED_ET_CONNECT: | 180 | case GNUNET_TESTBED_ET_CONNECT: |
181 | FAIL_TEST (event->details.peer_connect.peer1 == peers[0]); | 181 | FAIL_TEST(event->details.peer_connect.peer1 == peers[0]); |
182 | FAIL_TEST (event->details.peer_connect.peer2 == peers[1]); | 182 | FAIL_TEST(event->details.peer_connect.peer2 == peers[1]); |
183 | break; | 183 | break; |
184 | default: | 184 | |
185 | FAIL_TEST (0); | 185 | default: |
186 | } | 186 | FAIL_TEST(0); |
187 | } | ||
187 | } | 188 | } |
188 | 189 | ||
189 | 190 | ||
@@ -200,27 +201,27 @@ controller_event_cb (void *cls, | |||
200 | * failed | 201 | * failed |
201 | */ | 202 | */ |
202 | static void | 203 | static void |
203 | test_master (void *cls, | 204 | test_master(void *cls, |
204 | struct GNUNET_TESTBED_RunHandle *h, | 205 | struct GNUNET_TESTBED_RunHandle *h, |
205 | unsigned int num_peers, | 206 | unsigned int num_peers, |
206 | struct GNUNET_TESTBED_Peer **peers_, | 207 | struct GNUNET_TESTBED_Peer **peers_, |
207 | unsigned int links_succeeded, | 208 | unsigned int links_succeeded, |
208 | unsigned int links_failed) | 209 | unsigned int links_failed) |
209 | { | 210 | { |
210 | unsigned int peer; | 211 | unsigned int peer; |
211 | 212 | ||
212 | FAIL_TEST (NULL == cls); | 213 | FAIL_TEST(NULL == cls); |
213 | FAIL_TEST (NUM_PEERS == num_peers); | 214 | FAIL_TEST(NUM_PEERS == num_peers); |
214 | FAIL_TEST (NULL != peers_); | 215 | FAIL_TEST(NULL != peers_); |
215 | for (peer = 0; peer < num_peers; peer++) | 216 | for (peer = 0; peer < num_peers; peer++) |
216 | FAIL_TEST (NULL != peers_[peer]); | 217 | FAIL_TEST(NULL != peers_[peer]); |
217 | peers = peers_; | 218 | peers = peers_; |
218 | op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], | 219 | op = GNUNET_TESTBED_overlay_connect(NULL, &op_comp_cb, NULL, peers[0], |
219 | peers[1]); | 220 | peers[1]); |
220 | abort_task = | 221 | abort_task = |
221 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 222 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply |
222 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, | 223 | (GNUNET_TIME_UNIT_MINUTES, 3), &do_abort, |
223 | NULL); | 224 | NULL); |
224 | } | 225 | } |
225 | 226 | ||
226 | 227 | ||
@@ -228,7 +229,7 @@ test_master (void *cls, | |||
228 | * Main function | 229 | * Main function |
229 | */ | 230 | */ |
230 | int | 231 | int |
231 | main (int argc, char **argv) | 232 | main(int argc, char **argv) |
232 | { | 233 | { |
233 | uint64_t event_mask; | 234 | uint64_t event_mask; |
234 | 235 | ||
@@ -236,10 +237,10 @@ main (int argc, char **argv) | |||
236 | event_mask = 0; | 237 | event_mask = 0; |
237 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 238 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
238 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 239 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
239 | (void) GNUNET_TESTBED_test_run ("test_testbed_api_test", | 240 | (void)GNUNET_TESTBED_test_run("test_testbed_api_test", |
240 | "test_testbed_api.conf", NUM_PEERS, | 241 | "test_testbed_api.conf", NUM_PEERS, |
241 | event_mask, &controller_event_cb, NULL, | 242 | event_mask, &controller_event_cb, NULL, |
242 | &test_master, NULL); | 243 | &test_master, NULL); |
243 | if (GNUNET_OK != result) | 244 | if (GNUNET_OK != result) |
244 | return 1; | 245 | return 1; |
245 | return 0; | 246 | return 0; |