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