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 | 395 |
1 files changed, 0 insertions, 395 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 526f08e6a..000000000 --- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c +++ /dev/null | |||
@@ -1,395 +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 | struct GNUNET_TESTING_AsyncContext *ac; | ||
100 | |||
101 | GNUNET_TESTING_get_trait_async_context (&block_receive, | ||
102 | &ac); | ||
103 | GNUNET_assert (NULL != ac); | ||
104 | if (NULL == ac->cont) | ||
105 | GNUNET_TESTING_async_fail (ac); | ||
106 | else | ||
107 | GNUNET_TESTING_async_finish (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 | 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 (ac); | ||
127 | else | ||
128 | GNUNET_TESTING_async_finish (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 | 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 (ac); | ||
190 | else | ||
191 | GNUNET_TESTING_async_finish (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 (cmd,&bs); | ||
202 | |||
203 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
204 | "block state %u\n", | ||
205 | bs->asynchronous_finish); | ||
206 | bs->asynchronous_finish = GNUNET_YES; | ||
207 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
208 | "block state %u\n", | ||
209 | bs->asynchronous_finish); | ||
210 | } | ||
211 | |||
212 | return ret; | ||
213 | } | ||
214 | |||
215 | |||
216 | /** | ||
217 | * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api. | ||
218 | */ | ||
219 | static void | ||
220 | all_local_tests_prepared () | ||
221 | { | ||
222 | struct LocalPreparedState *lfs; | ||
223 | |||
224 | GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared, | ||
225 | &lfs); | ||
226 | GNUNET_assert (NULL != &lfs->ac); | ||
227 | if (NULL == lfs->ac.cont) | ||
228 | GNUNET_TESTING_async_fail (&lfs->ac); | ||
229 | else | ||
230 | GNUNET_TESTING_async_finish (&lfs->ac); | ||
231 | } | ||
232 | |||
233 | |||
234 | /** | ||
235 | * Function to start a local test case. | ||
236 | * | ||
237 | * @param write_message Callback to send a message to the master loop. | ||
238 | * @param router_ip Global address of the network namespace. | ||
239 | * @param node_ip Local address of a node i a network namespace. | ||
240 | * @param m The number of the node in a network namespace. | ||
241 | * @param n The number of the network namespace. | ||
242 | * @param local_m The number of nodes in a network namespace. | ||
243 | */ | ||
244 | static void | ||
245 | start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip, | ||
246 | char *node_ip, | ||
247 | char *m, | ||
248 | char *n, | ||
249 | char *local_m, | ||
250 | char *topology_data, | ||
251 | unsigned int *read_file) | ||
252 | { | ||
253 | unsigned int n_int; | ||
254 | unsigned int m_int; | ||
255 | unsigned int local_m_int; | ||
256 | unsigned int num; | ||
257 | struct TestState *ts = GNUNET_new (struct TestState); | ||
258 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
259 | |||
260 | |||
261 | |||
262 | if (GNUNET_YES == *read_file) | ||
263 | { | ||
264 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
265 | "read from file\n"); | ||
266 | topology = GNUNET_TESTING_get_topo_from_file (topology_data); | ||
267 | } | ||
268 | else | ||
269 | topology = GNUNET_TESTING_get_topo_from_string (topology_data); | ||
270 | |||
271 | ts->topology = topology; | ||
272 | |||
273 | sscanf (m, "%u", &m_int); | ||
274 | sscanf (n, "%u", &n_int); | ||
275 | sscanf (local_m, "%u", &local_m_int); | ||
276 | |||
277 | if (0 == n_int) | ||
278 | num = m_int; | ||
279 | else | ||
280 | num = (n_int - 1) * local_m_int + m_int + topology->nodes_x; | ||
281 | |||
282 | block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block"); | ||
283 | block_receive = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
284 | "block-receive"); | ||
285 | connect_peers = GNUNET_TESTING_cmd_block_until_external_trigger ( | ||
286 | "connect-peers"); | ||
287 | local_prepared = GNUNET_TESTING_cmd_local_test_prepared ( | ||
288 | "local-test-prepared", | ||
289 | write_message); | ||
290 | |||
291 | |||
292 | GNUNET_asprintf (&ts->cfgname, | ||
293 | "test_transport_api2_tcp_node1.conf"); | ||
294 | |||
295 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
296 | "plugin cfgname: %s\n", | ||
297 | ts->cfgname); | ||
298 | |||
299 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
300 | "node ip: %s\n", | ||
301 | node_ip); | ||
302 | |||
303 | GNUNET_asprintf (&ts->testdir, | ||
304 | "%s%s%s", | ||
305 | BASE_DIR, | ||
306 | m, | ||
307 | n); | ||
308 | |||
309 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
310 | GNUNET_MQ_hd_var_size (test, | ||
311 | GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, | ||
312 | struct GNUNET_TRANSPORT_TESTING_TestMessage, | ||
313 | ts), | ||
314 | GNUNET_MQ_handler_end () | ||
315 | }; | ||
316 | |||
317 | struct GNUNET_TESTING_Command commands[] = { | ||
318 | GNUNET_TESTING_cmd_system_create ("system-create", | ||
319 | ts->testdir), | ||
320 | GNUNET_TRANSPORT_cmd_start_peer ("start-peer", | ||
321 | "system-create", | ||
322 | num, | ||
323 | node_ip, | ||
324 | handlers, | ||
325 | ts->cfgname, | ||
326 | notify_connect, | ||
327 | GNUNET_YES), | ||
328 | GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", | ||
329 | write_message), | ||
330 | block_send, | ||
331 | connect_peers, | ||
332 | GNUNET_TRANSPORT_cmd_send_simple ("send-simple", | ||
333 | "start-peer", | ||
334 | "system-create", | ||
335 | num, | ||
336 | topology), | ||
337 | block_receive, | ||
338 | local_prepared, | ||
339 | GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer", | ||
340 | "start-peer"), | ||
341 | GNUNET_TESTING_cmd_system_destroy ("system-destroy", | ||
342 | "system-create"), | ||
343 | GNUNET_TESTING_cmd_end () | ||
344 | }; | ||
345 | |||
346 | ts->write_message = write_message; | ||
347 | |||
348 | GNUNET_TESTING_run (commands, | ||
349 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
350 | &handle_result, | ||
351 | ts); | ||
352 | |||
353 | } | ||
354 | |||
355 | |||
356 | /** | ||
357 | * Entry point for the plugin. | ||
358 | * | ||
359 | * @param cls NULL | ||
360 | * @return the exported block API | ||
361 | */ | ||
362 | void * | ||
363 | libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init (void *cls) | ||
364 | { | ||
365 | struct GNUNET_TESTING_PluginFunctions *api; | ||
366 | |||
367 | GNUNET_log_setup ("simple-send", | ||
368 | "DEBUG", | ||
369 | NULL); | ||
370 | |||
371 | api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); | ||
372 | api->start_testcase = &start_testcase; | ||
373 | api->all_peers_started = &all_peers_started; | ||
374 | api->all_local_tests_prepared = all_local_tests_prepared; | ||
375 | return api; | ||
376 | } | ||
377 | |||
378 | |||
379 | /** | ||
380 | * Exit point from the plugin. | ||
381 | * | ||
382 | * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init | ||
383 | * @return NULL | ||
384 | */ | ||
385 | void * | ||
386 | libgnunet_test_transport_plugin_cmd_simple_send_broadcast_done (void *cls) | ||
387 | { | ||
388 | struct GNUNET_TESTING_PluginFunctions *api = cls; | ||
389 | |||
390 | GNUNET_free (api); | ||
391 | return NULL; | ||
392 | } | ||
393 | |||
394 | |||
395 | /* end of plugin_cmd_simple_send_broadcast.c */ | ||