aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
diff options
context:
space:
mode:
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.c403
1 files changed, 0 insertions, 403 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 7381b1d7e..000000000
--- a/src/transport/test_transport_plugin_cmd_simple_send_broadcast.c
+++ /dev/null
@@ -1,403 +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_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
46static struct GNUNET_TESTING_Command block_send;
47
48static struct GNUNET_TESTING_Command block_receive;
49
50static struct GNUNET_TESTING_Command connect_peers;
51
52static struct GNUNET_TESTING_Command local_prepared;
53
54static 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 */
61static int
62check_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 */
74static void
75handle_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 ((GNUNET_NO == ac->finished) && (NULL == ac->cont))
84 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
85 else if (GNUNET_NO == ac->finished)
86 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
87}
88
89
90struct GNUNET_TESTING_BarrierList *
91get_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 */
102static void
103all_peers_started ()
104{
105 const struct GNUNET_TESTING_AsyncContext *ac;
106
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Received message\n");
109 GNUNET_TESTING_get_trait_async_context (&block_send,
110 &ac);
111 GNUNET_assert (NULL != ac);
112 if (NULL == ac->cont)
113 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
114 else
115 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
116}
117
118
119/**
120 * Function called with the final result of the test.
121 *
122 * @param cls the `struct MainParams`
123 * @param rv #GNUNET_OK if the test passed
124 */
125static void
126handle_result (void *cls,
127 enum GNUNET_GenericReturnValue rv)
128{
129 struct TestState *ts = cls;
130
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Local test exits with status %d\n",
133 rv);
134 ts->finished_cb (rv);
135 GNUNET_free (ts->testdir);
136 GNUNET_free (ts->cfgname);
137 GNUNET_TESTING_free_topology (ts->topology);
138 GNUNET_free (ts);
139}
140
141
142/**
143 * Callback from start peer cmd for signaling a peer got connected.
144 *
145 */
146static void *
147notify_connect (struct GNUNET_TESTING_Interpreter *is,
148 const struct GNUNET_PeerIdentity *peer)
149{
150 const struct GNUNET_TESTING_AsyncContext *ac;
151 void *ret = NULL;
152 const struct GNUNET_TESTING_Command *cmd;
153 struct GNUNET_TESTING_BlockState *bs;
154
155
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
157 "notify_connect\n");
158
159 GNUNET_TESTING_get_trait_async_context (&connect_peers,
160 &ac);
161
162 if (NULL != ac->is)
163 {
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 "notify_connect running\n");
166 GNUNET_assert (NULL != ac);
167 if (NULL == ac->cont)
168 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) ac);
169 else
170 GNUNET_TESTING_async_finish ((struct GNUNET_TESTING_AsyncContext *) ac);
171 }
172 else
173 {
174 cmd = GNUNET_TESTING_interpreter_lookup_future_command (is,
175 "connect-peers");
176
177 LOG (GNUNET_ERROR_TYPE_DEBUG,
178 "block state %s\n",
179 cmd->label);
180 GNUNET_TESTING_get_trait_block_state (
181 cmd,
182 (const struct GNUNET_TESTING_BlockState **) &bs);
183
184 LOG (GNUNET_ERROR_TYPE_DEBUG,
185 "block state %u\n",
186 bs->asynchronous_finish);
187 bs->asynchronous_finish = GNUNET_YES;
188 LOG (GNUNET_ERROR_TYPE_DEBUG,
189 "block state %u\n",
190 bs->asynchronous_finish);
191 }
192
193 return ret;
194}
195
196
197/**
198 * Callback to set the flag indicating all peers are prepared to finish. Will be called via the plugin api.
199 */
200static void
201all_local_tests_prepared ()
202{
203 const struct GNUNET_TESTING_LocalPreparedState *lfs;
204
205 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
206 &lfs);
207 GNUNET_assert (NULL != &lfs->ac);
208 if (NULL == lfs->ac.cont)
209 GNUNET_TESTING_async_fail ((struct GNUNET_TESTING_AsyncContext *) &lfs->ac);
210 else
211 GNUNET_TESTING_async_finish ((struct
212 GNUNET_TESTING_AsyncContext *) &lfs->ac);
213}
214
215
216/**
217 * Function to start a local test case.
218 *
219 * @param write_message Callback to send a message to the master loop.
220 * @param router_ip Global address of the network namespace.
221 * @param node_ip The IP address of the node.
222 * @param m The number of the node in a network namespace.
223 * @param n The number of the network namespace.
224 * @param local_m The number of nodes in a network namespace.
225 */
226static struct GNUNET_TESTING_Interpreter *
227start_testcase (GNUNET_TESTING_cmd_helper_write_cb write_message,
228 const char *router_ip,
229 const char *node_ip,
230 const char *m,
231 const char *n,
232 const char *local_m,
233 const char *topology_data,
234 unsigned int *read_file,
235 GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
236{
237 unsigned int n_int;
238 unsigned int m_int;
239 unsigned int local_m_int;
240 unsigned int num;
241 struct TestState *ts = GNUNET_new (struct TestState);
242 struct GNUNET_TESTING_NetjailTopology *topology;
243 unsigned int sscanf_ret = 0;
244
245 ts->finished_cb = finished_cb;
246 LOG (GNUNET_ERROR_TYPE_ERROR,
247 "n %s m %s\n",
248 n,
249 m);
250
251 if (GNUNET_YES == *read_file)
252 {
253 LOG (GNUNET_ERROR_TYPE_DEBUG,
254 "read from file\n");
255 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
256 }
257 else
258 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
259
260 ts->topology = topology;
261
262 errno = 0;
263 sscanf_ret = sscanf (m, "%u", &m_int);
264 if (errno != 0)
265 {
266 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
267 }
268 GNUNET_assert (0 < sscanf_ret);
269 errno = 0;
270 sscanf_ret = sscanf (n, "%u", &n_int);
271 if (errno != 0)
272 {
273 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
274 }
275 GNUNET_assert (0 < sscanf_ret);
276 errno = 0;
277 sscanf_ret = sscanf (local_m, "%u", &local_m_int);
278 if (errno != 0)
279 {
280 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sscanf");
281 }
282 GNUNET_assert (0 < sscanf_ret);
283
284 if (0 == n_int)
285 num = m_int;
286 else
287 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
288
289 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
290 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
291 "block-receive");
292 connect_peers = GNUNET_TESTING_cmd_block_until_external_trigger (
293 "connect-peers");
294 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
295 "local-test-prepared",
296 write_message);
297
298
299 GNUNET_asprintf (&ts->cfgname,
300 "test_transport_api2_tcp_node1.conf");
301
302 LOG (GNUNET_ERROR_TYPE_DEBUG,
303 "plugin cfgname: %s\n",
304 ts->cfgname);
305
306 LOG (GNUNET_ERROR_TYPE_DEBUG,
307 "node ip: %s\n",
308 node_ip);
309
310 GNUNET_asprintf (&ts->testdir,
311 "%s%s%s",
312 BASE_DIR,
313 m,
314 n);
315
316 struct GNUNET_MQ_MessageHandler handlers[] = {
317 GNUNET_MQ_hd_var_size (test,
318 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
319 struct GNUNET_TRANSPORT_TESTING_TestMessage,
320 ts),
321 GNUNET_MQ_handler_end ()
322 };
323
324 struct GNUNET_TESTING_Command commands[] = {
325 GNUNET_TESTING_cmd_system_create ("system-create",
326 ts->testdir),
327 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
328 "system-create",
329 num,
330 node_ip,
331 handlers,
332 ts->cfgname,
333 notify_connect,
334 GNUNET_YES),
335 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
336 write_message),
337 block_send,
338 connect_peers,
339 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
340 "start-peer",
341 "system-create",
342 num,
343 topology),
344 block_receive,
345 local_prepared,
346 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
347 "start-peer"),
348 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
349 "system-create"),
350 GNUNET_TESTING_cmd_end ()
351 };
352
353 ts->write_message = write_message;
354
355 is = GNUNET_TESTING_run (commands,
356 TIMEOUT,
357 &handle_result,
358 ts);
359 return is;
360}
361
362
363/**
364 * Entry point for the plugin.
365 *
366 * @param cls NULL
367 * @return the exported block API
368 */
369void *
370libgnunet_test_transport_plugin_cmd_simple_send_broadcast_init (void *cls)
371{
372 struct GNUNET_TESTING_PluginFunctions *api;
373
374 GNUNET_log_setup ("simple-send",
375 "DEBUG",
376 NULL);
377
378 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
379 api->start_testcase = &start_testcase;
380 api->all_peers_started = &all_peers_started;
381 api->all_local_tests_prepared = all_local_tests_prepared;
382 api->get_waiting_for_barriers = get_waiting_for_barriers;
383 return api;
384}
385
386
387/**
388 * Exit point from the plugin.
389 *
390 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
391 * @return NULL
392 */
393void *
394libgnunet_test_transport_plugin_cmd_simple_send_broadcast_done (void *cls)
395{
396 struct GNUNET_TESTING_PluginFunctions *api = cls;
397
398 GNUNET_free (api);
399 return NULL;
400}
401
402
403/* end of plugin_cmd_simple_send_broadcast.c */