diff options
Diffstat (limited to 'src/transport/test_transport_plugin_cmd_simple_send_broadcast.c')
-rw-r--r-- | src/transport/test_transport_plugin_cmd_simple_send_broadcast.c | 398 |
1 files changed, 0 insertions, 398 deletions
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c b/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c deleted file mode 100644 index 9d6844be1..000000000 --- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c +++ /dev/null | |||
@@ -1,398 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2021 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/plugin_cmd_simple_send_broadcast.c | ||
23 | * @brief a plugin to provide the API for running test cases. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_testing_ng_lib.h" | ||
28 | #include "gnunet_testing_netjail_lib.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_transport_application_service.h" | ||
31 | #include "transport-testing2.h" | ||
32 | #include "transport-testing-cmds.h" | ||
33 | |||
34 | /** | ||
35 | * Generic logging shortcut | ||
36 | */ | ||
37 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | ||
38 | |||
39 | #define BASE_DIR "testdir" | ||
40 | |||
41 | #define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf" | ||
42 | |||
43 | struct TestState | ||
44 | { | ||
45 | /** | ||
46 | * Callback to write messages to the master loop. | ||
47 | * | ||
48 | */ | ||
49 | TESTING_CMD_HELPER_write_cb write_message; | ||
50 | |||
51 | /** | ||
52 | * The name for a specific test environment directory. | ||
53 | * | ||
54 | */ | ||
55 | char *testdir; | ||
56 | |||
57 | /** | ||
58 | * The name for the configuration file of the specific node. | ||
59 | * | ||
60 | */ | ||
61 | char *cfgname; | ||
62 | |||
63 | /** | ||
64 | * The complete topology information. | ||
65 | */ | ||
66 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
67 | }; | ||
68 | |||
69 | static struct GNUNET_TESTING_Command block_send; | ||
70 | |||
71 | static struct GNUNET_TESTING_Command block_receive; | ||
72 | |||
73 | static struct GNUNET_TESTING_Command connect_peers; | ||
74 | |||
75 | static struct GNUNET_TESTING_Command local_prepared; | ||
76 | |||
77 | /** | ||
78 | * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being | ||
79 | * received. | ||
80 | * | ||
81 | */ | ||
82 | static int | ||
83 | check_test (void *cls, | ||
84 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
85 | { | ||
86 | return GNUNET_OK; | ||
87 | } | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE | ||
92 | * being received. | ||
93 | * | ||
94 | */ | ||
95 | static void | ||
96 | handle_test (void *cls, | ||
97 | const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) | ||
98 | { | ||
99 | const struct GNUNET_TESTING_AsyncContext *ac; | ||
100 | |||
101 | GNUNET_TESTING_get_trait_async_context (&block_receive, | ||
102 | &ac); | ||
103 | GNUNET_assert (NULL != ac); | ||
104 | if ((GNUNET_NO == ac->finished) && (NULL == ac->cont)) | ||
105 | GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
106 | else if (GNUNET_NO == ac->finished) | ||
107 | GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
108 | } | ||
109 | |||
110 | |||
111 | /** | ||
112 | * Callback to set the flag indicating all peers started. Will be called via the plugin api. | ||
113 | * | ||
114 | */ | ||
115 | static void | ||
116 | all_peers_started () | ||
117 | { | ||
118 | const struct GNUNET_TESTING_AsyncContext *ac; | ||
119 | |||
120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
121 | "Received message\n"); | ||
122 | GNUNET_TESTING_get_trait_async_context (&block_send, | ||
123 | &ac); | ||
124 | GNUNET_assert (NULL != ac); | ||
125 | if (NULL == ac->cont) | ||
126 | GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
127 | else | ||
128 | GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
129 | } | ||
130 | |||
131 | |||
132 | /** | ||
133 | * Function called with the final result of the test. | ||
134 | * | ||
135 | * @param cls the `struct MainParams` | ||
136 | * @param rv #GNUNET_OK if the test passed | ||
137 | */ | ||
138 | static void | ||
139 | handle_result (void *cls, | ||
140 | enum GNUNET_GenericReturnValue rv) | ||
141 | { | ||
142 | struct TestState *ts = cls; | ||
143 | struct GNUNET_MessageHeader *reply; | ||
144 | |||
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
146 | "Local test exits with status %d\n", | ||
147 | rv); | ||
148 | reply = GNUNET_TESTING_send_local_test_finished_msg (rv); | ||
149 | |||
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
151 | "message prepared\n"); | ||
152 | ts->write_message (reply, | ||
153 | ntohs (reply->size)); | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
155 | "message send\n"); | ||
156 | GNUNET_free (ts->testdir); | ||
157 | GNUNET_free (ts->cfgname); | ||
158 | GNUNET_TESTING_free_topology (ts->topology); | ||
159 | GNUNET_free (ts); | ||
160 | } | ||
161 | |||
162 | |||
163 | /** | ||
164 | * Callback from start peer cmd for signaling a peer got connected. | ||
165 | * | ||
166 | */ | ||
167 | static void * | ||
168 | notify_connect (struct GNUNET_TESTING_Interpreter *is, | ||
169 | const struct GNUNET_PeerIdentity *peer) | ||
170 | { | ||
171 | const struct GNUNET_TESTING_AsyncContext *ac; | ||
172 | void *ret = NULL; | ||
173 | const struct GNUNET_TESTING_Command *cmd; | ||
174 | struct BlockState *bs; | ||
175 | |||
176 | |||
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
178 | "notify_connect\n"); | ||
179 | |||
180 | GNUNET_TESTING_get_trait_async_context (&connect_peers, | ||
181 | &ac); | ||
182 | |||
183 | if (NULL != ac->is) | ||
184 | { | ||
185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
186 | "notify_connect running\n"); | ||
187 | GNUNET_assert (NULL != ac); | ||
188 | if (NULL == ac->cont) | ||
189 | GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
190 | else | ||
191 | GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac); | ||
192 | } | ||
193 | else | ||
194 | { | ||
195 | cmd = GNUNET_TESTING_interpreter_lookup_future_command (is, | ||
196 | "connect-peers"); | ||
197 | |||
198 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
199 | "block state %s\n", | ||
200 | cmd->label); | ||
201 | GNUNET_TESTING_get_trait_block_state ( | ||
202 | cmd, | ||
203 | (const struct BlockState **) &bs); | ||
204 | |||
205 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
206 | "block state %u\n", | ||
207 | bs->asynchronous_finish); | ||
208 | bs->asynchronous_finish = GNUNET_YES; | ||
209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
210 | "block state %u\n", | ||
211 | bs->asynchronous_finish); | ||
212 | } | ||
213 | |||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | |||
218 | /** | ||
219 | * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api. | ||
220 | */ | ||
221 | static void | ||
222 | all_local_tests_prepared () | ||
223 | { | ||
224 | const struct LocalPreparedState *lfs; | ||
225 | |||
226 | GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, | ||
227 | &lfs); | ||
228 | GNUNET_assert (NULL != &lfs->ac); | ||
229 | if (NULL == lfs->ac.cont) | ||
230 | GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac); | ||
231 | else | ||
232 | GNUNET_TESTING_async_finish ((struct | ||
233 | GNUNET_TESTING_AsyncContext *) &lfs->ac); | ||
234 | } | ||
235 | |||
236 | |||
237 | /** | ||
238 | * Function to start a local test case. | ||
239 | * | ||
240 | * @param write_message Callback to send a message to the master loop. | ||
241 | * @param router_ip Global address of the network namespace. | ||
242 | * @param node_ip Local address of a node i a network namespace. | ||
243 | * @param m The number of the node in a network namespace. | ||
244 | * @param n The number of the network namespace. | ||
245 | * @param local_m The number of nodes in a network namespace. | ||
246 | */ | ||
247 | static void | ||
248 | start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | ||
249 | char *node_ip, | ||
250 | char *m, | ||
251 | char *n, | ||
252 | char *local_m, | ||
253 | char *topology_data, | ||
254 | unsigned int *read_file) | ||
255 | { | ||
256 | unsigned int n_int; | ||
257 | unsigned int m_int; | ||
258 | unsigned int local_m_int; | ||
259 | unsigned int num; | ||
260 | struct TestState *ts = GNUNET_new (struct TestState); | ||
261 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
262 | |||
263 | |||
264 | |||
265 | if (GNUNET_YES == *read_file) | ||
266 | { | ||
267 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
268 | "read from file\n"); | ||
269 | topology = GNUNET_TESTING_get_topo_from_file (topology_data); | ||
270 | } | ||
271 | else | ||
272 | topology = GNUNET_TESTING_get_topo_from_string (topology_data); | ||
273 | |||
274 | ts->topology = topology; | ||
275 | |||
276 | sscanf (m, "%u", &m_int); | ||
277 | sscanf (n, "%u", &n_int); | ||
278 | sscanf (local_m, "%u", &local_m_int); | ||
279 | |||
280 | if (0 == n_int) | ||
281 | num = m_int; | ||
282 | else | ||
283 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | ||
284 | |||
285 | block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); | ||
286 | block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
287 | "block-receive"); | ||
288 | connect_peers = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
289 | "connect-peers"); | ||
290 | local_prepared = GNUNET_TESTING_cmd_local_test_prepared ( | ||
291 | "local-test-prepared", | ||
292 | write_message); | ||
293 | |||
294 | |||
295 | GNUNET_asprintf (&ts->cfgname, | ||
296 | "test_transport_api2_tcp_node1.conf"); | ||
297 | |||
298 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
299 | "plugin cfgname: %s\n", | ||
300 | ts->cfgname); | ||
301 | |||
302 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
303 | "node ip: %s\n", | ||
304 | node_ip); | ||
305 | |||
306 | GNUNET_asprintf (&ts->testdir, | ||
307 | "%s%s%s", | ||
308 | BASE_DIR, | ||
309 | m, | ||
310 | n); | ||
311 | |||
312 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
313 | GNUNET_MQ_hd_var_size (test, | ||
314 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | ||
315 | struct GNUNET_TRANSPORT_TESTING_TestMessage, | ||
316 | ts), | ||
317 | GNUNET_MQ_handler_end () | ||
318 | }; | ||
319 | |||
320 | struct GNUNET_TESTING_Command commands[] = { | ||
321 | GNUNET_TESTING_cmd_system_create ("system-create", | ||
322 | ts->testdir), | ||
323 | GNUNET_TRANSPORT_cmd_start_peer ("start-peer", | ||
324 | "system-create", | ||
325 | num, | ||
326 | node_ip, | ||
327 | handlers, | ||
328 | ts->cfgname, | ||
329 | notify_connect, | ||
330 | GNUNET_YES), | ||
331 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", | ||
332 | write_message), | ||
333 | block_send, | ||
334 | connect_peers, | ||
335 | GNUNET_TRANSPORT_cmd_send_simple ("send-simple", | ||
336 | "start-peer", | ||
337 | "system-create", | ||
338 | num, | ||
339 | topology), | ||
340 | block_receive, | ||
341 | local_prepared, | ||
342 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | ||
343 | "start-peer"), | ||
344 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | ||
345 | "system-create"), | ||
346 | GNUNET_TESTING_cmd_end () | ||
347 | }; | ||
348 | |||
349 | ts->write_message = write_message; | ||
350 | |||
351 | GNUNET_TESTING_run (commands, | ||
352 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
353 | &handle_result, | ||
354 | ts); | ||
355 | |||
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * Entry point for the plugin. | ||
361 | * | ||
362 | * @param cls NULL | ||
363 | * @return the exported block API | ||
364 | */ | ||
365 | void * | ||
366 | libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init (void *cls) | ||
367 | { | ||
368 | struct GNUNET_TESTING_PluginFunctions *api; | ||
369 | |||
370 | GNUNET_log_setup ("simple-send", | ||
371 | "DEBUG", | ||
372 | NULL); | ||
373 | |||
374 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); | ||
375 | api->start_testcase = &start_testcase; | ||
376 | api->all_peers_started = &all_peers_started; | ||
377 | api->all_local_tests_prepared = all_local_tests_prepared; | ||
378 | return api; | ||
379 | } | ||
380 | |||
381 | |||
382 | /** | ||
383 | * Exit point from the plugin. | ||
384 | * | ||
385 | * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init | ||
386 | * @return NULL | ||
387 | */ | ||
388 | void * | ||
389 | libgnunet_test_transport_plugin_cmd_simple_send_broadcast_done (void *cls) | ||
390 | { | ||
391 | struct GNUNET_TESTING_PluginFunctions *api = cls; | ||
392 | |||
393 | GNUNET_free (api); | ||
394 | return NULL; | ||
395 | } | ||
396 | |||
397 | |||
398 | /* end of plugin_cmd_simple_send_broadcast.c */ | ||